Boost logo

Boost :

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


On 6/24/11 4:33 PM, Simonson, Lucanus J wrote:
> er wrote:
>>> 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 was suggested, which is probably the best:
>>
>> push_front<1>( cont , _data = f, _repeat = n )( 1, 10, 100, 1000 );
>>
>> More generally,
>>
>> // Fixed arity:
>> push_front<I>( cont , options... )( a1,...,aI,...,z1,...,zI );
>>
>> // Variadic
>> push_front( cont , options... )( args1 )...( argsn );
>>
>> where in each case (fixed and variadic), options... modify the
>> semantics
>> of the subsequent calls to operator().
>
> Can we change the name of _data to something like _filter? Also, I don't like the pre and post _ names in the interface. If you want to use a convention related to pre and post _ in the implementation details that's fine, but I don't think it is appropriate in the interface. If you use boost.parameter I think you would get a post _ charater, I believe, so having both pre and post _ for different reasons seems confusing.

Indeed, I should follow the Boost.Parameter convention and use postfix _
for a const objects. _filter (or rather filter_) is fine.

>
> Also, it would be nice to have iterator pair and range be acceptable alternatives to the fixed arity and variadic options shown above. I realize that would require some SFINAE, but I think being able to consistently initialize containers and then mix the forms would be a big plus.

Take

push_back( cont )( range1 )( range2 )( range3 );

I guess your SFINAE approach would check whether range1 models
ConceptRange and if so, push back each of its elements at the back of
cont. Unfortunately, the actual intent might be to treat range1 as an
element of cont. So I actually prefer the current approach:

push_back( cont ).for_each( range1 ).for_each( range2 ).for_each( range3 );

This puts in cont a total of size( range1 ) + size( range2 ) + size(
range3 ) elements. Whereas this

push_back( cont )( range1 )( range2 )( range3 );

puts 3 elements in cont : range1, range2, and range3.

What do you think?

>
> char* cstr[] = "Hello world!";
> std::vector<char> chrs;
> push_back( chrs , filter = to_upper )( cstr, cstr+5 )( '\0' );

push_back(
     chrs, filter_ = to_upper
).for_each( make_iterator_range( cstr, cstr + 5) )( '\0' );

>
> chrs contains a null terminated string "HELLO".
>
> There is then a whole area of treating std::string like a container by specializing some of your library interfaces that would really be handy.

Sure, I welcome more examples/problem specifications such as that above.
Please do send them. Thanks.

>
> Regards,
> Luke
>
> _______________________________________________
> Unsubscribe& other changes: http://lists.boost.org/mailman/listinfo.cgi/boost
>


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