Index: base/win/scoped_handle.h |
diff --git a/base/win/scoped_handle.h b/base/win/scoped_handle.h |
index 458519d9bfe85f1348e5a193cec221b24cbe8922..6be2946129c570e2e8227e42c84a3524588cd744 100644 |
--- a/base/win/scoped_handle.h |
+++ b/base/win/scoped_handle.h |
@@ -11,6 +11,7 @@ |
#include "base/basictypes.h" |
#include "base/location.h" |
#include "base/logging.h" |
+#include "base/move.h" |
namespace base { |
namespace win { |
@@ -36,6 +37,8 @@ extern "C" { |
// takes a raw handle pointer only. |
template <class Traits, class Verifier> |
class GenericScopedHandle { |
+ MOVE_ONLY_TYPE_FOR_CPP_03(GenericScopedHandle, RValue) |
+ |
public: |
typedef typename Traits::Handle Handle; |
@@ -45,6 +48,14 @@ class GenericScopedHandle { |
Set(handle); |
} |
+ // Move constructor for C++03 move emulation of this type. |
+ GenericScopedHandle(RValue& other) |
+ // The type of the underlying object is GenericScopedHandle; we have to |
+ // reinterpret_cast back to the original type for the call to release to |
+ // be valid. (See C++11 5.2.10.7) |
+ : handle_(reinterpret_cast<GenericScopedHandle&>(other).Take()) { |
jar (doing other things)
2012/08/07 01:00:30
Should be a static_cast (possibly of pointers)? I
alexeypa (please no reviews)
2012/08/07 17:55:14
This code was copied from scoped_handle.h. It rein
|
+ } |
+ |
~GenericScopedHandle() { |
Close(); |
} |
@@ -53,6 +64,12 @@ class GenericScopedHandle { |
return Traits::IsHandleValid(handle_); |
} |
+ // Move operator= for C++03 move emulation of this type. |
+ GenericScopedHandle& operator=(RValue& other) { |
jar (doing other things)
2012/08/07 01:00:30
I'm a little surprised you didn't pass in a const
alexeypa (please no reviews)
2012/08/07 17:55:14
This is copied from scoped_ptr too. |other| has to
|
+ Swap(other); |
+ return *this; |
+ } |
+ |
void Set(Handle handle) { |
if (handle_ != handle) { |
Close(); |
@@ -82,6 +99,12 @@ class GenericScopedHandle { |
return &handle_; |
} |
+ void Swap(GenericScopedHandle& other) { |
+ Handle tmp = handle_; |
+ handle_ = other.handle_; |
+ other.handle_ = tmp; |
+ } |
+ |
// Transfers ownership away from this object. |
Handle Take() { |
Handle temp = handle_; |
@@ -106,8 +129,6 @@ class GenericScopedHandle { |
private: |
Handle handle_; |
- |
- DISALLOW_COPY_AND_ASSIGN(GenericScopedHandle); |
}; |
#undef BASE_WIN_GET_CALLER |