Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(2473)

Unified Diff: base/bind_helpers.h

Issue 8774032: Add Pass(), which implements move semantics, to scoped_ptr, scoped_array, and scoped_ptr_malloc. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: small fixes. Created 9 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | base/bind_internal.h » ('j') | base/memory/scoped_ptr.h » ('J')
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: base/bind_helpers.h
diff --git a/base/bind_helpers.h b/base/bind_helpers.h
index 6e0f8fe72742a06f7875d5f73a4b9e0ec97f6c45..c6e0e1c2b1cc09a33b8441fc68f450d8806ea164 100644
--- a/base/bind_helpers.h
+++ b/base/bind_helpers.h
@@ -90,6 +90,7 @@
#include "base/basictypes.h"
#include "base/bind.h"
#include "base/callback.h"
+#include "base/memory/scoped_ptr.h"
#include "base/memory/weak_ptr.h"
#include "base/template_util.h"
@@ -287,6 +288,19 @@ class OwnedWrapper {
mutable T* ptr_;
};
+template <typename T>
+class PassScopedWrapper {
+ public:
+ explicit PassScopedWrapper(T scoper) : scoper_(scoper.Pass()) {}
+ PassScopedWrapper(const PassScopedWrapper& other)
+ : scoper_(other.scoper_.Pass()) {
+ }
+ T Pass() const { return scoper_.Pass(); }
+
+ private:
+ mutable T scoper_;
+};
+
// Unwrap the stored parameters for the wrappers above.
template <typename T>
struct UnwrapTraits {
@@ -330,9 +344,16 @@ struct UnwrapTraits<OwnedWrapper<T> > {
}
};
+
+template <typename T>
+T& BindMoveSupport(T& t) { return t; }
+
+template <typename T>
+T BindMoveSupport(const PassScopedWrapper<T>& p) { return p.Pass(); }
+
// Utility for handling different refcounting semantics in the Bind()
// function.
-template <bool, typename T>
+template <bool is_method, typename T>
struct MaybeRefcount;
template <typename T>
@@ -348,21 +369,15 @@ struct MaybeRefcount<false, T[n]> {
};
template <typename T>
-struct MaybeRefcount<true, T*> {
- static void AddRef(T* o) { o->AddRef(); }
- static void Release(T* o) { o->Release(); }
-};
-
-template <typename T>
-struct MaybeRefcount<true, UnretainedWrapper<T> > {
- static void AddRef(const UnretainedWrapper<T>&) {}
- static void Release(const UnretainedWrapper<T>&) {}
+struct MaybeRefcount<true, T> {
+ static void AddRef(const T&) {}
+ static void Release(const T&) {}
};
template <typename T>
-struct MaybeRefcount<true, OwnedWrapper<T> > {
- static void AddRef(const OwnedWrapper<T>&) {}
- static void Release(const OwnedWrapper<T>&) {}
+struct MaybeRefcount<true, T*> {
+ static void AddRef(T* o) { o->AddRef(); }
+ static void Release(T* o) { o->Release(); }
};
// No need to additionally AddRef() and Release() since we are storing a
@@ -379,12 +394,6 @@ struct MaybeRefcount<true, const T*> {
static void Release(const T* o) { o->Release(); }
};
-template <typename T>
-struct MaybeRefcount<true, WeakPtr<T> > {
- static void AddRef(const WeakPtr<T>&) {}
- static void Release(const WeakPtr<T>&) {}
-};
-
template <typename R>
void VoidReturnAdapter(Callback<R(void)> callback) {
callback.Run();
@@ -422,6 +431,11 @@ static inline internal::OwnedWrapper<T> Owned(T* o) {
return internal::OwnedWrapper<T>(o);
}
+template <typename T>
+static inline internal::PassScopedWrapper<T> PassScoped(T* scoper) {
+ return internal::PassScopedWrapper<T>(scoper->Pass());
+}
+
template <typename R>
static inline Closure IgnoreReturn(Callback<R(void)> callback) {
return Bind(&internal::VoidReturnAdapter<R>, callback);
@@ -438,7 +452,6 @@ IgnoreResult(const Callback<T>& data) {
return internal::IgnoreResultHelper<Callback<T> >(data);
}
-
} // namespace base
#endif // BASE_BIND_HELPERS_H_
« no previous file with comments | « no previous file | base/bind_internal.h » ('j') | base/memory/scoped_ptr.h » ('J')

Powered by Google App Engine
This is Rietveld 408576698