OLD | NEW |
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 // This defines a set of argument wrappers and related factory methods that | 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 | 6 // can be used specify the refcounting and reference semantics of arguments |
7 // that are bound by the Bind() function in base/bind.h. | 7 // that are bound by the Bind() function in base/bind.h. |
8 // | 8 // |
9 // It also defines a set of simple functions and utilities that people want | 9 // It also defines a set of simple functions and utilities that people want |
10 // when using Callback<> and Bind(). | 10 // when using Callback<> and Bind(). |
(...skipping 545 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
556 } | 556 } |
557 | 557 |
558 // We offer 2 syntaxes for calling Passed(). The first takes an rvalue and | 558 // We offer 2 syntaxes for calling Passed(). The first takes an rvalue and |
559 // is best suited for use with the return value of a function or other temporary | 559 // is best suited for use with the return value of a function or other temporary |
560 // rvalues. The second takes a pointer to the scoper and is just syntactic sugar | 560 // rvalues. The second takes a pointer to the scoper and is just syntactic sugar |
561 // to avoid having to write Passed(std::move(scoper)). | 561 // to avoid having to write Passed(std::move(scoper)). |
562 // | 562 // |
563 // Both versions of Passed() prevent T from being an lvalue reference. The first | 563 // Both versions of Passed() prevent T from being an lvalue reference. The first |
564 // via use of enable_if, and the second takes a T* which will not bind to T&. | 564 // via use of enable_if, and the second takes a T* which will not bind to T&. |
565 template <typename T, | 565 template <typename T, |
566 typename std::enable_if<internal::IsMoveOnlyType<T>::value && | 566 typename std::enable_if<!std::is_lvalue_reference<T>::value>::type* = |
567 !std::is_lvalue_reference<T>::value>::type* = | |
568 nullptr> | 567 nullptr> |
569 static inline internal::PassedWrapper<T> Passed(T&& scoper) { | 568 static inline internal::PassedWrapper<T> Passed(T&& scoper) { |
570 return internal::PassedWrapper<T>(std::move(scoper)); | 569 return internal::PassedWrapper<T>(std::move(scoper)); |
571 } | 570 } |
572 template <typename T, | 571 template <typename T> |
573 typename std::enable_if<internal::IsMoveOnlyType<T>::value>::type* = | |
574 nullptr> | |
575 static inline internal::PassedWrapper<T> Passed(T* scoper) { | 572 static inline internal::PassedWrapper<T> Passed(T* scoper) { |
576 return internal::PassedWrapper<T>(std::move(*scoper)); | 573 return internal::PassedWrapper<T>(std::move(*scoper)); |
577 } | 574 } |
578 | 575 |
579 template <typename T> | 576 template <typename T> |
580 static inline internal::IgnoreResultHelper<T> IgnoreResult(T data) { | 577 static inline internal::IgnoreResultHelper<T> IgnoreResult(T data) { |
581 return internal::IgnoreResultHelper<T>(data); | 578 return internal::IgnoreResultHelper<T>(data); |
582 } | 579 } |
583 | 580 |
584 template <typename T> | 581 template <typename T> |
585 static inline internal::IgnoreResultHelper<Callback<T> > | 582 static inline internal::IgnoreResultHelper<Callback<T> > |
586 IgnoreResult(const Callback<T>& data) { | 583 IgnoreResult(const Callback<T>& data) { |
587 return internal::IgnoreResultHelper<Callback<T> >(data); | 584 return internal::IgnoreResultHelper<Callback<T> >(data); |
588 } | 585 } |
589 | 586 |
590 BASE_EXPORT void DoNothing(); | 587 BASE_EXPORT void DoNothing(); |
591 | 588 |
592 template<typename T> | 589 template<typename T> |
593 void DeletePointer(T* obj) { | 590 void DeletePointer(T* obj) { |
594 delete obj; | 591 delete obj; |
595 } | 592 } |
596 | 593 |
597 } // namespace base | 594 } // namespace base |
598 | 595 |
599 #endif // BASE_BIND_HELPERS_H_ | 596 #endif // BASE_BIND_HELPERS_H_ |
OLD | NEW |