| 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 | #include <utility> |
| 9 | |
| 10 | class X |
| 11 | { |
| 12 | private: |
| 13 | |
| 14 | std::pair<int, int> p_; |
| 15 | |
| 16 | public: |
| 17 | |
| 18 | std::pair<int, int>& f() { return p_; } |
| 19 | std::pair<int, int> const& f() const { return p_; } |
| 20 | |
| 21 | BOOST_DESCRIBE_CLASS(X, (), ((std::pair<int, int>& ()) f, (std::pair<int, int> const& () const) f), (), (p_)) |
| 22 | }; |
| 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 L1 = describe_members<X, mod_any_access>; |
| 43 | |
| 44 | BOOST_TEST_EQ( mp_size<L1>::value, 1 ); |
| 45 | |
| 46 | using D1 = mp_at_c<L1, 0>; |
| 47 | |
| 48 | BOOST_TEST_CSTR_EQ( D1::name, "p_" ); |
| 49 | BOOST_TEST_EQ( D1::modifiers, mod_private ); |
| 50 | |
| 51 | X x; |
| 52 | |
| 53 | auto& p = x.*D1::pointer; |
| 54 | |
| 55 | using L2 = describe_members<X, mod_any_access | mod_function>; |
| 56 | |
| 57 | BOOST_TEST_EQ( mp_size<L2>::value, 2 ); |
| 58 | |
| 59 | using D2 = mp_at_c<L2, 0>; |
| 60 | using D3 = mp_at_c<L2, 1>; |
| 61 | |
| 62 | BOOST_TEST_EQ( &(x.*D2::pointer)(), &p ); |
| 63 | BOOST_TEST_CSTR_EQ( D2::name, "f" ); |
| 64 | BOOST_TEST_EQ( D2::modifiers, mod_public | mod_function ); |
| 65 | |
| 66 | BOOST_TEST_EQ( &(x.*D3::pointer)(), &p ); |
| 67 | BOOST_TEST_CSTR_EQ( D3::name, "f" ); |
| 68 | BOOST_TEST_EQ( D3::modifiers, mod_public | mod_function ); |
| 69 | } |
| 70 | |
| 71 | return boost::report_errors(); |
| 72 | } |
| 73 | |
| 74 | #endif // !defined(BOOST_DESCRIBE_CXX14) |
| 75 | |