16.3.1. fill, fill_n, generate and generate_n

Figure 16.1 demonstrates algorithms fill, fill_n, generate and generate_n. Algorithms fill and fill_n set every element in a range of container elements to a specific value. Algorithms generate and generate_n use a generator function to create values for every element in a range of container elements. The generator function takes no arguments and returns a value that can be placed in an element of the container.

 1   // Fig. 16.1: fig16_01.cpp 2   // Algorithms fill, fill_n, generate and generate_n. 3   #include <iostream> 4   #include <algorithm> // algorithm definitions  5   #include <array> // array class-template definition 6   #include <iterator> // ostream_iterator ...

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.