Changed for-loop to std::transform.

This commit is contained in:
tastytea 2019-03-30 23:42:06 +01:00
parent d84a18a0e7
commit f5b05893cd
Signed by: tastytea
GPG Key ID: CFC39497F1B26E07
1 changed files with 15 additions and 10 deletions

View File

@ -15,6 +15,7 @@
*/
#include <array>
#include <algorithm>
#include "account.hpp"
#include "debug.hpp"
@ -94,11 +95,13 @@ const std::vector<Account::fields_pair> Account::fields() const
if (node.isArray())
{
std::vector<Account::fields_pair> vec;
for (const Json::Value &value : node)
{
vec.push_back(Account::fields_pair(value["name"].asString(),
value["value"].asString()));
}
std::transform(node.begin(), node.end(), std::back_inserter(vec),
[=](const Json::Value &value)
{
return Account::fields_pair
(value["name"].asString(),
value["value"].asString());
});
return vec;
}
@ -235,11 +238,13 @@ const std::vector<Account::fields_pair> Account::Source::fields() const
if (node.isArray())
{
std::vector<Account::fields_pair> vec;
for (const Json::Value &value : node)
{
vec.push_back(Account::fields_pair(value["name"].asString(),
value["value"].asString()));
}
std::transform(node.begin(), node.end(), std::back_inserter(vec),
[=](const Json::Value &value)
{
return Account::fields_pair
(value["name"].asString(),
value["value"].asString());
});
return vec;
}