Skip to content

Latest commit

 

History

History
75 lines (44 loc) · 1.62 KB

File metadata and controls

75 lines (44 loc) · 1.62 KB

 

 

 

 

 

 

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].

 

 

 

 

 

Example

 


#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; }

 

 

 

 

 

 

  1. Bjarne Stroustrup. The C++ Programming Language (3rd edition). ISBN: 0-201-88954-4. Chapter 18.12.1: 'Prefer algorithms to loops'
  2. Scott Meyers. Effective STL. ISBN:0-201-74962-9. Item 43: 'Prefer algorithm calls over hand-written loops'