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>
13
#include "
Framework/StructToTuple.h
"
14
15
struct
Foo0
{
16
};
17
18
struct
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.
25
struct
Bar
{
26
int
foo
= 1;
27
int
bar
= 2;
28
};
29
30
TEST_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
53
struct
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
134
struct
FooNested
{
135
int
foo
;
136
};
137
138
struct
Foo2
{
139
FooNested
foo
{
140
.
foo
= 100};
141
FooNested
foo2
{
142
.
foo
= 20};
143
int
foo3
= 40;
144
};
145
146
TEST_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
}
i
int32_t i
Definition
GPUCommonAlgorithm.h:443
StructToTuple.h
n
GLdouble n
Definition
glcorearb.h:1982
t0
GLuint GLfloat GLfloat GLfloat GLfloat GLfloat GLfloat GLfloat t0
Definition
glcorearb.h:5034
t1
GLuint GLfloat GLfloat GLfloat GLfloat GLfloat GLfloat GLfloat GLfloat GLfloat t1
Definition
glcorearb.h:5034
o2::framework::homogeneous_apply_refs
auto homogeneous_apply_refs(L l, T &&object)
Definition
StructToTuple.h:179
Bar
Definition
test_TypeTraits.cxx:151
Bar::bar
int bar
Definition
test_StructToTuple.cxx:27
Bar::foo
int foo
Definition
test_StructToTuple.cxx:26
Foo0
Definition
test_StructToTuple.cxx:15
Foo1
Definition
testAbstractRefAccessor.cxx:27
Foo1::foo
int foo
Definition
test_StructToTuple.cxx:19
Foo2
Definition
testAbstractRefAccessor.cxx:31
Foo2::foo
FooNested foo
Definition
test_StructToTuple.cxx:139
Foo2::foo2
FooNested foo2
Definition
test_StructToTuple.cxx:141
Foo2::foo3
int foo3
Definition
test_StructToTuple.cxx:143
FooMax
Largest supported struct.
Definition
test_StructToTuple.cxx:53
FooMax::foo18
int foo18
Definition
test_StructToTuple.cxx:71
FooMax::foo104
int foo104
Definition
test_StructToTuple.cxx:96
FooMax::foo30
int foo30
Definition
test_StructToTuple.cxx:83
FooMax::foo10
int foo10
Definition
test_StructToTuple.cxx:63
FooMax::foo114
int foo114
Definition
test_StructToTuple.cxx:106
FooMax::foo137
int foo137
Definition
test_StructToTuple.cxx:129
FooMax::foo35
int foo35
Definition
test_StructToTuple.cxx:88
FooMax::foo134
int foo134
Definition
test_StructToTuple.cxx:126
FooMax::foo27
int foo27
Definition
test_StructToTuple.cxx:80
FooMax::foo11
int foo11
Definition
test_StructToTuple.cxx:64
FooMax::foo17
int foo17
Definition
test_StructToTuple.cxx:70
FooMax::foo115
int foo115
Definition
test_StructToTuple.cxx:107
FooMax::foo136
int foo136
Definition
test_StructToTuple.cxx:128
FooMax::foo102
int foo102
Definition
test_StructToTuple.cxx:94
FooMax::foo129
int foo129
Definition
test_StructToTuple.cxx:121
FooMax::foo26
int foo26
Definition
test_StructToTuple.cxx:79
FooMax::foo133
int foo133
Definition
test_StructToTuple.cxx:125
FooMax::foo34
int foo34
Definition
test_StructToTuple.cxx:87
FooMax::foo139
int foo139
Definition
test_StructToTuple.cxx:131
FooMax::foo117
int foo117
Definition
test_StructToTuple.cxx:109
FooMax::foo31
int foo31
Definition
test_StructToTuple.cxx:84
FooMax::foo12
int foo12
Definition
test_StructToTuple.cxx:65
FooMax::foo119
int foo119
Definition
test_StructToTuple.cxx:111
FooMax::foo28
int foo28
Definition
test_StructToTuple.cxx:81
FooMax::foo120
int foo120
Definition
test_StructToTuple.cxx:112
FooMax::foo08
int foo08
Definition
test_StructToTuple.cxx:61
FooMax::foo39
int foo39
Definition
test_StructToTuple.cxx:92
FooMax::foo113
int foo113
Definition
test_StructToTuple.cxx:105
FooMax::foo108
int foo108
Definition
test_StructToTuple.cxx:100
FooMax::foo29
int foo29
Definition
test_StructToTuple.cxx:82
FooMax::foo06
int foo06
Definition
test_StructToTuple.cxx:59
FooMax::foo37
int foo37
Definition
test_StructToTuple.cxx:90
FooMax::foo126
int foo126
Definition
test_StructToTuple.cxx:118
FooMax::foo105
int foo105
Definition
test_StructToTuple.cxx:97
FooMax::foo22
int foo22
Definition
test_StructToTuple.cxx:75
FooMax::foo20
int foo20
Definition
test_StructToTuple.cxx:73
FooMax::foo118
int foo118
Definition
test_StructToTuple.cxx:110
FooMax::foo112
int foo112
Definition
test_StructToTuple.cxx:104
FooMax::foo32
int foo32
Definition
test_StructToTuple.cxx:85
FooMax::foo04
int foo04
Definition
test_StructToTuple.cxx:57
FooMax::foo107
int foo107
Definition
test_StructToTuple.cxx:99
FooMax::foo33
int foo33
Definition
test_StructToTuple.cxx:86
FooMax::foo106
int foo106
Definition
test_StructToTuple.cxx:98
FooMax::foo138
int foo138
Definition
test_StructToTuple.cxx:130
FooMax::foo101
int foo101
Definition
test_StructToTuple.cxx:93
FooMax::foo03
int foo03
Definition
test_StructToTuple.cxx:56
FooMax::foo15
int foo15
Definition
test_StructToTuple.cxx:68
FooMax::foo13
int foo13
Definition
test_StructToTuple.cxx:66
FooMax::foo09
int foo09
Definition
test_StructToTuple.cxx:62
FooMax::foo132
int foo132
Definition
test_StructToTuple.cxx:124
FooMax::foo110
int foo110
Definition
test_StructToTuple.cxx:102
FooMax::foo14
int foo14
Definition
test_StructToTuple.cxx:67
FooMax::foo135
int foo135
Definition
test_StructToTuple.cxx:127
FooMax::foo05
int foo05
Definition
test_StructToTuple.cxx:58
FooMax::foo122
int foo122
Definition
test_StructToTuple.cxx:114
FooMax::foo38
int foo38
Definition
test_StructToTuple.cxx:91
FooMax::foo130
int foo130
Definition
test_StructToTuple.cxx:122
FooMax::foo125
int foo125
Definition
test_StructToTuple.cxx:117
FooMax::foo116
int foo116
Definition
test_StructToTuple.cxx:108
FooMax::foo16
int foo16
Definition
test_StructToTuple.cxx:69
FooMax::foo23
int foo23
Definition
test_StructToTuple.cxx:76
FooMax::foo128
int foo128
Definition
test_StructToTuple.cxx:120
FooMax::foo111
int foo111
Definition
test_StructToTuple.cxx:103
FooMax::foo121
int foo121
Definition
test_StructToTuple.cxx:113
FooMax::foo123
int foo123
Definition
test_StructToTuple.cxx:115
FooMax::foo109
int foo109
Definition
test_StructToTuple.cxx:101
FooMax::foo21
int foo21
Definition
test_StructToTuple.cxx:74
FooMax::foo131
int foo131
Definition
test_StructToTuple.cxx:123
FooMax::foo19
int foo19
Definition
test_StructToTuple.cxx:72
FooMax::foo127
int foo127
Definition
test_StructToTuple.cxx:119
FooMax::foo02
int foo02
Definition
test_StructToTuple.cxx:55
FooMax::foo24
int foo24
Definition
test_StructToTuple.cxx:77
FooMax::foo01
int foo01
Definition
test_StructToTuple.cxx:54
FooMax::foo103
int foo103
Definition
test_StructToTuple.cxx:95
FooMax::foo07
int foo07
Definition
test_StructToTuple.cxx:60
FooMax::foo124
int foo124
Definition
test_StructToTuple.cxx:116
FooMax::foo36
int foo36
Definition
test_StructToTuple.cxx:89
FooMax::foo25
int foo25
Definition
test_StructToTuple.cxx:78
FooNested
Definition
test_StructToTuple.cxx:134
FooNested::foo
int foo
Definition
test_StructToTuple.cxx:135
TEST_CASE
TEST_CASE("SimpleDestructuring")
Definition
test_StructToTuple.cxx:30
Framework
Foundation
test
test_StructToTuple.cxx
Generated on Tue Feb 25 2025 23:16:41 for Project by
1.9.8