-
Notifications
You must be signed in to change notification settings - Fork 496
Expand file tree
/
Copy pathtest_StructToTuple.cxx
More file actions
166 lines (153 loc) · 3.75 KB
/
test_StructToTuple.cxx
File metadata and controls
166 lines (153 loc) · 3.75 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
// Copyright 2019-2020 CERN and copyright holders of ALICE O2.
// See https://alice-o2.web.cern.ch/copyright for details of the copyright holders.
// All rights not expressly granted are reserved.
//
// This software is distributed under the terms of the GNU General Public
// License v3 (GPL Version 3), copied verbatim in the file "COPYING".
//
// In applying this license CERN does not waive the privileges and immunities
// granted to it by virtue of its status as an Intergovernmental Organization
// or submit itself to any jurisdiction.
#include <catch_amalgamated.hpp>
#include "Framework/StructToTuple.h"
struct Foo0 {
};
struct Foo1 {
int foo = 1;
};
// FIXME: this should really struct Bar : Foo, but a c++17 bug
// in GCC 7.3 (solved in 7.4 / 8.x) prevents us from doing so
// for now.
struct Bar {
int foo = 1;
int bar = 2;
};
TEST_CASE("SimpleDestructuring")
{
Foo0 foo0;
auto t0 = o2::framework::homogeneous_apply_refs([](auto i) -> bool { return i > 1; }, foo0);
REQUIRE(t0.size() == 0);
Foo1 foo1;
auto t1 = o2::framework::homogeneous_apply_refs([](auto i) -> bool { return i > 1; }, foo1);
REQUIRE(t1.size() == 1);
// Should work with refs as well. When moving to C++20 this was
// not the case initially.
Foo1 const&& foo1ref = std::move(foo1);
auto t1ref = o2::framework::homogeneous_apply_refs([](auto i) -> bool { return i > 1; }, foo1ref);
REQUIRE(t1ref.size() == 1);
Bar bar;
auto t = o2::framework::homogeneous_apply_refs([](auto i) -> bool { return i > 1; }, bar);
REQUIRE(t[0] == false);
REQUIRE(t[1] == true);
}
/// Largest supported struct
struct FooMax {
int foo01 = 1;
int foo02 = 2;
int foo03 = 3;
int foo04 = 4;
int foo05 = 5;
int foo06 = 6;
int foo07 = 7;
int foo08 = 8;
int foo09 = 9;
int foo10 = 10;
int foo11 = 11;
int foo12 = 12;
int foo13 = 13;
int foo14 = 14;
int foo15 = 15;
int foo16 = 16;
int foo17 = 17;
int foo18 = 18;
int foo19 = 19;
int foo20 = 20;
int foo21 = 21;
int foo22 = 22;
int foo23 = 23;
int foo24 = 24;
int foo25 = 25;
int foo26 = 26;
int foo27 = 27;
int foo28 = 28;
int foo29 = 29;
int foo30 = 30;
int foo31 = 31;
int foo32 = 32;
int foo33 = 33;
int foo34 = 34;
int foo35 = 35;
int foo36 = 36;
int foo37 = 37;
int foo38 = 38;
int foo39 = 39;
int foo101 = 1;
int foo102 = 2;
int foo103 = 3;
int foo104 = 4;
int foo105 = 5;
int foo106 = 6;
int foo107 = 7;
int foo108 = 8;
int foo109 = 9;
int foo110 = 10;
int foo111 = 11;
int foo112 = 12;
int foo113 = 13;
int foo114 = 14;
int foo115 = 15;
int foo116 = 16;
int foo117 = 17;
int foo118 = 18;
int foo119 = 19;
int foo120 = 20;
int foo121 = 21;
int foo122 = 22;
int foo123 = 23;
int foo124 = 24;
int foo125 = 25;
int foo126 = 26;
int foo127 = 27;
int foo128 = 28;
int foo129 = 29;
int foo130 = 30;
int foo131 = 31;
int foo132 = 32;
int foo133 = 33;
int foo134 = 34;
int foo135 = 35;
int foo136 = 36;
int foo137 = 37;
int foo138 = 38;
int foo139 = 39;
};
struct FooNested {
int foo;
};
struct Foo2 {
FooNested foo{
.foo = 100};
FooNested foo2{
.foo = 20};
int foo3 = 40;
};
TEST_CASE("TestStructToTuple")
{
FooMax fooMax;
auto t5 = o2::framework::homogeneous_apply_refs([](auto i) -> bool { return i > 20; }, fooMax);
REQUIRE(t5[0] == false);
REQUIRE(t5[19] == false);
REQUIRE(t5[20] == true);
Foo2 nestedFoo;
auto t6 = o2::framework::homogeneous_apply_refs([](auto e) -> bool {
if constexpr (std::is_same_v<decltype(e), FooNested>) {
o2::framework::homogeneous_apply_refs([](auto n) -> bool { return n > 20; }, e);
return true;
} else {
return e > 20;
}
},
nestedFoo);
REQUIRE(t6.size() == 3);
REQUIRE(t6[0] == true);
}