Index: base/win/scoped_handle.h |
diff --git a/base/win/scoped_handle.h b/base/win/scoped_handle.h |
index 458519d9bfe85f1348e5a193cec221b24cbe8922..3378d004f32c96386cf29ef8defeee157ef9e51b 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,10 @@ class GenericScopedHandle { |
Set(handle); |
} |
+ // Move constructor for C++03 move emulation of this type. |
+ GenericScopedHandle(RValue& other) : handle_(other.Take()) { |
+ } |
+ |
~GenericScopedHandle() { |
Close(); |
} |
@@ -53,6 +60,14 @@ class GenericScopedHandle { |
return Traits::IsHandleValid(handle_); |
} |
+ // Move operator= for C++03 move emulation of this type. |
+ GenericScopedHandle& operator=(RValue& other) { |
+ // Swapping the handles helps to avoid problems while assigning a handle |
jar (doing other things)
2012/08/08 01:42:52
The usual "trick" with dealing with self assignmen
alexeypa (please no reviews)
2012/08/08 01:59:30
src/base/move.h has a long explanation what it is
|
+ // to itself. It is also cheap and matches base::scoped_ptr behavior. |
+ Swap(other); |
+ return *this; |
+ } |
+ |
void Set(Handle handle) { |
if (handle_ != handle) { |
Close(); |
@@ -82,6 +97,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 +127,6 @@ class GenericScopedHandle { |
private: |
Handle handle_; |
- |
- DISALLOW_COPY_AND_ASSIGN(GenericScopedHandle); |
}; |
#undef BASE_WIN_GET_CALLER |