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