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

Side by Side Diff: base/bind.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 unified diff | Download patch
« no previous file with comments | « no previous file | base/bind_helpers.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #ifndef BASE_BIND_H_ 5 #ifndef BASE_BIND_H_
6 #define BASE_BIND_H_ 6 #define BASE_BIND_H_
7 7
8 #include "base/bind_internal.h" 8 #include "base/bind_internal.h"
9 #include "base/callback_internal.h" 9 #include "base/callback_internal.h"
10 10
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
64 return Callback<typename BindState::UnboundRunType>( 64 return Callback<typename BindState::UnboundRunType>(
65 new BindState(internal::MakeRunnable(functor))); 65 new BindState(internal::MakeRunnable(functor)));
66 } 66 }
67 67
68 template <typename Functor, typename... Args> 68 template <typename Functor, typename... Args>
69 base::Callback< 69 base::Callback<
70 typename internal::BindState< 70 typename internal::BindState<
71 typename internal::FunctorTraits<Functor>::RunnableType, 71 typename internal::FunctorTraits<Functor>::RunnableType,
72 typename internal::FunctorTraits<Functor>::RunType, 72 typename internal::FunctorTraits<Functor>::RunType,
73 internal::TypeList< 73 internal::TypeList<
74 typename internal::CallbackParamTraits<Args>::StorageType...>> 74 typename std::decay<Args>::type...>>
75 ::UnboundRunType> 75 ::UnboundRunType>
76 Bind(Functor functor, const Args&... args) { 76 Bind(Functor functor, Args&&... args) {
77 // Typedefs for how to store and run the functor. 77 // Typedefs for how to store and run the functor.
78 typedef typename internal::FunctorTraits<Functor>::RunnableType RunnableType; 78 typedef typename internal::FunctorTraits<Functor>::RunnableType RunnableType;
79 typedef typename internal::FunctorTraits<Functor>::RunType RunType; 79 typedef typename internal::FunctorTraits<Functor>::RunType RunType;
80 80
81 // Use RunnableType::RunType instead of RunType above because our 81 // Use RunnableType::RunType instead of RunType above because our
82 // checks should below for bound references need to know what the actual 82 // checks should below for bound references need to know what the actual
83 // functor is going to interpret the argument as. 83 // functor is going to interpret the argument as.
84 typedef typename RunnableType::RunType BoundRunType; 84 typedef typename RunnableType::RunType BoundRunType;
85 85
86 // Do not allow binding a non-const reference parameter. Non-const reference 86 // Do not allow binding a non-const reference parameter. Non-const reference
(...skipping 11 matching lines...) Expand all
98 // methods. We also disallow binding of an array as the method's target 98 // methods. We also disallow binding of an array as the method's target
99 // object. 99 // object.
100 static_assert(!internal::BindsArrayToFirstArg<is_method, Args...>::value, 100 static_assert(!internal::BindsArrayToFirstArg<is_method, Args...>::value,
101 "first bound argument to method cannot be array"); 101 "first bound argument to method cannot be array");
102 static_assert( 102 static_assert(
103 !internal::HasRefCountedParamAsRawPtr<is_method, Args...>::value, 103 !internal::HasRefCountedParamAsRawPtr<is_method, Args...>::value,
104 "a parameter is a refcounted type and needs scoped_refptr"); 104 "a parameter is a refcounted type and needs scoped_refptr");
105 105
106 typedef internal::BindState< 106 typedef internal::BindState<
107 RunnableType, RunType, 107 RunnableType, RunType,
108 internal::TypeList< 108 internal::TypeList<typename std::decay<Args>::type...>>
109 typename internal::CallbackParamTraits<Args>::StorageType...>>
110 BindState; 109 BindState;
111 110
112 return Callback<typename BindState::UnboundRunType>( 111 return Callback<typename BindState::UnboundRunType>(new BindState(
113 new BindState(internal::MakeRunnable(functor), args...)); 112 internal::MakeRunnable(functor), std::forward<Args>(args)...));
114 } 113 }
115 114
116 } // namespace base 115 } // namespace base
117 116
118 #endif // BASE_BIND_H_ 117 #endif // BASE_BIND_H_
OLDNEW
« no previous file with comments | « no previous file | base/bind_helpers.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698