FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
AliceO2/Framework/Foundation/test/test_StructToTuple.cxx at dev · AliceO2Group/AliceO2 · GitHub
Uh oh!
There was an error while loading.
Please reload this page
.
AliceO2Group
/
AliceO2
Public
Notifications
You must be signed in to change notification settings
Fork
511
Star
125
Code
Issues
2
Pull requests
33
Actions
Security and quality
0
Insights
Additional navigation options
Code
Issues
Pull requests
Actions
Security and quality
Insights
Expand file tree
Breadcrumbs
AliceO2
/
Framework
/
Foundation
/
test
/
test_StructToTuple.cxx
Copy path
More file actions
More file actions
Latest commit
History
History
History
195 lines (178 loc) · 4.59 KB
Breadcrumbs
AliceO2
/
Framework
/
Foundation
/
test
/
test_StructToTuple.cxx
Copy path
File metadata and controls
195 lines (178 loc) · 4.59 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
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
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
//
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
);
}
//
/ Empty base class, mirroring o2::framework::ConfigurableGroup: structs
//
/ deriving from it must decompose to their own members only, and the empty
//
/ base must not be counted or bound. Exercised with B=true, as the option
//
/ group handling in AnalysisManagers.h does.
struct
EmptyBase
{
};
struct
DerivedGroup
: EmptyBase {
int
a =
3
;
int
b =
30
;
int
c =
300
;
};
TEST_CASE
(
"
EmptyBaseDestructuring
"
)
{
DerivedGroup g;
auto
t = o2::framework::homogeneous_apply_refs<
true
>([](
auto
i) ->
bool
{
return
i >
20
; }, g);
REQUIRE
(t.
size
() ==
3
);
REQUIRE
(t[
0
] ==
false
);
REQUIRE
(t[
1
] ==
true
);
REQUIRE
(t[
2
] ==
true
);
//
The binding must reach the derived members, not the base.
o2::framework::homogeneous_apply_refs<
true
>([](
auto
& i) { i +=
1
;
return
true
; }, g);
REQUIRE
(g.
a
==
4
);
REQUIRE
(g.
b
==
31
);
REQUIRE
(g.
c
==
301
);
}
Back
|
FazBrowse Home
|
New Git URL