Boost logo

Boost :

From: Terje Slettebø (tslettebo_at_[hidden])
Date: 2002-08-22 12:48:27


>From: "Victor A. Wagner, Jr." <vawjr_at_[hidden]>

> At Thursday 2002/08/22 03:44, you wrote:
> > >From: "Victor A. Wagner, Jr." <vawjr_at_[hidden]>
> >
> > > At Wednesday 2002/08/21 15:23, you wrote:
> > > >
> > > >a discussion on an STLport forum triggered a little discussion on
> > > >lexical_cast. I believe that current implementation has a couple of
> >flaws:
> > > >
> > > I agree here. I've often thought that
boost::lexical_cast<std::string>()
> > > should be a special case that doesn't to the >> afterwards, just swap
the
> > > buffer (might as well go for speed while we're at it).
> >
> >That sounds like a good idea. How do you do swap the buffer for
> >std::stringstream and std::string?
>
> you don't, tho I was stunned to see compile and execute (assume using
> namespace std here):
> ostringstream ost;
> ost << 5 << " abcdefghijklmnopqrstuvwxyz";
> string widget;
> widget.swap(ost.str());
> cout << widget << endl;
>
> do what I hoped...
>
> cout << ost.str() << endl;
> afterwards still had the original buffer, so I guess str() returns a
> constructed copy of the buffer;

Well, but is there any point in doing this, then, rather than using the
stream operators? Either way, it's a copy. If it doesn't copy it, it won't
work, since the interpreter is transient.

I thought about this afterwards, so perhaps it wasn't a good idea, after
all.

Regards,

Terje


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