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

Unified Diff: base/tuple.h

Issue 2270693003: Clean up DispatchTo{Function,Method} impl (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: rebase Created 4 years, 4 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 | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: base/tuple.h
diff --git a/base/tuple.h b/base/tuple.h
index e82f2e5f06ad8860f722879b44bfef1e150c23f1..9f62339f0d5df10eb9b43631151343fd3d1d4d85 100644
--- a/base/tuple.h
+++ b/base/tuple.h
@@ -121,6 +121,10 @@ auto get(T& t) -> decltype(std::get<I>(t)) {
template <size_t N>
using MakeIndexSequence = typename MakeIndexSequenceImpl<N>::Type;
+template <typename T>
+using MakeIndexSequenceForTuple =
+ MakeIndexSequence<std::tuple_size<typename std::decay<T>::type>::value>;
+
// Dispatchers ----------------------------------------------------------------
//
// Helper functions that call the given method on an object, with the unpacked
@@ -132,62 +136,63 @@ using MakeIndexSequence = typename MakeIndexSequenceImpl<N>::Type;
// Non-Static Dispatchers with no out params.
-template <typename ObjT, typename Method, typename... Ts, size_t... Ns>
+template <typename ObjT, typename Method, typename Tuple, size_t... Ns>
inline void DispatchToMethodImpl(const ObjT& obj,
Method method,
- const std::tuple<Ts...>& arg,
+ Tuple&& args,
IndexSequence<Ns...>) {
- (obj->*method)(internal::Unwrap(std::get<Ns>(arg))...);
+ (obj->*method)(base::get<Ns>(std::forward<Tuple>(args))...);
}
-template <typename ObjT, typename Method, typename... Ts>
+template <typename ObjT, typename Method, typename Tuple>
inline void DispatchToMethod(const ObjT& obj,
Method method,
- const std::tuple<Ts...>& arg) {
- DispatchToMethodImpl(obj, method, arg, MakeIndexSequence<sizeof...(Ts)>());
+ Tuple&& args) {
+ DispatchToMethodImpl(obj, method, std::forward<Tuple>(args),
+ MakeIndexSequenceForTuple<Tuple>());
}
// Static Dispatchers with no out params.
-template <typename Function, typename... Ts, size_t... Ns>
+template <typename Function, typename Tuple, size_t... Ns>
inline void DispatchToFunctionImpl(Function function,
- const std::tuple<Ts...>& arg,
+ Tuple&& args,
IndexSequence<Ns...>) {
- (*function)(internal::Unwrap(std::get<Ns>(arg))...);
+ (*function)(base::get<Ns>(std::forward<Tuple>(args))...);
}
-template <typename Function, typename... Ts>
-inline void DispatchToFunction(Function function,
- const std::tuple<Ts...>& arg) {
- DispatchToFunctionImpl(function, arg, MakeIndexSequence<sizeof...(Ts)>());
+template <typename Function, typename Tuple>
+inline void DispatchToFunction(Function function, Tuple&& args) {
+ DispatchToFunctionImpl(function, std::forward<Tuple>(args),
+ MakeIndexSequenceForTuple<Tuple>());
}
// Dispatchers with out parameters.
template <typename ObjT,
typename Method,
- typename... InTs,
- typename... OutTs,
+ typename InTuple,
+ typename OutTuple,
size_t... InNs,
size_t... OutNs>
inline void DispatchToMethodImpl(const ObjT& obj,
Method method,
- const std::tuple<InTs...>& in,
- std::tuple<OutTs...>* out,
+ InTuple&& in,
+ OutTuple* out,
IndexSequence<InNs...>,
IndexSequence<OutNs...>) {
- (obj->*method)(internal::Unwrap(std::get<InNs>(in))...,
+ (obj->*method)(base::get<InNs>(std::forward<InTuple>(in))...,
&std::get<OutNs>(*out)...);
}
-template <typename ObjT, typename Method, typename... InTs, typename... OutTs>
+template <typename ObjT, typename Method, typename InTuple, typename OutTuple>
inline void DispatchToMethod(const ObjT& obj,
Method method,
- const std::tuple<InTs...>& in,
- std::tuple<OutTs...>* out) {
- DispatchToMethodImpl(obj, method, in, out,
- MakeIndexSequence<sizeof...(InTs)>(),
- MakeIndexSequence<sizeof...(OutTs)>());
+ InTuple&& in,
+ OutTuple* out) {
+ DispatchToMethodImpl(obj, method, std::forward<InTuple>(in), out,
+ MakeIndexSequenceForTuple<InTuple>(),
+ MakeIndexSequenceForTuple<OutTuple>());
}
} // namespace base
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698