Boost logo

Boost :

From: Rob Stewart (stewart_at_[hidden])
Date: 2002-08-22 14:00:32


        <4.3.1.2.20020821171105.01be4018_at_[hidden]><4.3.1.2.20020822092629.03a06480_at_[hidden]>
        <200208221704.g7MH4ID00242_at_[hidden]>
        <0a2701c24a04$21be27f0$60fb5dd5_at_pc>
X-BeenThere: boost_at_[hidden]
X-Mailman-Version: 2.1b1
Precedence: bulk
Reply-To: boost_at_[hidden]
List-Help: <mailto:boost-request_at_[hidden]?subject=help>
List-Post: <mailto:boost_at_[hidden]>
List-Subscribe: <http://lists.boost.org/mailman/listinfo.cgi/boost>,
        <mailto:boost-request_at_[hidden]?subject=subscribe>
List-Id: Boost mailing list <boost.lists.boost.org>
List-Unsubscribe: <http://lists.boost.org/mailman/listinfo.cgi/boost>,
        <mailto:boost-request_at_[hidden]?subject=unsubscribe>
List-Archive: http://lists.boost.org/MailArchives/boost/
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
> to
> > widget, means that a copy of the temporary's contents is written to widget
> and
> > 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:

    return std::string(interpreter.str());

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