Boost logo

Boost :

Subject: Re: [boost] Assign V2 - first impression
From: er (er.ci.2020_at_[hidden])
Date: 2011-06-24 14:20:07


> The style the library is using is still.. interesting.

Features that already existed in V1 were made modular, and open for
extension, through the use of options. As I argued with Stewart, it's
possible to transition towards free functions, so that the use of
operator% is only reserved for the less common options, since it seems
to be causing some confusion.

Also, at the risk of stating the obvious, support for C++0x is an
improvement. For example, in

push_front<1>( cont )( args1... )...( argsn... );

argi... is variadic. This was done without letting C++03 down : both are
supported, such that the syntax is the same. In C++03, it is possible to
pass combinations of non-const and const arguments up to macro constant.
The total number of arguments is controlled by a macro constant. This
degree of control was not present in V1.

>I'm still not sure why the '_repeat = n' comes in, and things seem
attached strangely. I might perfer something that looked more like boost
range's
>
> make_range(1,10,100,1000) | f | push_front(cont)

Let's forget about _repeat = n, for now, and continue with your example.
This

copy(
        cvs_deque<int, 1>( 1, 10, 100, 1000 ) | adaptor::transform( f )
        std::front_inserter( cont )
);

and this

( put_front<1>( cont ) % ( _data = f ) )( 1, 10, 100, 1000 );

are quite close, I think. The first is more heavy at runtime since it
has to allocate a vector, while the second is perhaps more heavy at
compile time.

Now if you want to repeat the operation of inserting the element f( x ),
I'm not sure how you do that with Range, but with V2, after learning the
syntax, it's relatively straightforward:

( put_front<1>( cont ) % ( _data = f ) % ( _repeat = n ) )( 1, 10, 100,
1000 );

This is not the only option, of course. For example, say you want to
fill only the second half of cont with f( 1 ),..., f( 1000 ):

int index = cont.size() / 2;

( put_front<1>( cont )
     % ( _data = f )
     % ( _iterate = lambda::var( index )++ )
)( 1, 10, 100, 1000 );

is same as

cont[ index++ ] = f( 1 );
cont[ index++ ] = f( 10 );
cont[ index++ ] = f( 100 );
cont[ index++ ] = f( 1000 );

Assign is a container tool. Here, iterating is only possible because if
cont is a RandomAccessContainer.


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