|
Boost : |
From: Alexander Terekhov (terekhov_at_[hidden])
Date: 2002-10-12 06:40:24
Andrei Alexandrescu wrote:
[...]
> > > class T
> > > {
> > > ...
> > > T& operator=(const T& rhs)
> > > {
> > > T copy(rhs);
> > > rhs.swap(*this);
> > > return *this;
> > > }
> > > };
>
> By the way again :o), here there's an obvious typo in my original posting:
> it's copy.swap, not rhs.swap.
>
> > If you've been talking with Scott Meyers recently you might already
> > know that I certainly agree about operator= for lots of reasons.
>
> Cool. My point is, even when one wants to implement the copy-and-swap idiom,
> the implementation above is the worst that could possibly be written.
Uhmm, care to elaborate, Andrei? I quite often do: < kinda >
T& operator=(T temp) throw()
{ return this->swap(temp); }
What's wrong with it (other than "way too strong" argument, please)?
regards,
alexander.
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk