From d85190b113f418093b18c9c306d2d5e068612f52 Mon Sep 17 00:00:00 2001 From: tastytea Date: Mon, 11 Mar 2019 21:13:34 +0100 Subject: [PATCH] Use std::transform instead of for loop in json_array_to_vector. --- src/easy/easy.cpp | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/src/easy/easy.cpp b/src/easy/easy.cpp index 1f725fd..774beae 100644 --- a/src/easy/easy.cpp +++ b/src/easy/easy.cpp @@ -18,6 +18,7 @@ #include // get_time #include #include +#include #include "easy.hpp" #include "debug.hpp" @@ -81,11 +82,11 @@ const std::vector Easy::json_array_to_vector(const string &json) if (json_array.isArray()) { - std::vector vec; - for (const Json::Value &value : json_array) - { - vec.push_back(value.toStyledString()); - } + // Transform array of Json::Value to vector of string. + std::vector vec(json_array.size()); + std::transform(json_array.begin(), json_array.end(), vec.begin(), + [](const Json::Value &j) + { return j.toStyledString(); }); return vec; }