3 ms·
Those examples aren't really the same though. Transform is a free function which operates on anything that satisfies 'ForwardIterator', map would be a member fu
by hhmc 8y ago
Those examples aren't really the same though. Transform is a free function which operates on anything that satisfies 'ForwardIterator', map would be a member function of the vector class.
Theoretically you could add helper functions to all suitable containers which calls through to transform (I think this is what you're suggesting). But it would feel very heavyweight and add a lot of cruft to the std library.
You could also add your own utlity free function similar to
template<class T, class F>
void mymap(T &t, const F &f){
std::transform(t.begin(), t.end(), t.begin(), f);
}