C++ Language/Std/Stl/Algorithms/ApplyingItemByItem/ProcessingItemByItem

From Wikibooks, open books for an open world
Jump to navigation Jump to search

If you have a function like void DoubleEach(int& x) { x *= 2; }, then you can repeatedly apply that same callable-object, once per collection item. The algorithm to do so is std::for_each(v.begin(), v.end(), DoubleEach).

Additional information about item-by-item processing (includes interactive examples)