
on Wed Sep 10 2008, "Peter Dimov" <pdimov-AT-pdimov.com> wrote:
Niels Dekker:
T& operator=(T arg) { arg.swap(*this); return *this; }
...
Is the choice between swap(arg) and arg.swap(*this)) just a matter of taste?
Yes, I think so. I was just saying that
T& operator=( T arg ) { swap( arg ); return *this; }
is the form I've seen used (by Dave Abrahams, I think*). It certainly looks more "idiomatic" (in the sense of being recognizable as an idiom as opposed to ordinary code) because of the unusual swap call.
*) Turns out that I was right in thinking that. Dave's associative_vector submission:
http://lists.boost.org/Archives/boost/2000/05/3200.php
contains:
Self& operator=(Self rhs) { swap(rhs); return *this; } // strong guarantee
That's interesting. I'm pretty sure that when I wrote that, I wasn't aware of the copy elision advantages and was just trying to write the most compact strong-guarantee assignment that I could.
I was able to find a post by Valentin Bonnard also suggesting the same:
Looks like he wasn't aware of it either
Incidentally:
http://aspn.activestate.com/ASPN/Mail/Message/boost/1140338
"It doesn't compile with Borland C++Builder 4 or BCC 5.5.
Not that I'm worried about those anymore ;-) -- Dave Abrahams BoostPro Computing http://www.boostpro.com