Boost logo

Boost :

From: David Abrahams (dave_at_[hidden])
Date: 2004-07-07 10:56:02


"Andrei Alexandrescu \(See Website for Email\)" <andrewalex_at_[hidden]> writes:

> "Vladimir Prus" <ghost_at_[hidden]> wrote in message
> news:ccg4pu$pns$1_at_sea.gmane.org...
>> I think in this context it's more or less harmless. One can do:
>>
>> vector<int> v;
>> v += 1, 2, 3;
>>
>> but the += operator is only defined for specific containers, and it's not
>> defined for vector by default. So there's little risk that user will
>> inadvertently use it, meaning something else.
>
> I was worried more (only) about the order of evaluation. If I understand
> correctly, if I call:
>
> v += foo(), bar();
>
> the code will be same as:
>
> operator,(operator+=(v, foo()), bar());
>
> so the order of executing foo() and bar() is unspecified. This might
> surprise the user.

Well, it might.

But then, the user knows he's using the initialization library, and
operator, has a different meaning in that context, just like
operator<< means something else in the context of a Spirit gramar.

-- 
Dave Abrahams
Boost Consulting
http://www.boost-consulting.com

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