• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 // This defines a set of argument wrappers and related factory methods that
6 // can be used specify the refcounting and reference semantics of arguments
7 // that are bound by the Bind() function in base/bind.h.
8 //
9 // It also defines a set of simple functions and utilities that people want
10 // when using Callback<> and Bind().
11 //
12 //
13 // ARGUMENT BINDING WRAPPERS
14 //
15 // The wrapper functions are base::Unretained(), base::Owned(), base::Passed(),
16 // base::ConstRef(), and base::IgnoreResult().
17 //
18 // Unretained() allows Bind() to bind a non-refcounted class, and to disable
19 // refcounting on arguments that are refcounted objects.
20 //
21 // Owned() transfers ownership of an object to the Callback resulting from
22 // bind; the object will be deleted when the Callback is deleted.
23 //
24 // Passed() is for transferring movable-but-not-copyable types (eg. scoped_ptr)
25 // through a Callback. Logically, this signifies a destructive transfer of
26 // the state of the argument into the target function.  Invoking
27 // Callback::Run() twice on a Callback that was created with a Passed()
28 // argument will CHECK() because the first invocation would have already
29 // transferred ownership to the target function.
30 //
31 // ConstRef() allows binding a constant reference to an argument rather
32 // than a copy.
33 //
34 // IgnoreResult() is used to adapt a function or Callback with a return type to
35 // one with a void return. This is most useful if you have a function with,
36 // say, a pesky ignorable bool return that you want to use with PostTask or
37 // something else that expect a Callback with a void return.
38 //
39 // EXAMPLE OF Unretained():
40 //
41 //   class Foo {
42 //    public:
43 //     void func() { cout << "Foo:f" << endl; }
44 //   };
45 //
46 //   // In some function somewhere.
47 //   Foo foo;
48 //   Closure foo_callback =
49 //       Bind(&Foo::func, Unretained(&foo));
50 //   foo_callback.Run();  // Prints "Foo:f".
51 //
52 // Without the Unretained() wrapper on |&foo|, the above call would fail
53 // to compile because Foo does not support the AddRef() and Release() methods.
54 //
55 //
56 // EXAMPLE OF Owned():
57 //
58 //   void foo(int* arg) { cout << *arg << endl }
59 //
60 //   int* pn = new int(1);
61 //   Closure foo_callback = Bind(&foo, Owned(pn));
62 //
63 //   foo_callback.Run();  // Prints "1"
64 //   foo_callback.Run();  // Prints "1"
65 //   *n = 2;
66 //   foo_callback.Run();  // Prints "2"
67 //
68 //   foo_callback.Reset();  // |pn| is deleted.  Also will happen when
69 //                          // |foo_callback| goes out of scope.
70 //
71 // Without Owned(), someone would have to know to delete |pn| when the last
72 // reference to the Callback is deleted.
73 //
74 //
75 // EXAMPLE OF ConstRef():
76 //
77 //   void foo(int arg) { cout << arg << endl }
78 //
79 //   int n = 1;
80 //   Closure no_ref = Bind(&foo, n);
81 //   Closure has_ref = Bind(&foo, ConstRef(n));
82 //
83 //   no_ref.Run();  // Prints "1"
84 //   has_ref.Run();  // Prints "1"
85 //
86 //   n = 2;
87 //   no_ref.Run();  // Prints "1"
88 //   has_ref.Run();  // Prints "2"
89 //
90 // Note that because ConstRef() takes a reference on |n|, |n| must outlive all
91 // its bound callbacks.
92 //
93 //
94 // EXAMPLE OF IgnoreResult():
95 //
96 //   int DoSomething(int arg) { cout << arg << endl; }
97 //
98 //   // Assign to a Callback with a void return type.
99 //   Callback<void(int)> cb = Bind(IgnoreResult(&DoSomething));
100 //   cb->Run(1);  // Prints "1".
101 //
102 //   // Prints "1" on |ml|.
103 //   ml->PostTask(FROM_HERE, Bind(IgnoreResult(&DoSomething), 1);
104 //
105 //
106 // EXAMPLE OF Passed():
107 //
108 //   void TakesOwnership(scoped_ptr<Foo> arg) { }
109 //   scoped_ptr<Foo> CreateFoo() { return scoped_ptr<Foo>(new Foo()); }
110 //
111 //   scoped_ptr<Foo> f(new Foo());
112 //
113 //   // |cb| is given ownership of Foo(). |f| is now NULL.
114 //   // You can use std::move(f) in place of &f, but it's more verbose.
115 //   Closure cb = Bind(&TakesOwnership, Passed(&f));
116 //
117 //   // Run was never called so |cb| still owns Foo() and deletes
118 //   // it on Reset().
119 //   cb.Reset();
120 //
121 //   // |cb| is given a new Foo created by CreateFoo().
122 //   cb = Bind(&TakesOwnership, Passed(CreateFoo()));
123 //
124 //   // |arg| in TakesOwnership() is given ownership of Foo(). |cb|
125 //   // no longer owns Foo() and, if reset, would not delete Foo().
126 //   cb.Run();  // Foo() is now transferred to |arg| and deleted.
127 //   cb.Run();  // This CHECK()s since Foo() already been used once.
128 //
129 // Passed() is particularly useful with PostTask() when you are transferring
130 // ownership of an argument into a task, but don't necessarily know if the
131 // task will always be executed. This can happen if the task is cancellable
132 // or if it is posted to a TaskRunner.
133 //
134 //
135 // SIMPLE FUNCTIONS AND UTILITIES.
136 //
137 //   DoNothing() - Useful for creating a Closure that does nothing when called.
138 //   DeletePointer<T>() - Useful for creating a Closure that will delete a
139 //                        pointer when invoked. Only use this when necessary.
140 //                        In most cases MessageLoop::DeleteSoon() is a better
141 //                        fit.
142 
143 #ifndef BASE_BIND_HELPERS_H_
144 #define BASE_BIND_HELPERS_H_
145 
146 #include <stddef.h>
147 
148 #include <map>
149 #include <memory>
150 #include <type_traits>
151 #include <utility>
152 #include <vector>
153 
154 #include "base/callback.h"
155 #include "base/memory/weak_ptr.h"
156 #include "base/template_util.h"
157 #include "build/build_config.h"
158 
159 namespace base {
160 namespace internal {
161 
162 // Use the Substitution Failure Is Not An Error (SFINAE) trick to inspect T
163 // for the existence of AddRef() and Release() functions of the correct
164 // signature.
165 //
166 // http://en.wikipedia.org/wiki/Substitution_failure_is_not_an_error
167 // http://stackoverflow.com/questions/257288/is-it-possible-to-write-a-c-template-to-check-for-a-functions-existence
168 // http://stackoverflow.com/questions/4358584/sfinae-approach-comparison
169 // http://stackoverflow.com/questions/1966362/sfinae-to-check-for-inherited-member-functions
170 //
171 // The last link in particular show the method used below.
172 //
173 // For SFINAE to work with inherited methods, we need to pull some extra tricks
174 // with multiple inheritance.  In the more standard formulation, the overloads
175 // of Check would be:
176 //
177 //   template <typename C>
178 //   Yes NotTheCheckWeWant(Helper<&C::TargetFunc>*);
179 //
180 //   template <typename C>
181 //   No NotTheCheckWeWant(...);
182 //
183 //   static const bool value = sizeof(NotTheCheckWeWant<T>(0)) == sizeof(Yes);
184 //
185 // The problem here is that template resolution will not match
186 // C::TargetFunc if TargetFunc does not exist directly in C.  That is, if
187 // TargetFunc in inherited from an ancestor, &C::TargetFunc will not match,
188 // |value| will be false.  This formulation only checks for whether or
189 // not TargetFunc exist directly in the class being introspected.
190 //
191 // To get around this, we play a dirty trick with multiple inheritance.
192 // First, We create a class BaseMixin that declares each function that we
193 // want to probe for.  Then we create a class Base that inherits from both T
194 // (the class we wish to probe) and BaseMixin.  Note that the function
195 // signature in BaseMixin does not need to match the signature of the function
196 // we are probing for; thus it's easiest to just use void().
197 //
198 // Now, if TargetFunc exists somewhere in T, then &Base::TargetFunc has an
199 // ambiguous resolution between BaseMixin and T.  This lets us write the
200 // following:
201 //
202 //   template <typename C>
203 //   No GoodCheck(Helper<&C::TargetFunc>*);
204 //
205 //   template <typename C>
206 //   Yes GoodCheck(...);
207 //
208 //   static const bool value = sizeof(GoodCheck<Base>(0)) == sizeof(Yes);
209 //
210 // Notice here that the variadic version of GoodCheck() returns Yes here
211 // instead of No like the previous one. Also notice that we calculate |value|
212 // by specializing GoodCheck() on Base instead of T.
213 //
214 // We've reversed the roles of the variadic, and Helper overloads.
215 // GoodCheck(Helper<&C::TargetFunc>*), when C = Base, fails to be a valid
216 // substitution if T::TargetFunc exists. Thus GoodCheck<Base>(0) will resolve
217 // to the variadic version if T has TargetFunc.  If T::TargetFunc does not
218 // exist, then &C::TargetFunc is not ambiguous, and the overload resolution
219 // will prefer GoodCheck(Helper<&C::TargetFunc>*).
220 //
221 // This method of SFINAE will correctly probe for inherited names, but it cannot
222 // typecheck those names.  It's still a good enough sanity check though.
223 //
224 // Works on gcc-4.2, gcc-4.4, and Visual Studio 2008.
225 //
226 // TODO(ajwong): Move to ref_counted.h or template_util.h when we've vetted
227 // this works well.
228 //
229 // TODO(ajwong): Make this check for Release() as well.
230 // See http://crbug.com/82038.
231 template <typename T>
232 class SupportsAddRefAndRelease {
233   using Yes = char[1];
234   using No = char[2];
235 
236   struct BaseMixin {
237     void AddRef();
238   };
239 
240 // MSVC warns when you try to use Base if T has a private destructor, the
241 // common pattern for refcounted types. It does this even though no attempt to
242 // instantiate Base is made.  We disable the warning for this definition.
243 #if defined(OS_WIN)
244 #pragma warning(push)
245 #pragma warning(disable:4624)
246 #endif
247   struct Base : public T, public BaseMixin {
248   };
249 #if defined(OS_WIN)
250 #pragma warning(pop)
251 #endif
252 
253   template <void(BaseMixin::*)()> struct Helper {};
254 
255   template <typename C>
256   static No& Check(Helper<&C::AddRef>*);
257 
258   template <typename >
259   static Yes& Check(...);
260 
261  public:
262   enum { value = sizeof(Check<Base>(0)) == sizeof(Yes) };
263 };
264 
265 // Helpers to assert that arguments of a recounted type are bound with a
266 // scoped_refptr.
267 template <bool IsClasstype, typename T>
268 struct UnsafeBindtoRefCountedArgHelper : std::false_type {
269 };
270 
271 template <typename T>
272 struct UnsafeBindtoRefCountedArgHelper<true, T>
273     : std::integral_constant<bool, SupportsAddRefAndRelease<T>::value> {
274 };
275 
276 template <typename T>
277 struct UnsafeBindtoRefCountedArg : std::false_type {
278 };
279 
280 template <typename T>
281 struct UnsafeBindtoRefCountedArg<T*>
282     : UnsafeBindtoRefCountedArgHelper<std::is_class<T>::value, T> {
283 };
284 
285 template <typename T>
286 class HasIsMethodTag {
287   using Yes = char[1];
288   using No = char[2];
289 
290   template <typename U>
291   static Yes& Check(typename U::IsMethod*);
292 
293   template <typename U>
294   static No& Check(...);
295 
296  public:
297   enum { value = sizeof(Check<T>(0)) == sizeof(Yes) };
298 };
299 
300 template <typename T>
301 class UnretainedWrapper {
302  public:
303   explicit UnretainedWrapper(T* o) : ptr_(o) {}
304   T* get() const { return ptr_; }
305  private:
306   T* ptr_;
307 };
308 
309 template <typename T>
310 class ConstRefWrapper {
311  public:
312   explicit ConstRefWrapper(const T& o) : ptr_(&o) {}
313   const T& get() const { return *ptr_; }
314  private:
315   const T* ptr_;
316 };
317 
318 template <typename T>
319 struct IgnoreResultHelper {
320   explicit IgnoreResultHelper(T functor) : functor_(functor) {}
321 
322   T functor_;
323 };
324 
325 template <typename T>
326 struct IgnoreResultHelper<Callback<T> > {
327   explicit IgnoreResultHelper(const Callback<T>& functor) : functor_(functor) {}
328 
329   const Callback<T>& functor_;
330 };
331 
332 // An alternate implementation is to avoid the destructive copy, and instead
333 // specialize ParamTraits<> for OwnedWrapper<> to change the StorageType to
334 // a class that is essentially a scoped_ptr<>.
335 //
336 // The current implementation has the benefit though of leaving ParamTraits<>
337 // fully in callback_internal.h as well as avoiding type conversions during
338 // storage.
339 template <typename T>
340 class OwnedWrapper {
341  public:
342   explicit OwnedWrapper(T* o) : ptr_(o) {}
343   ~OwnedWrapper() { delete ptr_; }
344   T* get() const { return ptr_; }
345   OwnedWrapper(const OwnedWrapper& other) {
346     ptr_ = other.ptr_;
347     other.ptr_ = NULL;
348   }
349 
350  private:
351   mutable T* ptr_;
352 };
353 
354 // PassedWrapper is a copyable adapter for a scoper that ignores const.
355 //
356 // It is needed to get around the fact that Bind() takes a const reference to
357 // all its arguments.  Because Bind() takes a const reference to avoid
358 // unnecessary copies, it is incompatible with movable-but-not-copyable
359 // types; doing a destructive "move" of the type into Bind() would violate
360 // the const correctness.
361 //
362 // This conundrum cannot be solved without either C++11 rvalue references or
363 // a O(2^n) blowup of Bind() templates to handle each combination of regular
364 // types and movable-but-not-copyable types.  Thus we introduce a wrapper type
365 // that is copyable to transmit the correct type information down into
366 // BindState<>. Ignoring const in this type makes sense because it is only
367 // created when we are explicitly trying to do a destructive move.
368 //
369 // Two notes:
370 //  1) PassedWrapper supports any type that has a move constructor, however
371 //     the type will need to be specifically whitelisted in order for it to be
372 //     bound to a Callback. We guard this explicitly at the call of Passed()
373 //     to make for clear errors. Things not given to Passed() will be forwarded
374 //     and stored by value which will not work for general move-only types.
375 //  2) is_valid_ is distinct from NULL because it is valid to bind a "NULL"
376 //     scoper to a Callback and allow the Callback to execute once.
377 template <typename T>
378 class PassedWrapper {
379  public:
380   explicit PassedWrapper(T&& scoper)
381       : is_valid_(true), scoper_(std::move(scoper)) {}
382   PassedWrapper(const PassedWrapper& other)
383       : is_valid_(other.is_valid_), scoper_(std::move(other.scoper_)) {}
384   T Pass() const {
385     CHECK(is_valid_);
386     is_valid_ = false;
387     return std::move(scoper_);
388   }
389 
390  private:
391   mutable bool is_valid_;
392   mutable T scoper_;
393 };
394 
395 // Unwrap the stored parameters for the wrappers above.
396 template <typename T>
397 struct UnwrapTraits {
398   using ForwardType = const T&;
399   static ForwardType Unwrap(const T& o) { return o; }
400 };
401 
402 template <typename T>
403 struct UnwrapTraits<UnretainedWrapper<T> > {
404   using ForwardType = T*;
405   static ForwardType Unwrap(UnretainedWrapper<T> unretained) {
406     return unretained.get();
407   }
408 };
409 
410 template <typename T>
411 struct UnwrapTraits<ConstRefWrapper<T> > {
412   using ForwardType = const T&;
413   static ForwardType Unwrap(ConstRefWrapper<T> const_ref) {
414     return const_ref.get();
415   }
416 };
417 
418 template <typename T>
419 struct UnwrapTraits<scoped_refptr<T> > {
420   using ForwardType = T*;
421   static ForwardType Unwrap(const scoped_refptr<T>& o) { return o.get(); }
422 };
423 
424 template <typename T>
425 struct UnwrapTraits<WeakPtr<T> > {
426   using ForwardType = const WeakPtr<T>&;
427   static ForwardType Unwrap(const WeakPtr<T>& o) { return o; }
428 };
429 
430 template <typename T>
431 struct UnwrapTraits<OwnedWrapper<T> > {
432   using ForwardType = T*;
433   static ForwardType Unwrap(const OwnedWrapper<T>& o) {
434     return o.get();
435   }
436 };
437 
438 template <typename T>
439 struct UnwrapTraits<PassedWrapper<T> > {
440   using ForwardType = T;
441   static T Unwrap(PassedWrapper<T>& o) {
442     return o.Pass();
443   }
444 };
445 
446 // Utility for handling different refcounting semantics in the Bind()
447 // function.
448 template <bool is_method, typename... T>
449 struct MaybeScopedRefPtr;
450 
451 template <bool is_method>
452 struct MaybeScopedRefPtr<is_method> {
453   MaybeScopedRefPtr() {}
454 };
455 
456 template <typename T, typename... Rest>
457 struct MaybeScopedRefPtr<false, T, Rest...> {
458   MaybeScopedRefPtr(const T&, const Rest&...) {}
459 };
460 
461 template <typename T, size_t n, typename... Rest>
462 struct MaybeScopedRefPtr<false, T[n], Rest...> {
463   MaybeScopedRefPtr(const T*, const Rest&...) {}
464 };
465 
466 template <typename T, typename... Rest>
467 struct MaybeScopedRefPtr<true, T, Rest...> {
468   MaybeScopedRefPtr(const T& /* o */, const Rest&...) {}
469 };
470 
471 template <typename T, typename... Rest>
472 struct MaybeScopedRefPtr<true, T*, Rest...> {
473   MaybeScopedRefPtr(T* o, const Rest&...) : ref_(o) {}
474   scoped_refptr<T> ref_;
475 };
476 
477 // No need to additionally AddRef() and Release() since we are storing a
478 // scoped_refptr<> inside the storage object already.
479 template <typename T, typename... Rest>
480 struct MaybeScopedRefPtr<true, scoped_refptr<T>, Rest...> {
481   MaybeScopedRefPtr(const scoped_refptr<T>&, const Rest&...) {}
482 };
483 
484 template <typename T, typename... Rest>
485 struct MaybeScopedRefPtr<true, const T*, Rest...> {
486   MaybeScopedRefPtr(const T* o, const Rest&...) : ref_(o) {}
487   scoped_refptr<const T> ref_;
488 };
489 
490 // IsWeakMethod is a helper that determine if we are binding a WeakPtr<> to a
491 // method.  It is used internally by Bind() to select the correct
492 // InvokeHelper that will no-op itself in the event the WeakPtr<> for
493 // the target object is invalidated.
494 //
495 // The first argument should be the type of the object that will be received by
496 // the method.
497 template <bool IsMethod, typename... Args>
498 struct IsWeakMethod : public std::false_type {};
499 
500 template <typename T, typename... Args>
501 struct IsWeakMethod<true, WeakPtr<T>, Args...> : public std::true_type {};
502 
503 template <typename T, typename... Args>
504 struct IsWeakMethod<true, ConstRefWrapper<WeakPtr<T>>, Args...>
505     : public std::true_type {};
506 
507 
508 // Packs a list of types to hold them in a single type.
509 template <typename... Types>
510 struct TypeList {};
511 
512 // Used for DropTypeListItem implementation.
513 template <size_t n, typename List>
514 struct DropTypeListItemImpl;
515 
516 // Do not use enable_if and SFINAE here to avoid MSVC2013 compile failure.
517 template <size_t n, typename T, typename... List>
518 struct DropTypeListItemImpl<n, TypeList<T, List...>>
519     : DropTypeListItemImpl<n - 1, TypeList<List...>> {};
520 
521 template <typename T, typename... List>
522 struct DropTypeListItemImpl<0, TypeList<T, List...>> {
523   using Type = TypeList<T, List...>;
524 };
525 
526 template <>
527 struct DropTypeListItemImpl<0, TypeList<>> {
528   using Type = TypeList<>;
529 };
530 
531 // A type-level function that drops |n| list item from given TypeList.
532 template <size_t n, typename List>
533 using DropTypeListItem = typename DropTypeListItemImpl<n, List>::Type;
534 
535 // Used for TakeTypeListItem implementation.
536 template <size_t n, typename List, typename... Accum>
537 struct TakeTypeListItemImpl;
538 
539 // Do not use enable_if and SFINAE here to avoid MSVC2013 compile failure.
540 template <size_t n, typename T, typename... List, typename... Accum>
541 struct TakeTypeListItemImpl<n, TypeList<T, List...>, Accum...>
542     : TakeTypeListItemImpl<n - 1, TypeList<List...>, Accum..., T> {};
543 
544 template <typename T, typename... List, typename... Accum>
545 struct TakeTypeListItemImpl<0, TypeList<T, List...>, Accum...> {
546   using Type = TypeList<Accum...>;
547 };
548 
549 template <typename... Accum>
550 struct TakeTypeListItemImpl<0, TypeList<>, Accum...> {
551   using Type = TypeList<Accum...>;
552 };
553 
554 // A type-level function that takes first |n| list item from given TypeList.
555 // E.g. TakeTypeListItem<3, TypeList<A, B, C, D>> is evaluated to
556 // TypeList<A, B, C>.
557 template <size_t n, typename List>
558 using TakeTypeListItem = typename TakeTypeListItemImpl<n, List>::Type;
559 
560 // Used for ConcatTypeLists implementation.
561 template <typename List1, typename List2>
562 struct ConcatTypeListsImpl;
563 
564 template <typename... Types1, typename... Types2>
565 struct ConcatTypeListsImpl<TypeList<Types1...>, TypeList<Types2...>> {
566   using Type = TypeList<Types1..., Types2...>;
567 };
568 
569 // A type-level function that concats two TypeLists.
570 template <typename List1, typename List2>
571 using ConcatTypeLists = typename ConcatTypeListsImpl<List1, List2>::Type;
572 
573 // Used for MakeFunctionType implementation.
574 template <typename R, typename ArgList>
575 struct MakeFunctionTypeImpl;
576 
577 template <typename R, typename... Args>
578 struct MakeFunctionTypeImpl<R, TypeList<Args...>> {
579   // MSVC 2013 doesn't support Type Alias of function types.
580   // Revisit this after we update it to newer version.
581   typedef R Type(Args...);
582 };
583 
584 // A type-level function that constructs a function type that has |R| as its
585 // return type and has TypeLists items as its arguments.
586 template <typename R, typename ArgList>
587 using MakeFunctionType = typename MakeFunctionTypeImpl<R, ArgList>::Type;
588 
589 // Used for ExtractArgs.
590 template <typename Signature>
591 struct ExtractArgsImpl;
592 
593 template <typename R, typename... Args>
594 struct ExtractArgsImpl<R(Args...)> {
595   using Type = TypeList<Args...>;
596 };
597 
598 // A type-level function that extracts function arguments into a TypeList.
599 // E.g. ExtractArgs<R(A, B, C)> is evaluated to TypeList<A, B, C>.
600 template <typename Signature>
601 using ExtractArgs = typename ExtractArgsImpl<Signature>::Type;
602 
603 }  // namespace internal
604 
605 template <typename T>
606 static inline internal::UnretainedWrapper<T> Unretained(T* o) {
607   return internal::UnretainedWrapper<T>(o);
608 }
609 
610 template <typename T>
611 static inline internal::ConstRefWrapper<T> ConstRef(const T& o) {
612   return internal::ConstRefWrapper<T>(o);
613 }
614 
615 template <typename T>
616 static inline internal::OwnedWrapper<T> Owned(T* o) {
617   return internal::OwnedWrapper<T>(o);
618 }
619 
620 // We offer 2 syntaxes for calling Passed().  The first takes an rvalue and
621 // is best suited for use with the return value of a function or other temporary
622 // rvalues. The second takes a pointer to the scoper and is just syntactic sugar
623 // to avoid having to write Passed(std::move(scoper)).
624 //
625 // Both versions of Passed() prevent T from being an lvalue reference. The first
626 // via use of enable_if, and the second takes a T* which will not bind to T&.
627 template <typename T,
628           typename std::enable_if<internal::IsMoveOnlyType<T>::value &&
629                                   !std::is_lvalue_reference<T>::value>::type* =
630               nullptr>
631 static inline internal::PassedWrapper<T> Passed(T&& scoper) {
632   return internal::PassedWrapper<T>(std::move(scoper));
633 }
634 template <typename T,
635           typename std::enable_if<internal::IsMoveOnlyType<T>::value>::type* =
636               nullptr>
637 static inline internal::PassedWrapper<T> Passed(T* scoper) {
638   return internal::PassedWrapper<T>(std::move(*scoper));
639 }
640 
641 template <typename T>
642 static inline internal::IgnoreResultHelper<T> IgnoreResult(T data) {
643   return internal::IgnoreResultHelper<T>(data);
644 }
645 
646 template <typename T>
647 static inline internal::IgnoreResultHelper<Callback<T> >
648 IgnoreResult(const Callback<T>& data) {
649   return internal::IgnoreResultHelper<Callback<T> >(data);
650 }
651 
652 void DoNothing();
653 
654 template<typename T>
655 void DeletePointer(T* obj) {
656   delete obj;
657 }
658 
659 }  // namespace base
660 
661 #endif  // BASE_BIND_HELPERS_H_
662