boost::range::generate
References
Headers
boost::range::generate
is available by including
any of the following headers:
boost/range/algorithm/generate.hpp
orboost/range/algorithm.hpp
Examples
generate.cpp
#include <iostream>
#include <vector>
#include <boost/range/algorithm.hpp>
int generator() {
static int i = 0;
return 2 * i++;
}
int main() {
std::vector<int> vec(10, 0);
// Set each element of vec to the result of generator().
boost::range::generate(vec, generator);
boost::range::copy(vec, std::ostream_iterator<int>(std::cout, " "));
std::cout << std::endl;
return 0;
}
Output:
0 2 4 6 8 10 12 14 16 18
Boost Range for Humans
This reference is part of Boost Range for Humans. Click the link to the overview.