Listing 4

void print_out(int i) { std::cout << i << std::endl; }
int do_double( int i) { return i * 2; }
int do_multiply( int i, int j) { return i * j; }
bool is_consecutive( int i, int j) { return i + 1 == j; }

int main() {
    std::vector<int> v;
    v.resize( 10);
    // generate some random numbers, reverse them, and then print them
    rng::generate( v, rand );
    rng::reverse( v);
    rng::for_each( v, print_out );

    // multiply each element from v by 2, and insert it into d
    std::deque<int> d;
    rng::transform( v, std::back_inserter(d), do_double);
    rng::for_each( d, print_out );

    // merge v & d into l
    rng::sort( v);
    rng::sort( d);
    std::list<int> l;
    rng::merge( v, d, std::back_inserter(l) );
    rng::for_each( l, print_out );

    // computing product of v & d
    std::list<int> product;
    rng::transform( v, d, std::back_inserter(product), do_multiply);
    rng::for_each( product, print_out );

    // finds the first two consecutive elements and 
    // prints everything starting from there
    rng::for_each( rng::adjacent_find(l,is_consecutive), print_out);

    // print all elements that are equal to 6.
    rng::for_each( rng::equal_range( l, 6), print_out);
}