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

Use invocability helper variables

Summary: [Folly] Use invocability helper variables in preference to types.

Reviewed By: aary

Differential Revision: D18748026

fbshipit-source-id: e7a76c1238360c55dd6d41c53f763e9df4069acb
parent 0ea41166
......@@ -188,7 +188,7 @@ struct BenchmarkSuspender {
* function).
*/
template <typename Lambda>
typename std::enable_if<folly::is_invocable<Lambda, unsigned>::value>::type
typename std::enable_if<folly::is_invocable_v<Lambda, unsigned>>::type
addBenchmark(const char* file, StringPiece name, Lambda&& lambda) {
auto execute = [=](unsigned int times) {
BenchmarkSuspender::timeSpent = {};
......@@ -213,7 +213,7 @@ addBenchmark(const char* file, StringPiece name, Lambda&& lambda) {
* (iteration occurs outside the function).
*/
template <typename Lambda>
typename std::enable_if<folly::is_invocable<Lambda>::value>::type
typename std::enable_if<folly::is_invocable_v<Lambda>>::type
addBenchmark(const char* file, StringPiece name, Lambda&& lambda) {
addBenchmark(file, name, [=](unsigned int times) {
unsigned int niter = 0;
......@@ -230,7 +230,7 @@ addBenchmark(const char* file, StringPiece name, Lambda&& lambda) {
*/
template <typename Lambda>
typename std::enable_if<
folly::is_invocable<Lambda, UserCounters&, unsigned>::value>::type
folly::is_invocable_v<Lambda, UserCounters&, unsigned>>::type
addBenchmark(const char* file, StringPiece name, Lambda&& lambda) {
auto execute = [=](unsigned int times) {
BenchmarkSuspender::timeSpent = {};
......@@ -254,7 +254,7 @@ addBenchmark(const char* file, StringPiece name, Lambda&& lambda) {
}
template <typename Lambda>
typename std::enable_if<folly::is_invocable<Lambda, UserCounters&>::value>::type
typename std::enable_if<folly::is_invocable_v<Lambda, UserCounters&>>::type
addBenchmark(const char* file, StringPiece name, Lambda&& lambda) {
addBenchmark(file, name, [=](UserCounters& counters, unsigned int times) {
unsigned int niter = 0;
......
......@@ -86,7 +86,7 @@ class LockInterfaceDispatcher {
private:
// assert that the mutex type has basic lock and unlock functions
static_assert(
folly::is_invocable<member::lock_invoker, Mutex>::value,
folly::is_invocable_v<member::lock_invoker, Mutex>,
"The mutex type must support lock and unlock functions");
using duration = std::chrono::milliseconds;
......@@ -94,11 +94,11 @@ class LockInterfaceDispatcher {
public:
static constexpr bool has_lock_unique = true;
static constexpr bool has_lock_timed =
folly::is_invocable<member::try_lock_for_invoker, Mutex, duration>::value;
folly::is_invocable_v<member::try_lock_for_invoker, Mutex, duration>;
static constexpr bool has_lock_shared =
folly::is_invocable<member::lock_shared_invoker, Mutex>::value;
folly::is_invocable_v<member::lock_shared_invoker, Mutex>;
static constexpr bool has_lock_upgrade =
folly::is_invocable<member::lock_upgrade_invoker, Mutex>::value;
folly::is_invocable_v<member::lock_upgrade_invoker, Mutex>;
};
/**
......
......@@ -36,7 +36,7 @@ template <
class Map,
typename Key = typename Map::key_type,
typename Value = typename Map::mapped_type,
typename std::enable_if<!is_invocable<Value>::value>::type* = nullptr>
typename std::enable_if<!is_invocable_v<Value>>::type* = nullptr>
typename Map::mapped_type
get_default(const Map& map, const Key& key, Value&& dflt) {
using M = typename Map::mapped_type;
......@@ -53,7 +53,7 @@ template <
typename Key = typename Map::key_type,
typename Func,
typename = typename std::enable_if<
is_invocable_r<typename Map::mapped_type, Func>::value>::type>
is_invocable_r_v<typename Map::mapped_type, Func>>::type>
typename Map::mapped_type
get_default(const Map& map, const Key& key, Func&& dflt) {
auto pos = map.find(key);
......@@ -152,7 +152,7 @@ template <
typename Key = typename Map::key_type,
typename Func,
typename = typename std::enable_if<
is_invocable_r<const typename Map::mapped_type&, Func>::value>::type,
is_invocable_r_v<const typename Map::mapped_type&, Func>>::type,
typename = typename std::enable_if<
std::is_reference<invoke_result_t<Func>>::value>::type>
const typename Map::mapped_type&
......
......@@ -472,9 +472,7 @@ class AlignedSysAllocator : private Align {
public:
static_assert(std::is_nothrow_copy_constructible<Align>::value, "");
static_assert(
is_nothrow_invocable_r<std::size_t, Align, std::size_t>::value,
"");
static_assert(is_nothrow_invocable_r_v<std::size_t, Align, std::size_t>, "");
using value_type = T;
......
......@@ -61,7 +61,7 @@ class ThreadLocal {
public:
constexpr ThreadLocal() : constructor_([]() { return new T(); }) {}
template <typename F, std::enable_if_t<is_invocable_r<T*, F>::value, int> = 0>
template <typename F, std::enable_if_t<is_invocable_r_v<T*, F>, int> = 0>
explicit ThreadLocal(F&& constructor)
: constructor_(std::forward<F>(constructor)) {}
......
......@@ -133,29 +133,27 @@ struct IndexingTag {};
template <typename Func, typename Item, typename Iter>
using ForEachImplTag = std::conditional_t<
is_invocable<Func, Item, index_constant<0>, Iter>::value,
is_invocable_v<Func, Item, index_constant<0>, Iter>,
index_constant<3>,
std::conditional_t<
is_invocable<Func, Item, index_constant<0>>::value,
is_invocable_v<Func, Item, index_constant<0>>,
index_constant<2>,
std::conditional_t<
is_invocable<Func, Item>::value,
is_invocable_v<Func, Item>,
index_constant<1>,
void>>>;
template <
typename Func,
typename... Args,
std::enable_if_t<is_invocable_r<LoopControl, Func, Args...>::value, int> =
0>
std::enable_if_t<is_invocable_r_v<LoopControl, Func, Args...>, int> = 0>
LoopControl invoke_returning_loop_control(Func&& f, Args&&... a) {
return static_cast<Func&&>(f)(static_cast<Args&&>(a)...);
}
template <
typename Func,
typename... Args,
std::enable_if_t<!is_invocable_r<LoopControl, Func, Args...>::value, int> =
0>
std::enable_if_t<!is_invocable_r_v<LoopControl, Func, Args...>, int> = 0>
LoopControl invoke_returning_loop_control(Func&& f, Args&&... a) {
static_assert(
std::is_void<invoke_result_t<Func, Args...>>::value,
......
......@@ -180,7 +180,7 @@ struct StdNodeReplica<
V,
H,
std::enable_if_t<
!StdIsFastHash<H>::value || !is_nothrow_invocable<H, K>::value>> {
!StdIsFastHash<H>::value || !is_nothrow_invocable_v<H, K>>> {
void* next;
V value;
std::size_t hash;
......
......@@ -116,10 +116,10 @@ struct argResult {
template <typename T, typename F>
struct callableResult {
typedef typename std::conditional<
is_invocable<F>::value,
is_invocable_v<F>,
detail::argResult<false, F>,
typename std::conditional<
is_invocable<F, T&&>::value,
is_invocable_v<F, T&&>,
detail::argResult<false, F, T&&>,
detail::argResult<true, F, Try<T>&&>>::type>::type Arg;
typedef isFutureOrSemiFuture<typename Arg::Result> ReturnsFuture;
......@@ -129,10 +129,10 @@ struct callableResult {
template <typename T, typename F>
struct executorCallableResult {
typedef typename std::conditional<
is_invocable<F, Executor::KeepAlive<>&&>::value,
is_invocable_v<F, Executor::KeepAlive<>&&>,
detail::argResult<false, F, Executor::KeepAlive<>&&>,
typename std::conditional<
is_invocable<F, Executor::KeepAlive<>&&, T&&>::value,
is_invocable_v<F, Executor::KeepAlive<>&&, T&&>,
detail::argResult<false, F, Executor::KeepAlive<>&&, T&&>,
detail::argResult<true, F, Executor::KeepAlive<>&&, Try<T>&&>>::
type>::type Arg;
......@@ -143,7 +143,7 @@ struct executorCallableResult {
template <
typename T,
typename F,
typename = std::enable_if_t<is_invocable<F, Try<T>&&>::value>>
typename = std::enable_if_t<is_invocable_v<F, Try<T>&&>>>
struct tryCallableResult {
typedef detail::argResult<true, F, Try<T>&&> Arg;
typedef isFutureOrSemiFuture<typename Arg::Result> ReturnsFuture;
......@@ -154,7 +154,7 @@ struct tryCallableResult {
template <
typename T,
typename F,
typename = std::enable_if_t<is_invocable<F, Executor*, Try<T>&&>::value>>
typename = std::enable_if_t<is_invocable_v<F, Executor*, Try<T>&&>>>
struct tryExecutorCallableResult {
typedef detail::argResult<true, F, Executor::KeepAlive<>&&, Try<T>&&> Arg;
typedef isFutureOrSemiFuture<typename Arg::Result> ReturnsFuture;
......@@ -220,7 +220,7 @@ class DeferredExecutor;
template <class T, class F>
auto makeExecutorLambda(
F&& func,
typename std::enable_if<is_invocable<F>::value, int>::type = 0) {
typename std::enable_if<is_invocable_v<F>, int>::type = 0) {
return
[func = std::forward<F>(func)](Executor::KeepAlive<>&&, auto&&) mutable {
return std::forward<F>(func)();
......@@ -230,7 +230,7 @@ auto makeExecutorLambda(
template <class T, class F>
auto makeExecutorLambda(
F&& func,
typename std::enable_if<!is_invocable<F>::value, int>::type = 0) {
typename std::enable_if<!is_invocable_v<F>, int>::type = 0) {
using R = futures::detail::callableResult<T, F&&>;
return [func = std::forward<F>(func)](
Executor::KeepAlive<>&&,
......
......@@ -1525,7 +1525,7 @@ class Future : private futures::detail::FutureBase<T> {
[[deprecated(
"onError loses the attached executor and is weakly typed. Please move to thenError instead.")]]
typename std::enable_if<
!is_invocable<F, exception_wrapper>::value &&
!is_invocable_v<F, exception_wrapper> &&
!futures::detail::Extract<F>::ReturnsFuture::value,
Future<T>>::type
onError(F&& func) && = delete;
......@@ -1545,7 +1545,7 @@ class Future : private futures::detail::FutureBase<T> {
[[deprecated(
"onError loses the attached executor and is weakly typed. Please move to thenError instead.")]]
typename std::enable_if<
!is_invocable<F, exception_wrapper>::value &&
!is_invocable_v<F, exception_wrapper> &&
futures::detail::Extract<F>::ReturnsFuture::value,
Future<T>>::type
onError(F&& func) && = delete;
......@@ -1565,7 +1565,7 @@ class Future : private futures::detail::FutureBase<T> {
[[deprecated(
"onError loses the attached executor and is weakly typed. Please move to thenError instead.")]]
typename std::enable_if<
is_invocable<F, exception_wrapper>::value &&
is_invocable_v<F, exception_wrapper> &&
futures::detail::Extract<F>::ReturnsFuture::value,
Future<T>>::type
onError(F&& func) && = delete;
......@@ -1585,7 +1585,7 @@ class Future : private futures::detail::FutureBase<T> {
[[deprecated(
"onError loses the attached executor and is weakly typed. Please move to thenError instead.")]]
typename std::enable_if<
is_invocable<F, exception_wrapper>::value &&
is_invocable_v<F, exception_wrapper> &&
!futures::detail::Extract<F>::ReturnsFuture::value,
Future<T>>::type
onError(F&& func) && = delete;
......@@ -2043,8 +2043,7 @@ template <
class It,
class F,
class ItT = typename std::iterator_traits<It>::value_type,
class Tag =
std::enable_if_t<is_invocable<F, typename ItT::value_type&&>::value>,
class Tag = std::enable_if_t<is_invocable_v<F, typename ItT::value_type&&>>,
class Result = typename decltype(
std::declval<ItT>().thenValue(std::declval<F>()))::value_type>
std::vector<Future<Result>> mapValue(It first, It last, F func);
......@@ -2058,7 +2057,7 @@ template <
class F,
class ItT = typename std::iterator_traits<It>::value_type,
class Tag =
std::enable_if_t<!is_invocable<F, typename ItT::value_type&&>::value>,
std::enable_if_t<!is_invocable_v<F, typename ItT::value_type&&>>,
class Result = typename decltype(
std::declval<ItT>().thenTry(std::declval<F>()))::value_type>
std::vector<Future<Result>> mapTry(It first, It last, F func, int = 0);
......@@ -2072,8 +2071,7 @@ template <
class It,
class F,
class ItT = typename std::iterator_traits<It>::value_type,
class Tag =
std::enable_if_t<is_invocable<F, typename ItT::value_type&&>::value>,
class Tag = std::enable_if_t<is_invocable_v<F, typename ItT::value_type&&>>,
class Result =
typename decltype(std::move(std::declval<ItT>())
.via(std::declval<Executor*>())
......@@ -2090,7 +2088,7 @@ template <
class F,
class ItT = typename std::iterator_traits<It>::value_type,
class Tag =
std::enable_if_t<!is_invocable<F, typename ItT::value_type&&>::value>,
std::enable_if_t<!is_invocable_v<F, typename ItT::value_type&&>>,
class Result =
typename decltype(std::move(std::declval<ItT>())
.via(std::declval<Executor*>())
......@@ -2497,7 +2495,7 @@ window(Executor::KeepAlive<> executor, Collection input, F func, size_t n);
template <typename F, typename T, typename ItT>
using MaybeTryArg = typename std::
conditional<is_invocable<F, T&&, Try<ItT>&&>::value, Try<ItT>, ItT>::type;
conditional<is_invocable_v<F, T&&, Try<ItT>&&>, Try<ItT>, ItT>::type;
/** repeatedly calls func on every result, e.g.
reduce(reduce(reduce(T initial, result of first), result of second), ...)
......
......@@ -645,7 +645,7 @@ void throwIfExceptionOccurred(Request&, Waiter& waiter, bool exception) {
// avoid leaks. If we don't destroy the exception_ptr in storage, the
// refcount for the internal exception will never hit zero, thereby leaking
// memory
if (UNLIKELY(!folly::is_nothrow_invocable<const F&>{} && exception)) {
if (UNLIKELY(!folly::is_nothrow_invocable_v<const F&> && exception)) {
auto storage = &waiter.storage_;
auto exc = folly::launder(reinterpret_cast<std::exception_ptr*>(storage));
auto copy = std::move(*exc);
......
......@@ -135,7 +135,7 @@ class InlineFunctionRef<ReturnType(Args...), Size> {
std::enable_if_t<
!std::is_same<std::decay_t<Func>, InlineFunctionRef>{} &&
!std::is_reference<Func>{} &&
folly::is_invocable_r<ReturnType, Func&&, Args&&...>{}>* = nullptr>
folly::is_invocable_r_v<ReturnType, Func&&, Args&&...>>* = nullptr>
InlineFunctionRef(Func&& func) {
// We disallow construction from lvalues, so assert that this is not a
// reference type. When invoked with an lvalue, Func is a lvalue
......
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