|
| 1 | +// Copyright 2022 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_trait.hpp> |
| 8 | + |
| 9 | +#if !defined(BOOST_DESCRIBE_CXX14) |
| 10 | + |
| 11 | +#include <boost/config/pragma_message.hpp> |
| 12 | + |
| 13 | +BOOST_PRAGMA_MESSAGE("Skipping test because C++14 is not available") |
| 14 | +int main() {} |
| 15 | + |
| 16 | +#else |
| 17 | + |
| 18 | +#if defined(__clang__) |
| 19 | +#pragma clang diagnostic push |
| 20 | +#pragma clang diagnostic error "-Wgnu-zero-variadic-macro-arguments" |
| 21 | +#endif |
| 22 | + |
| 23 | + |
| 24 | +// Using (void) to specify empty bases for simple structs |
| 25 | +struct X { int foo; }; |
| 26 | +BOOST_DESCRIBE_STRUCT(X, (void), (foo)) |
| 27 | + |
| 28 | +// Using underlying macros for classes or empty types |
| 29 | +class Y { |
| 30 | + public: |
| 31 | + int foo; |
| 32 | + private: |
| 33 | + int bar; |
| 34 | + friend BOOST_DESCRIBE_BASES(Y, void) |
| 35 | + friend BOOST_DESCRIBE_PUBLIC_MEMBERS(Y, foo) |
| 36 | + friend BOOST_DESCRIBE_PROTECTED_MEMBERS_EMPTY(Y) |
| 37 | + friend BOOST_DESCRIBE_PRIVATE_MEMBERS(Y, bar) |
| 38 | +}; |
| 39 | + |
| 40 | + |
| 41 | +int main() |
| 42 | +{ |
| 43 | + using namespace boost::describe; |
| 44 | + using namespace boost::mp11; |
| 45 | + |
| 46 | + { |
| 47 | + using L = describe_bases<X, mod_any_access>; |
| 48 | + BOOST_TEST_EQ( mp_size<L>::value, 0 ); |
| 49 | + } |
| 50 | + |
| 51 | + { |
| 52 | + using L = describe_members<X, mod_any_access>; |
| 53 | + BOOST_TEST_EQ( mp_size<L>::value, 1 ); |
| 54 | + } |
| 55 | + |
| 56 | + { |
| 57 | + using L = describe_bases<Y, mod_any_access>; |
| 58 | + BOOST_TEST_EQ( mp_size<L>::value, 0 ); |
| 59 | + } |
| 60 | + |
| 61 | + { |
| 62 | + using L = describe_members<Y, mod_any_access>; |
| 63 | + BOOST_TEST_EQ( mp_size<L>::value, 2 ); |
| 64 | + } |
| 65 | + |
| 66 | + return boost::report_errors(); |
| 67 | +} |
| 68 | + |
| 69 | + |
| 70 | + |
| 71 | +#endif |
0 commit comments