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

Side by Side Diff: base/bind_helpers.h

Issue 1709483002: Support move-only type on base::Callback::Run (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: remove Passed() whitelist check Created 4 years, 10 months 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_internal.h » ('j') | base/bind_internal.h » ('J')
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 // 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
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* =
dcheng 2016/03/02 00:25:45 Is it worth trying to catch that the type is movab
tzik 2016/03/02 01:04:21 I think there's no good way to detect the type is
dcheng 2016/03/02 08:06:51 FWIW, I don't think it's that hard to end up with
tzik 2016/03/02 12:44:51 Ah sorry, I told something incorrect. I meant, it'
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_
OLDNEW
« no previous file with comments | « no previous file | base/bind_internal.h » ('j') | base/bind_internal.h » ('J')

Powered by Google App Engine
This is Rietveld 408576698