11#include <catch2/catch.hpp>
24using Example = tuple<unsigned char, int, double, unique_ptr<X>>;
30 static_assert(is_same_v<Example, Apply_t<tuple, ExampleList>>);
32 static_assert(is_tuple_v<Example>);
33 static_assert(!is_tuple_v<std::pair<int, double>>);
34 static_assert(!is_tuple_v<std::array<int, 2>>);
35 static_assert(!is_tuple_v<ExampleList>);
37 static_assert(is_tuple_like_v<Example>);
38 static_assert(is_tuple_like_v<std::pair<int, double>>);
39 static_assert(is_tuple_like_v<std::array<int, 2>>);
40 static_assert(!is_tuple_like_v<ExampleList>);
42 static_assert(Empty_v<tuple<>>);
43 REQUIRE(
Empty(tuple{}));
45 Example ex1{
'\0', 1, 2.0, make_unique<X>() };
46 static_assert(!Empty_v<Example>);
49 const auto &cex1 = ex1;
51 SECTION(
"Projections")
53 auto p0 = Project<>(ex1);
54 static_assert(is_same_v<
decltype(p0), tuple<>>);
56 auto p1 = Project<2>(cex1);
57 static_assert(is_same_v<
decltype(p1), tuple<double>>);
58 REQUIRE(get<0>(p1) == 2.0);
60 auto p2 = Project<0, 2>(move(cex1));
61 static_assert(is_same_v<
decltype(p2), tuple<unsigned char, double>>);
62 REQUIRE(get<0>(p2) ==
'\0');
64 auto p3 = Project<0, 1, 2>(ex1);
65 static_assert(is_same_v<
decltype(p3), tuple<unsigned char, int, double>>);
66 REQUIRE(get<1>(ex1) == 1);
67 REQUIRE(get<1>(p3) == 1);
70 REQUIRE(get<1>(ex1) == 2);
71 REQUIRE(get<1>(p3) == 1);
73 REQUIRE(get<1>(ex1) == 2);
74 REQUIRE(get<1>(p3) == 2);
76 const auto pX = get<3>(ex1).get();
78 auto p4 = Project<0, 1, 2, 3>(move(ex1));
79 static_assert(is_same_v<
decltype(p4),
Example>);
80 REQUIRE(get<3>(p4).get() == pX);
82 REQUIRE(!get<3>(ex1).get());
85 SECTION(
"Forwarding Projections")
87 auto p0 = ForwardProject<>(ex1);
88 static_assert(is_same_v<
decltype(p0), tuple<>>);
90 auto p1 = ForwardProject<2>(cex1);
91 static_assert(is_same_v<
decltype(p1), tuple<const double&>>);
92 REQUIRE(get<0>(p1) == 2.0);
94 auto p2 = ForwardProject<0, 2>(move(cex1));
95 static_assert(is_same_v<
decltype(p2),
96 tuple<const unsigned char &&, const double&&>>);
97 REQUIRE(get<0>(p2) ==
'\0');
99 auto p3 = ForwardProject<0, 1, 2>(ex1);
100 static_assert(is_same_v<
decltype(p3),
101 tuple<unsigned char&, int&, double&>>);
102 REQUIRE(get<1>(ex1) == 1);
103 REQUIRE(get<1>(p3) == 1);
106 REQUIRE(get<1>(ex1) == 2);
107 REQUIRE(get<1>(p3) == 2);
109 REQUIRE(get<1>(ex1) == 3);
110 REQUIRE(get<1>(p3) == 3);
112 const auto pX = get<3>(ex1).get();
114 auto p4 = ForwardProject<0, 1, 2, 3>(move(ex1));
115 static_assert(is_same_v<
decltype(p4),
116 tuple<
unsigned char &&,
int&&,
double &&, unique_ptr<X>&&>>);
117 REQUIRE(get<3>(p4).get() == pX);
119 REQUIRE(get<3>(ex1).get());
120 auto discard = move(get<3>(p4));
122 REQUIRE(!get<3>(ex1).get());
Extraction of sub-tuples of std::tuple (or other tuple-like classes)
Metaprogramming utilities for manipulating lists of types.
constexpr bool Empty(const Tuple &tuple)
Utilities for compile-time type manipulation. Some terminology as in Lisp.
tuple< unsigned char, int, double, unique_ptr< X > > Example
Primary template for a list of arbitrary types.