Can anyone explain why my last output line is garbage?
#include <iostream>
#include
#include
#include
#include
#include
#include
int doubled( int i ) { return i * 2; }
template <typename Range> void print_it( const Range & range )
{
boost::copy( range, std::ostream_iterator<int>( std::cout, " " ) );
std::cout << std::endl;
}
int main( )
{
using boost::adaptors::reversed;
using boost::adaptors::transformed;
using boost::counting_range;
using boost::phoenix::arg_names::_1;
print_it( counting_range( 1, 5 ) );
print_it( counting_range( 1, 5 ) | reversed );
print_it( counting_range( 1, 5 ) | transformed( doubled ) );
print_it( counting_range( 1, 5 ) | reversed | transformed( doubled ) );
print_it( counting_range( 1, 5 ) | transformed( bind(
doubled, _1 ) ) );
print_it( counting_range( 1, 5 ) | reversed | transformed( bind(
doubled, _1 ) ) );
}
Output is
1 2 3 4
4 3 2 1
2 4 6 8
8 6 4 2
2 4 6 8
-711713824 -711713824 -711713824 -711713824
Compiling with gcc-4.9.1, Boost 1.56 on Fedora 20 64-bit.
Thx, Rob.