Boost logo

Boost :

From: Rob Stewart (stewart_at_[hidden])
Date: 2002-08-22 12:04:18

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?"

> >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;

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.

Rob Stewart                           stewart_at_[hidden]
Software Engineer           
Susquehanna International Group, LLP  using std::disclaimer;

Boost list run by bdawes at, gregod at, cpdaniel at, john at