Reputation: 8863
In a functional language, if you have S
, a set whose elements have type T
, and f
, a function : T -> U
, you can write map f S
(or some language-specific version of that) to create a set of U
s.
Is it possible to achieve something similar in C++11 using for_each
or some other STL constructs?
Upvotes: 1
Views: 59
Reputation: 52611
std::set<U> SetOfUs;
std::transform(S.begin(), S.end(), std::inserter(SetOfUs, SetOfUs.begin()), f);
Upvotes: 3