C++: Lambda und map
-
Wie kann ich in C++ sowas wie
map
aus Haskell realisieren?std::vector<T> v; map(v.begin(), v.end(), [](T& t){t = foo(t);});
-
Mit std::transform.
-
Eventuell ca. so?
template<typename C, typename F> void map(C& c, F f) // evtl. kann man da was mit universal ref und std::forward machen, aber da musst die Experten fragen { std::transform(begin(c), end(c), begin(c), f); } std::vector<T> v; map(v, foo);
-
Danke!