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#if defined(__clang__)
6# pragma clang diagnostic ignored "-Wunused-private-field"
7#endif
8
9#include <boost/container_hash/hash.hpp>
10#include <boost/describe/class.hpp>
11#include <boost/describe/operators.hpp>
12#include <boost/core/lightweight_test_trait.hpp>
13
14#if !defined(BOOST_DESCRIBE_CXX14)
15
16#include <boost/config/pragma_message.hpp>
17
18BOOST_PRAGMA_MESSAGE( "Skipping test because BOOST_DESCRIBE_CXX14 is not defined" )
19
20int main() {}
21
22#else
23
24struct X1
25{
26 int m;
27 explicit X1( int m_ ): m( m_ ) {}
28};
29
30BOOST_DESCRIBE_STRUCT( X1, (), (m) )
31
32struct X2
33{
34 int m;
35 explicit X2( int m_ ): m( m_ ) {}
36};
37
38BOOST_DESCRIBE_STRUCT( X2, (), (m) )
39
40struct X3
41{
42 int m;
43 explicit X3( int m_ ): m( m_ ) {}
44};
45
46BOOST_DESCRIBE_STRUCT( X3, (), (m) )
47
48class Y: public X1, protected X2, private X3
49{
50public:
51
52 int m1;
53
54protected:
55
56 int m2;
57
58private:
59
60 int m3;
61
62public:
63
64 Y( int x1, int x2, int x3, int m1_, int m2_, int m3_ ):
65 X1( x1 ), X2( x2 ), X3( x3 ), m1( m1_ ), m2( m2_ ), m3( m3_ ) {}
66
67 BOOST_DESCRIBE_CLASS( Y, (X1, X2, X3), (m1), (m2), (m3) )
68};
69
70using boost::describe::operators::operator==;
71using boost::describe::operators::operator!=;
72using boost::describe::operators::operator<<;
73
74int main()
75{
76 Y y1( 0, 0, 0, 0, 0, 0 );
77
78 BOOST_TEST_EQ( y1, y1 );
79 BOOST_TEST_EQ( boost::hash<Y>()(y1), boost::hash<Y>()(y1) );
80
81 Y y2( 1, 0, 0, 0, 0, 0 );
82
83 BOOST_TEST_NE( y1, y2 );
84 BOOST_TEST_NE( boost::hash<Y>()(y1), boost::hash<Y>()(y2) );
85
86 Y y3( 0, 1, 0, 0, 0, 0 );
87
88 BOOST_TEST_NE( y1, y3 );
89 BOOST_TEST_NE( boost::hash<Y>()(y1), boost::hash<Y>()(y3) );
90
91 BOOST_TEST_NE( y2, y3 );
92 BOOST_TEST_NE( boost::hash<Y>()(y2), boost::hash<Y>()(y3) );
93
94 Y y4( 0, 0, 1, 0, 0, 0 );
95
96 BOOST_TEST_NE( y1, y4 );
97 BOOST_TEST_NE( boost::hash<Y>()(y1), boost::hash<Y>()(y4) );
98
99 BOOST_TEST_NE( y2, y4 );
100 BOOST_TEST_NE( boost::hash<Y>()(y2), boost::hash<Y>()(y4) );
101
102 BOOST_TEST_NE( y3, y4 );
103 BOOST_TEST_NE( boost::hash<Y>()(y3), boost::hash<Y>()(y4) );
104
105 Y y5( 0, 0, 0, 1, 0, 0 );
106
107 BOOST_TEST_NE( y1, y5 );
108 BOOST_TEST_NE( boost::hash<Y>()(y1), boost::hash<Y>()(y5) );
109
110 BOOST_TEST_NE( y2, y5 );
111 BOOST_TEST_NE( boost::hash<Y>()(y2), boost::hash<Y>()(y5) );
112
113 BOOST_TEST_NE( y3, y5 );
114 BOOST_TEST_NE( boost::hash<Y>()(y3), boost::hash<Y>()(y5) );
115
116 BOOST_TEST_NE( y4, y5 );
117 BOOST_TEST_NE( boost::hash<Y>()(y4), boost::hash<Y>()(y5) );
118
119 Y y6( 0, 0, 0, 0, 1, 0 );
120
121 BOOST_TEST_NE( y1, y6 );
122 BOOST_TEST_NE( boost::hash<Y>()(y1), boost::hash<Y>()(y6) );
123
124 BOOST_TEST_NE( y2, y6 );
125 BOOST_TEST_NE( boost::hash<Y>()(y2), boost::hash<Y>()(y6) );
126
127 BOOST_TEST_NE( y3, y6 );
128 BOOST_TEST_NE( boost::hash<Y>()(y3), boost::hash<Y>()(y6) );
129
130 BOOST_TEST_NE( y4, y6 );
131 BOOST_TEST_NE( boost::hash<Y>()(y4), boost::hash<Y>()(y6) );
132
133 BOOST_TEST_NE( y5, y6 );
134 BOOST_TEST_NE( boost::hash<Y>()(y5), boost::hash<Y>()(y6) );
135
136 Y y7( 0, 0, 0, 0, 0, 1 );
137
138 BOOST_TEST_NE( y1, y7 );
139 BOOST_TEST_NE( boost::hash<Y>()(y1), boost::hash<Y>()(y7) );
140
141 BOOST_TEST_NE( y2, y7 );
142 BOOST_TEST_NE( boost::hash<Y>()(y2), boost::hash<Y>()(y7) );
143
144 BOOST_TEST_NE( y3, y7 );
145 BOOST_TEST_NE( boost::hash<Y>()(y3), boost::hash<Y>()(y7) );
146
147 BOOST_TEST_NE( y4, y7 );
148 BOOST_TEST_NE( boost::hash<Y>()(y4), boost::hash<Y>()(y7) );
149
150 BOOST_TEST_NE( y5, y7 );
151 BOOST_TEST_NE( boost::hash<Y>()(y5), boost::hash<Y>()(y7) );
152
153 BOOST_TEST_NE( y6, y7 );
154 BOOST_TEST_NE( boost::hash<Y>()(y6), boost::hash<Y>()(y7) );
155
156 return boost::report_errors();
157}
158
159#endif
160

source code of boost/libs/container_hash/test/described_class_test.cpp