From: Mikko Rasa Date: Sun, 29 Aug 2021 14:16:04 +0000 (+0300) Subject: Add a shortcut for transforming a container in-place X-Git-Url: http://git.tdb.fi/?a=commitdiff_plain;h=31ab69904294bcbc0f38e4d401fcca620f7c6f61;p=libs%2Fcore.git Add a shortcut for transforming a container in-place --- diff --git a/source/core/algorithm.h b/source/core/algorithm.h index b79114e..268bf7b 100644 --- a/source/core/algorithm.h +++ b/source/core/algorithm.h @@ -171,6 +171,12 @@ inline void stable_sort_member(Container &cont, T Container::value_type::*mp) stable_sort(cont, MemberCompare(mp)); } +template +inline void transform(Container &cont, Predicate pred) +{ + transform(cont.begin(), cont.end(), cont.begin(), pred); +} + } // namespace Msp #endif diff --git a/source/strings/utils.cpp b/source/strings/utils.cpp index 6b659d0..eb2142d 100644 --- a/source/strings/utils.cpp +++ b/source/strings/utils.cpp @@ -1,7 +1,7 @@ -#include #include #include #include +#include #include "utils.h" using namespace std; @@ -63,14 +63,14 @@ int strcasecmp(const string &s1, const string &s2) string tolower(const string &str) { string result(str); - transform(result.begin(), result.end(), result.begin(), [](char c){ return std::tolower(c); }); + transform(result, [](char c){ return std::tolower(c); }); return result; } string toupper(const string &str) { string result(str); - transform(result.begin(), result.end(), result.begin(), [](char c){ return std::toupper(c); }); + transform(result, [](char c){ return std::toupper(c); }); return result; }