Boost logo

Boost :

From: Darren Cook (darren_at_[hidden])
Date: 2004-07-07 18:18:41


>>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.
>
> I see. So I'd like to make a quick poll for Boosters: Overloading the comma
> operator in a way that could change order of evaluation of its arguments is:
>
> a) an obsolete coding standard
> b) a valid coding standard
> c) a valid coding standard, but for reasons x, y, and z, the initialization
> library doesn't violate it/violates it but gets away with it/etc.

I'm not sure which of a/b/c I am, but if I saw the below code I would be
surprised if foo() was not evaluated before bar(). If it was a function:
   f( foo(), bar() );
would foo() always be executed before bar()?

If I was reviewing that code I'd demand either a comment on that line
pointing out that either could be called first, or request that foo() and
bar() are evaluated and assigned to variables first.

Darren

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


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