Use std::transform instead of for loop in json_array_to_vector.

This commit is contained in:
tastytea 2019-03-11 21:13:34 +01:00
parent e07dc45184
commit d85190b113
Signed by: tastytea
GPG Key ID: CFC39497F1B26E07
1 changed files with 6 additions and 5 deletions

View File

@ -18,6 +18,7 @@
#include <iomanip> // get_time
#include <sstream>
#include <regex>
#include <algorithm>
#include "easy.hpp"
#include "debug.hpp"
@ -81,11 +82,11 @@ const std::vector<string> Easy::json_array_to_vector(const string &json)
if (json_array.isArray())
{
std::vector<string> vec;
for (const Json::Value &value : json_array)
{
vec.push_back(value.toStyledString());
}
// Transform array of Json::Value to vector of string.
std::vector<string> vec(json_array.size());
std::transform(json_array.begin(), json_array.end(), vec.begin(),
[](const Json::Value &j)
{ return j.toStyledString(); });
return vec;
}