Boost logo

Boost :

From: Jody Hagins (jody-boost-011304_at_[hidden])
Date: 2005-02-15 15:21:41

On Tue, 15 Feb 2005 18:02:57 -0200
Bruno Martínez Aguerre <br1_at_[hidden]> wrote:

> Why not:
> optional& operator=(optional rhs)
> {
> optional_swap(*this, rhs);
> return *this;
> }
> ?

That is a very valid option as well. In fact, in his book, Sutter
mentions that option specifically...

Exceptional C++, page 48:

"If you're one of those folks who like terse code, you can write the
operator=() canonical form more compactly as:

    Stack& operator=(Stack other)
      Swap( other );
      return *this;

Not being very up to date on optimization techniques, I do not know if a
compiler can turn one into better code than the other. Barring that, I
prefer the less-terse one, because I also prefer passing ref-to-const
over by-value, unless there is a good reason to do otherwise.

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