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

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