Boost logo

Boost :

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


> I continued with the tutorial, but it didn't help me much in the
> understanding how V2 would make my life easier.
>
> V2's first example:
>
>>
>> typedef std::string word_;
>> const char x[] = "foo";
>> const char y[4] = { 'b', 'a', 'r', '\0' };
>> word_ z = "***baz";
>> std::map<int, word_> map;
>> put( map )( 1, x, 3 )( 2, y )( 3, z, 3, 3 )( 4, "qux" );
>
>
> If I was given the above code and had to figure out the contents of map, I
> would fail to do so.

It's impossible to have a syntax that is 100% self-explanatory. The
tutorial states:

For a map, as above, the first argument is treated as a key, and the
rest is forwarded to the mapped-type's constructor, word_( x, 3 ), in
the first call. Key and data are then combined into a pair, which is
inserted using modifier insert.

> What's the benefit of the library to construct the container's value_type,
> instead of explicitly by the user?

Yet this is what you do (construct the container's value_type) in your
previous example:

"To my taste, I prefer V1
insert( m )( "Bar", 1 )( "Foo", 2 );"

While you only state a preference over V2, it's hard to see that you are
unhappy with it.

"Bar" and 1 are combined into a pair, which is the value_type of the
map containers. My example just uses varying number of arguments to
create the mapped value.


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