summaryrefslogtreecommitdiffstats
path: root/base/callback_internal.h
diff options
context:
space:
mode:
authorsergeyu@chromium.org <sergeyu@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-12-09 02:25:47 +0000
committersergeyu@chromium.org <sergeyu@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-12-09 02:25:47 +0000
commit3e6d120bf18e6ba69373cc635e1e7dd46543ea33 (patch)
tree3353f324a4796ffc419f3468daf436866b0036fd /base/callback_internal.h
parentd17d2fcf157bd17b810c25328a8e0960c9d1d834 (diff)
downloadchromium_src-3e6d120bf18e6ba69373cc635e1e7dd46543ea33.zip
chromium_src-3e6d120bf18e6ba69373cc635e1e7dd46543ea33.tar.gz
chromium_src-3e6d120bf18e6ba69373cc635e1e7dd46543ea33.tar.bz2
Revert 113722 - Add Pass(), which implements move semantics, to scoped_ptr, scoped_array, and scoped_ptr_malloc.
This modification to the scopers implements the "moveable but not copyable" semantics that were introduced in C++11's unique_ptr<>. With this, is now possible to use scopers as an argument type or a return type. This signifies, in the type system, transfer of ownership into a function or out of a function respectively. Calling, or returning such a function MUST use the temporary resulting from the scoper's Pass() function. You CANNOT just pass the scoper by copy as there is still no copy constructor or assignment operator; trying to do so will yield a compilation error. This distinction makes it possible to avoid the implicit ownership transfer issues of auto_ptr, but still allow us to have compiler enforced ownership transfer. Also adds a Passed() helper that allows using a scoper with Bind(). BUG=96118 TEST=new unittests Review URL: http://codereview.chromium.org/8774032 TBR=ajwong@chromium.org Review URL: http://codereview.chromium.org/8890060 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@113738 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'base/callback_internal.h')
-rw-r--r--base/callback_internal.h59
1 files changed, 0 insertions, 59 deletions
diff --git a/base/callback_internal.h b/base/callback_internal.h
index b734568..81c87c0 100644
--- a/base/callback_internal.h
+++ b/base/callback_internal.h
@@ -13,7 +13,6 @@
#include "base/base_export.h"
#include "base/memory/ref_counted.h"
-#include "base/memory/scoped_ptr.h"
namespace base {
namespace internal {
@@ -131,64 +130,6 @@ struct CallbackParamTraits<T[]> {
typedef const T* StorageType;
};
-// Parameter traits for movable-but-not-copyable scopers.
-//
-// Callback<>/Bind() understands movable-but-not-copyable semantics where
-// the type cannot be copied but can still have its state destructively
-// transferred (aka. moved) to another instance of the same type by calling a
-// helper function. When used with Bind(), this signifies transferal of the
-// object's state to the target function.
-//
-// For these types, the ForwardType must not be a const reference, or a
-// reference. A const reference is inappropriate, and would break const
-// correctness, because we are implementing a destructive move. A non-const
-// reference cannot be used with temporaries which means the result of a
-// function or a cast would not be usable with Callback<> or Bind().
-//
-// TODO(ajwong): We might be able to use SFINAE to search for the existence of
-// a Pass() function in the type and avoid the whitelist in CallbackParamTraits
-// and CallbackForward.
-template <typename T>
-struct CallbackParamTraits<scoped_ptr<T> > {
- typedef scoped_ptr<T> ForwardType;
- typedef scoped_ptr<T> StorageType;
-};
-
-template <typename T>
-struct CallbackParamTraits<scoped_array<T> > {
- typedef scoped_array<T> ForwardType;
- typedef scoped_array<T> StorageType;
-};
-
-template <typename T>
-struct CallbackParamTraits<scoped_ptr_malloc<T> > {
- typedef scoped_ptr_malloc<T> ForwardType;
- typedef scoped_ptr_malloc<T> StorageType;
-};
-
-// CallbackForward() is a very limited simulation of C++11's std::forward()
-// used by the Callback/Bind system for a set of movable-but-not-copyable
-// types. It is needed because forwarding a movable-but-not-copyable
-// argument to another function requires us to invoke the proper move
-// operator to create a rvalue version of the type. The supported types are
-// whitelisted below as overloads of the CallbackForward() function. The
-// default template compiles out to be a no-op.
-//
-// In C++11, std::forward would replace all uses of this function. However, it
-// is impossible to implement a general std::forward with C++11 due to a lack
-// of rvalue references.
-template <typename T>
-T& CallbackForward(T& t) { return t; }
-
-template <typename T>
-scoped_ptr<T> CallbackForward(scoped_ptr<T>& p) { return p.Pass(); }
-
-template <typename T>
-scoped_ptr<T> CallbackForward(scoped_array<T>& p) { return p.Pass(); }
-
-template <typename T>
-scoped_ptr<T> CallbackForward(scoped_ptr_malloc<T>& p) { return p.Pass(); }
-
} // namespace internal
} // namespace base