| 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 | |
| 9 | struct A |
| 10 | { |
| 11 | int m1; |
| 12 | static int m2; |
| 13 | int f1() const { return m1; } |
| 14 | static int f2() { return m2; } |
| 15 | }; |
| 16 | |
| 17 | BOOST_DESCRIBE_STRUCT(A, (), (m1, m2, f1, f2)) |
| 18 | |
| 19 | int A::m2; |
| 20 | |
| 21 | #if !defined(BOOST_DESCRIBE_CXX14) |
| 22 | |
| 23 | #include <boost/config/pragma_message.hpp> |
| 24 | |
| 25 | BOOST_PRAGMA_MESSAGE("Skipping test because C++14 is not available" ) |
| 26 | int main() {} |
| 27 | |
| 28 | #else |
| 29 | |
| 30 | #include <boost/mp11.hpp> |
| 31 | |
| 32 | int main() |
| 33 | { |
| 34 | using namespace boost::describe; |
| 35 | using namespace boost::mp11; |
| 36 | |
| 37 | { |
| 38 | using L = describe_members<A, mod_any_access | mod_any_member>; |
| 39 | |
| 40 | BOOST_TEST_EQ( mp_size<L>::value, 4 ); |
| 41 | |
| 42 | using D1 = mp_at_c<L, 0>; |
| 43 | using D2 = mp_at_c<L, 1>; |
| 44 | using D3 = mp_at_c<L, 2>; |
| 45 | using D4 = mp_at_c<L, 3>; |
| 46 | |
| 47 | BOOST_TEST( D1::pointer == &A::m1 ); |
| 48 | BOOST_TEST_CSTR_EQ( D1::name, "m1" ); |
| 49 | BOOST_TEST_EQ( D1::modifiers, mod_public ); |
| 50 | |
| 51 | BOOST_TEST( D2::pointer == &A::m2 ); |
| 52 | BOOST_TEST_CSTR_EQ( D2::name, "m2" ); |
| 53 | BOOST_TEST_EQ( D2::modifiers, mod_public | mod_static ); |
| 54 | |
| 55 | BOOST_TEST( D3::pointer == &A::f1 ); |
| 56 | BOOST_TEST_CSTR_EQ( D3::name, "f1" ); |
| 57 | BOOST_TEST_EQ( D3::modifiers, mod_public | mod_function ); |
| 58 | |
| 59 | BOOST_TEST( D4::pointer == &A::f2 ); |
| 60 | BOOST_TEST_CSTR_EQ( D4::name, "f2" ); |
| 61 | BOOST_TEST_EQ( D4::modifiers, mod_public | mod_static | mod_function ); |
| 62 | } |
| 63 | |
| 64 | return boost::report_errors(); |
| 65 | } |
| 66 | |
| 67 | #endif // !defined(BOOST_DESCRIBE_CXX14) |
| 68 | |