29{
30 static_assert(is_same_v<Example, Apply_t<tuple, ExampleList>>);
31
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>);
36
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>);
41
42 static_assert(Empty_v<tuple<>>);
43 REQUIRE(
Empty(tuple{}));
44
45 Example ex1{
'\0', 1, 2.0, make_unique<X>() };
46 static_assert(!Empty_v<Example>);
48
49 const auto &cex1 = ex1;
50
51 SECTION("Projections")
52 {
53 auto p0 = Project<>(ex1);
54 static_assert(is_same_v<decltype(p0), tuple<>>);
55
56 auto p1 = Project<2>(cex1);
57 static_assert(is_same_v<decltype(p1), tuple<double>>);
58 REQUIRE(get<0>(p1) == 2.0);
59
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');
63
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);
68
69 ++get<1>(ex1);
70 REQUIRE(get<1>(ex1) == 2);
71 REQUIRE(get<1>(p3) == 1);
72 ++get<1>(p3);
73 REQUIRE(get<1>(ex1) == 2);
74 REQUIRE(get<1>(p3) == 2);
75
76 const auto pX = get<3>(ex1).get();
77 REQUIRE(pX);
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);
81
82 REQUIRE(!get<3>(ex1).get());
83 }
84
85 SECTION("Forwarding Projections")
86 {
87 auto p0 = ForwardProject<>(ex1);
88 static_assert(is_same_v<decltype(p0), tuple<>>);
89
90 auto p1 = ForwardProject<2>(cex1);
91 static_assert(is_same_v<decltype(p1), tuple<const double&>>);
92 REQUIRE(get<0>(p1) == 2.0);
93
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');
98
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);
104
105 ++get<1>(ex1);
106 REQUIRE(get<1>(ex1) == 2);
107 REQUIRE(get<1>(p3) == 2);
108 ++get<1>(p3);
109 REQUIRE(get<1>(ex1) == 3);
110 REQUIRE(get<1>(p3) == 3);
111
112 const auto pX = get<3>(ex1).get();
113 REQUIRE(pX);
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);
118
119 REQUIRE(get<3>(ex1).get());
120 auto discard = move(get<3>(p4));
121
122 REQUIRE(!get<3>(ex1).get());
123 }
124}
constexpr bool Empty(const Tuple &tuple)
tuple< unsigned char, int, double, unique_ptr< X > > Example