[llvm-commits] [llvm] r157546 - /llvm/trunk/include/llvm/ADT/IntrusiveRefCntPtr.h
Richard Smith
richard at metafoo.co.uk
Mon May 28 16:28:11 PDT 2012
On Sun, May 27, 2012 at 1:46 PM, Benjamin Kramer
<benny.kra at googlemail.com>wrote:
> Author: d0k
> Date: Sun May 27 15:46:04 2012
> New Revision: 157546
>
> URL: http://llvm.org/viewvc/llvm-project?rev=157546&view=rev
> Log:
> IntrusiveRefCntPtr: Use the same pattern as the other operator= overloads
> when using rvalue refs.
>
> Modified:
> llvm/trunk/include/llvm/ADT/IntrusiveRefCntPtr.h
>
> Modified: llvm/trunk/include/llvm/ADT/IntrusiveRefCntPtr.h
> URL:
> http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/ADT/IntrusiveRefCntPtr.h?rev=157546&r1=157545&r2=157546&view=diff
>
> ==============================================================================
> --- llvm/trunk/include/llvm/ADT/IntrusiveRefCntPtr.h (original)
> +++ llvm/trunk/include/llvm/ADT/IntrusiveRefCntPtr.h Sun May 27 15:46:04
> 2012
> @@ -23,6 +23,7 @@
>
> #include "llvm/Support/Casting.h"
> #include "llvm/Support/Compiler.h"
> +#include <memory>
>
> namespace llvm {
>
> @@ -146,15 +147,13 @@
>
> #if LLVM_USE_RVALUE_REFERENCES
> IntrusiveRefCntPtr& operator=(IntrusiveRefCntPtr&& S) {
> - Obj = S.Obj;
> - S.Obj = 0;
> + this_type(std::move(S)).swap(*this);
> return *this;
> }
>
> template <class X>
> IntrusiveRefCntPtr& operator=(IntrusiveRefCntPtr<X>&& S) {
> - Obj = S.getPtr();
> - S.Obj = 0;
> + this_type(std::move(S)).swap(*this);
> return *this;
> }
>
How about replacing all five operator= overloads (duplicating the work of
the constructors) and the 'replace' member function with just:
IntrusiveRefCntPtr& operator=(IntrusiveRefCntPtr O) {
swap(O);
return *this;
}
As well as simplifying the code, this would give us move semantics in some
cases in C++98.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20120528/23b25ee7/attachment.html>
More information about the llvm-commits
mailing list