Boost logo

Boost :

Subject: Re: [boost] Temporary objects
From: Thomas Klimpel (Thomas.Klimpel_at_[hidden])
Date: 2009-10-31 11:37:20


Mathias Gaunard wrote:
> Thomas Klimpel wrote:
> > What I really would like for the move-proposal is to allow implementing the move-assignment operator as a simple swap
>
> Testing shows that this is suboptimal and can hurt performance
> significantly.

You probably want to say that implementing "a = std::move(b)" as

tmp.members = a.members
a.members = b.members
b.members = tmp.members

is significantly slower than implementing it as

a.members = b.members

I believe this without testing. What I'm talking about is that the move-assignment operator of the proposed boost::container::vector is implemented for good reasons as

   vector& operator=(BOOST_RV_REF(vector) x)
   {
      if (&x != this){
         this->swap(x);
         x.clear();
      }
      return *this;
   }

and it would be nice if it would be allowed to implement it as

   vector& operator=(BOOST_RV_REF(vector) x)
   {
      this->swap(x);
      return *this;
   }

However, I accepted that "it would be nice" won't come reality, because the good reasons are just too good (with the otherwise required language change as final word).

Regards,
Thomas


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