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

Cut Futures private invocability helpers

Summary: [Folly] Cut Futures private invocability helpers, which can be replaced with invoke_result, is_invocable, etc.

Reviewed By: marshallcline

Differential Revision: D8087901

fbshipit-source-id: 17282d77aaff61350d1e7f1b0c363c25db8fb5b1
parent e2fcfa38
......@@ -980,7 +980,7 @@ Future<Unit> Future<T>::then() {
template <class T>
template <class F>
typename std::enable_if<
!futures::detail::callableWith<F, exception_wrapper>::value &&
!is_invocable<F, exception_wrapper>::value &&
!futures::detail::Extract<F>::ReturnsFuture::value,
Future<T>>::type
Future<T>::onError(F&& func) {
......@@ -1015,7 +1015,7 @@ Future<T>::onError(F&& func) {
template <class T>
template <class F>
typename std::enable_if<
!futures::detail::callableWith<F, exception_wrapper>::value &&
!is_invocable<F, exception_wrapper>::value &&
futures::detail::Extract<F>::ReturnsFuture::value,
Future<T>>::type
Future<T>::onError(F&& func) {
......@@ -1074,7 +1074,7 @@ Future<T> Future<T>::onTimeout(Duration dur, F&& func, Timekeeper* tk) {
template <class T>
template <class F>
typename std::enable_if<
futures::detail::callableWith<F, exception_wrapper>::value &&
is_invocable<F, exception_wrapper>::value &&
futures::detail::Extract<F>::ReturnsFuture::value,
Future<T>>::type
Future<T>::onError(F&& func) {
......@@ -1112,7 +1112,7 @@ Future<T>::onError(F&& func) {
template <class T>
template <class F>
typename std::enable_if<
futures::detail::callableWith<F, exception_wrapper>::value &&
is_invocable<F, exception_wrapper>::value &&
!futures::detail::Extract<F>::ReturnsFuture::value,
Future<T>>::type
Future<T>::onError(F&& func) {
......@@ -1496,10 +1496,9 @@ Future<T> reduce(It first, It last, T&& initial, F&& func) {
}
typedef typename std::iterator_traits<It>::value_type::value_type ItT;
typedef typename std::conditional<
futures::detail::callableWith<F, T&&, Try<ItT>&&>::value,
Try<ItT>,
ItT>::type Arg;
typedef typename std::
conditional<is_invocable<F, T&&, Try<ItT>&&>::value, Try<ItT>, ItT>::type
Arg;
typedef isTry<Arg> IsTry;
auto sfunc = std::make_shared<F>(std::move(func));
......
......@@ -76,9 +76,6 @@ template <class...> struct CollectAllVariadicContext;
template <class...> struct CollectVariadicContext;
template <class> struct CollectContext;
template <typename F, typename... Args>
using resultOf = decltype(std::declval<F>()(std::declval<Args>()...));
template <typename...>
struct ArgType;
......@@ -95,30 +92,16 @@ struct ArgType<> {
template <bool isTry, typename F, typename... Args>
struct argResult {
using ArgList = ArgType<Args...>;
using Result = resultOf<F, Args...>;
};
template <typename F, typename... Args>
struct callableWith {
template <typename T, typename = detail::resultOf<T, Args...>>
static constexpr std::true_type
check(std::nullptr_t) { return std::true_type{}; }
template <typename>
static constexpr std::false_type
check(...) { return std::false_type{}; }
typedef decltype(check<F>(nullptr)) type;
static constexpr bool value = type::value;
using Result = invoke_result_t<F, Args...>;
};
template <typename T, typename F>
struct callableResult {
typedef typename std::conditional<
callableWith<F>::value,
is_invocable<F>::value,
detail::argResult<false, F>,
typename std::conditional<
callableWith<F, T&&>::value,
is_invocable<F, T&&>::value,
detail::argResult<false, F, T&&>,
detail::argResult<true, F, Try<T>&&>>::type>::type Arg;
typedef isFutureOrSemiFuture<typename Arg::Result> ReturnsFuture;
......@@ -128,7 +111,7 @@ struct callableResult {
template <typename T, typename F>
struct tryCallableResult {
typedef typename std::conditional<
callableWith<F>::value,
is_invocable<F>::value,
detail::argResult<false, F>,
detail::argResult<true, F, Try<T>&&>>::type Arg;
typedef isFutureOrSemiFuture<typename Arg::Result> ReturnsFuture;
......@@ -138,7 +121,7 @@ struct tryCallableResult {
template <typename T, typename F>
struct valueCallableResult {
typedef typename std::conditional<
callableWith<F>::value,
is_invocable<F>::value,
detail::argResult<false, F>,
detail::argResult<false, F, T&&>>::type Arg;
typedef isFutureOrSemiFuture<typename Arg::Result> ReturnsFuture;
......
......@@ -33,6 +33,7 @@
#include <folly/Utility.h>
#include <folly/executors/DrivableExecutor.h>
#include <folly/executors/TimedDrivableExecutor.h>
#include <folly/functional/Invoke.h>
#include <folly/futures/Promise.h>
#include <folly/futures/detail/Types.h>
#include <folly/lang/Exception.h>
......@@ -871,7 +872,7 @@ class Future : private futures::detail::FutureBase<T> {
/// });
template <class F>
typename std::enable_if<
!futures::detail::callableWith<F, exception_wrapper>::value &&
!is_invocable<F, exception_wrapper>::value &&
!futures::detail::Extract<F>::ReturnsFuture::value,
Future<T>>::type
onError(F&& func);
......@@ -879,7 +880,7 @@ class Future : private futures::detail::FutureBase<T> {
/// Overload of onError where the error callback returns a Future<T>
template <class F>
typename std::enable_if<
!futures::detail::callableWith<F, exception_wrapper>::value &&
!is_invocable<F, exception_wrapper>::value &&
futures::detail::Extract<F>::ReturnsFuture::value,
Future<T>>::type
onError(F&& func);
......@@ -887,7 +888,7 @@ class Future : private futures::detail::FutureBase<T> {
/// Overload of onError that takes exception_wrapper and returns Future<T>
template <class F>
typename std::enable_if<
futures::detail::callableWith<F, exception_wrapper>::value &&
is_invocable<F, exception_wrapper>::value &&
futures::detail::Extract<F>::ReturnsFuture::value,
Future<T>>::type
onError(F&& func);
......@@ -895,7 +896,7 @@ class Future : private futures::detail::FutureBase<T> {
/// Overload of onError that takes exception_wrapper and returns T
template <class F>
typename std::enable_if<
futures::detail::callableWith<F, exception_wrapper>::value &&
is_invocable<F, exception_wrapper>::value &&
!futures::detail::Extract<F>::ReturnsFuture::value,
Future<T>>::type
onError(F&& func);
......
......@@ -437,7 +437,7 @@ template <
class F,
class ItT = typename std::iterator_traits<
typename Collection::iterator>::value_type,
class Result = typename futures::detail::resultOf<F, ItT&&>::value_type>
class Result = typename invoke_result_t<F, ItT&&>::value_type>
std::vector<Future<Result>> window(Collection input, F func, size_t n);
template <
......@@ -445,15 +445,13 @@ template <
class F,
class ItT = typename std::iterator_traits<
typename Collection::iterator>::value_type,
class Result = typename futures::detail::resultOf<F, ItT&&>::value_type>
class Result = typename invoke_result_t<F, ItT&&>::value_type>
std::vector<Future<Result>>
window(Executor* executor, Collection input, F func, size_t n);
template <typename F, typename T, typename ItT>
using MaybeTryArg = typename std::conditional<
futures::detail::callableWith<F, T&&, Try<ItT>&&>::value,
Try<ItT>,
ItT>::type;
using MaybeTryArg = typename std::
conditional<is_invocable<F, T&&, Try<ItT>&&>::value, Try<ItT>, ItT>::type;
/** repeatedly calls func on every result, e.g.
reduce(reduce(reduce(T initial, result of first), result of second), ...)
......
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