MCPcopy Create free account
hub / github.com/cbeck88/visit_struct / main

Function main

test_visit_struct.cpp:209–442  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

207static_assert(std::is_same<visit_struct::type_at<2, test_struct_one>, std::string>::value, "");
208
209int main() {
210 // Test version string
211 std::cout << VISIT_STRUCT_VERSION_STRING << std::endl;
212
213 std::cout << __FILE__ << std::endl;
214
215 {
216 test_struct_one s{ 5, 7.5f, "asdf" };
217
218 debug_print(s);
219
220 // Test getters
221
222 assert(visit_struct::field_count(s) == 3);
223 assert(visit_struct::get<0>(s) == 5);
224 assert(visit_struct::get<1>(s) == 7.5f);
225 assert(visit_struct::get<2>(s) == "asdf");
226 assert(visit_struct::get_name<0>(s) == std::string{"a"});
227 assert(visit_struct::get_name<1>(s) == std::string{"b"});
228 assert(visit_struct::get_name<2>(s) == std::string{"c"});
229 assert(visit_struct::get_accessor<0>(s)(s) == visit_struct::get<0>(s));
230 assert(visit_struct::get_accessor<1>(s)(s) == visit_struct::get<1>(s));
231 assert(visit_struct::get_accessor<2>(s)(s) == visit_struct::get<2>(s));
232
233 // Test visitation
234
235 test_visitor_one vis1;
236 visit_struct::apply_visitor(vis1, s);
237
238 assert(vis1.result.size() == 3);
239 assert(vis1.result[0].first == "a");
240 assert(vis1.result[0].second == "5");
241 assert(vis1.result[1].first == "b");
242 assert(vis1.result[1].second == "7.500000");
243 assert(vis1.result[2].first == "c");
244 assert(vis1.result[2].second == "asdf");
245
246 test_visitor_two vis2;
247 visit_struct::apply_visitor(vis2, s);
248
249 assert(vis2.result.size() == 3);
250 assert(vis2.result[0].second == &s.a);
251 assert(vis2.result[1].second == &s.b);
252 assert(vis2.result[2].second == &s.c);
253
254 test_struct_one t{ 0, 0.0f, "jkl" };
255
256 debug_print(t);
257
258 assert(visit_struct::field_count(t) == 3);
259 assert(visit_struct::get<0>(t) == 0);
260 assert(visit_struct::get<1>(t) == 0.0f);
261 assert(visit_struct::get<2>(t) == "jkl");
262 assert(visit_struct::get_name<0>(t) == std::string{"a"});
263 assert(visit_struct::get_name<1>(t) == std::string{"b"});
264 assert(visit_struct::get_name<2>(t) == std::string{"c"});
265
266 test_visitor_one vis3;

Callers

nothing calls this directly

Calls 6

apply_visitorFunction · 0.85
for_eachFunction · 0.85
get_nameFunction · 0.85
struct_eqFunction · 0.85
struct_int_cmpFunction · 0.85
debug_printFunction · 0.70

Tested by

no test coverage detected