Index: base/callback.h |
diff --git a/base/callback.h b/base/callback.h |
index 3bf0008b6d33bf73e075f502523327817ddb1345..fb3659cf055ec1f0328bcd788aefbc3110d7b178 100644 |
--- a/base/callback.h |
+++ b/base/callback.h |
@@ -344,54 +344,55 @@ |
namespace base { |
-// First, we forward declare the Callback class template. This informs the |
-// compiler that the template only has 1 type parameter which is the function |
-// signature that the Callback is representing. |
-// |
-// After this, create template specializations for 0-7 parameters. Note that |
-// even though the template typelist grows, the specialization still |
-// only has one type: the function signature. |
-// |
-// If you are thinking of forward declaring Callback in your own header file, |
-// please include "base/callback_forward.h" instead. |
Nico
2016/02/15 21:47:57
This paragraph could maybe stay?
tzik
2016/02/16 09:33:32
Done.
|
- |
namespace internal { |
+ |
template <typename Runnable, typename RunType, typename... BoundArgsType> |
struct BindState; |
+ |
+template <CopyMode copy_mode> |
+using CallbackBase = typename std::conditional< |
+ copy_mode == CopyMode::MoveOnly, |
+ MoveOnlyCallbackBase, CopyableCallbackBase>::type; |
+ |
} // namespace internal |
-template <typename R, typename... Args> |
-class Callback<R(Args...)> : public internal::CallbackBase { |
+template <typename R, typename... Args, |
+ internal::CopyMode copy_mode> |
+class Callback<R(Args...), copy_mode> |
+ : public internal::CallbackBase<copy_mode> { |
public: |
// MSVC 2013 doesn't support Type Alias of function types. |
// Revisit this after we update it to newer version. |
typedef R RunType(Args...); |
- Callback() : CallbackBase(nullptr) { } |
+ Callback() {} |
- template <typename Runnable, typename BindRunType, typename... BoundArgsType> |
+ template <typename Runnable, typename BindRunType, typename... BoundArgs> |
explicit Callback( |
- internal::BindState<Runnable, BindRunType, BoundArgsType...>* bind_state) |
- : CallbackBase(bind_state) { |
+ internal::BindState<Runnable, BindRunType, BoundArgs...>* bind_state) { |
+ this->set_bind_state(bind_state); |
Nico
2016/02/15 21:47:57
i'm a bit surpised the this-> wasn't necessary bef
|
+ |
// Force the assignment to a local variable of PolymorphicInvoke |
// so the compiler will typecheck that the passed in Run() method has |
// the correct type. |
PolymorphicInvoke invoke_func = |
- &internal::BindState<Runnable, BindRunType, BoundArgsType...> |
+ &internal::BindState<Runnable, BindRunType, BoundArgs...> |
::InvokerType::Run; |
- polymorphic_invoke_ = reinterpret_cast<InvokeFuncStorage>(invoke_func); |
+ using InvokeFuncStorage = |
+ typename internal::CallbackBase<copy_mode>::InvokeFuncStorage; |
+ this->polymorphic_invoke_ = |
+ reinterpret_cast<InvokeFuncStorage>(invoke_func); |
} |
bool Equals(const Callback& other) const { |
- return CallbackBase::Equals(other); |
+ return this->EqualsInternal(other); |
} |
R Run(typename internal::CallbackParamTraits<Args>::ForwardType... args) |
const { |
PolymorphicInvoke f = |
- reinterpret_cast<PolymorphicInvoke>(polymorphic_invoke_); |
- |
- return f(bind_state_.get(), internal::CallbackForward(args)...); |
+ reinterpret_cast<PolymorphicInvoke>(this->polymorphic_invoke_); |
+ return f(this->bind_state_.get(), internal::CallbackForward(args)...); |
} |
private: |