For futures::retrying, detect policy type using std::result_of
authorYedidya Feldblum <yfeldblum@fb.com>
Mon, 3 Jul 2017 20:20:29 +0000 (13:20 -0700)
committerFacebook Github Bot <facebook-github-bot@users.noreply.github.com>
Mon, 3 Jul 2017 20:39:58 +0000 (13:39 -0700)
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

folly/futures/Future-inl.h

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