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

For futures::retrying, detect policy type using std::result_of

Summary:
[Folly] For `futures::retrying`, detect policy type using `std::result_of`.

`FOLLY_CREATE_HAS_MEMBER_FN_TRAITS` does not work in all cases. For example, it does not work with inherited members.

And it is not really what we want, anyway, which is to dispatch based on the result type of invoking the policy with a particular set of arguments. We can do that more directly using `std::result_of`. And if we did not have `std::result_of`, then we could do that with SFINAE directly.

Reviewed By: WillerZ

Differential Revision: D5361808

fbshipit-source-id: 23f969dfd6dbaaa944dc2288e70c3ea11d3398f0
parent 8bedb7e1
...@@ -24,7 +24,6 @@ ...@@ -24,7 +24,6 @@
#include <folly/Baton.h> #include <folly/Baton.h>
#include <folly/Optional.h> #include <folly/Optional.h>
#include <folly/Random.h> #include <folly/Random.h>
#include <folly/Traits.h>
#include <folly/futures/detail/Core.h> #include <folly/futures/detail/Core.h>
#include <folly/futures/Timekeeper.h> #include <folly/futures/Timekeeper.h>
...@@ -1251,14 +1250,9 @@ struct retrying_policy_fut_tag {}; ...@@ -1251,14 +1250,9 @@ struct retrying_policy_fut_tag {};
template <class Policy> template <class Policy>
struct retrying_policy_traits { struct retrying_policy_traits {
using ew = exception_wrapper; using result = std::result_of_t<Policy(size_t, const exception_wrapper&)>;
FOLLY_CREATE_HAS_MEMBER_FN_TRAITS(has_op_call, operator()); using is_raw = std::is_same<result, bool>;
template <class Ret> using is_fut = std::is_same<result, Future<bool>>;
using has_op = typename std::integral_constant<bool,
has_op_call<Policy, Ret(size_t, const ew&)>::value ||
has_op_call<Policy, Ret(size_t, const ew&) const>::value>;
using is_raw = has_op<bool>;
using is_fut = has_op<Future<bool>>;
using tag = typename std::conditional< using tag = typename std::conditional<
is_raw::value, retrying_policy_raw_tag, typename std::conditional< is_raw::value, retrying_policy_raw_tag, typename std::conditional<
is_fut::value, retrying_policy_fut_tag, void>::type>::type; is_fut::value, retrying_policy_fut_tag, void>::type>::type;
......
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