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

Unified Diff: base/bind_internal.h

Issue 1498973002: WIP: base::Bind for rvalue references. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 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 | « base/bind_helpers.h ('k') | base/bind_internal_win.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: base/bind_internal.h
diff --git a/base/bind_internal.h b/base/bind_internal.h
index c6832e6a479ed3da0a386855327de207e6fedca6..65563fa94ab69557bf5a8daa340bfe22276ee139 100644
--- a/base/bind_internal.h
+++ b/base/bind_internal.h
@@ -108,7 +108,8 @@ template <bool is_method, typename... Args>
struct BindsArrayToFirstArg : false_type {};
template <typename T, typename... Args>
-struct BindsArrayToFirstArg<true, T, Args...> : is_array<T> {};
+struct BindsArrayToFirstArg<true, T, Args...>
+ : is_array<typename std::remove_reference<T>::type> {};
// HasRefCountedParamAsRawPtr is the same to HasRefCountedTypeAsRawPtr except
// when |is_method| is true HasRefCountedParamAsRawPtr skips the first argument.
@@ -155,8 +156,9 @@ class RunnableAdapter<R(*)(Args...)> {
: function_(function) {
}
- R Run(typename CallbackParamTraits<Args>::ForwardType... args) {
- return function_(CallbackForward(args)...);
+ template <typename... RunArgs>
+ R Run(RunArgs&&... args) {
+ return function_(std::forward<RunArgs>(args)...);
}
private:
@@ -174,8 +176,9 @@ class RunnableAdapter<R(T::*)(Args...)> {
: method_(method) {
}
- R Run(T* object, typename CallbackParamTraits<Args>::ForwardType... args) {
- return (object->*method_)(CallbackForward(args)...);
+ template <typename... RunArgs>
+ R Run(T* object, RunArgs&&... args) {
+ return (object->*method_)(std::forward<RunArgs>(args)...);
}
private:
@@ -193,9 +196,10 @@ class RunnableAdapter<R(T::*)(Args...) const> {
: method_(method) {
}
+ template <typename... RunArgs>
R Run(const T* object,
- typename CallbackParamTraits<Args>::ForwardType... args) {
- return (object->*method_)(CallbackForward(args)...);
+ RunArgs&&... args) {
+ return (object->*method_)(std::forward<RunArgs>(args)...);
}
private:
@@ -284,25 +288,30 @@ struct InvokeHelper;
template <typename ReturnType, typename Runnable, typename... Args>
struct InvokeHelper<false, ReturnType, Runnable, TypeList<Args...>> {
- static ReturnType MakeItSo(Runnable runnable, Args... args) {
- return runnable.Run(CallbackForward(args)...);
+ template <typename... RunArgs>
+ static ReturnType MakeItSo(Runnable runnable, RunArgs&&... args) {
+ return runnable.Run(std::forward<RunArgs>(args)...);
}
};
template <typename Runnable, typename... Args>
struct InvokeHelper<false, void, Runnable, TypeList<Args...>> {
- static void MakeItSo(Runnable runnable, Args... args) {
- runnable.Run(CallbackForward(args)...);
+ template <typename... RunArgs>
+ static void MakeItSo(Runnable runnable, RunArgs&&... args) {
+ runnable.Run(std::forward<RunArgs>(args)...);
}
};
template <typename Runnable, typename BoundWeakPtr, typename... Args>
struct InvokeHelper<true, void, Runnable, TypeList<BoundWeakPtr, Args...>> {
- static void MakeItSo(Runnable runnable, BoundWeakPtr weak_ptr, Args... args) {
+ template <typename... RunArgs>
+ static void MakeItSo(Runnable runnable,
+ BoundWeakPtr weak_ptr,
+ RunArgs&&... args) {
if (!weak_ptr.get()) {
return;
}
- runnable.Run(weak_ptr.get(), CallbackForward(args)...);
+ runnable.Run(weak_ptr.get(), std::forward<RunArgs>(args)...);
}
};
@@ -337,7 +346,8 @@ struct Invoker<IndexSequence<bound_indices...>,
StorageType, TypeList<Unwrappers...>,
InvokeHelperType, R(UnboundForwardArgs...)> {
static R Run(BindStateBase* base,
- UnboundForwardArgs... unbound_args) {
+ typename CallbackParamTraits<
+ UnboundForwardArgs>::ForwardType... unbound_args) {
StorageType* storage = static_cast<StorageType*>(base);
// Local references to make debugger stepping easier. If in a debugger,
// you really want to warp ahead and step through the
@@ -345,11 +355,10 @@ struct Invoker<IndexSequence<bound_indices...>,
return InvokeHelperType::MakeItSo(
storage->runnable_,
Unwrappers::Unwrap(get<bound_indices>(storage->bound_args_))...,
- CallbackForward(unbound_args)...);
+ CallbackForward2(unbound_args)...);
}
};
-
// BindState<>
//
// This stores all the state passed into Bind() and is also where most
@@ -382,9 +391,8 @@ struct BindState<Runnable, R(Args...), TypeList<BoundArgs...>> final
using BoundIndices = MakeIndexSequence<sizeof...(BoundArgs)>;
using Unwrappers = TypeList<UnwrapTraits<BoundArgs>...>;
- using UnboundForwardArgs = DropTypeListItem<
- sizeof...(BoundArgs),
- TypeList<typename CallbackParamTraits<Args>::ForwardType...>>;
+ using UnboundForwardArgs =
+ DropTypeListItem<sizeof...(BoundArgs), TypeList<Args...>>;
using UnboundForwardRunType = MakeFunctionType<R, UnboundForwardArgs>;
using InvokeHelperArgs = ConcatTypeLists<
@@ -400,15 +408,16 @@ struct BindState<Runnable, R(Args...), TypeList<BoundArgs...>> final
InvokeHelperType, UnboundForwardRunType>;
using UnboundRunType = MakeFunctionType<R, UnboundArgs>;
- BindState(const Runnable& runnable, const BoundArgs&... bound_args)
+ template <typename... PassedBoundArgs>
+ BindState(const Runnable& runnable, PassedBoundArgs&&... bound_args)
: BindStateBase(&Destroy),
runnable_(runnable),
ref_(bound_args...),
- bound_args_(bound_args...) {}
+ bound_args_(std::forward<PassedBoundArgs>(bound_args)...) {}
RunnableType runnable_;
MaybeScopedRefPtr<HasIsMethodTag<Runnable>::value, BoundArgs...> ref_;
- Tuple<BoundArgs...> bound_args_;
+ std::tuple<BoundArgs...> bound_args_;
private:
~BindState() {}
« no previous file with comments | « base/bind_helpers.h ('k') | base/bind_internal_win.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698