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

Unified Diff: base/callback_internal.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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « base/callback.h ('k') | base/template_util.h » ('j') | 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 4b47bc7978db33f0946a9c30645d4b35f241751e..a36aa1fa6f71c58ff9f837fae3c45079bb996bbe 100644
--- a/base/callback_internal.h
+++ b/base/callback_internal.h
@@ -127,11 +127,25 @@ struct CallbackParamTraitsForNonMoveOnlyType;
// 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>
+template <typename T, typename = void>
struct CallbackParamTraits
- : std::conditional<IsMoveOnlyType<T>::value,
- CallbackParamTraitsForMoveOnlyType<T>,
- CallbackParamTraitsForNonMoveOnlyType<T>>::type {
+ : std::conditional<is_move_only<typename std::decay<T>::type>::value,
+ CallbackParamTraitsForMoveOnlyType<T>,
+ CallbackParamTraitsForNonMoveOnlyType<T>>::type {
+};
+
+template <typename T>
+struct CallbackParamTraits<
+ T,
+ typename std::conditional<false,
+ typename std::decay<T>::type::value_type,
+ void>::type>
+ : public std::conditional<
+ base::is_move_only<typename std::decay<T>::type>::value ||
+ base::is_move_only<
+ typename std::decay<T>::type::value_type>::value,
+ CallbackParamTraitsForMoveOnlyType<T>,
+ CallbackParamTraitsForNonMoveOnlyType<T>>::type {
};
template <typename T>
@@ -145,11 +159,11 @@ struct CallbackParamTraitsForNonMoveOnlyType {
// this will guard against us accidentally storing a reference parameter.
//
// The ForwardType should only be used for unbound arguments.
-template <typename T>
-struct CallbackParamTraitsForNonMoveOnlyType<T&> {
- typedef T& ForwardType;
- typedef T StorageType;
-};
+// template <typename T>
+// struct CallbackParamTraits<T&> {
+ // typedef T& ForwardType;
+ // typedef T StorageType;
+// };
// Note that for array types, we implicitly add a const in the conversion. This
// means that it is not possible to bind array arguments to functions that take
@@ -184,7 +198,7 @@ struct CallbackParamTraitsForNonMoveOnlyType<T[]> {
// function or a cast would not be usable with Callback<> or Bind().
template <typename T>
struct CallbackParamTraitsForMoveOnlyType {
- typedef T ForwardType;
+ typedef typename std::remove_reference<T>::type&& ForwardType;
typedef T StorageType;
};
@@ -214,6 +228,12 @@ typename enable_if<IsMoveOnlyType<T>::value, T>::type CallbackForward(T& t) {
return t.Pass();
}
+template <typename T>
+auto CallbackForward2(T&& t) ->
+ typename CallbackParamTraits<T>::ForwardType {
+ return static_cast<typename CallbackParamTraits<T>::ForwardType>(t);
+}
+
} // namespace internal
} // namespace base
« no previous file with comments | « base/callback.h ('k') | base/template_util.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698