16.3.5. Mathematical Algorithms

Figure 16.5 demonstrates several common mathematical algorithms, including random_shuffle, count, count_if, min_element, max_element, minmax_element, accumulate, for_each and transform.

 1   // Fig. 16.5: fig16_05.cpp 2   // Mathematical algorithms of the Standard Library. 3   #include <iostream> 4   #include <algorithm> // algorithm definitions 5   #include <numeric> // accumulate is defined here  6   #include <array> 7   #include <iterator> 8   using namespace std; 9 10   bool greater9( int ); // predicate function prototype11   void outputSquare( int ); // output square of a value12   int calculateCube( int ); // calculate cube of a value13 14   int main()15   {16      const size_t ...

Get C++11 for Programmers, Second Edition now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.