MCPcopy Create free account
hub / github.com/boostorg/pfr / test_examples

Function test_examples

example/quick_examples.cpp:16–167  ·  view source on GitHub ↗

boost-no-inspect

Source from the content-addressed store, hash-verified

14
15// boost-no-inspect
16void test_examples() {
17
18#if BOOST_PFR_USE_CPP17
19 {
20//[pfr_quick_examples_ops
21 // Assert equality.
22 // Note that the equality operator for structure is not defined.
23
24 struct test {
25 std::string f1;
26 std::string_view f2;
27 };
28
29 assert(
30 boost::pfr::eq(test{"aaa", "zomg"}, test{"aaa", "zomg"})
31 );
32//]
33 }
34#endif
35
36 {
37//[pfr_quick_examples_for_each
38 // Increment each field of the variable on 1 and
39 // output the content of the variable.
40
41 struct test {
42 int f1;
43 long f2;
44 };
45
46 test var{42, 43};
47
48 boost::pfr::for_each_field(var, [](auto& field) {
49 field += 1;
50 });
51
52 // Outputs: {43, 44}
53 std::cout << boost::pfr::io(var);
54//]
55 }
56
57 {
58//[pfr_quick_examples_for_each_idx
59 // Iterate over fields of a variable and output index and
60 // type of a variable.
61
62 struct tag0{};
63 struct tag1{};
64 struct sample {
65 tag0 a;
66 tag1 b;
67 };
68
69 // Outputs:
70 // 0: tag0
71 // 1: tag1
72 boost::pfr::for_each_field(sample{}, [](const auto& field, std::size_t idx) {
73 std::cout << '\n' << idx << ": "

Callers 1

mainFunction · 0.85

Calls 5

eqFunction · 0.85
for_each_fieldFunction · 0.85
ioFunction · 0.85
structure_to_tupleFunction · 0.85
structure_tieFunction · 0.85

Tested by

no test coverage detected