From: Rob Stewart (stewart_at_[hidden])
Date: 2002-08-22 14:00:32
List-Id: Boost mailing list <boost.lists.boost.org>
X-List-Received-Date: Thu, 22 Aug 2002 19:00:03 -0000
From: =?Windows-1252?Q?Terje_Sletteb=F8?= <tslettebo_at_[hidden]>
> >From: "Rob Stewart" <stewart_at_[hidden]>
> > From: "Victor A. Wagner, Jr." <vawjr_at_[hidden]>
> > >
> > > At Thursday 2002/08/22 03:44, you wrote:
> > These attributions are not very helpful. Who's "you?"
> Me. :)
Unfortunately, his attribution line doesn't make that clear.
> > The swap is still valuable because it swaps the contents between widget
> and the
> > temporary returned by ost.str(). The alternative, assigning the temporary
> > widget, means that a copy of the temporary's contents is written to widget
> > then the temporary is destroyed.
> But in what way would this be useful for lexical_cast?
That may well be a separate question from the one I was answering!
> if you have std::string as target, you have something like:
> std::stringstream interpreter;
> return std::string(interpreter.c_str());
> How will a swap help you here?
My guess is that you meant:
In that case, swap() is not useful, since this line makes explicit the copy
construction that must -- in theory -- occur anyway. (Actually, I'm left to
wonder whether this tells the compiler to invoke the copy constructor, thus
preventing the RVO.) There is no place for a swap to occur as there is no named
return value to swap with and str() already creates a copy of the
stringstream's internal buffer.
-- 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