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; |
}; |