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 <boost/config.hpp>
9
10struct X
11{
12};
13
14BOOST_DESCRIBE_STRUCT(X, (), ())
15
16class Y
17{
18public:
19
20 int m1;
21 int m2;
22
23private:
24
25 int m3;
26 int m4;
27
28 BOOST_DESCRIBE_CLASS(Y, (), (m1, m2), (), (m3, m4))
29
30public:
31
32 Y( int m1, int m2, int m3, int m4 ): m1( m1 ), m2( m2 ), m3( m3 ), m4( m4 )
33 {
34 }
35
36 // using Pm = int Y::*;
37 typedef int Y::* Pm;
38
39 static Pm m3_pointer() BOOST_NOEXCEPT
40 {
41 return &Y::m3;
42 }
43
44 static Pm m4_pointer() BOOST_NOEXCEPT
45 {
46 return &Y::m4;
47 }
48};
49
50#if !defined(BOOST_DESCRIBE_CXX14)
51
52#include <boost/config/pragma_message.hpp>
53
54BOOST_PRAGMA_MESSAGE("Skipping test because C++14 is not available")
55int main() {}
56
57#else
58
59#include <boost/mp11.hpp>
60
61int main()
62{
63 using namespace boost::describe;
64 using namespace boost::mp11;
65
66 {
67 using L = describe_members<X, mod_any_access>;
68
69 BOOST_TEST_EQ( mp_size<L>::value, 0 );
70 }
71
72 {
73 using L = describe_members<Y, mod_any_access>;
74
75 BOOST_TEST_EQ( mp_size<L>::value, 4 );
76
77 BOOST_TEST( (mp_at_c<L, 0>::pointer) == &Y::m1 );
78 BOOST_TEST_CSTR_EQ( (mp_at_c<L, 0>::name), "m1" );
79 BOOST_TEST_EQ( (mp_at_c<L, 0>::modifiers), mod_public );
80
81 BOOST_TEST( (mp_at_c<L, 1>::pointer) == &Y::m2 );
82 BOOST_TEST_CSTR_EQ( (mp_at_c<L, 1>::name), "m2" );
83 BOOST_TEST_EQ( (mp_at_c<L, 1>::modifiers), mod_public );
84
85 BOOST_TEST( (mp_at_c<L, 2>::pointer) == Y::m3_pointer() );
86 BOOST_TEST_CSTR_EQ( (mp_at_c<L, 2>::name), "m3" );
87 BOOST_TEST_EQ( (mp_at_c<L, 2>::modifiers), mod_private );
88
89 BOOST_TEST( (mp_at_c<L, 3>::pointer) == Y::m4_pointer() );
90 BOOST_TEST_CSTR_EQ( (mp_at_c<L, 3>::name), "m4" );
91 BOOST_TEST_EQ( (mp_at_c<L, 3>::modifiers), mod_private );
92 }
93
94 {
95 using L = describe_members<Y, mod_public>;
96
97 BOOST_TEST_EQ( mp_size<L>::value, 2 );
98
99 BOOST_TEST( (mp_at_c<L, 0>::pointer) == &Y::m1 );
100 BOOST_TEST_CSTR_EQ( (mp_at_c<L, 0>::name), "m1" );
101 BOOST_TEST_EQ( (mp_at_c<L, 0>::modifiers), mod_public );
102
103 BOOST_TEST( (mp_at_c<L, 1>::pointer) == &Y::m2 );
104 BOOST_TEST_CSTR_EQ( (mp_at_c<L, 1>::name), "m2" );
105 BOOST_TEST_EQ( (mp_at_c<L, 1>::modifiers), mod_public );
106 }
107
108 {
109 using L = describe_members<Y, mod_private>;
110
111 BOOST_TEST_EQ( mp_size<L>::value, 2 );
112
113 BOOST_TEST( (mp_at_c<L, 0>::pointer) == Y::m3_pointer() );
114 BOOST_TEST_CSTR_EQ( (mp_at_c<L, 0>::name), "m3" );
115 BOOST_TEST_EQ( (mp_at_c<L, 0>::modifiers), mod_private );
116
117 BOOST_TEST( (mp_at_c<L, 1>::pointer) == Y::m4_pointer() );
118 BOOST_TEST_CSTR_EQ( (mp_at_c<L, 1>::name), "m4" );
119 BOOST_TEST_EQ( (mp_at_c<L, 1>::modifiers), mod_private );
120 }
121
122 {
123 using L = describe_members<Y, mod_protected>;
124
125 BOOST_TEST_EQ( mp_size<L>::value, 0 );
126 }
127
128 return boost::report_errors();
129}
130
131#endif // !defined(BOOST_DESCRIBE_CXX14)
132

source code of boost/libs/describe/test/members_test.cpp