File: bases_test.cpp

package info (click to toggle)
boost1.88 1.88.0-1
  • links: PTS, VCS
  • area: main
  • in suites: trixie
  • size: 576,932 kB
  • sloc: cpp: 4,149,234; xml: 136,789; ansic: 35,092; python: 33,910; asm: 5,698; sh: 4,604; ada: 1,681; makefile: 1,633; pascal: 1,139; perl: 1,124; sql: 640; yacc: 478; ruby: 271; java: 77; lisp: 24; csh: 6
file content (180 lines) | stat: -rw-r--r-- 4,448 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
// Copyright 2020 Peter Dimov
// Distributed under the Boost Software License, Version 1.0.
// https://www.boost.org/LICENSE_1_0.txt

#include <boost/describe/bases.hpp>
#include <boost/describe/class.hpp>
#include <boost/core/lightweight_test.hpp>
#include <boost/core/lightweight_test_trait.hpp>

#if defined(_MSC_VER) && _MSC_VER < 1900
# pragma warning(disable: 4510) // default constructor could not be generated
# pragma warning(disable: 4610) // struct can never be instantiated
#endif

struct X
{
};

BOOST_DESCRIBE_STRUCT(X, (), ())

struct X1
{
};

struct X2
{
};

struct X3
{
};

struct V1
{
    V1(int);
};

struct V2
{
    V2(int);
};

struct V3
{
    V3(int);
};

struct Y: public X1, protected X2, private X3, public virtual V1, protected virtual V2, private virtual V3
{
};

BOOST_DESCRIBE_STRUCT(Y, (X1, X2, X3, V1, V2, V3), ())

#if !defined(BOOST_DESCRIBE_CXX14)

#include <boost/config/pragma_message.hpp>

BOOST_PRAGMA_MESSAGE("Skipping test because C++14 is not available")
int main() {}

#else

#include <boost/mp11.hpp>

template<typename ...Bases>
struct ZT: Bases...
{
    BOOST_DESCRIBE_CLASS(ZT, (Bases...), (), (), ());
};

using Z = ZT<X1, X2, X3>;

int main()
{
    using namespace boost::describe;
    using namespace boost::mp11;

    {
        using L = describe_bases<X, mod_any_access>;

        BOOST_TEST_EQ( mp_size<L>::value, 0 );
    }

    {
        using L = describe_bases<X, mod_public>;

        BOOST_TEST_EQ( mp_size<L>::value, 0 );
    }

    {
        using L = describe_bases<X, mod_protected>;

        BOOST_TEST_EQ( mp_size<L>::value, 0 );
    }

    {
        using L = describe_bases<X, mod_private>;

        BOOST_TEST_EQ( mp_size<L>::value, 0 );
    }

    {
        using L = describe_bases<Y, mod_any_access>;

        BOOST_TEST_EQ( mp_size<L>::value, 6 );

        BOOST_TEST_TRAIT_SAME( typename mp_at_c<L, 0>::type, X1 );
        BOOST_TEST_EQ( (mp_at_c<L, 0>::modifiers), mod_public );

        BOOST_TEST_TRAIT_SAME( typename mp_at_c<L, 1>::type, X2 );
        BOOST_TEST_EQ( (mp_at_c<L, 1>::modifiers), mod_protected );

        BOOST_TEST_TRAIT_SAME( typename mp_at_c<L, 2>::type, X3 );
        BOOST_TEST_EQ( (mp_at_c<L, 2>::modifiers), mod_private );

        BOOST_TEST_TRAIT_SAME( typename mp_at_c<L, 3>::type, V1 );
        BOOST_TEST_EQ( (mp_at_c<L, 3>::modifiers), mod_public | mod_virtual );

        BOOST_TEST_TRAIT_SAME( typename mp_at_c<L, 4>::type, V2 );
        BOOST_TEST_EQ( (mp_at_c<L, 4>::modifiers), mod_protected | mod_virtual );

        BOOST_TEST_TRAIT_SAME( typename mp_at_c<L, 5>::type, V3 );
        BOOST_TEST_EQ( (mp_at_c<L, 5>::modifiers), mod_private | mod_virtual );
    }

    {
        using L = describe_bases<Y, mod_public>;

        BOOST_TEST_EQ( mp_size<L>::value, 2 );

        BOOST_TEST_TRAIT_SAME( typename mp_at_c<L, 0>::type, X1 );
        BOOST_TEST_EQ( (mp_at_c<L, 0>::modifiers), mod_public );

        BOOST_TEST_TRAIT_SAME( typename mp_at_c<L, 1>::type, V1 );
        BOOST_TEST_EQ( (mp_at_c<L, 1>::modifiers), mod_public | mod_virtual );
    }

    {
        using L = describe_bases<Y, mod_protected>;

        BOOST_TEST_EQ( mp_size<L>::value, 2 );

        BOOST_TEST_TRAIT_SAME( typename mp_at_c<L, 0>::type, X2 );
        BOOST_TEST_EQ( (mp_at_c<L, 0>::modifiers), mod_protected );

        BOOST_TEST_TRAIT_SAME( typename mp_at_c<L, 1>::type, V2 );
        BOOST_TEST_EQ( (mp_at_c<L, 1>::modifiers), mod_protected | mod_virtual );
    }

    {
        using L = describe_bases<Y, mod_private>;

        BOOST_TEST_EQ( mp_size<L>::value, 2 );

        BOOST_TEST_TRAIT_SAME( typename mp_at_c<L, 0>::type, X3 );
        BOOST_TEST_EQ( (mp_at_c<L, 0>::modifiers), mod_private );

        BOOST_TEST_TRAIT_SAME( typename mp_at_c<L, 1>::type, V3 );
        BOOST_TEST_EQ( (mp_at_c<L, 1>::modifiers), mod_private | mod_virtual );
    }

    {
        using L = describe_bases<Z, mod_any_access>;

        BOOST_TEST_EQ( mp_size<L>::value, 3 );

        BOOST_TEST_TRAIT_SAME( typename mp_at_c<L, 0>::type, X1 );
        BOOST_TEST_EQ( (mp_at_c<L, 0>::modifiers), mod_public );

        BOOST_TEST_TRAIT_SAME( typename mp_at_c<L, 1>::type, X2 );
        BOOST_TEST_EQ( (mp_at_c<L, 1>::modifiers), mod_public );

        BOOST_TEST_TRAIT_SAME( typename mp_at_c<L, 2>::type, X3 );
        BOOST_TEST_EQ( (mp_at_c<L, 2>::modifiers), mod_public );
    }

    return boost::report_errors();
}

#endif // !defined(BOOST_DESCRIBE_CXX14)