January 2018
Intermediate to advanced
374 pages
9h 53m
English
As an addition to the STL algorithms, std::transform_reduce has also been added. It does exactly what it says; it transforms a range of elements as std::transform and then applies a functor. This accumulates them out of order, like std::reduce:
auto mice = std::vector<std::string>{"Mickey","Minnie","Jerry"};
auto num_chars = std::transform_reduce(
mice.begin(),
mice.end(),
size_t{0},
[](const std::string& m) { return m.size(); }, // Transform
[](size_t a, size_t b) { return a + b; } // Reduce
);
// num_chars is 17