AssnsTraits_test.cc
Go to the documentation of this file.
1 /**
2  * @file AssnsTraits_test.cc
3  * @brief Unit tests on _art_ association trait utilities.
4  * @author Gianluca Petrillo (petrillo@fnal.gov)
5  * @date April 17, 2018
6  *
7  * The relevant components of this test are static.
8  */
9 
10 // LArSoft libraries
12 
13 // framework libraries
15 
16 // C/C++ standard libraries
17 #include <utility> // std::declval()
18 #include <type_traits> // std::is_same<>, std::decay_t
19 
20 // -----------------------------------------------------------------------------
21 // types used for the test
24 
25 // iterator types
26 using PlainAssnsIter
27  = std::decay_t<decltype(std::declval<PlainAssns>().begin())>;
28 using MetaAssnsIter
29  = std::decay_t<decltype(std::declval<MetaAssns>().begin())>;
30 
31 // node types
32 using PlainAssnsNode
33  = std::decay_t<decltype(*(std::declval<PlainAssnsIter>()))>;
34 using MetaAssnsNode
35  = std::decay_t<decltype(*(std::declval<MetaAssnsIter>()))>;
36 
37 
38 // -----------------------------------------------------------------------------
39 // lar::util::assns_metadata_type
40 //
41 static_assert(
43  "assns_metadata_type<PlainAssns> should have been void! "
44  );
45 static_assert(
47  "assns_metadata_type<PlainAssns> node should have been void! "
48  );
49 static_assert(
51  "assns_metadata_type<MetaAssns> should have been char! "
52  );
53 static_assert(
55  "assns_metadata_type<MetaAssns> node should have been char! "
56  );
57 
58 //
59 // lar::util::assns_metadata_t
60 //
61 static_assert(
62  std::is_same<lar::util::assns_metadata_t<PlainAssns>, void>(),
63  "assns_metadata_type_t<PlainAssns> should have been void! "
64  );
65 static_assert(
66  std::is_same<lar::util::assns_metadata_t<PlainAssnsNode>, void>(),
67  "assns_metadata_type_t<PlainAssns> node should have been void! "
68  );
69 static_assert(
70  std::is_same<lar::util::assns_metadata_t<MetaAssns>, char>(),
71  "assns_metadata_type_t<MetaAssns> should have been char! "
72  );
73 static_assert(
74  std::is_same<lar::util::assns_metadata_t<MetaAssnsNode>, char>(),
75  "assns_metadata_type_t<MetaAssns> node should have been char! "
76  );
77 
78 
79 // -----------------------------------------------------------------------------
80 // lar::util::assns_has_metadata
81 //
82 static_assert(
84  "assns_has_metadata<PlainAssns> should have been false! "
85  );
86 static_assert(
88  "assns_has_metadata<PlainAssns> node should have been false! "
89  );
90 static_assert(
92  "assns_has_metadata<MetaAssns> should have been true! "
93  );
94 static_assert(
96  "assns_has_metadata<MetaAssns> node should have been true! "
97  );
98 
99 //
100 // lar::util::assns_has_metadata_v
101 //
102 static_assert(
103  !lar::util::assns_has_metadata_v<PlainAssns>,
104  "assns_has_metadata<PlainAssns> should have been false! "
105  );
106 static_assert(
107  !lar::util::assns_has_metadata_v<PlainAssnsNode>,
108  "assns_has_metadata<PlainAssns> node should have been false! "
109  );
110 static_assert(
111  lar::util::assns_has_metadata_v<MetaAssns>,
112  "assns_has_metadata<MetaAssns> should have been true! "
113  );
114 static_assert(
115  lar::util::assns_has_metadata_v<MetaAssnsNode>,
116  "assns_has_metadata<MetaAssns> node should have been true! "
117  );
118 
119 
120 //------------------------------------------------------------------------------
121 // lar::util::assns_traits
122 //
124 static_assert(
125  std::is_same<PlainAssnsTraits::left_t, int>(),
126  "left element of PlainAssns should have been `int`!"
127  );
128 static_assert(
129  std::is_same<PlainAssnsTraits::right_t, double>(),
130  "right element of PlainAssns should have been `double`!"
131  );
132 static_assert(
133  std::is_same<PlainAssnsTraits::data_t, void>(),
134  "metadata of PlainAssns should have been `void`!"
135  );
136 static_assert(
137  std::is_same<PlainAssnsTraits::leftptr_t, art::Ptr<int>>(),
138  "left element pointer of PlainAssns should have been `art::Ptr<int>`!"
139  );
140 static_assert(
141  std::is_same<PlainAssnsTraits::rightptr_t, art::Ptr<double>>(),
142  "right element pointer of PlainAssns should have been `art::Ptr<double>`!"
143  );
144 static_assert(
145  std::is_same<PlainAssnsTraits::dataptr_t, void const*>(),
146  "metadata pointer of PlainAssns should have been `void const*`!"
147  );
148 static_assert(
149  std::is_same<PlainAssnsTraits::assns_t, PlainAssns>(),
150  "PlainAssns traits should report `PlainAssns` as association class!"
151  );
152 static_assert(
153  std::is_same<PlainAssnsTraits::assns_iterator_t, PlainAssnsIter>(),
154  "PlainAssns traits should report `PlainAssnsIter` as association iterator!"
155  );
156 static_assert(
157  std::is_same<PlainAssnsTraits::art_assns_node_t, PlainAssnsNode>(),
158  "PlainAssns traits should report `PlainAssnsNode` as association node!"
159  );
160 static_assert(
161  !PlainAssnsTraits::hasMetadata,
162  "PlainAssns should have reported not to have metadata!"
163  );
164 
166 static_assert(
167  std::is_same<MetaAssnsTraits::left_t, long int>(),
168  "left element of MetaAssns should have been `long int`!"
169  );
170 static_assert(
171  std::is_same<MetaAssnsTraits::right_t, float>(),
172  "right element of MetaAssns should have been `float`!"
173  );
174 static_assert(
175  std::is_same<MetaAssnsTraits::data_t, char>(),
176  "metadata of MetaAssns should have been `char`!"
177  );
178 static_assert(
179  std::is_same<MetaAssnsTraits::leftptr_t, art::Ptr<long int>>(),
180  "left element pointer of MetaAssns should have been `art::Ptr<long int>`!"
181  );
182 static_assert(
183  std::is_same<MetaAssnsTraits::rightptr_t, art::Ptr<float>>(),
184  "right element pointer of MetaAssns should have been `art::Ptr<float>`!"
185  );
186 static_assert(
187  std::is_same<MetaAssnsTraits::dataptr_t, char const*>(),
188  "metadata pointer of MetaAssns should have been `char const*`!"
189  );
190 static_assert(
191  std::is_same<MetaAssnsTraits::assns_t, MetaAssns>(),
192  "MetaAssns traits should report `MetaAssns` as association class!"
193  );
194 static_assert(
195  std::is_same<MetaAssnsTraits::assns_iterator_t, MetaAssnsIter>(),
196  "MetaAssns traits should report `MetaAssnsIter` as association iterator!"
197  );
198 static_assert(
199  std::is_same<MetaAssnsTraits::art_assns_node_t, MetaAssnsNode>(),
200  "MetaAssns traits should report `MetaAssnsNode` as association node!"
201  );
202 static_assert(
203  MetaAssnsTraits::hasMetadata,
204  "MetaAssns should have reported to have metadata!"
205  );
206 
207 
208 //------------------------------------------------------------------------------
209 // lar::util::assns_iterator_type
210 //
211 static_assert(
213  "assns_metadata_type<PlainAssns> should have been void! "
214  );
215 static_assert(
217  "assns_metadata_type<MetaAssns> should have been char! "
218  );
219 
220 //------------------------------------------------------------------------------
221 // lar::util::assns_iterator_t
222 //
223 static_assert(
225  "assns_metadata_type<PlainAssns> should have been void! "
226  );
227 static_assert(
229  "assns_metadata_type<MetaAssns> should have been char! "
230  );
231 
232 
233 //==============================================================================
234 // we need a main program because every test that compiles must run
235 int main() {}
236 
237 //------------------------------------------------------------------------------
int main()
typename assns_metadata_type< Assns >::type assns_metadata_t
Trait: type of metadata in Assns (association or its node).
Definition: AssnsTraits.h:62
Trait: type is metadata in Assns (association or its node).
Definition: AssnsTraits.h:57
typename assns_iterator_type< Assns >::type assns_iterator_t
Trait: type of iterator of Assns.
Definition: AssnsTraits.h:75
Trait: value true if Assns (association or its node) has metadata.
Definition: AssnsTraits.h:46
Data types for the specified association type (or its node).
Definition: AssnsTraits.h:102
std::decay_t< decltype(*(std::declval< MetaAssnsIter >()))> MetaAssnsNode
Traits for art associations.
decltype(auto) constexpr begin(T &&obj)
ADL-aware version of std::begin.
Definition: StdUtils.h:72
std::decay_t< decltype(std::declval< PlainAssns >().begin())> PlainAssnsIter
std::decay_t< decltype(std::declval< MetaAssns >().begin())> MetaAssnsIter
Definition: fwd.h:31
std::decay_t< decltype(*(std::declval< PlainAssnsIter >()))> PlainAssnsNode
Trait: type is iterator of Assns.
Definition: AssnsTraits.h:70