Commit 2387a825 authored by tzik's avatar tzik Committed by Commit bot

Clean up DispatchTo{Function,Method} impl

* Remove Unwrap call, which is no longer needed after http://crrev.com/2268283002
* Use Perfect Forwarding on Dispatch{Function,Method}

Review-Url: https://codereview.chromium.org/2270693003
Cr-Commit-Position: refs/heads/master@{#414424}
parent 62bb97b2
...@@ -121,6 +121,10 @@ auto get(T& t) -> decltype(std::get<I>(t)) { ...@@ -121,6 +121,10 @@ auto get(T& t) -> decltype(std::get<I>(t)) {
template <size_t N> template <size_t N>
using MakeIndexSequence = typename MakeIndexSequenceImpl<N>::Type; using MakeIndexSequence = typename MakeIndexSequenceImpl<N>::Type;
template <typename T>
using MakeIndexSequenceForTuple =
MakeIndexSequence<std::tuple_size<typename std::decay<T>::type>::value>;
// Dispatchers ---------------------------------------------------------------- // Dispatchers ----------------------------------------------------------------
// //
// Helper functions that call the given method on an object, with the unpacked // Helper functions that call the given method on an object, with the unpacked
...@@ -132,62 +136,63 @@ using MakeIndexSequence = typename MakeIndexSequenceImpl<N>::Type; ...@@ -132,62 +136,63 @@ using MakeIndexSequence = typename MakeIndexSequenceImpl<N>::Type;
// Non-Static Dispatchers with no out params. // 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, inline void DispatchToMethodImpl(const ObjT& obj,
Method method, Method method,
const std::tuple<Ts...>& arg, Tuple&& args,
IndexSequence<Ns...>) { 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, inline void DispatchToMethod(const ObjT& obj,
Method method, Method method,
const std::tuple<Ts...>& arg) { Tuple&& args) {
DispatchToMethodImpl(obj, method, arg, MakeIndexSequence<sizeof...(Ts)>()); DispatchToMethodImpl(obj, method, std::forward<Tuple>(args),
MakeIndexSequenceForTuple<Tuple>());
} }
// Static Dispatchers with no out params. // 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, inline void DispatchToFunctionImpl(Function function,
const std::tuple<Ts...>& arg, Tuple&& args,
IndexSequence<Ns...>) { IndexSequence<Ns...>) {
(*function)(internal::Unwrap(std::get<Ns>(arg))...); (*function)(base::get<Ns>(std::forward<Tuple>(args))...);
} }
template <typename Function, typename... Ts> template <typename Function, typename Tuple>
inline void DispatchToFunction(Function function, inline void DispatchToFunction(Function function, Tuple&& args) {
const std::tuple<Ts...>& arg) { DispatchToFunctionImpl(function, std::forward<Tuple>(args),
DispatchToFunctionImpl(function, arg, MakeIndexSequence<sizeof...(Ts)>()); MakeIndexSequenceForTuple<Tuple>());
} }
// Dispatchers with out parameters. // Dispatchers with out parameters.
template <typename ObjT, template <typename ObjT,
typename Method, typename Method,
typename... InTs, typename InTuple,
typename... OutTs, typename OutTuple,
size_t... InNs, size_t... InNs,
size_t... OutNs> size_t... OutNs>
inline void DispatchToMethodImpl(const ObjT& obj, inline void DispatchToMethodImpl(const ObjT& obj,
Method method, Method method,
const std::tuple<InTs...>& in, InTuple&& in,
std::tuple<OutTs...>* out, OutTuple* out,
IndexSequence<InNs...>, IndexSequence<InNs...>,
IndexSequence<OutNs...>) { IndexSequence<OutNs...>) {
(obj->*method)(internal::Unwrap(std::get<InNs>(in))..., (obj->*method)(base::get<InNs>(std::forward<InTuple>(in))...,
&std::get<OutNs>(*out)...); &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, inline void DispatchToMethod(const ObjT& obj,
Method method, Method method,
const std::tuple<InTs...>& in, InTuple&& in,
std::tuple<OutTs...>* out) { OutTuple* out) {
DispatchToMethodImpl(obj, method, in, out, DispatchToMethodImpl(obj, method, std::forward<InTuple>(in), out,
MakeIndexSequence<sizeof...(InTs)>(), MakeIndexSequenceForTuple<InTuple>(),
MakeIndexSequence<sizeof...(OutTs)>()); MakeIndexSequenceForTuple<OutTuple>());
} }
} // namespace base } // namespace base
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment