Changed for-loop to std::transform.

This commit is contained in:
tastytea 2019-03-30 23:57:25 +01:00
parent 3328821bca
commit 07c39ab4bf
Signed by: tastytea
GPG Key ID: CFC39497F1B26E07
1 changed files with 10 additions and 12 deletions

View File

@ -14,6 +14,7 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
#include <algorithm>
#include <jsoncpp/json/json.h> #include <jsoncpp/json/json.h>
#include "results.hpp" #include "results.hpp"
@ -38,10 +39,9 @@ const std::vector<Easy::Account> Results::accounts() const
if (node.isArray()) if (node.isArray())
{ {
std::vector<Easy::Account> vec; std::vector<Easy::Account> vec;
for (const Json::Value &value : node) std::transform(node.begin(), node.end(), std::back_inserter(vec),
{ [](const Json::Value &value)
vec.push_back(Easy::Account(value.toStyledString())); { return Easy::Account(value); });
}
return vec; return vec;
} }
@ -54,10 +54,9 @@ const std::vector<Easy::Status> Results::statuses() const
if (node.isArray()) if (node.isArray())
{ {
std::vector<Easy::Status> vec; std::vector<Easy::Status> vec;
for (const Json::Value &value : node) std::transform(node.begin(), node.end(), std::back_inserter(vec),
{ [](const Json::Value &value)
vec.push_back(Easy::Status(value.toStyledString())); { return Easy::Status(value); });
}
return vec; return vec;
} }
@ -75,10 +74,9 @@ const std::vector<Easy::Tag> Results::hashtags_v2() const
if (node.isArray()) if (node.isArray())
{ {
std::vector<Easy::Tag> vec; std::vector<Easy::Tag> vec;
for (const Json::Value &value : node) std::transform(node.begin(), node.end(), std::back_inserter(vec),
{ [](const Json::Value &value)
vec.push_back(Easy::Tag(value.toStyledString())); { return Easy::Tag(value); });
}
return vec; return vec;
} }