Boost logo

Boost :

From: David Abrahams (dave_at_[hidden])
Date: 2008-04-29 12:00:41


on Tue Apr 29 2008, "Slavomir Kaslev" <slavomir.kaslev-AT-gmail.com> wrote:

> Can someone explain why this simple snippet fails to compile? Am I
> doing something wrong or is this iterator_range problem?
>
> I've tested it on msvc 2005 and g++ 4.2.3 against boost trunk.
>
> #include <boost/static_assert.hpp>
> #include <boost/mpl/int.hpp>
> #include <boost/mpl/equal.hpp>
> #include <boost/mpl/vector_c.hpp>
> #include <boost/mpl/transform.hpp>
> #include <boost/mpl/iterator_range.hpp>
>
> int main()
> {
> using namespace boost::mpl;
> using namespace boost::mpl::placeholders;
>
> typedef vector_c<int, 1, 2, 3, 4> test_t;
> typedef begin<test_t>::type first;
> typedef advance<first, int_<2> >::type last;
> typedef iterator_range<first, last>::type range;
>
> BOOST_STATIC_ASSERT(( equal<range, vector_c<int, 1, 2> >::value ));
>
> typedef transform<range, identity<_> >::type transformed_range;
> }
>
> Thank you in advance.

Sequence-building algorithms like transform will try to produce the same
kind of sequence on output as they do on input, but in general we can't
do that when the type is iterator_range. You need to pass an inserter
that will help build the kind of sequence you want.

Regards,

-- 
Dave Abrahams
Boost Consulting
http://boost-consulting.com

Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk