Subject: Re: [boost] [move][container] Review Request (new versions ofBoost.Move and Boost.Container in sandbox and vault)
From: David Abrahams (dave_at_[hidden])
Date: 2009-09-07 20:37:54
on Mon Sep 07 2009, Howard Hinnant <howard.hinnant-AT-gmail.com> wrote:
> std::swap will only do a self-move-assignment using a moved-from
You mean the target will be a moved-from object. OK, so?
> Of course
> vector will never use this definition. But if it did, then:
> template <class _Tp, class _Allocator>
> vector<_Tp, _Allocator>&
> vector<_Tp, _Allocator>::operator=(vector&& __x)
> return *this;
> would work just fine. clear() is a no-op, and then you swap an empty capacity vector
> with itself.
> My point is that I don't want to be told I need to put a if(this !=
> &x) in my move assignment operator. It is a useless performance
> penalty. Everyone should not have to pay (in terms of lost
> performance) for someone's bad code just to make sure self-move-
> assignment does a no-op instead of crashes.
And the reason this argument doesn't also apply to copy assignment
> If you want to cast an lvalue to an rvalue, that's fine. Just make
> sure your code logic is such that such a cast is safe. I believe
> std::swap's use of move assignment is safe because by the time it
> move-assigns, if it is self referencing, all of your resources have
> already been moved to a local temp.
Then what is the coding guideline, exactly? "Make sure it's safe"
-- Dave Abrahams BoostPro Computing http://www.boostpro.com
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk