Boost logo

Boost Users :

Subject: [Boost-users] [Range] Strange!
From: Robert Jones (robertgbjones_at_[hidden])
Date: 2014-08-28 15:50:45


Can anyone explain why my last output line is garbage?

#include <iostream>
#include <boost/range/algorithm/copy.hpp>
#include <boost/range/counting_range.hpp>
#include <boost/range/adaptor/reversed.hpp>
#include <boost/range/adaptor/transformed.hpp>
#include <boost/phoenix/bind/bind_function.hpp>
#include <boost/phoenix/core/argument.hpp>

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.



Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net