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

Helper variable templates for tuple applicability traits

Summary: [Folly] Helper variable templates for tuple applicability traits: `is_applicable_v`, `is_applicable_r_v`, `is_nothrow_applicable_v`, `is_nothrow_applicable_r_v`.

Reviewed By: lewissbaker

Differential Revision: D18746853

fbshipit-source-id: 9d01b24030f95ab5b4963660dc4ef471b5e0ad02
parent 59c0f069
...@@ -134,13 +134,25 @@ template <typename F, typename Tuple> ...@@ -134,13 +134,25 @@ template <typename F, typename Tuple>
using apply_result_t = invoke_result_t<ApplyInvoke, F, Tuple>; using apply_result_t = invoke_result_t<ApplyInvoke, F, Tuple>;
template <typename F, typename Tuple> template <typename F, typename Tuple>
struct is_applicable : is_invocable<ApplyInvoke, F, Tuple> {}; struct is_applicable : is_invocable<ApplyInvoke, F, Tuple> {};
template <typename F, typename Tuple>
FOLLY_INLINE_VARIABLE constexpr bool is_applicable_v =
is_applicable<F, Tuple>::value;
template <typename R, typename F, typename Tuple> template <typename R, typename F, typename Tuple>
struct is_applicable_r : is_invocable_r<R, ApplyInvoke, F, Tuple> {}; struct is_applicable_r : is_invocable_r<R, ApplyInvoke, F, Tuple> {};
template <typename R, typename F, typename Tuple>
FOLLY_INLINE_VARIABLE constexpr bool is_applicable_r_v =
is_applicable_r<R, F, Tuple>::value;
template <typename F, typename Tuple> template <typename F, typename Tuple>
struct is_nothrow_applicable : is_nothrow_invocable<ApplyInvoke, F, Tuple> {}; struct is_nothrow_applicable : is_nothrow_invocable<ApplyInvoke, F, Tuple> {};
template <typename F, typename Tuple>
FOLLY_INLINE_VARIABLE constexpr bool is_nothrow_applicable_v =
is_nothrow_applicable<F, Tuple>::value;
template <typename R, typename F, typename Tuple> template <typename R, typename F, typename Tuple>
struct is_nothrow_applicable_r struct is_nothrow_applicable_r
: is_nothrow_invocable_r<R, ApplyInvoke, F, Tuple> {}; : is_nothrow_invocable_r<R, ApplyInvoke, F, Tuple> {};
template <typename R, typename F, typename Tuple>
FOLLY_INLINE_VARIABLE constexpr bool is_nothrow_applicable_r_v =
is_nothrow_applicable_r<R, F, Tuple>::value;
namespace detail { namespace detail {
namespace apply_tuple { namespace apply_tuple {
......
...@@ -477,56 +477,55 @@ TEST(ApplyResult, Basic) { ...@@ -477,56 +477,55 @@ TEST(ApplyResult, Basic) {
TEST(IsApplicable, Basic) { TEST(IsApplicable, Basic) {
{ {
auto f = [] {}; auto f = [] {};
EXPECT_TRUE((folly::is_applicable<decltype(f), std::tuple<>>::value)); EXPECT_TRUE((folly::is_applicable_v<decltype(f), std::tuple<>>));
EXPECT_FALSE((folly::is_applicable<decltype(f), std::tuple<int>>::value)); EXPECT_FALSE((folly::is_applicable_v<decltype(f), std::tuple<int>>));
} }
{ {
auto f = folly::overload([](int) {}, [](double) -> double { return {}; }); auto f = folly::overload([](int) {}, [](double) -> double { return {}; });
EXPECT_TRUE((folly::is_applicable<decltype(f), std::tuple<double>>::value)); EXPECT_TRUE((folly::is_applicable_v<decltype(f), std::tuple<double>>));
EXPECT_TRUE((folly::is_applicable<decltype(f), std::tuple<int>>::value)); EXPECT_TRUE((folly::is_applicable_v<decltype(f), std::tuple<int>>));
EXPECT_FALSE((folly::is_applicable<decltype(f), std::tuple<>>::value)); EXPECT_FALSE((folly::is_applicable_v<decltype(f), std::tuple<>>));
EXPECT_FALSE( EXPECT_FALSE(
(folly::is_applicable<decltype(f), std::tuple<int, double>>::value)); (folly::is_applicable_v<decltype(f), std::tuple<int, double>>));
} }
} }
TEST(IsNothrowApplicable, Basic) { TEST(IsNothrowApplicable, Basic) {
{ {
auto f = []() noexcept {}; auto f = []() noexcept {};
EXPECT_TRUE((folly::is_nothrow_applicable<decltype(f), std::tuple<>>{})); EXPECT_TRUE((folly::is_nothrow_applicable_v<decltype(f), std::tuple<>>));
EXPECT_FALSE( EXPECT_FALSE(
(folly::is_nothrow_applicable<decltype(f), std::tuple<int>>{})); (folly::is_nothrow_applicable_v<decltype(f), std::tuple<int>>));
} }
{ {
auto f = folly::overload( auto f = folly::overload(
[](int) noexcept {}, [](double) -> double { return {}; }); [](int) noexcept {}, [](double) -> double { return {}; });
EXPECT_FALSE( EXPECT_FALSE(
(folly::is_nothrow_applicable<decltype(f), std::tuple<double>>{})); (folly::is_nothrow_applicable_v<decltype(f), std::tuple<double>>));
EXPECT_TRUE((folly::is_nothrow_applicable<decltype(f), std::tuple<int>>{})); EXPECT_TRUE((folly::is_nothrow_applicable_v<decltype(f), std::tuple<int>>));
EXPECT_FALSE((folly::is_nothrow_applicable<decltype(f), std::tuple<>>{})); EXPECT_FALSE((folly::is_nothrow_applicable_v<decltype(f), std::tuple<>>));
EXPECT_FALSE( EXPECT_FALSE(
(folly::is_nothrow_applicable<decltype(f), std::tuple<int, double>>:: (folly::is_nothrow_applicable_v<decltype(f), std::tuple<int, double>>));
value));
} }
} }
TEST(IsApplicableR, Basic) { TEST(IsApplicableR, Basic) {
{ {
auto f = []() -> int { return {}; }; auto f = []() -> int { return {}; };
EXPECT_TRUE((folly::is_applicable_r<double, decltype(f), std::tuple<>>{})); EXPECT_TRUE((folly::is_applicable_r_v<double, decltype(f), std::tuple<>>));
EXPECT_FALSE( EXPECT_FALSE(
(folly::is_applicable_r<double, decltype(f), std::tuple<int>>{})); (folly::is_applicable_r_v<double, decltype(f), std::tuple<int>>));
} }
{ {
auto f = folly::overload( auto f = folly::overload(
[](int) noexcept {}, [](double) -> double { return {}; }); [](int) noexcept {}, [](double) -> double { return {}; });
EXPECT_TRUE( EXPECT_TRUE(
(folly::is_applicable_r<float, decltype(f), std::tuple<double>>{})); (folly::is_applicable_r_v<float, decltype(f), std::tuple<double>>));
EXPECT_TRUE((folly::is_applicable_r<void, decltype(f), std::tuple<int>>{})); EXPECT_TRUE((folly::is_applicable_r_v<void, decltype(f), std::tuple<int>>));
EXPECT_FALSE((folly::is_applicable_r<void, decltype(f), std::tuple<>>{})); EXPECT_FALSE((folly::is_applicable_r_v<void, decltype(f), std::tuple<>>));
EXPECT_FALSE( EXPECT_FALSE(
(folly::is_applicable_r<double, decltype(f), std::tuple<int, double>>:: (folly::
value)); is_applicable_r_v<double, decltype(f), std::tuple<int, double>>));
} }
} }
...@@ -536,25 +535,25 @@ TEST(IsNothrowApplicableR, Basic) { ...@@ -536,25 +535,25 @@ TEST(IsNothrowApplicableR, Basic) {
return {}; return {};
}; };
EXPECT_TRUE( EXPECT_TRUE(
(folly::is_nothrow_applicable_r<double, decltype(f), std::tuple<>>{})); (folly::is_nothrow_applicable_r_v<double, decltype(f), std::tuple<>>));
EXPECT_FALSE( EXPECT_FALSE(
(folly:: (folly::
is_nothrow_applicable_r<double, decltype(f), std::tuple<int>>{})); is_nothrow_applicable_r_v<double, decltype(f), std::tuple<int>>));
} }
{ {
auto f = folly::overload( auto f = folly::overload(
[](int) noexcept {}, [](double) -> double { return {}; }); [](int) noexcept {}, [](double) -> double { return {}; });
EXPECT_FALSE(( EXPECT_FALSE((
folly:: folly::
is_nothrow_applicable_r<float, decltype(f), std::tuple<double>>{})); is_nothrow_applicable_r_v<float, decltype(f), std::tuple<double>>));
EXPECT_TRUE( EXPECT_TRUE(
(folly::is_nothrow_applicable_r<void, decltype(f), std::tuple<int>>{})); (folly::is_nothrow_applicable_r_v<void, decltype(f), std::tuple<int>>));
EXPECT_FALSE( EXPECT_FALSE(
(folly::is_nothrow_applicable_r<void, decltype(f), std::tuple<>>{})); (folly::is_nothrow_applicable_r_v<void, decltype(f), std::tuple<>>));
EXPECT_FALSE((folly::is_nothrow_applicable_r< EXPECT_FALSE((folly::is_nothrow_applicable_r_v<
double, double,
decltype(f), decltype(f),
std::tuple<int, double>>::value)); std::tuple<int, double>>));
} }
} }
......
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