16.3.4. replace, replace_if, replace_copy and replace_copy_if

Figure 16.4 demonstrates replacing values from a sequence using algorithms replace, replace_if, replace_copy and replace_copy_if.

 1   // Fig. 16.4: fig16_04.cpp 2   // Algorithms replace, replace_if, replace_copy and replace_copy_if. 3   #include <iostream> 4   #include <algorithm> 5   #include <array> 6   #include <iterator> // ostream_iterator 7   using namespace std; 8  9   bool greater9( int ); // predicate function prototype10 11   int main()12   {13      const size_t SIZE = 10;14      array< int, SIZE > init =  = { 10, 2, 10, 4, 16, 6, 14, 8, 12, 10 };15      ostream_iterator< int > output( cout, " " );16 17      array< int, SIZE >  a1( init ); ...

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.