generate()
generate() fills a sequence by applying the specified generator.
#include <algorithm>
class GenByTwo {
public:
void operator()(){
static int seed = -1; return seed += 2; }
};
list<int> ilist( 10 );
// fills ilist: 1 3 5 7 9 11 13 15 17 19
generate( ilist.begin(), ilist.end(), GenByTwo() );
|