|
Boost : |
From: Dave Harris (brangdon_at_[hidden])
Date: 2004-07-07 18:00:05
In-Reply-To: <200407072103.i67L3Jk28273_at_[hidden]>
stewart_at_[hidden] (Rob Stewart) wrote (abridged):
> > v << foo() << bar();
>
> I don't like that. It suggests formatted insertion rather than
> initialization.
It's not intended to be initialisation. It does a push_back(), so you can
do it at any time and not just on empty vectors. I guess I'd pick a
different name for the library, but as written that includes += so it too
is not just for initialisation.
As I said, I don't think formatting is an essential characteristic of
operator<<(). It happens to be necessary for streams because they are text
oriented. The serialisation library uses operator<<() without formatting.
> As you point out, conversion is possible, but one can't overload
> operator<< to customize the initialization.
Why not?
vector<Foo> &operator<<( vector<Foo> &v, const Bar &bar ) {
return v << bar.toFoo(); // Or whatever conversion you want.
}
Or whatever the right types are.
> Thus, it doesn't fit neatly with IOStreams.
It's not polymorphic with them, but I think it fits about as neatly as the
serialisation library.
-- Dave Harris, Nottingham, UK
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk