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

Side by Side Diff: base/bind_helpers.h

Issue 1498973002: WIP: base::Bind for rvalue references. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « base/bind.h ('k') | base/bind_internal.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 // 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 366 matching lines...) Expand 10 before | Expand all | Expand 10 after
377 return scoper_.Pass(); 377 return scoper_.Pass();
378 } 378 }
379 379
380 private: 380 private:
381 mutable bool is_valid_; 381 mutable bool is_valid_;
382 mutable T scoper_; 382 mutable T scoper_;
383 }; 383 };
384 384
385 // Unwrap the stored parameters for the wrappers above. 385 // Unwrap the stored parameters for the wrappers above.
386 template <typename T> 386 template <typename T>
387 struct UnwrapTraits { 387 struct MoveOnlyUnwrapTraits {
388 typedef T&& ForwardType;
389 static ForwardType Unwrap(T& o) { return std::move(o); }
390 };
391
392 template <typename T>
393 struct CopyUnwrapTraits {
388 typedef const T& ForwardType; 394 typedef const T& ForwardType;
389 static ForwardType Unwrap(const T& o) { return o; } 395 static ForwardType Unwrap(const T& o) { return o; }
390 }; 396 };
391 397
398 // BindState<>
399 template <typename T, typename U = void>
400 struct UnwrapTraits : public std::conditional<base::is_move_only<T>::value,
401 MoveOnlyUnwrapTraits<T>,
402 CopyUnwrapTraits<T>>::type {};
403
404 template <typename T>
405 struct UnwrapTraits<
406 T,
407 typename std::conditional<false, typename T::value_type, void>::type>
408 : public std::conditional<base::is_move_only<typename T::value_type>::value,
409 MoveOnlyUnwrapTraits<T>,
410 CopyUnwrapTraits<T>>::type {};
411
392 template <typename T> 412 template <typename T>
393 struct UnwrapTraits<UnretainedWrapper<T> > { 413 struct UnwrapTraits<UnretainedWrapper<T> > {
394 typedef T* ForwardType; 414 typedef T* ForwardType;
395 static ForwardType Unwrap(UnretainedWrapper<T> unretained) { 415 static ForwardType Unwrap(UnretainedWrapper<T> unretained) {
396 return unretained.get(); 416 return unretained.get();
397 } 417 }
398 }; 418 };
399 419
400 template <typename T> 420 template <typename T>
401 struct UnwrapTraits<ConstRefWrapper<T> > { 421 struct UnwrapTraits<ConstRefWrapper<T> > {
(...skipping 191 matching lines...) Expand 10 before | Expand all | Expand 10 after
593 BASE_EXPORT void DoNothing(); 613 BASE_EXPORT void DoNothing();
594 614
595 template<typename T> 615 template<typename T>
596 void DeletePointer(T* obj) { 616 void DeletePointer(T* obj) {
597 delete obj; 617 delete obj;
598 } 618 }
599 619
600 } // namespace base 620 } // namespace base
601 621
602 #endif // BASE_BIND_HELPERS_H_ 622 #endif // BASE_BIND_HELPERS_H_
OLDNEW
« no previous file with comments | « base/bind.h ('k') | base/bind_internal.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698