Lumiera 0.pre.04~rc.1
»edit your freedom«
Loading...
Searching...
No Matches
variadic-helper-test.cpp
Go to the documentation of this file.
1/*
2 VariadicHelper(Test) - verify helpers for transforming variadics and tuple-like types
3
4 Copyright (C)
5 2024, Hermann Vosseler <Ichthyostega@web.de>
6
7  **Lumiera** is free software; you can redistribute it and/or modify it
8  under the terms of the GNU General Public License as published by the
9  Free Software Foundation; either version 2 of the License, or (at your
10  option) any later version. See the file COPYING for further details.
11
12* *****************************************************************/
13
14
25#include "lib/test/run.hpp"
29#include "lib/hetero-data.hpp"
31
32#include <array>
33
35using std::array;
36using std::tuple;
37
38
39namespace lib {
40namespace meta {
41namespace test {
42
43
44
45
46
47 /*********************************************************************/
51 class VariadicHelper_test : public Test
52 {
53 virtual void
54 run (Arg)
55 {
57 }
58
59
65 void
67 {
68 // CASE-1 : a tuple....
69 using T1 = tuple<int,double>;
70
71 using S1 = ElmTypes<T1>;
72 CHECK (2 == S1::SIZ);
73 CHECK (showType< S1 >() == "ElmTypes<tuple<int, double>, void>"_expect);
74 CHECK (showType< S1::Seq >() == "Types<int, double>"_expect);
75 CHECK (showType< S1::Tup >() == "tuple<int, double>"_expect);
76 CHECK (showType< S1::Idx >() == "integer_sequence<ulong, 0ul, 1ul>"_expect);
77
78 using S1A = S1::Apply<std::is_pointer>;
79 CHECK (showType< S1A >() == "Types<is_pointer<int>, is_pointer<double> >"_expect);
80
81 using S1AR = ElmTypes<S1A>::Rebind<std::__and_>;
82 CHECK (showType< S1AR >() == "__and_<is_pointer<int>, is_pointer<double> >"_expect);
83 CHECK (false == S1AR::value);
84
85 using S1AA = S1::AndAll<std::is_pointer>;
86 CHECK (showType< S1AA >() == "__and_<is_pointer<int>, is_pointer<double> >"_expect);
87 CHECK (false == S1AA::value);
88
89 using S1OA = S1::OrAll<std::is_pointer>;
90 CHECK (showType< S1OA >() == "__or_<is_pointer<int>, is_pointer<double> >"_expect);
91 CHECK (false == S1OA::value);
92
93
94
95 // CASE-0 : handling an unstructured simple type....
96 using T0 = int*;
97
98 using S0 = ElmTypes<T0>;
99 CHECK (1 == S0::SIZ);
100 CHECK (showType< S0 >() == "ElmTypes<int*, void>"_expect);
101 CHECK (showType< S0::Seq >() == "Types<int*>"_expect);
102 CHECK (showType< S0::Tup >() == "tuple<int*>"_expect);
103 CHECK (showType< S0::Idx >() == "integer_sequence<ulong, 1ul>"_expect);
104
105 using S0A = S0::Apply<std::is_pointer>;
106 CHECK (showType< S0A >() == "Types<is_pointer<int*> >"_expect);
107
108 using S0AA = S0::AndAll<std::is_pointer>;
109 CHECK (showType< S0AA >() == "__and_<is_pointer<int*> >"_expect);
110 CHECK (true == S0AA::value);
111
112 using S0OA = S0::OrAll<std::is_pointer>;
113 CHECK (showType< S0OA >() == "__or_<is_pointer<int*> >"_expect);
114 CHECK (true == S0OA::value);
115
116
117
118 // CASE-2 : can also handle a std::array....
119 using T2 = array<int*,3>;
120
121 using S2 = ElmTypes<T2>;
122 CHECK (3 == S2::SIZ);
123 CHECK (showType< S2 >() == "ElmTypes<array<int*, 3ul>, void>"_expect);
124 CHECK (showType< S2::Seq >() == "Types<int*, int*, int*>"_expect);
125 CHECK (showType< S2::Tup >() == "tuple<int*, int*, int*>"_expect);
126 CHECK (showType< S2::Idx >() == "integer_sequence<ulong, 0ul, 1ul, 2ul>"_expect);
127
128 using S2A = S2::Apply<std::is_pointer>;
129 CHECK (showType< S2A >() == "Types<is_pointer<int*>, is_pointer<int*>, is_pointer<int*> >"_expect);
130
131 using S2AA = S2::AndAll<std::is_pointer>;
132 CHECK (showType< S2AA >() == "__and_<is_pointer<int*>, is_pointer<int*>, is_pointer<int*> >"_expect);
133 CHECK (true == S2AA::value);
134
135 using S2OA = S2::OrAll<std::is_pointer>;
136 CHECK (showType< S2OA >() == "__or_<is_pointer<int*>, is_pointer<int*>, is_pointer<int*> >"_expect);
137 CHECK (true == S2OA::value);
138
139
140
141 // CASE-3 : a custom type which implements the C++ »tuple protocol«....
143
144 using S3 = ElmTypes<T3>;
145 CHECK (3 == S3::SIZ);
146 CHECK (showType< S3 >() == "ElmTypes<HeteroData<int*, long, double*>, void>"_expect);
147 CHECK (showType< S3::Seq >() == "Types<int*, long, double*>"_expect);
148 CHECK (showType< S3::Idx >() == "integer_sequence<ulong, 0ul, 1ul, 2ul>"_expect);
149
150 using S3A = S3::Apply<std::is_pointer>;
151 CHECK (showType< S3A >() == "Types<is_pointer<int*>, is_pointer<long>, is_pointer<double*> >"_expect);
152
153 using S3AA = S3::AndAll<std::is_pointer>;
154 CHECK (showType< S3AA >() == "__and_<is_pointer<int*>, is_pointer<long>, is_pointer<double*> >"_expect);
155 CHECK (false == S3AA::value);
156
157 using S3OA = S3::OrAll<std::is_pointer>;
158 CHECK (showType< S3OA >() == "__or_<is_pointer<int*>, is_pointer<long>, is_pointer<double*> >"_expect);
159 CHECK (true == S3OA::value);
160 }
161 };
162
163
166
167
168
169}}} // namespace lib::meta::test
A setup with chained data tuples residing in distributed storage.
Helpers typically used while writing tests.
Maintain a chained sequence of heterogeneous data blocks without allocation.
enable_if_c< Cond::value, T >::type enable_if
SFINAE helper to control the visibility of specialisations and overloads.
Definition meta/util.hpp:87
string showType()
diagnostic type output, including const and similar adornments
Implementation namespace for support and library code.
Test runner and basic definitions for tests.
Simplistic test class runner.
#define LAUNCHER(_TEST_CLASS_, _GROUPS_)
Definition run.hpp:116
A collection of frequently used helper functions to support unit testing.
Metaprogramming with tuples-of-types and the std::tuple record.
Metaprogramming with type sequences based on variadic template parameters.