Boost logo

Boost :

Subject: Re: [boost] Improving the assignment operators of various Boosttypes
From: David Abrahams (dave_at_[hidden])
Date: 2008-09-11 10:22:35

on Thu Sep 11 2008, Joel Falcou <> wrote:

> David Abrahams a écrit :
>> self& operator=(self x) { swap(*this,x); return *this; }
>> with the rationale given in
>>> (I suspect Andrei's CUJ article is equally good or better but much
>> longer)
>> ...but I would think given the thread mentioned above that answer would
>> be self-evident, so it makes me wonder if you're trying to ask something
>> else
> Sorry if i was unclear. My question was is the old operator= form still needed
> soemtime , thus making the 2 forms of the operator to be taught.

The only other form that makes sense for operator= doesn't use swap at
all, and does things "the hard way:" destroy LHS resources and then copy
the RHS resources into it. You might choose that approach if you were
willing to accept the basic guarantee in order to avoid the spike in
resource usage caused by having the LHS data and two copies of the RHS
data all at once. The standard containers generally do it that way.

Dave Abrahams
BoostPro Computing

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