Boost logo

Boost :

From: Peter Dimov (pdimov_at_[hidden])
Date: 2001-12-18 07:53:45


From: "Aleksey Gurtovoy" <alexy_at_[hidden]>
> Agree, current 'mpl::copy' is strange. The intention was to allow 'copy'
to
> add elements to an output sequence, as well as to create a "fresh copy" of
> them, and as I was sloppy at the time I wrote the function, instead of
> defining compile-time Output Iterator concept and implementing inserters,
I
> decided to just go with the current interface:
>
> // (1) adds numbers [0..10] to a value_list<20,25,30,35>
> typedef mpl::value_list<20,25,30,35> numbers;
> typedef mpl::copy<
> mpl::value_range<0,10>
> , numbers // should support 'push_back'
> >::type result;
>
> BOOST_MPL_ASSERT_IS_SAME(
> result
> , mpl::value_list<0, 1, 2, 3,.., 9, 10, 20, 25, 30, 35>
> );
>
> // should be something like
> //
> // typedef mpl::value_list<20,25,30,35> numbers;
> // typedef mpl::copy<
> // mpl::value_range<0,10>
> // , mpl::back_inserter<numbers>
> // >::type result;
> //
> // or (much more effective ;)
> //
> // typedef mpl::copy_backward<
> // mpl::value_range<0,10>
> // , mpl::front_inserter<numbers>
> // >::type result;

But why do you need an OutputIterator, or a Container in a pure functional
world? There is no place (or need) for these concepts as they imply
mutability. You can do everything you need without them.

std::copy is simply mpl::identity.

std::append, if there was one, would have looked like this:

template<class I, class J, class O> O append(I first, I last, J first2, J
last2, O out)
{
    return copy(first2, last2, copy(first, last, out));
}

--
Peter Dimov
Multi Media Ltd.

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