| 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 | using boost::describe::operators::operator<<; |
| 32 | |
| 33 | struct Y |
| 34 | { |
| 35 | int a = 1; |
| 36 | }; |
| 37 | |
| 38 | BOOST_DESCRIBE_STRUCT(Y, (), (a)) |
| 39 | |
| 40 | using boost::describe::operators::operator<; |
| 41 | using boost::describe::operators::operator>; |
| 42 | using boost::describe::operators::operator<=; |
| 43 | using boost::describe::operators::operator>=; |
| 44 | using boost::describe::operators::operator<<; |
| 45 | |
| 46 | struct Z: X, Y |
| 47 | { |
| 48 | int b = 4; |
| 49 | }; |
| 50 | |
| 51 | BOOST_DESCRIBE_STRUCT(Z, (X, Y), (b)) |
| 52 | |
| 53 | using boost::describe::operators::operator<; |
| 54 | using boost::describe::operators::operator>; |
| 55 | using boost::describe::operators::operator<=; |
| 56 | using boost::describe::operators::operator>=; |
| 57 | using boost::describe::operators::operator<<; |
| 58 | |
| 59 | } // namespace app |
| 60 | |
| 61 | #define TEST_EQ(x, y) BOOST_TEST_LE(x, y); BOOST_TEST_GE(x, y); BOOST_TEST_NOT((x) < (y)); BOOST_TEST_NOT((x) > (y)) |
| 62 | #define TEST_LT(x, y) BOOST_TEST_LT(x, y); BOOST_TEST_LE(x, y); BOOST_TEST_GT(y, x); BOOST_TEST_GE(y, x) |
| 63 | |
| 64 | int main() |
| 65 | { |
| 66 | using app::X; |
| 67 | |
| 68 | { |
| 69 | X x1, x2; |
| 70 | TEST_EQ( x1, x2 ); |
| 71 | } |
| 72 | |
| 73 | using app::Y; |
| 74 | |
| 75 | { |
| 76 | Y y1, y2, y3; |
| 77 | |
| 78 | y3.a = 2; |
| 79 | |
| 80 | TEST_EQ( y1, y2 ); |
| 81 | TEST_LT( y1, y3 ); |
| 82 | } |
| 83 | |
| 84 | using app::Z; |
| 85 | |
| 86 | { |
| 87 | Z z1, z2, z3, z4; |
| 88 | |
| 89 | z3.a = 2; |
| 90 | z4.b = 3; |
| 91 | |
| 92 | TEST_EQ( z1, z2 ); |
| 93 | TEST_LT( z1, z3 ); |
| 94 | TEST_LT( z4, z1 ); |
| 95 | TEST_LT( z4, z3 ); |
| 96 | } |
| 97 | |
| 98 | return boost::report_errors(); |
| 99 | } |
| 100 | |
| 101 | #endif // !defined(BOOST_DESCRIBE_CXX14) |
| 102 | |