Boost logo

Boost :

From: Jon Willesen (jon_boost_at_[hidden])
Date: 2006-02-17 13:01:38


> Jon Willesen wrote:
>> The only other thing I can think of that concerns me at all is if I'm trying
>> to call a function that has been overloaded to take 1..N arguments using the
>> preprocessor library or some other code generator. Then this code:
>>
>> func(list_of<string>(), "foo", "bar", "baz");
>>
>> might compile successfully and pass four arguments to func when I
>> really meant
>> to pass one argument:
>>
>> func((list_of<string>(), "foo", "bar", "baz"));

Thorsten Ottosen wrote:
> I think was the motivation. I had a user that called
> a constructor:
>
> cons( list_of(3)(5), 4, 5 );
>
> he wanted to pass 3 arguments, but only one was passed.

You got it backwards -- your example *does* pass three arguments. You have to
add parentheses to only pass one:

cons( (list_of(3)(5), 4, 5) );

> Requiring paranthesis in certain contexts seems like a very subtle thing
> to do. I like easy syntax, but I also think surprising and subtle
> behavior can be
> a pain for users.

If you use the list_of comma syntax, surrounding parentheses are *always*
required in every context. In most cases, forgetting the surrounding
parentheses will result in a compile error. It doesn't seem so subtle to me;
the consistency makes the rule easy to learn.

-- 
Jon Willesen

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