[email protected] | b38d357 | 2011-02-15 01:27:38 | [diff] [blame] | 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 |
| 3 | // found in the LICENSE file. |
| 4 | |
| 5 | #ifndef BASE_BIND_INTERNAL_H_ |
| 6 | #define BASE_BIND_INTERNAL_H_ |
[email protected] | b38d357 | 2011-02-15 01:27:38 | [diff] [blame] | 7 | |
avi | 9b6f4293 | 2015-12-26 22:15:14 | [diff] [blame] | 8 | #include <stddef.h> |
| 9 | |
jdoerrie | 5c4dc4e | 2019-02-01 18:02:33 | [diff] [blame^] | 10 | #include <tuple> |
vmpstr | c52317f | 2015-11-18 08:43:26 | [diff] [blame] | 11 | #include <type_traits> |
Jeremy Roman | 84956fa | 2017-08-16 15:55:20 | [diff] [blame] | 12 | #include <utility> |
vmpstr | c52317f | 2015-11-18 08:43:26 | [diff] [blame] | 13 | |
Sebastien Marchand | 6d0558fd | 2019-01-25 16:49:37 | [diff] [blame] | 14 | #include "base/bind.h" |
[email protected] | 59eff91 | 2011-02-18 23:29:31 | [diff] [blame] | 15 | #include "base/callback_internal.h" |
Sylvain Defresne | ec3270c | 2018-05-31 17:19:15 | [diff] [blame] | 16 | #include "base/compiler_specific.h" |
[email protected] | 8217d454 | 2011-10-01 06:31:41 | [diff] [blame] | 17 | #include "base/memory/raw_scoped_refptr_mismatch_checker.h" |
[email protected] | 9354058 | 2011-05-16 22:35:14 | [diff] [blame] | 18 | #include "base/memory/weak_ptr.h" |
[email protected] | b38d357 | 2011-02-15 01:27:38 | [diff] [blame] | 19 | #include "base/template_util.h" |
[email protected] | 054ac754 | 2011-02-27 01:25:59 | [diff] [blame] | 20 | #include "build/build_config.h" |
| 21 | |
Sylvain Defresne | ec3270c | 2018-05-31 17:19:15 | [diff] [blame] | 22 | #if defined(OS_MACOSX) && !HAS_FEATURE(objc_arc) |
| 23 | #include "base/mac/scoped_block.h" |
| 24 | #endif |
| 25 | |
[email protected] | 2429264 | 2012-07-12 20:06:40 | [diff] [blame] | 26 | // See base/callback.h for user documentation. |
| 27 | // |
| 28 | // |
[email protected] | 7296f276 | 2011-11-21 19:23:44 | [diff] [blame] | 29 | // CONCEPTS: |
tzik | 99de02b | 2016-07-01 05:54:12 | [diff] [blame] | 30 | // Functor -- A movable type representing something that should be called. |
| 31 | // All function pointers and Callback<> are functors even if the |
| 32 | // invocation syntax differs. |
[email protected] | 7296f276 | 2011-11-21 19:23:44 | [diff] [blame] | 33 | // RunType -- A function type (as opposed to function _pointer_ type) for |
tzik | 99de02b | 2016-07-01 05:54:12 | [diff] [blame] | 34 | // a Callback<>::Run(). Usually just a convenience typedef. |
tzik | ce3ecf8 | 2015-12-15 06:41:49 | [diff] [blame] | 35 | // (Bound)Args -- A set of types that stores the arguments. |
[email protected] | b38d357 | 2011-02-15 01:27:38 | [diff] [blame] | 36 | // |
[email protected] | 7296f276 | 2011-11-21 19:23:44 | [diff] [blame] | 37 | // Types: |
[email protected] | 7296f276 | 2011-11-21 19:23:44 | [diff] [blame] | 38 | // ForceVoidReturn<> -- Helper class for translating function signatures to |
| 39 | // equivalent forms with a "void" return type. |
tzik | 99de02b | 2016-07-01 05:54:12 | [diff] [blame] | 40 | // FunctorTraits<> -- Type traits used to determine the correct RunType and |
| 41 | // invocation manner for a Functor. This is where function |
[email protected] | 7296f276 | 2011-11-21 19:23:44 | [diff] [blame] | 42 | // signature adapters are applied. |
tzik | 99de02b | 2016-07-01 05:54:12 | [diff] [blame] | 43 | // InvokeHelper<> -- Take a Functor + arguments and actully invokes it. |
tzik | 8ce6570 | 2015-02-05 19:11:26 | [diff] [blame] | 44 | // Handle the differing syntaxes needed for WeakPtr<> |
tzik | 99de02b | 2016-07-01 05:54:12 | [diff] [blame] | 45 | // support. This is separate from Invoker to avoid creating |
| 46 | // multiple version of Invoker<>. |
| 47 | // Invoker<> -- Unwraps the curried parameters and executes the Functor. |
[email protected] | 7296f276 | 2011-11-21 19:23:44 | [diff] [blame] | 48 | // BindState<> -- Stores the curried parameters, and is the main entry point |
tzik | 99de02b | 2016-07-01 05:54:12 | [diff] [blame] | 49 | // into the Bind() system. |
[email protected] | 4346ef91 | 2011-02-19 00:52:15 | [diff] [blame] | 50 | |
tzik | c44f810 | 2018-07-24 09:49:19 | [diff] [blame] | 51 | #if defined(OS_WIN) |
| 52 | namespace Microsoft { |
| 53 | namespace WRL { |
| 54 | template <typename> |
| 55 | class ComPtr; |
| 56 | } // namespace WRL |
| 57 | } // namespace Microsoft |
| 58 | #endif |
| 59 | |
Peter Kasting | a85265e3 | 2018-02-15 08:30:23 | [diff] [blame] | 60 | namespace base { |
| 61 | |
| 62 | template <typename T> |
| 63 | struct IsWeakReceiver; |
| 64 | |
| 65 | template <typename> |
| 66 | struct BindUnwrapTraits; |
| 67 | |
| 68 | template <typename Functor, typename BoundArgsTuple, typename SFINAE = void> |
| 69 | struct CallbackCancellationTraits; |
| 70 | |
| 71 | namespace internal { |
| 72 | |
| 73 | template <typename Functor, typename SFINAE = void> |
| 74 | struct FunctorTraits; |
| 75 | |
| 76 | template <typename T> |
| 77 | class UnretainedWrapper { |
| 78 | public: |
| 79 | explicit UnretainedWrapper(T* o) : ptr_(o) {} |
| 80 | T* get() const { return ptr_; } |
| 81 | |
| 82 | private: |
| 83 | T* ptr_; |
| 84 | }; |
| 85 | |
| 86 | template <typename T> |
| 87 | class ConstRefWrapper { |
| 88 | public: |
| 89 | explicit ConstRefWrapper(const T& o) : ptr_(&o) {} |
| 90 | const T& get() const { return *ptr_; } |
| 91 | |
| 92 | private: |
| 93 | const T* ptr_; |
| 94 | }; |
| 95 | |
| 96 | template <typename T> |
| 97 | class RetainedRefWrapper { |
| 98 | public: |
| 99 | explicit RetainedRefWrapper(T* o) : ptr_(o) {} |
| 100 | explicit RetainedRefWrapper(scoped_refptr<T> o) : ptr_(std::move(o)) {} |
| 101 | T* get() const { return ptr_.get(); } |
| 102 | |
| 103 | private: |
| 104 | scoped_refptr<T> ptr_; |
| 105 | }; |
| 106 | |
| 107 | template <typename T> |
| 108 | struct IgnoreResultHelper { |
| 109 | explicit IgnoreResultHelper(T functor) : functor_(std::move(functor)) {} |
| 110 | explicit operator bool() const { return !!functor_; } |
| 111 | |
| 112 | T functor_; |
| 113 | }; |
| 114 | |
| 115 | // An alternate implementation is to avoid the destructive copy, and instead |
| 116 | // specialize ParamTraits<> for OwnedWrapper<> to change the StorageType to |
| 117 | // a class that is essentially a std::unique_ptr<>. |
| 118 | // |
| 119 | // The current implementation has the benefit though of leaving ParamTraits<> |
| 120 | // fully in callback_internal.h as well as avoiding type conversions during |
| 121 | // storage. |
| 122 | template <typename T> |
| 123 | class OwnedWrapper { |
| 124 | public: |
| 125 | explicit OwnedWrapper(T* o) : ptr_(o) {} |
| 126 | ~OwnedWrapper() { delete ptr_; } |
| 127 | T* get() const { return ptr_; } |
| 128 | OwnedWrapper(OwnedWrapper&& other) { |
| 129 | ptr_ = other.ptr_; |
| 130 | other.ptr_ = NULL; |
| 131 | } |
| 132 | |
| 133 | private: |
| 134 | mutable T* ptr_; |
| 135 | }; |
| 136 | |
| 137 | // PassedWrapper is a copyable adapter for a scoper that ignores const. |
| 138 | // |
| 139 | // It is needed to get around the fact that Bind() takes a const reference to |
| 140 | // all its arguments. Because Bind() takes a const reference to avoid |
| 141 | // unnecessary copies, it is incompatible with movable-but-not-copyable |
| 142 | // types; doing a destructive "move" of the type into Bind() would violate |
| 143 | // the const correctness. |
| 144 | // |
| 145 | // This conundrum cannot be solved without either C++11 rvalue references or |
| 146 | // a O(2^n) blowup of Bind() templates to handle each combination of regular |
| 147 | // types and movable-but-not-copyable types. Thus we introduce a wrapper type |
| 148 | // that is copyable to transmit the correct type information down into |
| 149 | // BindState<>. Ignoring const in this type makes sense because it is only |
| 150 | // created when we are explicitly trying to do a destructive move. |
| 151 | // |
| 152 | // Two notes: |
| 153 | // 1) PassedWrapper supports any type that has a move constructor, however |
| 154 | // the type will need to be specifically whitelisted in order for it to be |
| 155 | // bound to a Callback. We guard this explicitly at the call of Passed() |
| 156 | // to make for clear errors. Things not given to Passed() will be forwarded |
| 157 | // and stored by value which will not work for general move-only types. |
| 158 | // 2) is_valid_ is distinct from NULL because it is valid to bind a "NULL" |
| 159 | // scoper to a Callback and allow the Callback to execute once. |
| 160 | template <typename T> |
| 161 | class PassedWrapper { |
| 162 | public: |
| 163 | explicit PassedWrapper(T&& scoper) |
| 164 | : is_valid_(true), scoper_(std::move(scoper)) {} |
| 165 | PassedWrapper(PassedWrapper&& other) |
| 166 | : is_valid_(other.is_valid_), scoper_(std::move(other.scoper_)) {} |
| 167 | T Take() const { |
| 168 | CHECK(is_valid_); |
| 169 | is_valid_ = false; |
| 170 | return std::move(scoper_); |
| 171 | } |
| 172 | |
| 173 | private: |
| 174 | mutable bool is_valid_; |
| 175 | mutable T scoper_; |
| 176 | }; |
| 177 | |
| 178 | template <typename T> |
| 179 | using Unwrapper = BindUnwrapTraits<std::decay_t<T>>; |
| 180 | |
| 181 | template <typename T> |
Peter Kasting | c2f8749bf | 2018-03-31 03:32:37 | [diff] [blame] | 182 | decltype(auto) Unwrap(T&& o) { |
Peter Kasting | a85265e3 | 2018-02-15 08:30:23 | [diff] [blame] | 183 | return Unwrapper<T>::Unwrap(std::forward<T>(o)); |
| 184 | } |
| 185 | |
| 186 | // IsWeakMethod is a helper that determine if we are binding a WeakPtr<> to a |
| 187 | // method. It is used internally by Bind() to select the correct |
| 188 | // InvokeHelper that will no-op itself in the event the WeakPtr<> for |
| 189 | // the target object is invalidated. |
| 190 | // |
| 191 | // The first argument should be the type of the object that will be received by |
| 192 | // the method. |
| 193 | template <bool is_method, typename... Args> |
| 194 | struct IsWeakMethod : std::false_type {}; |
| 195 | |
| 196 | template <typename T, typename... Args> |
| 197 | struct IsWeakMethod<true, T, Args...> : IsWeakReceiver<T> {}; |
| 198 | |
| 199 | // Packs a list of types to hold them in a single type. |
| 200 | template <typename... Types> |
| 201 | struct TypeList {}; |
| 202 | |
| 203 | // Used for DropTypeListItem implementation. |
| 204 | template <size_t n, typename List> |
| 205 | struct DropTypeListItemImpl; |
| 206 | |
| 207 | // Do not use enable_if and SFINAE here to avoid MSVC2013 compile failure. |
| 208 | template <size_t n, typename T, typename... List> |
| 209 | struct DropTypeListItemImpl<n, TypeList<T, List...>> |
| 210 | : DropTypeListItemImpl<n - 1, TypeList<List...>> {}; |
| 211 | |
| 212 | template <typename T, typename... List> |
| 213 | struct DropTypeListItemImpl<0, TypeList<T, List...>> { |
| 214 | using Type = TypeList<T, List...>; |
| 215 | }; |
| 216 | |
| 217 | template <> |
| 218 | struct DropTypeListItemImpl<0, TypeList<>> { |
| 219 | using Type = TypeList<>; |
| 220 | }; |
| 221 | |
| 222 | // A type-level function that drops |n| list item from given TypeList. |
| 223 | template <size_t n, typename List> |
| 224 | using DropTypeListItem = typename DropTypeListItemImpl<n, List>::Type; |
| 225 | |
| 226 | // Used for TakeTypeListItem implementation. |
| 227 | template <size_t n, typename List, typename... Accum> |
| 228 | struct TakeTypeListItemImpl; |
| 229 | |
| 230 | // Do not use enable_if and SFINAE here to avoid MSVC2013 compile failure. |
| 231 | template <size_t n, typename T, typename... List, typename... Accum> |
| 232 | struct TakeTypeListItemImpl<n, TypeList<T, List...>, Accum...> |
| 233 | : TakeTypeListItemImpl<n - 1, TypeList<List...>, Accum..., T> {}; |
| 234 | |
| 235 | template <typename T, typename... List, typename... Accum> |
| 236 | struct TakeTypeListItemImpl<0, TypeList<T, List...>, Accum...> { |
| 237 | using Type = TypeList<Accum...>; |
| 238 | }; |
| 239 | |
| 240 | template <typename... Accum> |
| 241 | struct TakeTypeListItemImpl<0, TypeList<>, Accum...> { |
| 242 | using Type = TypeList<Accum...>; |
| 243 | }; |
| 244 | |
| 245 | // A type-level function that takes first |n| list item from given TypeList. |
| 246 | // E.g. TakeTypeListItem<3, TypeList<A, B, C, D>> is evaluated to |
| 247 | // TypeList<A, B, C>. |
| 248 | template <size_t n, typename List> |
| 249 | using TakeTypeListItem = typename TakeTypeListItemImpl<n, List>::Type; |
| 250 | |
| 251 | // Used for ConcatTypeLists implementation. |
| 252 | template <typename List1, typename List2> |
| 253 | struct ConcatTypeListsImpl; |
| 254 | |
| 255 | template <typename... Types1, typename... Types2> |
| 256 | struct ConcatTypeListsImpl<TypeList<Types1...>, TypeList<Types2...>> { |
| 257 | using Type = TypeList<Types1..., Types2...>; |
| 258 | }; |
| 259 | |
| 260 | // A type-level function that concats two TypeLists. |
| 261 | template <typename List1, typename List2> |
| 262 | using ConcatTypeLists = typename ConcatTypeListsImpl<List1, List2>::Type; |
| 263 | |
| 264 | // Used for MakeFunctionType implementation. |
| 265 | template <typename R, typename ArgList> |
| 266 | struct MakeFunctionTypeImpl; |
| 267 | |
| 268 | template <typename R, typename... Args> |
| 269 | struct MakeFunctionTypeImpl<R, TypeList<Args...>> { |
| 270 | // MSVC 2013 doesn't support Type Alias of function types. |
| 271 | // Revisit this after we update it to newer version. |
| 272 | typedef R Type(Args...); |
| 273 | }; |
| 274 | |
| 275 | // A type-level function that constructs a function type that has |R| as its |
| 276 | // return type and has TypeLists items as its arguments. |
| 277 | template <typename R, typename ArgList> |
| 278 | using MakeFunctionType = typename MakeFunctionTypeImpl<R, ArgList>::Type; |
| 279 | |
| 280 | // Used for ExtractArgs and ExtractReturnType. |
| 281 | template <typename Signature> |
| 282 | struct ExtractArgsImpl; |
| 283 | |
| 284 | template <typename R, typename... Args> |
| 285 | struct ExtractArgsImpl<R(Args...)> { |
| 286 | using ReturnType = R; |
| 287 | using ArgsList = TypeList<Args...>; |
| 288 | }; |
| 289 | |
| 290 | // A type-level function that extracts function arguments into a TypeList. |
| 291 | // E.g. ExtractArgs<R(A, B, C)> is evaluated to TypeList<A, B, C>. |
| 292 | template <typename Signature> |
| 293 | using ExtractArgs = typename ExtractArgsImpl<Signature>::ArgsList; |
| 294 | |
| 295 | // A type-level function that extracts the return type of a function. |
| 296 | // E.g. ExtractReturnType<R(A, B, C)> is evaluated to R. |
| 297 | template <typename Signature> |
| 298 | using ExtractReturnType = typename ExtractArgsImpl<Signature>::ReturnType; |
| 299 | |
tzik | c1db7265 | 2016-07-08 09:42:38 | [diff] [blame] | 300 | template <typename Callable, |
| 301 | typename Signature = decltype(&Callable::operator())> |
| 302 | struct ExtractCallableRunTypeImpl; |
| 303 | |
| 304 | template <typename Callable, typename R, typename... Args> |
tzik | f98654b | 2017-12-02 03:28:58 | [diff] [blame] | 305 | struct ExtractCallableRunTypeImpl<Callable, R (Callable::*)(Args...)> { |
| 306 | using Type = R(Args...); |
| 307 | }; |
| 308 | |
| 309 | template <typename Callable, typename R, typename... Args> |
| 310 | struct ExtractCallableRunTypeImpl<Callable, R (Callable::*)(Args...) const> { |
tzik | c1db7265 | 2016-07-08 09:42:38 | [diff] [blame] | 311 | using Type = R(Args...); |
| 312 | }; |
| 313 | |
| 314 | // Evaluated to RunType of the given callable type. |
| 315 | // Example: |
| 316 | // auto f = [](int, char*) { return 0.1; }; |
| 317 | // ExtractCallableRunType<decltype(f)> |
| 318 | // is evaluated to |
| 319 | // double(int, char*); |
| 320 | template <typename Callable> |
| 321 | using ExtractCallableRunType = |
| 322 | typename ExtractCallableRunTypeImpl<Callable>::Type; |
| 323 | |
tzik | f98654b | 2017-12-02 03:28:58 | [diff] [blame] | 324 | // IsCallableObject<Functor> is std::true_type if |Functor| has operator(). |
| 325 | // Otherwise, it's std::false_type. |
tzik | c1db7265 | 2016-07-08 09:42:38 | [diff] [blame] | 326 | // Example: |
tzik | f98654b | 2017-12-02 03:28:58 | [diff] [blame] | 327 | // IsCallableObject<void(*)()>::value is false. |
tzik | c1db7265 | 2016-07-08 09:42:38 | [diff] [blame] | 328 | // |
| 329 | // struct Foo {}; |
tzik | f98654b | 2017-12-02 03:28:58 | [diff] [blame] | 330 | // IsCallableObject<void(Foo::*)()>::value is false. |
tzik | c1db7265 | 2016-07-08 09:42:38 | [diff] [blame] | 331 | // |
| 332 | // int i = 0; |
tzik | f98654b | 2017-12-02 03:28:58 | [diff] [blame] | 333 | // auto f = [i]() {}; |
| 334 | // IsCallableObject<decltype(f)>::value is false. |
tzik | c1db7265 | 2016-07-08 09:42:38 | [diff] [blame] | 335 | template <typename Functor, typename SFINAE = void> |
tzik | f98654b | 2017-12-02 03:28:58 | [diff] [blame] | 336 | struct IsCallableObject : std::false_type {}; |
tzik | c1db7265 | 2016-07-08 09:42:38 | [diff] [blame] | 337 | |
| 338 | template <typename Callable> |
tzik | f98654b | 2017-12-02 03:28:58 | [diff] [blame] | 339 | struct IsCallableObject<Callable, void_t<decltype(&Callable::operator())>> |
| 340 | : std::true_type {}; |
tzik | c1db7265 | 2016-07-08 09:42:38 | [diff] [blame] | 341 | |
tzik | 401dd367 | 2014-11-26 07:54:58 | [diff] [blame] | 342 | // HasRefCountedTypeAsRawPtr selects true_type when any of the |Args| is a raw |
| 343 | // pointer to a RefCounted type. |
| 344 | // Implementation note: This non-specialized case handles zero-arity case only. |
| 345 | // Non-zero-arity cases should be handled by the specialization below. |
| 346 | template <typename... Args> |
tzik | 403cb6c | 2016-03-10 07:17:25 | [diff] [blame] | 347 | struct HasRefCountedTypeAsRawPtr : std::false_type {}; |
tzik | 401dd367 | 2014-11-26 07:54:58 | [diff] [blame] | 348 | |
| 349 | // Implementation note: Select true_type if the first parameter is a raw pointer |
| 350 | // to a RefCounted type. Otherwise, skip the first parameter and check rest of |
| 351 | // parameters recursively. |
| 352 | template <typename T, typename... Args> |
| 353 | struct HasRefCountedTypeAsRawPtr<T, Args...> |
Jeremy Roman | 35a31743 | 2017-08-16 22:20:53 | [diff] [blame] | 354 | : std::conditional_t<NeedsScopedRefptrButGetsRawPtr<T>::value, |
| 355 | std::true_type, |
| 356 | HasRefCountedTypeAsRawPtr<Args...>> {}; |
tzik | 401dd367 | 2014-11-26 07:54:58 | [diff] [blame] | 357 | |
[email protected] | 7296f276 | 2011-11-21 19:23:44 | [diff] [blame] | 358 | // ForceVoidReturn<> |
| 359 | // |
| 360 | // Set of templates that support forcing the function return type to void. |
| 361 | template <typename Sig> |
| 362 | struct ForceVoidReturn; |
| 363 | |
tzik | c8214992 | 2014-11-20 10:09:45 | [diff] [blame] | 364 | template <typename R, typename... Args> |
| 365 | struct ForceVoidReturn<R(Args...)> { |
tzik | 99de02b | 2016-07-01 05:54:12 | [diff] [blame] | 366 | using RunType = void(Args...); |
[email protected] | fccef155 | 2011-11-28 22:13:54 | [diff] [blame] | 367 | }; |
| 368 | |
[email protected] | 7296f276 | 2011-11-21 19:23:44 | [diff] [blame] | 369 | // FunctorTraits<> |
| 370 | // |
| 371 | // See description at top of file. |
tzik | 6c92eab | 2016-11-25 15:56:36 | [diff] [blame] | 372 | template <typename Functor, typename SFINAE> |
tzik | 99de02b | 2016-07-01 05:54:12 | [diff] [blame] | 373 | struct FunctorTraits; |
| 374 | |
tzik | f98654b | 2017-12-02 03:28:58 | [diff] [blame] | 375 | // For empty callable types. |
tzik | c1db7265 | 2016-07-08 09:42:38 | [diff] [blame] | 376 | // This specialization is intended to allow binding captureless lambdas by |
tzik | f98654b | 2017-12-02 03:28:58 | [diff] [blame] | 377 | // base::Bind(), based on the fact that captureless lambdas are empty while |
| 378 | // capturing lambdas are not. This also allows any functors as far as it's an |
| 379 | // empty class. |
| 380 | // Example: |
| 381 | // |
| 382 | // // Captureless lambdas are allowed. |
| 383 | // []() {return 42;}; |
| 384 | // |
| 385 | // // Capturing lambdas are *not* allowed. |
| 386 | // int x; |
| 387 | // [x]() {return x;}; |
| 388 | // |
| 389 | // // Any empty class with operator() is allowed. |
| 390 | // struct Foo { |
| 391 | // void operator()() const {} |
| 392 | // // No non-static member variable and no virtual functions. |
| 393 | // }; |
tzik | c1db7265 | 2016-07-08 09:42:38 | [diff] [blame] | 394 | template <typename Functor> |
Jeremy Roman | 35a31743 | 2017-08-16 22:20:53 | [diff] [blame] | 395 | struct FunctorTraits<Functor, |
tzik | f98654b | 2017-12-02 03:28:58 | [diff] [blame] | 396 | std::enable_if_t<IsCallableObject<Functor>::value && |
| 397 | std::is_empty<Functor>::value>> { |
tzik | c1db7265 | 2016-07-08 09:42:38 | [diff] [blame] | 398 | using RunType = ExtractCallableRunType<Functor>; |
| 399 | static constexpr bool is_method = false; |
| 400 | static constexpr bool is_nullable = false; |
| 401 | |
tzik | f98654b | 2017-12-02 03:28:58 | [diff] [blame] | 402 | template <typename RunFunctor, typename... RunArgs> |
| 403 | static ExtractReturnType<RunType> Invoke(RunFunctor&& functor, |
| 404 | RunArgs&&... args) { |
| 405 | return std::forward<RunFunctor>(functor)(std::forward<RunArgs>(args)...); |
tzik | c1db7265 | 2016-07-08 09:42:38 | [diff] [blame] | 406 | } |
| 407 | }; |
| 408 | |
tzik | 99de02b | 2016-07-01 05:54:12 | [diff] [blame] | 409 | // For functions. |
| 410 | template <typename R, typename... Args> |
| 411 | struct FunctorTraits<R (*)(Args...)> { |
| 412 | using RunType = R(Args...); |
| 413 | static constexpr bool is_method = false; |
tzik | c1db7265 | 2016-07-08 09:42:38 | [diff] [blame] | 414 | static constexpr bool is_nullable = true; |
tzik | 99de02b | 2016-07-01 05:54:12 | [diff] [blame] | 415 | |
tzik | d58a8923 | 2018-04-26 04:29:53 | [diff] [blame] | 416 | template <typename Function, typename... RunArgs> |
| 417 | static R Invoke(Function&& function, RunArgs&&... args) { |
| 418 | return std::forward<Function>(function)(std::forward<RunArgs>(args)...); |
tzik | 99de02b | 2016-07-01 05:54:12 | [diff] [blame] | 419 | } |
[email protected] | 7296f276 | 2011-11-21 19:23:44 | [diff] [blame] | 420 | }; |
| 421 | |
Gaurav Dhol | f6e3f59 | 2018-10-29 17:22:41 | [diff] [blame] | 422 | #if defined(OS_WIN) && !defined(ARCH_CPU_64_BITS) |
tzik | 99de02b | 2016-07-01 05:54:12 | [diff] [blame] | 423 | |
| 424 | // For functions. |
| 425 | template <typename R, typename... Args> |
| 426 | struct FunctorTraits<R(__stdcall*)(Args...)> { |
| 427 | using RunType = R(Args...); |
| 428 | static constexpr bool is_method = false; |
tzik | c1db7265 | 2016-07-08 09:42:38 | [diff] [blame] | 429 | static constexpr bool is_nullable = true; |
tzik | 99de02b | 2016-07-01 05:54:12 | [diff] [blame] | 430 | |
| 431 | template <typename... RunArgs> |
| 432 | static R Invoke(R(__stdcall* function)(Args...), RunArgs&&... args) { |
| 433 | return function(std::forward<RunArgs>(args)...); |
| 434 | } |
| 435 | }; |
| 436 | |
| 437 | // For functions. |
| 438 | template <typename R, typename... Args> |
| 439 | struct FunctorTraits<R(__fastcall*)(Args...)> { |
| 440 | using RunType = R(Args...); |
| 441 | static constexpr bool is_method = false; |
tzik | c1db7265 | 2016-07-08 09:42:38 | [diff] [blame] | 442 | static constexpr bool is_nullable = true; |
tzik | 99de02b | 2016-07-01 05:54:12 | [diff] [blame] | 443 | |
| 444 | template <typename... RunArgs> |
| 445 | static R Invoke(R(__fastcall* function)(Args...), RunArgs&&... args) { |
| 446 | return function(std::forward<RunArgs>(args)...); |
| 447 | } |
| 448 | }; |
| 449 | |
Gaurav Dhol | f6e3f59 | 2018-10-29 17:22:41 | [diff] [blame] | 450 | #endif // defined(OS_WIN) && !defined(ARCH_CPU_64_BITS) |
tzik | 99de02b | 2016-07-01 05:54:12 | [diff] [blame] | 451 | |
Sylvain Defresne | ec3270c | 2018-05-31 17:19:15 | [diff] [blame] | 452 | #if defined(OS_MACOSX) |
| 453 | |
| 454 | // Support for Objective-C blocks. There are two implementation depending |
| 455 | // on whether Automated Reference Counting (ARC) is enabled. When ARC is |
| 456 | // enabled, then the block itself can be bound as the compiler will ensure |
| 457 | // its lifetime will be correctly managed. Otherwise, require the block to |
| 458 | // be wrapped in a base::mac::ScopedBlock (via base::RetainBlock) that will |
| 459 | // correctly manage the block lifetime. |
| 460 | // |
| 461 | // The two implementation ensure that the One Definition Rule (ODR) is not |
| 462 | // broken (it is not possible to write a template base::RetainBlock that would |
| 463 | // work correctly both with ARC enabled and disabled). |
| 464 | |
| 465 | #if HAS_FEATURE(objc_arc) |
| 466 | |
| 467 | template <typename R, typename... Args> |
| 468 | struct FunctorTraits<R (^)(Args...)> { |
| 469 | using RunType = R(Args...); |
| 470 | static constexpr bool is_method = false; |
| 471 | static constexpr bool is_nullable = true; |
| 472 | |
| 473 | template <typename BlockType, typename... RunArgs> |
| 474 | static R Invoke(BlockType&& block, RunArgs&&... args) { |
| 475 | // According to LLVM documentation (§ 6.3), "local variables of automatic |
| 476 | // storage duration do not have precise lifetime." Use objc_precise_lifetime |
| 477 | // to ensure that the Objective-C block is not deallocated until it has |
| 478 | // finished executing even if the Callback<> is destroyed during the block |
| 479 | // execution. |
| 480 | // https://clang.llvm.org/docs/AutomaticReferenceCounting.html#precise-lifetime-semantics |
| 481 | __attribute__((objc_precise_lifetime)) R (^scoped_block)(Args...) = block; |
| 482 | return scoped_block(std::forward<RunArgs>(args)...); |
| 483 | } |
| 484 | }; |
| 485 | |
| 486 | #else // HAS_FEATURE(objc_arc) |
| 487 | |
| 488 | template <typename R, typename... Args> |
| 489 | struct FunctorTraits<base::mac::ScopedBlock<R (^)(Args...)>> { |
| 490 | using RunType = R(Args...); |
| 491 | static constexpr bool is_method = false; |
| 492 | static constexpr bool is_nullable = true; |
| 493 | |
| 494 | template <typename BlockType, typename... RunArgs> |
| 495 | static R Invoke(BlockType&& block, RunArgs&&... args) { |
| 496 | // Copy the block to ensure that the Objective-C block is not deallocated |
| 497 | // until it has finished executing even if the Callback<> is destroyed |
| 498 | // during the block execution. |
| 499 | base::mac::ScopedBlock<R (^)(Args...)> scoped_block(block); |
| 500 | return scoped_block.get()(std::forward<RunArgs>(args)...); |
| 501 | } |
| 502 | }; |
| 503 | |
| 504 | #endif // HAS_FEATURE(objc_arc) |
| 505 | #endif // defined(OS_MACOSX) |
| 506 | |
tzik | 99de02b | 2016-07-01 05:54:12 | [diff] [blame] | 507 | // For methods. |
| 508 | template <typename R, typename Receiver, typename... Args> |
| 509 | struct FunctorTraits<R (Receiver::*)(Args...)> { |
| 510 | using RunType = R(Receiver*, Args...); |
| 511 | static constexpr bool is_method = true; |
tzik | c1db7265 | 2016-07-08 09:42:38 | [diff] [blame] | 512 | static constexpr bool is_nullable = true; |
tzik | 99de02b | 2016-07-01 05:54:12 | [diff] [blame] | 513 | |
tzik | d58a8923 | 2018-04-26 04:29:53 | [diff] [blame] | 514 | template <typename Method, typename ReceiverPtr, typename... RunArgs> |
| 515 | static R Invoke(Method method, |
tzik | 99de02b | 2016-07-01 05:54:12 | [diff] [blame] | 516 | ReceiverPtr&& receiver_ptr, |
| 517 | RunArgs&&... args) { |
tzik | 75851f4 | 2017-06-14 06:57:01 | [diff] [blame] | 518 | return ((*receiver_ptr).*method)(std::forward<RunArgs>(args)...); |
tzik | 99de02b | 2016-07-01 05:54:12 | [diff] [blame] | 519 | } |
| 520 | }; |
| 521 | |
| 522 | // For const methods. |
| 523 | template <typename R, typename Receiver, typename... Args> |
| 524 | struct FunctorTraits<R (Receiver::*)(Args...) const> { |
| 525 | using RunType = R(const Receiver*, Args...); |
| 526 | static constexpr bool is_method = true; |
tzik | c1db7265 | 2016-07-08 09:42:38 | [diff] [blame] | 527 | static constexpr bool is_nullable = true; |
tzik | 99de02b | 2016-07-01 05:54:12 | [diff] [blame] | 528 | |
tzik | d58a8923 | 2018-04-26 04:29:53 | [diff] [blame] | 529 | template <typename Method, typename ReceiverPtr, typename... RunArgs> |
| 530 | static R Invoke(Method method, |
tzik | 99de02b | 2016-07-01 05:54:12 | [diff] [blame] | 531 | ReceiverPtr&& receiver_ptr, |
| 532 | RunArgs&&... args) { |
tzik | 75851f4 | 2017-06-14 06:57:01 | [diff] [blame] | 533 | return ((*receiver_ptr).*method)(std::forward<RunArgs>(args)...); |
tzik | 99de02b | 2016-07-01 05:54:12 | [diff] [blame] | 534 | } |
| 535 | }; |
| 536 | |
tzik | d58a8923 | 2018-04-26 04:29:53 | [diff] [blame] | 537 | #ifdef __cpp_noexcept_function_type |
| 538 | // noexcept makes a distinct function type in C++17. |
| 539 | // I.e. `void(*)()` and `void(*)() noexcept` are same in pre-C++17, and |
| 540 | // different in C++17. |
| 541 | template <typename R, typename... Args> |
| 542 | struct FunctorTraits<R (*)(Args...) noexcept> : FunctorTraits<R (*)(Args...)> { |
| 543 | }; |
| 544 | |
| 545 | template <typename R, typename Receiver, typename... Args> |
| 546 | struct FunctorTraits<R (Receiver::*)(Args...) noexcept> |
| 547 | : FunctorTraits<R (Receiver::*)(Args...)> {}; |
| 548 | |
| 549 | template <typename R, typename Receiver, typename... Args> |
| 550 | struct FunctorTraits<R (Receiver::*)(Args...) const noexcept> |
| 551 | : FunctorTraits<R (Receiver::*)(Args...) const> {}; |
| 552 | #endif |
| 553 | |
tzik | 99de02b | 2016-07-01 05:54:12 | [diff] [blame] | 554 | // For IgnoreResults. |
[email protected] | 7296f276 | 2011-11-21 19:23:44 | [diff] [blame] | 555 | template <typename T> |
tzik | 99de02b | 2016-07-01 05:54:12 | [diff] [blame] | 556 | struct FunctorTraits<IgnoreResultHelper<T>> : FunctorTraits<T> { |
tzik | 3bc7779b | 2015-12-19 09:18:46 | [diff] [blame] | 557 | using RunType = |
tzik | 99de02b | 2016-07-01 05:54:12 | [diff] [blame] | 558 | typename ForceVoidReturn<typename FunctorTraits<T>::RunType>::RunType; |
| 559 | |
| 560 | template <typename IgnoreResultType, typename... RunArgs> |
| 561 | static void Invoke(IgnoreResultType&& ignore_result_helper, |
| 562 | RunArgs&&... args) { |
tzik | ff54a5b15 | 2016-08-31 11:50:41 | [diff] [blame] | 563 | FunctorTraits<T>::Invoke( |
| 564 | std::forward<IgnoreResultType>(ignore_result_helper).functor_, |
| 565 | std::forward<RunArgs>(args)...); |
tzik | 99de02b | 2016-07-01 05:54:12 | [diff] [blame] | 566 | } |
[email protected] | 7296f276 | 2011-11-21 19:23:44 | [diff] [blame] | 567 | }; |
| 568 | |
tzik | d4bb5b7d | 2017-08-28 19:08:52 | [diff] [blame] | 569 | // For OnceCallbacks. |
| 570 | template <typename R, typename... Args> |
| 571 | struct FunctorTraits<OnceCallback<R(Args...)>> { |
| 572 | using RunType = R(Args...); |
| 573 | static constexpr bool is_method = false; |
| 574 | static constexpr bool is_nullable = true; |
| 575 | |
| 576 | template <typename CallbackType, typename... RunArgs> |
| 577 | static R Invoke(CallbackType&& callback, RunArgs&&... args) { |
| 578 | DCHECK(!callback.is_null()); |
| 579 | return std::forward<CallbackType>(callback).Run( |
| 580 | std::forward<RunArgs>(args)...); |
| 581 | } |
| 582 | }; |
| 583 | |
| 584 | // For RepeatingCallbacks. |
| 585 | template <typename R, typename... Args> |
| 586 | struct FunctorTraits<RepeatingCallback<R(Args...)>> { |
tzik | 99de02b | 2016-07-01 05:54:12 | [diff] [blame] | 587 | using RunType = R(Args...); |
| 588 | static constexpr bool is_method = false; |
tzik | c1db7265 | 2016-07-08 09:42:38 | [diff] [blame] | 589 | static constexpr bool is_nullable = true; |
tzik | 99de02b | 2016-07-01 05:54:12 | [diff] [blame] | 590 | |
| 591 | template <typename CallbackType, typename... RunArgs> |
| 592 | static R Invoke(CallbackType&& callback, RunArgs&&... args) { |
| 593 | DCHECK(!callback.is_null()); |
| 594 | return std::forward<CallbackType>(callback).Run( |
| 595 | std::forward<RunArgs>(args)...); |
| 596 | } |
[email protected] | 7296f276 | 2011-11-21 19:23:44 | [diff] [blame] | 597 | }; |
| 598 | |
tzik | ae4202e | 2017-07-31 10:41:54 | [diff] [blame] | 599 | template <typename Functor> |
Jeremy Roman | 35a31743 | 2017-08-16 22:20:53 | [diff] [blame] | 600 | using MakeFunctorTraits = FunctorTraits<std::decay_t<Functor>>; |
tzik | ae4202e | 2017-07-31 10:41:54 | [diff] [blame] | 601 | |
[email protected] | 7296f276 | 2011-11-21 19:23:44 | [diff] [blame] | 602 | // InvokeHelper<> |
| 603 | // |
tzik | 99de02b | 2016-07-01 05:54:12 | [diff] [blame] | 604 | // There are 2 logical InvokeHelper<> specializations: normal, WeakCalls. |
[email protected] | 7296f276 | 2011-11-21 19:23:44 | [diff] [blame] | 605 | // |
| 606 | // The normal type just calls the underlying runnable. |
| 607 | // |
tzik | 99de02b | 2016-07-01 05:54:12 | [diff] [blame] | 608 | // WeakCalls need special syntax that is applied to the first argument to check |
| 609 | // if they should no-op themselves. |
tzik | ee24872 | 2016-06-01 08:22:51 | [diff] [blame] | 610 | template <bool is_weak_call, typename ReturnType> |
[email protected] | 7296f276 | 2011-11-21 19:23:44 | [diff] [blame] | 611 | struct InvokeHelper; |
| 612 | |
tzik | ee24872 | 2016-06-01 08:22:51 | [diff] [blame] | 613 | template <typename ReturnType> |
| 614 | struct InvokeHelper<false, ReturnType> { |
tzik | 99de02b | 2016-07-01 05:54:12 | [diff] [blame] | 615 | template <typename Functor, typename... RunArgs> |
| 616 | static inline ReturnType MakeItSo(Functor&& functor, RunArgs&&... args) { |
tzik | ae4202e | 2017-07-31 10:41:54 | [diff] [blame] | 617 | using Traits = MakeFunctorTraits<Functor>; |
tzik | 99de02b | 2016-07-01 05:54:12 | [diff] [blame] | 618 | return Traits::Invoke(std::forward<Functor>(functor), |
| 619 | std::forward<RunArgs>(args)...); |
[email protected] | 7296f276 | 2011-11-21 19:23:44 | [diff] [blame] | 620 | } |
| 621 | }; |
| 622 | |
tzik | ee24872 | 2016-06-01 08:22:51 | [diff] [blame] | 623 | template <typename ReturnType> |
| 624 | struct InvokeHelper<true, ReturnType> { |
[email protected] | 7296f276 | 2011-11-21 19:23:44 | [diff] [blame] | 625 | // WeakCalls are only supported for functions with a void return type. |
| 626 | // Otherwise, the function result would be undefined if the the WeakPtr<> |
| 627 | // is invalidated. |
tzik | 403cb6c | 2016-03-10 07:17:25 | [diff] [blame] | 628 | static_assert(std::is_void<ReturnType>::value, |
avi | 4ec0dff | 2015-11-24 14:26:24 | [diff] [blame] | 629 | "weak_ptrs can only bind to methods without return values"); |
[email protected] | c18b105 | 2011-03-24 02:02:17 | [diff] [blame] | 630 | |
tzik | 99de02b | 2016-07-01 05:54:12 | [diff] [blame] | 631 | template <typename Functor, typename BoundWeakPtr, typename... RunArgs> |
| 632 | static inline void MakeItSo(Functor&& functor, |
tzik | 33871d8 | 2016-07-14 12:12:06 | [diff] [blame] | 633 | BoundWeakPtr&& weak_ptr, |
tzik | 99de02b | 2016-07-01 05:54:12 | [diff] [blame] | 634 | RunArgs&&... args) { |
| 635 | if (!weak_ptr) |
| 636 | return; |
tzik | ae4202e | 2017-07-31 10:41:54 | [diff] [blame] | 637 | using Traits = MakeFunctorTraits<Functor>; |
tzik | 99de02b | 2016-07-01 05:54:12 | [diff] [blame] | 638 | Traits::Invoke(std::forward<Functor>(functor), |
| 639 | std::forward<BoundWeakPtr>(weak_ptr), |
| 640 | std::forward<RunArgs>(args)...); |
| 641 | } |
| 642 | }; |
[email protected] | b38d357 | 2011-02-15 01:27:38 | [diff] [blame] | 643 | |
[email protected] | 7296f276 | 2011-11-21 19:23:44 | [diff] [blame] | 644 | // Invoker<> |
| 645 | // |
| 646 | // See description at the top of the file. |
tzik | caf1d84b | 2016-06-28 12:22:21 | [diff] [blame] | 647 | template <typename StorageType, typename UnboundRunType> |
[email protected] | 7296f276 | 2011-11-21 19:23:44 | [diff] [blame] | 648 | struct Invoker; |
| 649 | |
tzik | caf1d84b | 2016-06-28 12:22:21 | [diff] [blame] | 650 | template <typename StorageType, typename R, typename... UnboundArgs> |
| 651 | struct Invoker<StorageType, R(UnboundArgs...)> { |
Vladislav Kuzkokov | 6d208e1 | 2017-11-08 21:31:08 | [diff] [blame] | 652 | static R RunOnce(BindStateBase* base, |
tzik | 9bc6837b | 2018-06-28 20:20:47 | [diff] [blame] | 653 | PassingType<UnboundArgs>... unbound_args) { |
tzik | 27d1e31 | 2016-09-13 05:28:59 | [diff] [blame] | 654 | // Local references to make debugger stepping easier. If in a debugger, |
| 655 | // you really want to warp ahead and step through the |
| 656 | // InvokeHelper<>::MakeItSo() call below. |
| 657 | StorageType* storage = static_cast<StorageType*>(base); |
| 658 | static constexpr size_t num_bound_args = |
| 659 | std::tuple_size<decltype(storage->bound_args_)>::value; |
| 660 | return RunImpl(std::move(storage->functor_), |
| 661 | std::move(storage->bound_args_), |
Jeremy Roman | 84956fa | 2017-08-16 15:55:20 | [diff] [blame] | 662 | std::make_index_sequence<num_bound_args>(), |
tzik | 27d1e31 | 2016-09-13 05:28:59 | [diff] [blame] | 663 | std::forward<UnboundArgs>(unbound_args)...); |
| 664 | } |
| 665 | |
tzik | 9bc6837b | 2018-06-28 20:20:47 | [diff] [blame] | 666 | static R Run(BindStateBase* base, PassingType<UnboundArgs>... unbound_args) { |
[email protected] | 7296f276 | 2011-11-21 19:23:44 | [diff] [blame] | 667 | // Local references to make debugger stepping easier. If in a debugger, |
| 668 | // you really want to warp ahead and step through the |
| 669 | // InvokeHelper<>::MakeItSo() call below. |
tzik | caf1d84b | 2016-06-28 12:22:21 | [diff] [blame] | 670 | const StorageType* storage = static_cast<StorageType*>(base); |
| 671 | static constexpr size_t num_bound_args = |
| 672 | std::tuple_size<decltype(storage->bound_args_)>::value; |
Jeremy Roman | 84956fa | 2017-08-16 15:55:20 | [diff] [blame] | 673 | return RunImpl(storage->functor_, storage->bound_args_, |
| 674 | std::make_index_sequence<num_bound_args>(), |
tzik | caf1d84b | 2016-06-28 12:22:21 | [diff] [blame] | 675 | std::forward<UnboundArgs>(unbound_args)...); |
| 676 | } |
| 677 | |
tzik | 99de02b | 2016-07-01 05:54:12 | [diff] [blame] | 678 | private: |
| 679 | template <typename Functor, typename BoundArgsTuple, size_t... indices> |
| 680 | static inline R RunImpl(Functor&& functor, |
tzik | caf1d84b | 2016-06-28 12:22:21 | [diff] [blame] | 681 | BoundArgsTuple&& bound, |
Jeremy Roman | 84956fa | 2017-08-16 15:55:20 | [diff] [blame] | 682 | std::index_sequence<indices...>, |
tzik | caf1d84b | 2016-06-28 12:22:21 | [diff] [blame] | 683 | UnboundArgs&&... unbound_args) { |
tzik | ae4202e | 2017-07-31 10:41:54 | [diff] [blame] | 684 | static constexpr bool is_method = MakeFunctorTraits<Functor>::is_method; |
tzik | caf1d84b | 2016-06-28 12:22:21 | [diff] [blame] | 685 | |
Jeremy Roman | 35a31743 | 2017-08-16 22:20:53 | [diff] [blame] | 686 | using DecayedArgsTuple = std::decay_t<BoundArgsTuple>; |
tzik | caf1d84b | 2016-06-28 12:22:21 | [diff] [blame] | 687 | static constexpr bool is_weak_call = |
| 688 | IsWeakMethod<is_method, |
Jeremy Roman | 35a31743 | 2017-08-16 22:20:53 | [diff] [blame] | 689 | std::tuple_element_t<indices, DecayedArgsTuple>...>(); |
tzik | caf1d84b | 2016-06-28 12:22:21 | [diff] [blame] | 690 | |
tzik | ee24872 | 2016-06-01 08:22:51 | [diff] [blame] | 691 | return InvokeHelper<is_weak_call, R>::MakeItSo( |
tzik | 99de02b | 2016-07-01 05:54:12 | [diff] [blame] | 692 | std::forward<Functor>(functor), |
tzik | f7c4757 | 2017-04-05 21:45:03 | [diff] [blame] | 693 | Unwrap(std::get<indices>(std::forward<BoundArgsTuple>(bound)))..., |
tzik | a43eff0 | 2016-03-09 05:46:05 | [diff] [blame] | 694 | std::forward<UnboundArgs>(unbound_args)...); |
[email protected] | fccef155 | 2011-11-28 22:13:54 | [diff] [blame] | 695 | } |
| 696 | }; |
| 697 | |
tzik | ae4202e | 2017-07-31 10:41:54 | [diff] [blame] | 698 | // Extracts necessary type info from Functor and BoundArgs. |
| 699 | // Used to implement MakeUnboundRunType, BindOnce and BindRepeating. |
tzik | caf1d84b | 2016-06-28 12:22:21 | [diff] [blame] | 700 | template <typename Functor, typename... BoundArgs> |
tzik | ae4202e | 2017-07-31 10:41:54 | [diff] [blame] | 701 | struct BindTypeHelper { |
| 702 | static constexpr size_t num_bounds = sizeof...(BoundArgs); |
| 703 | using FunctorTraits = MakeFunctorTraits<Functor>; |
| 704 | |
| 705 | // Example: |
| 706 | // When Functor is `double (Foo::*)(int, const std::string&)`, and BoundArgs |
| 707 | // is a template pack of `Foo*` and `int16_t`: |
| 708 | // - RunType is `double(Foo*, int, const std::string&)`, |
| 709 | // - ReturnType is `double`, |
| 710 | // - RunParamsList is `TypeList<Foo*, int, const std::string&>`, |
| 711 | // - BoundParamsList is `TypeList<Foo*, int>`, |
| 712 | // - UnboundParamsList is `TypeList<const std::string&>`, |
| 713 | // - BoundArgsList is `TypeList<Foo*, int16_t>`, |
| 714 | // - UnboundRunType is `double(const std::string&)`. |
| 715 | using RunType = typename FunctorTraits::RunType; |
tzik | caf1d84b | 2016-06-28 12:22:21 | [diff] [blame] | 716 | using ReturnType = ExtractReturnType<RunType>; |
tzik | ae4202e | 2017-07-31 10:41:54 | [diff] [blame] | 717 | |
| 718 | using RunParamsList = ExtractArgs<RunType>; |
| 719 | using BoundParamsList = TakeTypeListItem<num_bounds, RunParamsList>; |
| 720 | using UnboundParamsList = DropTypeListItem<num_bounds, RunParamsList>; |
| 721 | |
| 722 | using BoundArgsList = TypeList<BoundArgs...>; |
| 723 | |
| 724 | using UnboundRunType = MakeFunctionType<ReturnType, UnboundParamsList>; |
tzik | caf1d84b | 2016-06-28 12:22:21 | [diff] [blame] | 725 | }; |
tzik | ae4202e | 2017-07-31 10:41:54 | [diff] [blame] | 726 | |
tzik | c1db7265 | 2016-07-08 09:42:38 | [diff] [blame] | 727 | template <typename Functor> |
Jeremy Roman | 35a31743 | 2017-08-16 22:20:53 | [diff] [blame] | 728 | std::enable_if_t<FunctorTraits<Functor>::is_nullable, bool> IsNull( |
| 729 | const Functor& functor) { |
tzik | c1db7265 | 2016-07-08 09:42:38 | [diff] [blame] | 730 | return !functor; |
| 731 | } |
| 732 | |
| 733 | template <typename Functor> |
Jeremy Roman | 35a31743 | 2017-08-16 22:20:53 | [diff] [blame] | 734 | std::enable_if_t<!FunctorTraits<Functor>::is_nullable, bool> IsNull( |
| 735 | const Functor&) { |
tzik | c1db7265 | 2016-07-08 09:42:38 | [diff] [blame] | 736 | return false; |
| 737 | } |
tzik | caf1d84b | 2016-06-28 12:22:21 | [diff] [blame] | 738 | |
tzik | 9697d49e | 2018-08-02 13:35:19 | [diff] [blame] | 739 | // Used by QueryCancellationTraits below. |
tzik | 6c92eab | 2016-11-25 15:56:36 | [diff] [blame] | 740 | template <typename Functor, typename BoundArgsTuple, size_t... indices> |
tzik | 9697d49e | 2018-08-02 13:35:19 | [diff] [blame] | 741 | bool QueryCancellationTraitsImpl(BindStateBase::CancellationQueryMode mode, |
| 742 | const Functor& functor, |
| 743 | const BoundArgsTuple& bound_args, |
| 744 | std::index_sequence<indices...>) { |
| 745 | switch (mode) { |
| 746 | case BindStateBase::IS_CANCELLED: |
| 747 | return CallbackCancellationTraits<Functor, BoundArgsTuple>::IsCancelled( |
| 748 | functor, std::get<indices>(bound_args)...); |
| 749 | case BindStateBase::MAYBE_VALID: |
| 750 | return CallbackCancellationTraits<Functor, BoundArgsTuple>::MaybeValid( |
| 751 | functor, std::get<indices>(bound_args)...); |
| 752 | } |
| 753 | NOTREACHED(); |
tzik | 6c92eab | 2016-11-25 15:56:36 | [diff] [blame] | 754 | } |
tzik | 59aa6bb1 | 2016-09-08 10:58:53 | [diff] [blame] | 755 | |
tzik | 6c92eab | 2016-11-25 15:56:36 | [diff] [blame] | 756 | // Relays |base| to corresponding CallbackCancellationTraits<>::Run(). Returns |
| 757 | // true if the callback |base| represents is canceled. |
| 758 | template <typename BindStateType> |
tzik | 9697d49e | 2018-08-02 13:35:19 | [diff] [blame] | 759 | bool QueryCancellationTraits(const BindStateBase* base, |
| 760 | BindStateBase::CancellationQueryMode mode) { |
tzik | 6c92eab | 2016-11-25 15:56:36 | [diff] [blame] | 761 | const BindStateType* storage = static_cast<const BindStateType*>(base); |
| 762 | static constexpr size_t num_bound_args = |
| 763 | std::tuple_size<decltype(storage->bound_args_)>::value; |
tzik | 9697d49e | 2018-08-02 13:35:19 | [diff] [blame] | 764 | return QueryCancellationTraitsImpl( |
| 765 | mode, storage->functor_, storage->bound_args_, |
Nicolas Ouellet-payeur | 40f8e9a | 2018-07-30 16:26:48 | [diff] [blame] | 766 | std::make_index_sequence<num_bound_args>()); |
Nicolas Ouellet-payeur | 40f8e9a | 2018-07-30 16:26:48 | [diff] [blame] | 767 | } |
| 768 | |
tzik | efea4f5 | 2018-08-02 15:20:46 | [diff] [blame] | 769 | // The base case of BanUnconstructedRefCountedReceiver that checks nothing. |
| 770 | template <typename Functor, typename Receiver, typename... Unused> |
| 771 | std::enable_if_t< |
| 772 | !(MakeFunctorTraits<Functor>::is_method && |
| 773 | std::is_pointer<std::decay_t<Receiver>>::value && |
| 774 | IsRefCountedType<std::remove_pointer_t<std::decay_t<Receiver>>>::value)> |
| 775 | BanUnconstructedRefCountedReceiver(const Receiver& receiver, Unused&&...) {} |
| 776 | |
| 777 | template <typename Functor> |
| 778 | void BanUnconstructedRefCountedReceiver() {} |
| 779 | |
| 780 | // Asserts that Callback is not the first owner of a ref-counted receiver. |
| 781 | template <typename Functor, typename Receiver, typename... Unused> |
| 782 | std::enable_if_t< |
| 783 | MakeFunctorTraits<Functor>::is_method && |
| 784 | std::is_pointer<std::decay_t<Receiver>>::value && |
| 785 | IsRefCountedType<std::remove_pointer_t<std::decay_t<Receiver>>>::value> |
| 786 | BanUnconstructedRefCountedReceiver(const Receiver& receiver, Unused&&...) { |
| 787 | DCHECK(receiver); |
| 788 | |
| 789 | // It's error prone to make the implicit first reference to ref-counted types. |
| 790 | // In the example below, base::BindOnce() makes the implicit first reference |
| 791 | // to the ref-counted Foo. If PostTask() failed or the posted task ran fast |
| 792 | // enough, the newly created instance can be destroyed before |oo| makes |
| 793 | // another reference. |
| 794 | // Foo::Foo() { |
| 795 | // base::PostTask(FROM_HERE, base::BindOnce(&Foo::Bar, this)); |
| 796 | // } |
| 797 | // |
| 798 | // scoped_refptr<Foo> oo = new Foo(); |
| 799 | // |
| 800 | // Instead of doing like above, please consider adding a static constructor, |
| 801 | // and keep the first reference alive explicitly. |
| 802 | // // static |
| 803 | // scoped_refptr<Foo> Foo::Create() { |
| 804 | // auto foo = base::WrapRefCounted(new Foo()); |
| 805 | // base::PostTask(FROM_HERE, base::BindOnce(&Foo::Bar, foo)); |
| 806 | // return foo; |
| 807 | // } |
| 808 | // |
| 809 | // Foo::Foo() {} |
| 810 | // |
| 811 | // scoped_refptr<Foo> oo = Foo::Create(); |
| 812 | DCHECK(receiver->HasAtLeastOneRef()) |
| 813 | << "base::Bind() refuses to create the first reference to ref-counted " |
| 814 | "objects. That is typically happens around PostTask() in their " |
| 815 | "constructor, and such objects can be destroyed before `new` returns " |
| 816 | "if the task resolves fast enough."; |
| 817 | } |
| 818 | |
[email protected] | 7296f276 | 2011-11-21 19:23:44 | [diff] [blame] | 819 | // BindState<> |
| 820 | // |
tzik | 99de02b | 2016-07-01 05:54:12 | [diff] [blame] | 821 | // This stores all the state passed into Bind(). |
| 822 | template <typename Functor, typename... BoundArgs> |
| 823 | struct BindState final : BindStateBase { |
tzik | 1fdcca3 | 2016-09-14 07:15:00 | [diff] [blame] | 824 | using IsCancellable = std::integral_constant< |
tzik | 6c92eab | 2016-11-25 15:56:36 | [diff] [blame] | 825 | bool, |
| 826 | CallbackCancellationTraits<Functor, |
| 827 | std::tuple<BoundArgs...>>::is_cancellable>; |
tzik | 1fdcca3 | 2016-09-14 07:15:00 | [diff] [blame] | 828 | |
tzik | bfe6612 | 2016-07-08 14:14:01 | [diff] [blame] | 829 | template <typename ForwardFunctor, typename... ForwardBoundArgs> |
tzik | efea4f5 | 2018-08-02 15:20:46 | [diff] [blame] | 830 | static BindState* Create(BindStateBase::InvokeFuncStorage invoke_func, |
| 831 | ForwardFunctor&& functor, |
| 832 | ForwardBoundArgs&&... bound_args) { |
| 833 | // Ban ref counted receivers that were not yet fully constructed to avoid |
| 834 | // a common pattern of racy situation. |
| 835 | BanUnconstructedRefCountedReceiver<ForwardFunctor>(bound_args...); |
| 836 | |
| 837 | // IsCancellable is std::false_type if |
| 838 | // CallbackCancellationTraits<>::IsCancelled returns always false. |
| 839 | // Otherwise, it's std::true_type. |
| 840 | return new BindState(IsCancellable{}, invoke_func, |
| 841 | std::forward<ForwardFunctor>(functor), |
| 842 | std::forward<ForwardBoundArgs>(bound_args)...); |
| 843 | } |
tzik | 1fdcca3 | 2016-09-14 07:15:00 | [diff] [blame] | 844 | |
| 845 | Functor functor_; |
| 846 | std::tuple<BoundArgs...> bound_args_; |
| 847 | |
| 848 | private: |
| 849 | template <typename ForwardFunctor, typename... ForwardBoundArgs> |
| 850 | explicit BindState(std::true_type, |
| 851 | BindStateBase::InvokeFuncStorage invoke_func, |
| 852 | ForwardFunctor&& functor, |
| 853 | ForwardBoundArgs&&... bound_args) |
tzik | 6c92eab | 2016-11-25 15:56:36 | [diff] [blame] | 854 | : BindStateBase(invoke_func, |
| 855 | &Destroy, |
tzik | 9697d49e | 2018-08-02 13:35:19 | [diff] [blame] | 856 | &QueryCancellationTraits<BindState>), |
tzik | ff54a5b15 | 2016-08-31 11:50:41 | [diff] [blame] | 857 | functor_(std::forward<ForwardFunctor>(functor)), |
tzik | 99de02b | 2016-07-01 05:54:12 | [diff] [blame] | 858 | bound_args_(std::forward<ForwardBoundArgs>(bound_args)...) { |
tzik | c1db7265 | 2016-07-08 09:42:38 | [diff] [blame] | 859 | DCHECK(!IsNull(functor_)); |
tzik | 99de02b | 2016-07-01 05:54:12 | [diff] [blame] | 860 | } |
[email protected] | 7296f276 | 2011-11-21 19:23:44 | [diff] [blame] | 861 | |
tzik | 1fdcca3 | 2016-09-14 07:15:00 | [diff] [blame] | 862 | template <typename ForwardFunctor, typename... ForwardBoundArgs> |
| 863 | explicit BindState(std::false_type, |
| 864 | BindStateBase::InvokeFuncStorage invoke_func, |
| 865 | ForwardFunctor&& functor, |
| 866 | ForwardBoundArgs&&... bound_args) |
| 867 | : BindStateBase(invoke_func, &Destroy), |
| 868 | functor_(std::forward<ForwardFunctor>(functor)), |
| 869 | bound_args_(std::forward<ForwardBoundArgs>(bound_args)...) { |
| 870 | DCHECK(!IsNull(functor_)); |
| 871 | } |
dmichael | 7d09007e | 2014-12-18 22:30:11 | [diff] [blame] | 872 | |
Chris Watkins | 091d629 | 2017-12-13 04:25:58 | [diff] [blame] | 873 | ~BindState() = default; |
tapted | e7e804c | 2015-05-14 08:03:32 | [diff] [blame] | 874 | |
tzik | 30e0c31 | 2016-09-21 08:06:54 | [diff] [blame] | 875 | static void Destroy(const BindStateBase* self) { |
| 876 | delete static_cast<const BindState*>(self); |
tapted | e7e804c | 2015-05-14 08:03:32 | [diff] [blame] | 877 | } |
[email protected] | fccef155 | 2011-11-28 22:13:54 | [diff] [blame] | 878 | }; |
| 879 | |
tzik | 99de02b | 2016-07-01 05:54:12 | [diff] [blame] | 880 | // Used to implement MakeBindStateType. |
| 881 | template <bool is_method, typename Functor, typename... BoundArgs> |
| 882 | struct MakeBindStateTypeImpl; |
| 883 | |
| 884 | template <typename Functor, typename... BoundArgs> |
| 885 | struct MakeBindStateTypeImpl<false, Functor, BoundArgs...> { |
Jeremy Roman | 35a31743 | 2017-08-16 22:20:53 | [diff] [blame] | 886 | static_assert(!HasRefCountedTypeAsRawPtr<std::decay_t<BoundArgs>...>::value, |
tzik | 99de02b | 2016-07-01 05:54:12 | [diff] [blame] | 887 | "A parameter is a refcounted type and needs scoped_refptr."); |
Jeremy Roman | 35a31743 | 2017-08-16 22:20:53 | [diff] [blame] | 888 | using Type = BindState<std::decay_t<Functor>, std::decay_t<BoundArgs>...>; |
tzik | 99de02b | 2016-07-01 05:54:12 | [diff] [blame] | 889 | }; |
| 890 | |
| 891 | template <typename Functor> |
| 892 | struct MakeBindStateTypeImpl<true, Functor> { |
Jeremy Roman | 35a31743 | 2017-08-16 22:20:53 | [diff] [blame] | 893 | using Type = BindState<std::decay_t<Functor>>; |
tzik | 99de02b | 2016-07-01 05:54:12 | [diff] [blame] | 894 | }; |
| 895 | |
| 896 | template <typename Functor, typename Receiver, typename... BoundArgs> |
| 897 | struct MakeBindStateTypeImpl<true, Functor, Receiver, BoundArgs...> { |
tzik | 99de02b | 2016-07-01 05:54:12 | [diff] [blame] | 898 | private: |
Jeremy Roman | 35a31743 | 2017-08-16 22:20:53 | [diff] [blame] | 899 | using DecayedReceiver = std::decay_t<Receiver>; |
tzik | 99de02b | 2016-07-01 05:54:12 | [diff] [blame] | 900 | |
tzik | 4625ac61 | 2018-02-28 09:43:55 | [diff] [blame] | 901 | static_assert(!std::is_array<std::remove_reference_t<Receiver>>::value, |
| 902 | "First bound argument to a method cannot be an array."); |
| 903 | static_assert( |
| 904 | !std::is_pointer<DecayedReceiver>::value || |
| 905 | IsRefCountedType<std::remove_pointer_t<DecayedReceiver>>::value, |
| 906 | "Receivers may not be raw pointers. If using a raw pointer here is safe" |
| 907 | " and has no lifetime concerns, use base::Unretained() and document why" |
| 908 | " it's safe."); |
| 909 | static_assert(!HasRefCountedTypeAsRawPtr<std::decay_t<BoundArgs>...>::value, |
| 910 | "A parameter is a refcounted type and needs scoped_refptr."); |
| 911 | |
tzik | 99de02b | 2016-07-01 05:54:12 | [diff] [blame] | 912 | public: |
| 913 | using Type = BindState< |
Jeremy Roman | 35a31743 | 2017-08-16 22:20:53 | [diff] [blame] | 914 | std::decay_t<Functor>, |
| 915 | std::conditional_t<std::is_pointer<DecayedReceiver>::value, |
| 916 | scoped_refptr<std::remove_pointer_t<DecayedReceiver>>, |
| 917 | DecayedReceiver>, |
| 918 | std::decay_t<BoundArgs>...>; |
tzik | 99de02b | 2016-07-01 05:54:12 | [diff] [blame] | 919 | }; |
| 920 | |
| 921 | template <typename Functor, typename... BoundArgs> |
tzik | ae4202e | 2017-07-31 10:41:54 | [diff] [blame] | 922 | using MakeBindStateType = |
| 923 | typename MakeBindStateTypeImpl<MakeFunctorTraits<Functor>::is_method, |
| 924 | Functor, |
| 925 | BoundArgs...>::Type; |
tzik | 99de02b | 2016-07-01 05:54:12 | [diff] [blame] | 926 | |
[email protected] | b38d357 | 2011-02-15 01:27:38 | [diff] [blame] | 927 | } // namespace internal |
tzik | caf1d84b | 2016-06-28 12:22:21 | [diff] [blame] | 928 | |
Peter Kasting | a85265e3 | 2018-02-15 08:30:23 | [diff] [blame] | 929 | // An injection point to control |this| pointer behavior on a method invocation. |
| 930 | // If IsWeakReceiver<> is true_type for |T| and |T| is used for a receiver of a |
| 931 | // method, base::Bind cancels the method invocation if the receiver is tested as |
| 932 | // false. |
| 933 | // E.g. Foo::bar() is not called: |
| 934 | // struct Foo : base::SupportsWeakPtr<Foo> { |
| 935 | // void bar() {} |
| 936 | // }; |
| 937 | // |
| 938 | // WeakPtr<Foo> oo = nullptr; |
| 939 | // base::Bind(&Foo::bar, oo).Run(); |
| 940 | template <typename T> |
| 941 | struct IsWeakReceiver : std::false_type {}; |
| 942 | |
| 943 | template <typename T> |
| 944 | struct IsWeakReceiver<internal::ConstRefWrapper<T>> : IsWeakReceiver<T> {}; |
| 945 | |
| 946 | template <typename T> |
| 947 | struct IsWeakReceiver<WeakPtr<T>> : std::true_type {}; |
| 948 | |
| 949 | // An injection point to control how bound objects passed to the target |
| 950 | // function. BindUnwrapTraits<>::Unwrap() is called for each bound objects right |
| 951 | // before the target function is invoked. |
| 952 | template <typename> |
| 953 | struct BindUnwrapTraits { |
| 954 | template <typename T> |
| 955 | static T&& Unwrap(T&& o) { |
| 956 | return std::forward<T>(o); |
| 957 | } |
| 958 | }; |
| 959 | |
| 960 | template <typename T> |
| 961 | struct BindUnwrapTraits<internal::UnretainedWrapper<T>> { |
| 962 | static T* Unwrap(const internal::UnretainedWrapper<T>& o) { return o.get(); } |
| 963 | }; |
| 964 | |
| 965 | template <typename T> |
| 966 | struct BindUnwrapTraits<internal::ConstRefWrapper<T>> { |
| 967 | static const T& Unwrap(const internal::ConstRefWrapper<T>& o) { |
| 968 | return o.get(); |
| 969 | } |
| 970 | }; |
| 971 | |
| 972 | template <typename T> |
| 973 | struct BindUnwrapTraits<internal::RetainedRefWrapper<T>> { |
| 974 | static T* Unwrap(const internal::RetainedRefWrapper<T>& o) { return o.get(); } |
| 975 | }; |
| 976 | |
| 977 | template <typename T> |
| 978 | struct BindUnwrapTraits<internal::OwnedWrapper<T>> { |
| 979 | static T* Unwrap(const internal::OwnedWrapper<T>& o) { return o.get(); } |
| 980 | }; |
| 981 | |
| 982 | template <typename T> |
| 983 | struct BindUnwrapTraits<internal::PassedWrapper<T>> { |
| 984 | static T Unwrap(const internal::PassedWrapper<T>& o) { return o.Take(); } |
| 985 | }; |
| 986 | |
tzik | c44f810 | 2018-07-24 09:49:19 | [diff] [blame] | 987 | #if defined(OS_WIN) |
| 988 | template <typename T> |
| 989 | struct BindUnwrapTraits<Microsoft::WRL::ComPtr<T>> { |
| 990 | static T* Unwrap(const Microsoft::WRL::ComPtr<T>& ptr) { return ptr.Get(); } |
| 991 | }; |
| 992 | #endif |
| 993 | |
Peter Kasting | a85265e3 | 2018-02-15 08:30:23 | [diff] [blame] | 994 | // CallbackCancellationTraits allows customization of Callback's cancellation |
| 995 | // semantics. By default, callbacks are not cancellable. A specialization should |
| 996 | // set is_cancellable = true and implement an IsCancelled() that returns if the |
| 997 | // callback should be cancelled. |
| 998 | template <typename Functor, typename BoundArgsTuple, typename SFINAE> |
| 999 | struct CallbackCancellationTraits { |
| 1000 | static constexpr bool is_cancellable = false; |
| 1001 | }; |
| 1002 | |
| 1003 | // Specialization for method bound to weak pointer receiver. |
| 1004 | template <typename Functor, typename... BoundArgs> |
| 1005 | struct CallbackCancellationTraits< |
| 1006 | Functor, |
| 1007 | std::tuple<BoundArgs...>, |
| 1008 | std::enable_if_t< |
| 1009 | internal::IsWeakMethod<internal::FunctorTraits<Functor>::is_method, |
| 1010 | BoundArgs...>::value>> { |
| 1011 | static constexpr bool is_cancellable = true; |
| 1012 | |
| 1013 | template <typename Receiver, typename... Args> |
| 1014 | static bool IsCancelled(const Functor&, |
| 1015 | const Receiver& receiver, |
| 1016 | const Args&...) { |
| 1017 | return !receiver; |
| 1018 | } |
Nicolas Ouellet-payeur | 40f8e9a | 2018-07-30 16:26:48 | [diff] [blame] | 1019 | |
| 1020 | template <typename Receiver, typename... Args> |
| 1021 | static bool MaybeValid(const Functor&, |
| 1022 | const Receiver& receiver, |
| 1023 | const Args&...) { |
| 1024 | return receiver.MaybeValid(); |
| 1025 | } |
Peter Kasting | a85265e3 | 2018-02-15 08:30:23 | [diff] [blame] | 1026 | }; |
| 1027 | |
| 1028 | // Specialization for a nested bind. |
| 1029 | template <typename Signature, typename... BoundArgs> |
| 1030 | struct CallbackCancellationTraits<OnceCallback<Signature>, |
| 1031 | std::tuple<BoundArgs...>> { |
| 1032 | static constexpr bool is_cancellable = true; |
| 1033 | |
| 1034 | template <typename Functor> |
| 1035 | static bool IsCancelled(const Functor& functor, const BoundArgs&...) { |
| 1036 | return functor.IsCancelled(); |
| 1037 | } |
Nicolas Ouellet-payeur | 40f8e9a | 2018-07-30 16:26:48 | [diff] [blame] | 1038 | |
| 1039 | template <typename Functor> |
| 1040 | static bool MaybeValid(const Functor& functor, const BoundArgs&...) { |
| 1041 | return functor.MaybeValid(); |
| 1042 | } |
Peter Kasting | a85265e3 | 2018-02-15 08:30:23 | [diff] [blame] | 1043 | }; |
| 1044 | |
| 1045 | template <typename Signature, typename... BoundArgs> |
| 1046 | struct CallbackCancellationTraits<RepeatingCallback<Signature>, |
| 1047 | std::tuple<BoundArgs...>> { |
| 1048 | static constexpr bool is_cancellable = true; |
| 1049 | |
| 1050 | template <typename Functor> |
| 1051 | static bool IsCancelled(const Functor& functor, const BoundArgs&...) { |
| 1052 | return functor.IsCancelled(); |
| 1053 | } |
Nicolas Ouellet-payeur | 40f8e9a | 2018-07-30 16:26:48 | [diff] [blame] | 1054 | |
| 1055 | template <typename Functor> |
| 1056 | static bool MaybeValid(const Functor& functor, const BoundArgs&...) { |
| 1057 | return functor.MaybeValid(); |
| 1058 | } |
Peter Kasting | a85265e3 | 2018-02-15 08:30:23 | [diff] [blame] | 1059 | }; |
| 1060 | |
tzik | caf1d84b | 2016-06-28 12:22:21 | [diff] [blame] | 1061 | // Returns a RunType of bound functor. |
| 1062 | // E.g. MakeUnboundRunType<R(A, B, C), A, B> is evaluated to R(C). |
| 1063 | template <typename Functor, typename... BoundArgs> |
| 1064 | using MakeUnboundRunType = |
tzik | ae4202e | 2017-07-31 10:41:54 | [diff] [blame] | 1065 | typename internal::BindTypeHelper<Functor, BoundArgs...>::UnboundRunType; |
tzik | caf1d84b | 2016-06-28 12:22:21 | [diff] [blame] | 1066 | |
[email protected] | b38d357 | 2011-02-15 01:27:38 | [diff] [blame] | 1067 | } // namespace base |
| 1068 | |
| 1069 | #endif // BASE_BIND_INTERNAL_H_ |