| 1 | // Copyright 2020, 2021 Peter Dimov |
| 2 | // Distributed under the Boost Software License, Version 1.0. |
| 3 | // https://www.boost.org/LICENSE_1_0.txt |
| 4 | |
| 5 | #include <boost/describe/members.hpp> |
| 6 | #include <boost/describe/class.hpp> |
| 7 | #include <boost/core/lightweight_test.hpp> |
| 8 | #include <boost/config/pragma_message.hpp> |
| 9 | |
| 10 | #if !defined(BOOST_DESCRIBE_CXX11) |
| 11 | |
| 12 | BOOST_PRAGMA_MESSAGE("Skipping test because C++11 is not available" ) |
| 13 | int main() {} |
| 14 | |
| 15 | #elif defined(__GNUC__) && __GNUC__ < 5 |
| 16 | |
| 17 | BOOST_PRAGMA_MESSAGE("Skipping test because g++ 4.8" ) |
| 18 | int main() {} |
| 19 | |
| 20 | #else |
| 21 | |
| 22 | union A |
| 23 | { |
| 24 | public: |
| 25 | |
| 26 | int m1; |
| 27 | static int m2; |
| 28 | int f1() const { return m1; } |
| 29 | static int f2() { return m2; } |
| 30 | |
| 31 | protected: |
| 32 | |
| 33 | int m3; |
| 34 | static int m4; |
| 35 | int f3() const { return m3; } |
| 36 | static int f4() { return m4; } |
| 37 | |
| 38 | private: |
| 39 | |
| 40 | int m5; |
| 41 | static int m6; |
| 42 | int f5() const { return m5; } |
| 43 | static int f6() { return m6; } |
| 44 | |
| 45 | BOOST_DESCRIBE_CLASS(A, (), (m1, m2, f1, f2), (m3, m4, f3, f4), (m5, m6, f5, f6)) |
| 46 | |
| 47 | friend int main(); |
| 48 | }; |
| 49 | |
| 50 | int A::m2; |
| 51 | int A::m4; |
| 52 | int A::m6; |
| 53 | |
| 54 | #if !defined(BOOST_DESCRIBE_CXX14) |
| 55 | |
| 56 | BOOST_PRAGMA_MESSAGE("Skipping test because C++14 is not available" ) |
| 57 | int main() {} |
| 58 | |
| 59 | #else |
| 60 | |
| 61 | #include <boost/mp11.hpp> |
| 62 | |
| 63 | int main() |
| 64 | { |
| 65 | using namespace boost::describe; |
| 66 | using namespace boost::mp11; |
| 67 | |
| 68 | { |
| 69 | using L = describe_members<A, mod_public | mod_any_member>; |
| 70 | |
| 71 | BOOST_TEST_EQ( mp_size<L>::value, 4 ); |
| 72 | |
| 73 | using D1 = mp_at_c<L, 0>; |
| 74 | using D2 = mp_at_c<L, 1>; |
| 75 | using D3 = mp_at_c<L, 2>; |
| 76 | using D4 = mp_at_c<L, 3>; |
| 77 | |
| 78 | BOOST_TEST( D1::pointer == &A::m1 ); |
| 79 | BOOST_TEST_CSTR_EQ( D1::name, "m1" ); |
| 80 | BOOST_TEST_EQ( D1::modifiers, mod_public ); |
| 81 | |
| 82 | BOOST_TEST( D2::pointer == &A::m2 ); |
| 83 | BOOST_TEST_CSTR_EQ( D2::name, "m2" ); |
| 84 | BOOST_TEST_EQ( D2::modifiers, mod_public | mod_static ); |
| 85 | |
| 86 | BOOST_TEST( D3::pointer == &A::f1 ); |
| 87 | BOOST_TEST_CSTR_EQ( D3::name, "f1" ); |
| 88 | BOOST_TEST_EQ( D3::modifiers, mod_public | mod_function ); |
| 89 | |
| 90 | BOOST_TEST( D4::pointer == &A::f2 ); |
| 91 | BOOST_TEST_CSTR_EQ( D4::name, "f2" ); |
| 92 | BOOST_TEST_EQ( D4::modifiers, mod_public | mod_static | mod_function ); |
| 93 | } |
| 94 | |
| 95 | { |
| 96 | using L = describe_members<A, mod_protected | mod_any_member>; |
| 97 | |
| 98 | BOOST_TEST_EQ( mp_size<L>::value, 4 ); |
| 99 | |
| 100 | using D1 = mp_at_c<L, 0>; |
| 101 | using D2 = mp_at_c<L, 1>; |
| 102 | using D3 = mp_at_c<L, 2>; |
| 103 | using D4 = mp_at_c<L, 3>; |
| 104 | |
| 105 | BOOST_TEST( D1::pointer == &A::m3 ); |
| 106 | BOOST_TEST_CSTR_EQ( D1::name, "m3" ); |
| 107 | BOOST_TEST_EQ( D1::modifiers, mod_protected ); |
| 108 | |
| 109 | BOOST_TEST( D2::pointer == &A::m4 ); |
| 110 | BOOST_TEST_CSTR_EQ( D2::name, "m4" ); |
| 111 | BOOST_TEST_EQ( D2::modifiers, mod_protected | mod_static ); |
| 112 | |
| 113 | BOOST_TEST( D3::pointer == &A::f3 ); |
| 114 | BOOST_TEST_CSTR_EQ( D3::name, "f3" ); |
| 115 | BOOST_TEST_EQ( D3::modifiers, mod_protected | mod_function ); |
| 116 | |
| 117 | BOOST_TEST( D4::pointer == &A::f4 ); |
| 118 | BOOST_TEST_CSTR_EQ( D4::name, "f4" ); |
| 119 | BOOST_TEST_EQ( D4::modifiers, mod_protected | mod_static | mod_function ); |
| 120 | } |
| 121 | |
| 122 | { |
| 123 | using L = describe_members<A, mod_private | mod_any_member>; |
| 124 | |
| 125 | BOOST_TEST_EQ( mp_size<L>::value, 4 ); |
| 126 | |
| 127 | using D1 = mp_at_c<L, 0>; |
| 128 | using D2 = mp_at_c<L, 1>; |
| 129 | using D3 = mp_at_c<L, 2>; |
| 130 | using D4 = mp_at_c<L, 3>; |
| 131 | |
| 132 | BOOST_TEST( D1::pointer == &A::m5 ); |
| 133 | BOOST_TEST_CSTR_EQ( D1::name, "m5" ); |
| 134 | BOOST_TEST_EQ( D1::modifiers, mod_private ); |
| 135 | |
| 136 | BOOST_TEST( D2::pointer == &A::m6 ); |
| 137 | BOOST_TEST_CSTR_EQ( D2::name, "m6" ); |
| 138 | BOOST_TEST_EQ( D2::modifiers, mod_private | mod_static ); |
| 139 | |
| 140 | BOOST_TEST( D3::pointer == &A::f5 ); |
| 141 | BOOST_TEST_CSTR_EQ( D3::name, "f5" ); |
| 142 | BOOST_TEST_EQ( D3::modifiers, mod_private | mod_function ); |
| 143 | |
| 144 | BOOST_TEST( D4::pointer == &A::f6 ); |
| 145 | BOOST_TEST_CSTR_EQ( D4::name, "f6" ); |
| 146 | BOOST_TEST_EQ( D4::modifiers, mod_private | mod_static | mod_function ); |
| 147 | } |
| 148 | |
| 149 | return boost::report_errors(); |
| 150 | } |
| 151 | |
| 152 | #endif // !defined(BOOST_DESCRIBE_CXX14) |
| 153 | #endif // !defined(BOOST_DESCRIBE_CXX11) |
| 154 | |