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

Unified Diff: base/callback_internal.h

Issue 610423003: [Base] Use variadic template in base/callback.h (wave 1) (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: workaround for win toolchain Created 6 years, 3 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « base/callback.h.pump ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: base/callback_internal.h
diff --git a/base/callback_internal.h b/base/callback_internal.h
index 9d7761c409781ac613340b26cca474cea5c148a2..4ecbcca500816616f086023e2a952ba183e6c813 100644
--- a/base/callback_internal.h
+++ b/base/callback_internal.h
@@ -81,6 +81,23 @@ template <typename T> struct IsMoveOnlyType {
!is_const<T>::value;
};
+// Returns Then as |type| if condition is true. Otherwise returns Else.
Aaron Boodman 2014/09/30 21:05:37 The pipes are usually used around param names in c
tzik 2014/10/01 01:22:40 Done.
+template <bool condition, typename Then, typename Else>
+struct SelectType {
+ typedef Then type;
+};
+
+template <typename Then, typename Else>
+struct SelectType<false, Then, Else> {
+ typedef Else type;
+};
+
+template <typename>
+struct CallbackParamTraitsForMoveOnlyType;
+
+template <typename>
+struct CallbackParamTraitsForNonMoveOnlyType;
Nico 2014/09/30 11:41:04 Should there be a "TODO: Use a default parameter o
tzik 2014/09/30 14:43:10 Done.
+
// This is a typetraits object that's used to take an argument type, and
// extract a suitable type for storing and forwarding arguments.
//
@@ -92,8 +109,15 @@ template <typename T> struct IsMoveOnlyType {
// parameters by const reference. In this case, we end up passing an actual
// array type in the initializer list which C++ does not allow. This will
// break passing of C-string literals.
-template <typename T, bool is_move_only = IsMoveOnlyType<T>::value>
-struct CallbackParamTraits {
+template <typename T>
+struct CallbackParamTraits
+ : SelectType<IsMoveOnlyType<T>::value,
+ CallbackParamTraitsForMoveOnlyType<T>,
+ CallbackParamTraitsForNonMoveOnlyType<T> >::type {
+};
+
+template <typename T>
+struct CallbackParamTraitsForNonMoveOnlyType {
typedef const T& ForwardType;
typedef T StorageType;
};
@@ -104,7 +128,7 @@ struct CallbackParamTraits {
//
// The ForwardType should only be used for unbound arguments.
template <typename T>
-struct CallbackParamTraits<T&, false> {
+struct CallbackParamTraitsForNonMoveOnlyType<T&> {
typedef T& ForwardType;
typedef T StorageType;
};
@@ -115,14 +139,14 @@ struct CallbackParamTraits<T&, false> {
// T[n]" does not seem to match correctly, so we are stuck with this
// restriction.
template <typename T, size_t n>
-struct CallbackParamTraits<T[n], false> {
+struct CallbackParamTraitsForNonMoveOnlyType<T[n]> {
typedef const T* ForwardType;
typedef const T* StorageType;
};
// See comment for CallbackParamTraits<T[n]>.
template <typename T>
-struct CallbackParamTraits<T[], false> {
+struct CallbackParamTraitsForNonMoveOnlyType<T[]> {
typedef const T* ForwardType;
typedef const T* StorageType;
};
@@ -141,7 +165,7 @@ struct CallbackParamTraits<T[], false> {
// reference cannot be used with temporaries which means the result of a
// function or a cast would not be usable with Callback<> or Bind().
template <typename T>
-struct CallbackParamTraits<T, true> {
+struct CallbackParamTraitsForMoveOnlyType {
typedef T ForwardType;
typedef T StorageType;
};
« no previous file with comments | « base/callback.h.pump ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698