| 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/operators.hpp> |
| 6 | #include <boost/describe/class.hpp> |
| 7 | #include <boost/core/lightweight_test.hpp> |
| 8 | |
| 9 | #if !defined(BOOST_DESCRIBE_CXX14) |
| 10 | |
| 11 | #include <boost/config/pragma_message.hpp> |
| 12 | |
| 13 | BOOST_PRAGMA_MESSAGE("Skipping test because C++14 is not available" ) |
| 14 | int main() {} |
| 15 | |
| 16 | #else |
| 17 | |
| 18 | namespace app |
| 19 | { |
| 20 | |
| 21 | struct X |
| 22 | { |
| 23 | void f() const {} |
| 24 | static void g() {} |
| 25 | }; |
| 26 | |
| 27 | BOOST_DESCRIBE_STRUCT(X, (), (f, g)) |
| 28 | |
| 29 | using boost::describe::operators::operator==; |
| 30 | using boost::describe::operators::operator<<; |
| 31 | |
| 32 | struct Y |
| 33 | { |
| 34 | int a = 1; |
| 35 | }; |
| 36 | |
| 37 | BOOST_DESCRIBE_STRUCT(Y, (), (a)) |
| 38 | |
| 39 | using boost::describe::operators::operator==; |
| 40 | using boost::describe::operators::operator!=; |
| 41 | using boost::describe::operators::operator<<; |
| 42 | |
| 43 | struct Z: X, Y |
| 44 | { |
| 45 | int b = 4; |
| 46 | }; |
| 47 | |
| 48 | BOOST_DESCRIBE_STRUCT(Z, (X, Y), (b)) |
| 49 | |
| 50 | using boost::describe::operators::operator==; |
| 51 | using boost::describe::operators::operator!=; |
| 52 | using boost::describe::operators::operator<<; |
| 53 | |
| 54 | } // namespace app |
| 55 | |
| 56 | int main() |
| 57 | { |
| 58 | using app::X; |
| 59 | |
| 60 | { |
| 61 | X x1, x2; |
| 62 | BOOST_TEST_EQ( x1, x2 ); |
| 63 | } |
| 64 | |
| 65 | using app::Y; |
| 66 | |
| 67 | { |
| 68 | Y y1, y2, y3; |
| 69 | |
| 70 | y3.a = 2; |
| 71 | |
| 72 | BOOST_TEST_EQ( y1, y2 ); |
| 73 | BOOST_TEST_NE( y1, y3 ); |
| 74 | } |
| 75 | |
| 76 | using app::Z; |
| 77 | |
| 78 | { |
| 79 | Z z1, z2, z3, z4; |
| 80 | |
| 81 | z3.a = 2; |
| 82 | z4.b = 3; |
| 83 | |
| 84 | BOOST_TEST_EQ( z1, z2 ); |
| 85 | BOOST_TEST_NE( z1, z3 ); |
| 86 | BOOST_TEST_NE( z1, z4 ); |
| 87 | BOOST_TEST_NE( z3, z4 ); |
| 88 | } |
| 89 | |
| 90 | return boost::report_errors(); |
| 91 | } |
| 92 | |
| 93 | #endif // !defined(BOOST_DESCRIBE_CXX14) |
| 94 | |