Boost logo

Boost :

Subject: Re: [boost] Improving the assignment operators of various Boost types
From: Peter Dimov (pdimov_at_[hidden])
Date: 2008-09-09 19:00:53


Niels Dekker:

> Basically it was concluded that /if/ an assignment operator is
> implemented by means of copy-and-swap, it should preferably be done as
> follows:
>
> T& operator=(T arg)
> {
> arg.swap(*this);
> return *this;
> }

This is well known (although the typical form is swap(arg) instead of
arg.swap(*this)). It is not widely used in Boost because it creates problems
with some compilers (I recall Borland being one). The "classic" form is,
unsurprisingly, much better supported across the board. Things may have
improved now, of course.


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