| 1 | // Copyright 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/descriptor_by_name.hpp> |
| 6 | #include <boost/describe/class.hpp> |
| 7 | #include <boost/describe/members.hpp> |
| 8 | #include <boost/core/lightweight_test.hpp> |
| 9 | |
| 10 | #if !defined(BOOST_DESCRIBE_CXX14) |
| 11 | |
| 12 | #include <boost/config/pragma_message.hpp> |
| 13 | |
| 14 | BOOST_PRAGMA_MESSAGE("Skipping test because C++14 is not available" ) |
| 15 | int main() {} |
| 16 | |
| 17 | #else |
| 18 | |
| 19 | struct X |
| 20 | { |
| 21 | int a = 1; |
| 22 | int b = 2; |
| 23 | }; |
| 24 | |
| 25 | BOOST_DESCRIBE_STRUCT(X, (), (a, b)) |
| 26 | |
| 27 | struct Y |
| 28 | { |
| 29 | int a = 1; |
| 30 | int c = 3; |
| 31 | }; |
| 32 | |
| 33 | BOOST_DESCRIBE_STRUCT(Y, (), (a, c)) |
| 34 | |
| 35 | int main() |
| 36 | { |
| 37 | { |
| 38 | using L = boost::describe::describe_members<X, boost::describe::mod_any_access>; |
| 39 | |
| 40 | using Na = BOOST_DESCRIBE_MAKE_NAME( a ); |
| 41 | using Da = boost::describe::descriptor_by_name<L, Na>; |
| 42 | BOOST_TEST_CSTR_EQ( Da::name, "a" ); |
| 43 | |
| 44 | using Nb = BOOST_DESCRIBE_MAKE_NAME( b ); |
| 45 | using Db = boost::describe::descriptor_by_name<L, Nb>; |
| 46 | BOOST_TEST_CSTR_EQ( Db::name, "b" ); |
| 47 | } |
| 48 | |
| 49 | { |
| 50 | using L = boost::describe::describe_members<Y, boost::describe::mod_any_access>; |
| 51 | |
| 52 | using Na = BOOST_DESCRIBE_MAKE_NAME( a ); |
| 53 | using Da = boost::describe::descriptor_by_name<L, Na>; |
| 54 | BOOST_TEST_CSTR_EQ( Da::name, "a" ); |
| 55 | |
| 56 | using Nc = BOOST_DESCRIBE_MAKE_NAME( c ); |
| 57 | using Dc = boost::describe::descriptor_by_name<L, Nc>; |
| 58 | BOOST_TEST_CSTR_EQ( Dc::name, "c" ); |
| 59 | } |
| 60 | |
| 61 | return boost::report_errors(); |
| 62 | } |
| 63 | |
| 64 | #endif // !defined(BOOST_DESCRIBE_CXX14) |
| 65 | |