Boost logo

Boost :

From: Rob Stewart (stewart_at_[hidden])
Date: 2004-07-07 16:03:19


From: brangdon_at_[hidden] (Dave Harris)
> In-Reply-To: <cch4as$941$1_at_[hidden]>
> andrewalex_at_[hidden] (Andrei Alexandrescu \(See Website for Email\))
> wrote (abridged):
> > I was worried more (only) about the order of evaluation.
> >
> > v += foo(), bar();

Unless I'm mistaken, there is but one sequence point in such an
expression, regardless of whether you overload operator,. Thus,
any expression using commas must be understood to have
indeterminant order of evaluation.

Consider:

   int v[] = { foo(), bar() };

Doesn't this exhibit the same problem? If so, the problem is
only that an initialization library exposes the problem to more
daylight.

> I don't think order of evaluation is sacred. However, I am also not keen
> on using comma for this. I'd rather use operator<<().
>
> v << foo() << bar();
>
> This is partly because comma is so small its easy to overlook, partly
> because it is used for so many other common things, and partly because I
> think the semantics of operator<<() fit better here. "Append these items
> to that stream or container, with conversion or formatting if
> appropriate."

I don't like that. It suggests formatted insertion rather than
initialization. As you point out, conversion is possible, but
one can't overload operator<< to customize the initialization.
Thus, it doesn't fit neatly with IOStreams.

-- 
Rob Stewart                           stewart_at_[hidden]
Software Engineer                     http://www.sig.com
Susquehanna International Group, LLP  using std::disclaimer;

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