Modernize; Move some apis to range based for loop
There were a couple places in code where we still use index based for
loops. Move these to the more modern range based for loops.
Tested: Needs testing. Changes made by clang-tidy.
Signed-off-by: Ed Tanous <ed.tanous@intel.com>
Change-Id: I30bf6fae6b2540434d5c98900a8f6bd0c8f2be93
diff --git a/include/openbmc_dbus_rest.hpp b/include/openbmc_dbus_rest.hpp
index f049c00..d66c5f1 100644
--- a/include/openbmc_dbus_rest.hpp
+++ b/include/openbmc_dbus_rest.hpp
@@ -744,10 +744,9 @@
return r;
}
- for (nlohmann::json::const_iterator it = j->begin(); it != j->end();
- ++it)
+ for (const auto& it : *j)
{
- r = convertJsonToDbus(m, containedType, *it);
+ r = convertJsonToDbus(m, containedType, it);
if (r < 0)
{
return r;
diff --git a/include/sessions.hpp b/include/sessions.hpp
index f0de8c9..e745845 100644
--- a/include/sessions.hpp
+++ b/include/sessions.hpp
@@ -233,9 +233,9 @@
OpenSSLGenerator gen;
- for (size_t i = 0; i < sessionToken.size(); ++i)
+ for (char& sessionChar : sessionToken)
{
- sessionToken[i] = alphanum[dist(gen)];
+ sessionChar = alphanum[dist(gen)];
if (gen.error())
{
return nullptr;
@@ -244,9 +244,9 @@
// Only need csrf tokens for cookie based auth, token doesn't matter
std::string csrfToken;
csrfToken.resize(sessionTokenSize, '0');
- for (size_t i = 0; i < csrfToken.size(); ++i)
+ for (char& csrfChar : csrfToken)
{
- csrfToken[i] = alphanum[dist(gen)];
+ csrfChar = alphanum[dist(gen)];
if (gen.error())
{
return nullptr;
@@ -255,9 +255,9 @@
std::string uniqueId;
uniqueId.resize(10, '0');
- for (size_t i = 0; i < uniqueId.size(); ++i)
+ for (char& uidChar : uniqueId)
{
- uniqueId[i] = alphanum[dist(gen)];
+ uidChar = alphanum[dist(gen)];
if (gen.error())
{
return nullptr;