|
| 1 | +// Copyright 2020 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/members.hpp> |
| 6 | +#include <boost/describe/constructor.hpp> |
| 7 | +#include <boost/describe/class.hpp> |
| 8 | +#include <boost/core/lightweight_test.hpp> |
| 9 | +#include <utility> |
| 10 | + |
| 11 | +class X |
| 12 | +{ |
| 13 | +private: |
| 14 | + |
| 15 | + std::pair<int, int> p_; |
| 16 | + |
| 17 | + |
| 18 | + X() : p_(0,0) {} |
| 19 | +public: |
| 20 | + X(int x, int y) noexcept : p_(x, y) {} |
| 21 | + X(const std::pair<int, int> & p) : p_(p) {} |
| 22 | + BOOST_DESCRIBE_CLASS(X, (), (), (), (p_)); |
| 23 | + BOOST_DESCRIBE_CLASS_CONSTRUCTORS(X, (), (int, int), (const std::pair<int, int>&)); |
| 24 | + |
| 25 | + int x() {return p_.first; } |
| 26 | + int y() {return p_.second; } |
| 27 | +}; |
| 28 | + |
| 29 | + |
| 30 | +#if !defined(BOOST_DESCRIBE_CXX14) |
| 31 | + |
| 32 | +#include <boost/config/pragma_message.hpp> |
| 33 | + |
| 34 | +BOOST_PRAGMA_MESSAGE("Skipping test because C++14 is not available") |
| 35 | +int main() {} |
| 36 | + |
| 37 | +#else |
| 38 | + |
| 39 | +#include <boost/mp11.hpp> |
| 40 | + |
| 41 | + |
| 42 | +int main() |
| 43 | +{ |
| 44 | + using namespace boost::describe; |
| 45 | + using namespace boost::mp11; |
| 46 | + |
| 47 | + { |
| 48 | + |
| 49 | + X x(1, 2); |
| 50 | + BOOST_TEST_EQ(x.x(), 1); |
| 51 | + BOOST_TEST_EQ(x.y(), 2); |
| 52 | + using L1 = describe_constructors<X>; |
| 53 | + |
| 54 | + BOOST_TEST_EQ( mp_size<L1>::value, 3 ); |
| 55 | + |
| 56 | + using C1 = mp_at_c<L1, 0>; |
| 57 | + BOOST_TEST( (std::is_same<C1::signature, X() >::value) ); |
| 58 | + BOOST_TEST_EQ( C1::modifiers, mod_constructor ); |
| 59 | + BOOST_TEST_EQ( C1::is_noexcept, false ); |
| 60 | + BOOST_TEST_EQ( C1::is_trivial, false ); |
| 61 | + BOOST_TEST_EQ(&x, C1::construct_at(&x)); |
| 62 | + BOOST_TEST_EQ(x.x(), 0); |
| 63 | + BOOST_TEST_EQ(x.y(), 0); |
| 64 | + |
| 65 | + using C2 = mp_at_c<L1, 1>; |
| 66 | + BOOST_TEST( (std::is_same<C2::signature, X(int, int) >::value) ); |
| 67 | + BOOST_TEST_EQ( C2::modifiers, mod_constructor ); |
| 68 | + BOOST_TEST_EQ( C2::is_noexcept, true ); |
| 69 | + BOOST_TEST_EQ( C2::is_trivial, false ); |
| 70 | + BOOST_TEST_EQ(&x, C2::construct_at(&x, 3, 4)); |
| 71 | + BOOST_TEST_EQ(x.x(), 3); |
| 72 | + BOOST_TEST_EQ(x.y(), 4); |
| 73 | + |
| 74 | + using C3 = mp_at_c<L1, 2>; |
| 75 | + BOOST_TEST( (std::is_same<C3::signature, X(const std::pair<int, int> &) >::value) ); |
| 76 | + BOOST_TEST_EQ( C3::modifiers, mod_constructor ); |
| 77 | + BOOST_TEST_EQ( C3::is_noexcept, false ); |
| 78 | + BOOST_TEST_EQ( C3::is_trivial, false ); |
| 79 | + BOOST_TEST_EQ(&x, C3::construct_at(&x, {5,6})); |
| 80 | + BOOST_TEST_EQ(x.x(), 5); |
| 81 | + BOOST_TEST_EQ(x.y(), 6); |
| 82 | + |
| 83 | + } |
| 84 | + |
| 85 | + return boost::report_errors(); |
| 86 | +} |
| 87 | + |
| 88 | +#endif // !defined(BOOST_DESCRIBE_CXX14) |
0 commit comments