Commit ad1abbab authored by Yedidya Feldblum's avatar Yedidya Feldblum Committed by Facebook Github Bot

Use invoke in applyTuple implementation

Summary:
[Folly] Use `invoke` in `applyTuple` implementation.

V.s. reimplementing `invoke` as `makeCallable`

Reviewed By: spacedentist

Differential Revision: D6843993

fbshipit-source-id: 82f3e121486972245b75f808654d0a1299b7eafe
parent 4bd057b2
...@@ -32,6 +32,7 @@ ...@@ -32,6 +32,7 @@
#include <utility> #include <utility>
#include <folly/Utility.h> #include <folly/Utility.h>
#include <folly/functional/Invoke.h>
namespace folly { namespace folly {
...@@ -57,22 +58,13 @@ template <typename... Tuples> ...@@ -57,22 +58,13 @@ template <typename... Tuples>
using MakeIndexSequenceFromTuple = folly::make_index_sequence< using MakeIndexSequenceFromTuple = folly::make_index_sequence<
TupleSizeSum<typename std::decay<Tuples>::type...>::value>; TupleSizeSum<typename std::decay<Tuples>::type...>::value>;
// This is to allow using this with pointers to member functions,
// where the first argument in the tuple will be the this pointer.
template <class F>
inline constexpr F&& makeCallable(F&& f) {
return std::forward<F>(f);
}
template <class M, class C>
inline constexpr auto makeCallable(M(C::*d)) -> decltype(std::mem_fn(d)) {
return std::mem_fn(d);
}
template <class F, class Tuple, std::size_t... Indexes> template <class F, class Tuple, std::size_t... Indexes>
inline constexpr auto call(F&& f, Tuple&& t, folly::index_sequence<Indexes...>) inline constexpr auto call(F&& f, Tuple&& t, folly::index_sequence<Indexes...>)
-> decltype( -> decltype(invoke(
std::forward<F>(f)(std::get<Indexes>(std::forward<Tuple>(t))...)) { std::forward<F>(f),
return std::forward<F>(f)(std::get<Indexes>(std::forward<Tuple>(t))...); std::get<Indexes>(std::forward<Tuple>(t))...)) {
return invoke(
std::forward<F>(f), std::get<Indexes>(std::forward<Tuple>(t))...);
} }
template <class Tuple, std::size_t... Indexes> template <class Tuple, std::size_t... Indexes>
...@@ -100,13 +92,13 @@ inline constexpr auto forwardTuple(Tuple&& t, folly::index_sequence<Indexes...>) ...@@ -100,13 +92,13 @@ inline constexpr auto forwardTuple(Tuple&& t, folly::index_sequence<Indexes...>)
template <class F, class... Tuples> template <class F, class... Tuples>
inline constexpr auto applyTuple(F&& f, Tuples&&... t) inline constexpr auto applyTuple(F&& f, Tuples&&... t)
-> decltype(detail::apply_tuple::call( -> decltype(detail::apply_tuple::call(
detail::apply_tuple::makeCallable(std::forward<F>(f)), std::forward<F>(f),
std::tuple_cat(detail::apply_tuple::forwardTuple( std::tuple_cat(detail::apply_tuple::forwardTuple(
std::forward<Tuples>(t), std::forward<Tuples>(t),
detail::apply_tuple::MakeIndexSequenceFromTuple<Tuples>{})...), detail::apply_tuple::MakeIndexSequenceFromTuple<Tuples>{})...),
detail::apply_tuple::MakeIndexSequenceFromTuple<Tuples...>{})) { detail::apply_tuple::MakeIndexSequenceFromTuple<Tuples...>{})) {
return detail::apply_tuple::call( return detail::apply_tuple::call(
detail::apply_tuple::makeCallable(std::forward<F>(f)), std::forward<F>(f),
std::tuple_cat(detail::apply_tuple::forwardTuple( std::tuple_cat(detail::apply_tuple::forwardTuple(
std::forward<Tuples>(t), std::forward<Tuples>(t),
detail::apply_tuple::MakeIndexSequenceFromTuple<Tuples>{})...), detail::apply_tuple::MakeIndexSequenceFromTuple<Tuples>{})...),
......
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