Project
Loading...
Searching...
No Matches
test_StructToTuple.cxx
Go to the documentation of this file.
1// Copyright 2019-2020 CERN and copyright holders of ALICE O2.
2// See https://alice-o2.web.cern.ch/copyright for details of the copyright holders.
3// All rights not expressly granted are reserved.
4//
5// This software is distributed under the terms of the GNU General Public
6// License v3 (GPL Version 3), copied verbatim in the file "COPYING".
7//
8// In applying this license CERN does not waive the privileges and immunities
9// granted to it by virtue of its status as an Intergovernmental Organization
10// or submit itself to any jurisdiction.
11
12#include <catch_amalgamated.hpp>
14
15struct Foo0 {
16};
17
18struct Foo1 {
19 int foo = 1;
20};
21
22// FIXME: this should really struct Bar : Foo, but a c++17 bug
23// in GCC 7.3 (solved in 7.4 / 8.x) prevents us from doing so
24// for now.
25struct Bar {
26 int foo = 1;
27 int bar = 2;
28};
29
30TEST_CASE("SimpleDestructuring")
31{
32 Foo0 foo0;
33 auto t0 = o2::framework::homogeneous_apply_refs([](auto i) -> bool { return i > 1; }, foo0);
34 REQUIRE(t0.size() == 0);
35 Foo1 foo1;
36 auto t1 = o2::framework::homogeneous_apply_refs([](auto i) -> bool { return i > 1; }, foo1);
37
38 REQUIRE(t1.size() == 1);
39
40 // Should work with refs as well. When moving to C++20 this was
41 // not the case initially.
42 Foo1 const&& foo1ref = std::move(foo1);
43 auto t1ref = o2::framework::homogeneous_apply_refs([](auto i) -> bool { return i > 1; }, foo1ref);
44 REQUIRE(t1ref.size() == 1);
45
46 Bar bar;
47 auto t = o2::framework::homogeneous_apply_refs([](auto i) -> bool { return i > 1; }, bar);
48 REQUIRE(t[0] == false);
49 REQUIRE(t[1] == true);
50}
51
53struct FooMax {
54 int foo01 = 1;
55 int foo02 = 2;
56 int foo03 = 3;
57 int foo04 = 4;
58 int foo05 = 5;
59 int foo06 = 6;
60 int foo07 = 7;
61 int foo08 = 8;
62 int foo09 = 9;
63 int foo10 = 10;
64 int foo11 = 11;
65 int foo12 = 12;
66 int foo13 = 13;
67 int foo14 = 14;
68 int foo15 = 15;
69 int foo16 = 16;
70 int foo17 = 17;
71 int foo18 = 18;
72 int foo19 = 19;
73 int foo20 = 20;
74 int foo21 = 21;
75 int foo22 = 22;
76 int foo23 = 23;
77 int foo24 = 24;
78 int foo25 = 25;
79 int foo26 = 26;
80 int foo27 = 27;
81 int foo28 = 28;
82 int foo29 = 29;
83 int foo30 = 30;
84 int foo31 = 31;
85 int foo32 = 32;
86 int foo33 = 33;
87 int foo34 = 34;
88 int foo35 = 35;
89 int foo36 = 36;
90 int foo37 = 37;
91 int foo38 = 38;
92 int foo39 = 39;
93 int foo101 = 1;
94 int foo102 = 2;
95 int foo103 = 3;
96 int foo104 = 4;
97 int foo105 = 5;
98 int foo106 = 6;
99 int foo107 = 7;
100 int foo108 = 8;
101 int foo109 = 9;
102 int foo110 = 10;
103 int foo111 = 11;
104 int foo112 = 12;
105 int foo113 = 13;
106 int foo114 = 14;
107 int foo115 = 15;
108 int foo116 = 16;
109 int foo117 = 17;
110 int foo118 = 18;
111 int foo119 = 19;
112 int foo120 = 20;
113 int foo121 = 21;
114 int foo122 = 22;
115 int foo123 = 23;
116 int foo124 = 24;
117 int foo125 = 25;
118 int foo126 = 26;
119 int foo127 = 27;
120 int foo128 = 28;
121 int foo129 = 29;
122 int foo130 = 30;
123 int foo131 = 31;
124 int foo132 = 32;
125 int foo133 = 33;
126 int foo134 = 34;
127 int foo135 = 35;
128 int foo136 = 36;
129 int foo137 = 37;
130 int foo138 = 38;
131 int foo139 = 39;
132};
133
134struct FooNested {
135 int foo;
136};
137
138struct Foo2 {
140 .foo = 100};
142 .foo = 20};
143 int foo3 = 40;
144};
145
146TEST_CASE("TestStructToTuple")
147{
148 FooMax fooMax;
149
150 auto t5 = o2::framework::homogeneous_apply_refs([](auto i) -> bool { return i > 20; }, fooMax);
151 REQUIRE(t5[0] == false);
152 REQUIRE(t5[19] == false);
153 REQUIRE(t5[20] == true);
154 Foo2 nestedFoo;
155 auto t6 = o2::framework::homogeneous_apply_refs([](auto e) -> bool {
156 if constexpr (std::is_same_v<decltype(e), FooNested>) {
157 o2::framework::homogeneous_apply_refs([](auto n) -> bool { return n > 20; }, e);
158 return true;
159 } else {
160 return e > 20;
161 }
162 },
163 nestedFoo);
164 REQUIRE(t6.size() == 3);
165 REQUIRE(t6[0] == true);
166}
167
172struct EmptyBase {
173};
174
176 int a = 3;
177 int b = 30;
178 int c = 300;
179};
180
181TEST_CASE("EmptyBaseDestructuring")
182{
184 auto t = o2::framework::homogeneous_apply_refs<true>([](auto i) -> bool { return i > 20; }, g);
185 REQUIRE(t.size() == 3);
186 REQUIRE(t[0] == false);
187 REQUIRE(t[1] == true);
188 REQUIRE(t[2] == true);
189
190 // The binding must reach the derived members, not the base.
191 o2::framework::homogeneous_apply_refs<true>([](auto& i) { i += 1; return true; }, g);
192 REQUIRE(g.a == 4);
193 REQUIRE(g.b == 31);
194 REQUIRE(g.c == 301);
195}
int32_t i
Timeframe settings Average distance in cm of events merged into Randomize distance around average distance of merged events Simulate correct bunch interactions instead of placing only the average number of events A value[n] sets TFlen for[n] collisions in Number of bunches per trainsort Number of bunch trains Instantaneous interaction rate Do not simulate border Total number of collisions to be placed in the interior of all time Do not select random but walk over array of events in stride steps h Event generator settings h configStandalone Use CPU for GPU Force usage of the specified GPU device no CPU fallback Continue processing after an error First event to Number of events to Number of iterations to Number of iterations to Number of initial iterations excluded from const char e
GLboolean GLboolean g
Definition glcorearb.h:1233
GLdouble n
Definition glcorearb.h:1982
GLboolean GLboolean GLboolean b
Definition glcorearb.h:1233
GLuint GLfloat GLfloat GLfloat GLfloat GLfloat GLfloat GLfloat t0
Definition glcorearb.h:5034
GLboolean GLboolean GLboolean GLboolean a
Definition glcorearb.h:1233
GLuint GLfloat GLfloat GLfloat GLfloat GLfloat GLfloat GLfloat GLfloat GLfloat t1
Definition glcorearb.h:5034
constexpr auto homogeneous_apply_refs(L l, T &&object)
FooNested foo
FooNested foo2
Largest supported struct.
TEST_CASE("SimpleDestructuring")