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>
using apply_result_t = invoke_result_t<ApplyInvoke, F, Tuple>;
template <typename F, typename 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>
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>
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>
struct is_nothrow_applicable_r
: 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 apply_tuple {
......
......@@ -477,56 +477,55 @@ TEST(ApplyResult, Basic) {
TEST(IsApplicable, Basic) {
{
auto f = [] {};
EXPECT_TRUE((folly::is_applicable<decltype(f), std::tuple<>>::value));
EXPECT_FALSE((folly::is_applicable<decltype(f), std::tuple<int>>::value));
EXPECT_TRUE((folly::is_applicable_v<decltype(f), std::tuple<>>));
EXPECT_FALSE((folly::is_applicable_v<decltype(f), std::tuple<int>>));
}
{
auto f = folly::overload([](int) {}, [](double) -> double { return {}; });
EXPECT_TRUE((folly::is_applicable<decltype(f), std::tuple<double>>::value));
EXPECT_TRUE((folly::is_applicable<decltype(f), std::tuple<int>>::value));
EXPECT_FALSE((folly::is_applicable<decltype(f), std::tuple<>>::value));
EXPECT_TRUE((folly::is_applicable_v<decltype(f), std::tuple<double>>));
EXPECT_TRUE((folly::is_applicable_v<decltype(f), std::tuple<int>>));
EXPECT_FALSE((folly::is_applicable_v<decltype(f), std::tuple<>>));
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) {
{
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(
(folly::is_nothrow_applicable<decltype(f), std::tuple<int>>{}));
(folly::is_nothrow_applicable_v<decltype(f), std::tuple<int>>));
}
{
auto f = folly::overload(
[](int) noexcept {}, [](double) -> double { return {}; });
EXPECT_FALSE(
(folly::is_nothrow_applicable<decltype(f), std::tuple<double>>{}));
EXPECT_TRUE((folly::is_nothrow_applicable<decltype(f), std::tuple<int>>{}));
EXPECT_FALSE((folly::is_nothrow_applicable<decltype(f), std::tuple<>>{}));
(folly::is_nothrow_applicable_v<decltype(f), std::tuple<double>>));
EXPECT_TRUE((folly::is_nothrow_applicable_v<decltype(f), std::tuple<int>>));
EXPECT_FALSE((folly::is_nothrow_applicable_v<decltype(f), std::tuple<>>));
EXPECT_FALSE(
(folly::is_nothrow_applicable<decltype(f), std::tuple<int, double>>::
value));
(folly::is_nothrow_applicable_v<decltype(f), std::tuple<int, double>>));
}
}
TEST(IsApplicableR, Basic) {
{
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(
(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(
[](int) noexcept {}, [](double) -> double { return {}; });
EXPECT_TRUE(
(folly::is_applicable_r<float, decltype(f), std::tuple<double>>{}));
EXPECT_TRUE((folly::is_applicable_r<void, decltype(f), std::tuple<int>>{}));
EXPECT_FALSE((folly::is_applicable_r<void, decltype(f), std::tuple<>>{}));
(folly::is_applicable_r_v<float, decltype(f), std::tuple<double>>));
EXPECT_TRUE((folly::is_applicable_r_v<void, decltype(f), std::tuple<int>>));
EXPECT_FALSE((folly::is_applicable_r_v<void, decltype(f), std::tuple<>>));
EXPECT_FALSE(
(folly::is_applicable_r<double, decltype(f), std::tuple<int, double>>::
value));
(folly::
is_applicable_r_v<double, decltype(f), std::tuple<int, double>>));
}
}
......@@ -536,25 +535,25 @@ TEST(IsNothrowApplicableR, Basic) {
return {};
};
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(
(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(
[](int) noexcept {}, [](double) -> double { return {}; });
EXPECT_FALSE((
folly::
is_nothrow_applicable_r<float, decltype(f), std::tuple<double>>{}));
is_nothrow_applicable_r_v<float, decltype(f), std::tuple<double>>));
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(
(folly::is_nothrow_applicable_r<void, decltype(f), std::tuple<>>{}));
EXPECT_FALSE((folly::is_nothrow_applicable_r<
(folly::is_nothrow_applicable_r_v<void, decltype(f), std::tuple<>>));
EXPECT_FALSE((folly::is_nothrow_applicable_r_v<
double,
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