An adapter to be able to use the algorithm for_each on a function of T stored in a container as T, instead of using loops. Prefer algorithm calls over hand-written loops [1,2].
#include <algorithm> #include <cctype> #include <string> //From http://www.richelbilderbeek.nl/CppStrToUpper.htm const std::string StrToUpper (std::string s) { std::transform(s.begin(), s.end(), s.begin(),std::ptr_fun(std::toupper)); return s; }
- Bjarne Stroustrup. The C++ Programming Language (3rd edition). ISBN: 0-201-88954-4. Chapter 18.12.1: 'Prefer algorithms to loops'
- Scott Meyers. Effective STL. ISBN:0-201-74962-9. Item 43: 'Prefer algorithm calls over hand-written loops'