diff options
author | ajwong@chromium.org <ajwong@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-12-09 01:29:38 +0000 |
---|---|---|
committer | ajwong@chromium.org <ajwong@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-12-09 01:29:38 +0000 |
commit | 63a822490bb1ac98d4fb8a1e76187ecd3ae5c118 (patch) | |
tree | 1cb16380bb4fa9fd56471b31102ad06dc7b16236 /base/callback.h | |
parent | f749f9cee070a7a15107fa9cce6b89ad1d969bcf (diff) | |
download | chromium_src-63a822490bb1ac98d4fb8a1e76187ecd3ae5c118.zip chromium_src-63a822490bb1ac98d4fb8a1e76187ecd3ae5c118.tar.gz chromium_src-63a822490bb1ac98d4fb8a1e76187ecd3ae5c118.tar.bz2 |
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
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@113722 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'base/callback.h')
-rw-r--r-- | base/callback.h | 56 |
1 files changed, 28 insertions, 28 deletions
diff --git a/base/callback.h b/base/callback.h index 09c3ef7..001dd07 100644 --- a/base/callback.h +++ b/base/callback.h @@ -312,7 +312,7 @@ class Callback<R(A1)> : public internal::CallbackBase { PolymorphicInvoke f = reinterpret_cast<PolymorphicInvoke>(polymorphic_invoke_); - return f(bind_state_.get(), a1); + return f(bind_state_.get(), internal::CallbackForward(a1)); } private: @@ -355,8 +355,8 @@ class Callback<R(A1, A2)> : public internal::CallbackBase { PolymorphicInvoke f = reinterpret_cast<PolymorphicInvoke>(polymorphic_invoke_); - return f(bind_state_.get(), a1, - a2); + return f(bind_state_.get(), internal::CallbackForward(a1), + internal::CallbackForward(a2)); } private: @@ -401,9 +401,9 @@ class Callback<R(A1, A2, A3)> : public internal::CallbackBase { PolymorphicInvoke f = reinterpret_cast<PolymorphicInvoke>(polymorphic_invoke_); - return f(bind_state_.get(), a1, - a2, - a3); + return f(bind_state_.get(), internal::CallbackForward(a1), + internal::CallbackForward(a2), + internal::CallbackForward(a3)); } private: @@ -450,10 +450,10 @@ class Callback<R(A1, A2, A3, A4)> : public internal::CallbackBase { PolymorphicInvoke f = reinterpret_cast<PolymorphicInvoke>(polymorphic_invoke_); - return f(bind_state_.get(), a1, - a2, - a3, - a4); + return f(bind_state_.get(), internal::CallbackForward(a1), + internal::CallbackForward(a2), + internal::CallbackForward(a3), + internal::CallbackForward(a4)); } private: @@ -503,11 +503,11 @@ class Callback<R(A1, A2, A3, A4, A5)> : public internal::CallbackBase { PolymorphicInvoke f = reinterpret_cast<PolymorphicInvoke>(polymorphic_invoke_); - return f(bind_state_.get(), a1, - a2, - a3, - a4, - a5); + return f(bind_state_.get(), internal::CallbackForward(a1), + internal::CallbackForward(a2), + internal::CallbackForward(a3), + internal::CallbackForward(a4), + internal::CallbackForward(a5)); } private: @@ -559,12 +559,12 @@ class Callback<R(A1, A2, A3, A4, A5, A6)> : public internal::CallbackBase { PolymorphicInvoke f = reinterpret_cast<PolymorphicInvoke>(polymorphic_invoke_); - return f(bind_state_.get(), a1, - a2, - a3, - a4, - a5, - a6); + return f(bind_state_.get(), internal::CallbackForward(a1), + internal::CallbackForward(a2), + internal::CallbackForward(a3), + internal::CallbackForward(a4), + internal::CallbackForward(a5), + internal::CallbackForward(a6)); } private: @@ -618,13 +618,13 @@ class Callback<R(A1, A2, A3, A4, A5, A6, A7)> : public internal::CallbackBase { PolymorphicInvoke f = reinterpret_cast<PolymorphicInvoke>(polymorphic_invoke_); - return f(bind_state_.get(), a1, - a2, - a3, - a4, - a5, - a6, - a7); + return f(bind_state_.get(), internal::CallbackForward(a1), + internal::CallbackForward(a2), + internal::CallbackForward(a3), + internal::CallbackForward(a4), + internal::CallbackForward(a5), + internal::CallbackForward(a6), + internal::CallbackForward(a7)); } private: |