Chromium Code Reviews| Index: base/bind_internal.h |
| diff --git a/base/bind_internal.h b/base/bind_internal.h |
| index 98a73908375394b8e03b70eea60b40741aba4b0d..724f0aa5696644f800f74cff8ee2ac8223299c71 100644 |
| --- a/base/bind_internal.h |
| +++ b/base/bind_internal.h |
| @@ -378,6 +378,7 @@ struct BindState; |
| template <typename BindStateType, typename SFINAE = void> |
| struct CancellationChecker { |
| + static constexpr bool is_cancellable = false; |
| static bool Run(const BindStateBase*) { |
| return false; |
| } |
| @@ -388,6 +389,7 @@ struct CancellationChecker< |
| BindState<Functor, BoundArgs...>, |
| typename std::enable_if<IsWeakMethod<FunctorTraits<Functor>::is_method, |
| BoundArgs...>::value>::type> { |
| + static constexpr bool is_cancellable = true; |
| static bool Run(const BindStateBase* base) { |
| using BindStateType = BindState<Functor, BoundArgs...>; |
| const BindStateType* bind_state = static_cast<const BindStateType*>(base); |
| @@ -397,6 +399,7 @@ struct CancellationChecker< |
| template <typename Signature, typename... BoundArgs> |
| struct CancellationChecker<BindState<Callback<Signature>, BoundArgs...>> { |
| + static constexpr bool is_cancellable = true; |
| static bool Run(const BindStateBase* base) { |
| using Functor = Callback<Signature>; |
| using BindStateType = BindState<Functor, BoundArgs...>; |
| @@ -410,10 +413,27 @@ struct CancellationChecker<BindState<Callback<Signature>, BoundArgs...>> { |
| // This stores all the state passed into Bind(). |
| template <typename Functor, typename... BoundArgs> |
| struct BindState final : BindStateBase { |
| + using IsCancellable = std::integral_constant< |
| + bool, CancellationChecker<BindState>::is_cancellable>; |
| + |
| template <typename ForwardFunctor, typename... ForwardBoundArgs> |
| explicit BindState(BindStateBase::InvokeFuncStorage invoke_func, |
| ForwardFunctor&& functor, |
| ForwardBoundArgs&&... bound_args) |
| + : BindState(IsCancellable(), |
|
dcheng
2016/09/09 20:39:01
Is this a C++14ism? How does it work with our tool
dcheng
2016/09/09 20:39:27
Also, see https://github.com/llvm-mirror/libcxx/bl
|
| + invoke_func, |
| + std::forward<ForwardFunctor>(functor), |
| + std::forward<ForwardBoundArgs>(bound_args)...) {} |
| + |
| + Functor functor_; |
| + std::tuple<BoundArgs...> bound_args_; |
| + |
| + private: |
| + template <typename ForwardFunctor, typename... ForwardBoundArgs> |
| + explicit BindState(std::true_type, |
| + BindStateBase::InvokeFuncStorage invoke_func, |
| + ForwardFunctor&& functor, |
| + ForwardBoundArgs&&... bound_args) |
| : BindStateBase(invoke_func, &Destroy, |
| &CancellationChecker<BindState>::Run), |
| functor_(std::forward<ForwardFunctor>(functor)), |
| @@ -421,10 +441,17 @@ struct BindState final : BindStateBase { |
| DCHECK(!IsNull(functor_)); |
| } |
| - Functor functor_; |
| - std::tuple<BoundArgs...> bound_args_; |
| + template <typename ForwardFunctor, typename... ForwardBoundArgs> |
| + explicit BindState(std::false_type, |
| + BindStateBase::InvokeFuncStorage invoke_func, |
| + ForwardFunctor&& functor, |
| + ForwardBoundArgs&&... bound_args) |
| + : BindStateBase(invoke_func, &Destroy), |
| + functor_(std::forward<ForwardFunctor>(functor)), |
| + bound_args_(std::forward<ForwardBoundArgs>(bound_args)...) { |
| + DCHECK(!IsNull(functor_)); |
| + } |
| - private: |
| ~BindState() {} |
| static void Destroy(BindStateBase* self) { |