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

DRY the applicability traits tests a little

Summary: [Folly] DRY the applicability traits tests a little by extracting a type alias.

Reviewed By: markisaa

Differential Revision: D18748005

fbshipit-source-id: 15d0ceec078a925e7205e7d9398b55cd03004a07
parent b6a14167
...@@ -451,9 +451,9 @@ TEST(MakeIndexSequenceFromTuple, Basic) { ...@@ -451,9 +451,9 @@ TEST(MakeIndexSequenceFromTuple, Basic) {
TEST(ApplyResult, Basic) { TEST(ApplyResult, Basic) {
{ {
auto f = [](auto) -> int { return {}; }; auto f = [](auto) -> int { return {}; };
EXPECT_TRUE((std::is_same< using F = decltype(f);
folly::apply_result_t<decltype(f), std::tuple<int>>, EXPECT_TRUE(
int>{})); (std::is_same<folly::apply_result_t<F, std::tuple<int>>, int>{}));
} }
{ {
...@@ -461,71 +461,70 @@ TEST(ApplyResult, Basic) { ...@@ -461,71 +461,70 @@ TEST(ApplyResult, Basic) {
[](int) {}, [](int) {},
[](double) -> double { return {}; }, [](double) -> double { return {}; },
[](int, int) -> int { return {}; }); [](int, int) -> int { return {}; });
using F = decltype(f);
EXPECT_TRUE((std::is_same< EXPECT_TRUE(
folly::apply_result_t<decltype(f), std::tuple<int>>, (std::is_same<folly::apply_result_t<F, std::tuple<int>>, void>::value));
void>::value)); EXPECT_TRUE(
EXPECT_TRUE((std::is_same< (std::is_same<folly::apply_result_t<F, std::tuple<double>>, double>::
folly::apply_result_t<decltype(f), std::tuple<double>>, value));
double>::value)); EXPECT_TRUE(
EXPECT_TRUE((std::is_same< (std::is_same<folly::apply_result_t<F, std::tuple<int, int>>, int>::
folly::apply_result_t<decltype(f), std::tuple<int, int>>, value));
int>::value));
} }
} }
TEST(IsApplicable, Basic) { TEST(IsApplicable, Basic) {
{ {
auto f = [] {}; auto f = [] {};
EXPECT_TRUE((folly::is_applicable_v<decltype(f), std::tuple<>>)); using F = decltype(f);
EXPECT_FALSE((folly::is_applicable_v<decltype(f), std::tuple<int>>)); EXPECT_TRUE((folly::is_applicable_v<F, std::tuple<>>));
EXPECT_FALSE((folly::is_applicable_v<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_v<decltype(f), std::tuple<double>>)); using F = decltype(f);
EXPECT_TRUE((folly::is_applicable_v<decltype(f), std::tuple<int>>)); EXPECT_TRUE((folly::is_applicable_v<F, std::tuple<double>>));
EXPECT_FALSE((folly::is_applicable_v<decltype(f), std::tuple<>>)); EXPECT_TRUE((folly::is_applicable_v<F, std::tuple<int>>));
EXPECT_FALSE( EXPECT_FALSE((folly::is_applicable_v<F, std::tuple<>>));
(folly::is_applicable_v<decltype(f), std::tuple<int, double>>)); EXPECT_FALSE((folly::is_applicable_v<F, std::tuple<int, double>>));
} }
} }
TEST(IsNothrowApplicable, Basic) { TEST(IsNothrowApplicable, Basic) {
{ {
auto f = []() noexcept {}; auto f = []() noexcept {};
EXPECT_TRUE((folly::is_nothrow_applicable_v<decltype(f), std::tuple<>>)); using F = decltype(f);
EXPECT_FALSE( EXPECT_TRUE((folly::is_nothrow_applicable_v<F, std::tuple<>>));
(folly::is_nothrow_applicable_v<decltype(f), std::tuple<int>>)); EXPECT_FALSE((folly::is_nothrow_applicable_v<F, std::tuple<int>>));
} }
{ {
auto f = folly::overload( auto f = folly::overload(
[](int) noexcept {}, [](double) -> double { return {}; }); [](int) noexcept {}, [](double) -> double { return {}; });
EXPECT_FALSE( using F = decltype(f);
(folly::is_nothrow_applicable_v<decltype(f), std::tuple<double>>)); EXPECT_FALSE((folly::is_nothrow_applicable_v<F, std::tuple<double>>));
EXPECT_TRUE((folly::is_nothrow_applicable_v<decltype(f), std::tuple<int>>)); EXPECT_TRUE((folly::is_nothrow_applicable_v<F, std::tuple<int>>));
EXPECT_FALSE((folly::is_nothrow_applicable_v<decltype(f), std::tuple<>>)); EXPECT_FALSE((folly::is_nothrow_applicable_v<F, std::tuple<>>));
EXPECT_FALSE( EXPECT_FALSE((folly::is_nothrow_applicable_v<F, std::tuple<int, double>>));
(folly::is_nothrow_applicable_v<decltype(f), std::tuple<int, double>>));
} }
} }
TEST(IsApplicableR, Basic) { TEST(IsApplicableR, Basic) {
{ {
auto f = []() -> int { return {}; }; auto f = []() -> int { return {}; };
EXPECT_TRUE((folly::is_applicable_r_v<double, decltype(f), std::tuple<>>)); using F = decltype(f);
EXPECT_FALSE( EXPECT_TRUE((folly::is_applicable_r_v<double, F, std::tuple<>>));
(folly::is_applicable_r_v<double, decltype(f), std::tuple<int>>)); EXPECT_FALSE((folly::is_applicable_r_v<double, F, std::tuple<int>>));
} }
{ {
auto f = folly::overload( auto f = folly::overload(
[](int) noexcept {}, [](double) -> double { return {}; }); [](int) noexcept {}, [](double) -> double { return {}; });
EXPECT_TRUE( using F = decltype(f);
(folly::is_applicable_r_v<float, decltype(f), std::tuple<double>>)); EXPECT_TRUE((folly::is_applicable_r_v<float, F, std::tuple<double>>));
EXPECT_TRUE((folly::is_applicable_r_v<void, decltype(f), std::tuple<int>>)); EXPECT_TRUE((folly::is_applicable_r_v<void, F, std::tuple<int>>));
EXPECT_FALSE((folly::is_applicable_r_v<void, decltype(f), std::tuple<>>)); EXPECT_FALSE((folly::is_applicable_r_v<void, F, std::tuple<>>));
EXPECT_FALSE( EXPECT_FALSE(
(folly:: (folly::is_applicable_r_v<double, F, std::tuple<int, double>>));
is_applicable_r_v<double, decltype(f), std::tuple<int, double>>));
} }
} }
...@@ -534,26 +533,21 @@ TEST(IsNothrowApplicableR, Basic) { ...@@ -534,26 +533,21 @@ TEST(IsNothrowApplicableR, Basic) {
auto f = []() noexcept->int { auto f = []() noexcept->int {
return {}; return {};
}; };
EXPECT_TRUE( using F = decltype(f);
(folly::is_nothrow_applicable_r_v<double, decltype(f), std::tuple<>>)); EXPECT_TRUE((folly::is_nothrow_applicable_r_v<double, F, std::tuple<>>));
EXPECT_FALSE( EXPECT_FALSE(
(folly:: (folly::is_nothrow_applicable_r_v<double, 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(( using F = decltype(f);
folly:: EXPECT_FALSE(
is_nothrow_applicable_r_v<float, decltype(f), std::tuple<double>>)); (folly::is_nothrow_applicable_r_v<float, F, std::tuple<double>>));
EXPECT_TRUE( EXPECT_TRUE((folly::is_nothrow_applicable_r_v<void, F, std::tuple<int>>));
(folly::is_nothrow_applicable_r_v<void, decltype(f), std::tuple<int>>)); EXPECT_FALSE((folly::is_nothrow_applicable_r_v<void, F, std::tuple<>>));
EXPECT_FALSE( EXPECT_FALSE(
(folly::is_nothrow_applicable_r_v<void, decltype(f), std::tuple<>>)); (folly::is_nothrow_applicable_r_v<double, F, std::tuple<int, double>>));
EXPECT_FALSE((folly::is_nothrow_applicable_r_v<
double,
decltype(f),
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