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

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