| 1 | // Copyright 2020 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 X |
| 10 | { |
| 11 | int f() { return 1; } |
| 12 | int f() const { return 2; } |
| 13 | |
| 14 | static int f( int x ) { return x; } |
| 15 | static int f( int x, int y ) { return x + y; } |
| 16 | }; |
| 17 | |
| 18 | BOOST_DESCRIBE_STRUCT(X, (), ( |
| 19 | (int ()) f, |
| 20 | (int () const) f, |
| 21 | (int (int)) f, |
| 22 | (int (int, int)) f |
| 23 | )) |
| 24 | |
| 25 | #if !defined(BOOST_DESCRIBE_CXX14) |
| 26 | |
| 27 | #include <boost/config/pragma_message.hpp> |
| 28 | |
| 29 | BOOST_PRAGMA_MESSAGE("Skipping test because C++14 is not available" ) |
| 30 | int main() {} |
| 31 | |
| 32 | #else |
| 33 | |
| 34 | #include <boost/mp11.hpp> |
| 35 | |
| 36 | int main() |
| 37 | { |
| 38 | using namespace boost::describe; |
| 39 | using namespace boost::mp11; |
| 40 | |
| 41 | { |
| 42 | using L = describe_members<X, mod_any_access | mod_function>; |
| 43 | |
| 44 | BOOST_TEST_EQ( mp_size<L>::value, 2 ); |
| 45 | |
| 46 | using D1 = mp_at_c<L, 0>; |
| 47 | using D2 = mp_at_c<L, 1>; |
| 48 | |
| 49 | X x; |
| 50 | |
| 51 | BOOST_TEST_EQ( (x.*D1::pointer)(), 1 ); |
| 52 | BOOST_TEST_CSTR_EQ( D1::name, "f" ); |
| 53 | BOOST_TEST_EQ( D1::modifiers, mod_public | mod_function ); |
| 54 | |
| 55 | BOOST_TEST_EQ( (x.*D2::pointer)(), 2 ); |
| 56 | BOOST_TEST_CSTR_EQ( D2::name, "f" ); |
| 57 | BOOST_TEST_EQ( D2::modifiers, mod_public | mod_function ); |
| 58 | } |
| 59 | |
| 60 | { |
| 61 | using L = describe_members<X, mod_any_access | mod_static | mod_function>; |
| 62 | |
| 63 | BOOST_TEST_EQ( mp_size<L>::value, 2 ); |
| 64 | |
| 65 | using D1 = mp_at_c<L, 0>; |
| 66 | |
| 67 | using D1 = mp_at_c<L, 0>; |
| 68 | using D2 = mp_at_c<L, 1>; |
| 69 | |
| 70 | BOOST_TEST_EQ( (*D1::pointer)( 3 ), 3 ); |
| 71 | BOOST_TEST_CSTR_EQ( D1::name, "f" ); |
| 72 | BOOST_TEST_EQ( D1::modifiers, mod_public | mod_static | mod_function ); |
| 73 | |
| 74 | BOOST_TEST_EQ( (*D2::pointer)( 4, 5 ), 9 ); |
| 75 | BOOST_TEST_CSTR_EQ( D2::name, "f" ); |
| 76 | BOOST_TEST_EQ( D2::modifiers, mod_public | mod_static | mod_function ); |
| 77 | } |
| 78 | |
| 79 | return boost::report_errors(); |
| 80 | } |
| 81 | |
| 82 | #endif // !defined(BOOST_DESCRIBE_CXX14) |
| 83 | |