Boost logo

Boost :

Subject: Re: [boost] Assign V2 - first impression
From: Christian Holmquist (c.holmquist_at_[hidden])
Date: 2011-06-23 11:01:34


>
>
>> 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.
>
> It is not at all impossible to have self-explanatory code that doesn't not
do anything more complicated than populating a container.

>
> 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:

You didn't answer the question, why would I need a library that does this
for me? It obfuscates the code for no clear advantage.
You argue that std::container.insert() isn't enough, and that we need a
global
insert(Container& c, ...args)
(although you call it put, which is also unclear to me)

I disagree to put such things into a library, if user needs that it can be
easily expressed in c+0x.

>
>
> "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.
>
I think your library needs to do better than coming up with a slightly
different syntax than V1, otherwise I don't see the point of having it.
To be clear, I'm not happy with V2 and I think V1 is much clearer.

>
> "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.
>
>

You never commented on the keypad example. Is my code correct? If so, don't
you find it a bit easier to read than yours?

- Christian


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