| 1 | // Copyright (c) 2023 Denis Mikhailov |
| 2 | // |
| 3 | // Distributed under the Boost Software License, Version 1.0. (See accompanying |
| 4 | // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) |
| 5 | |
| 6 | #include <boost/pfr/core.hpp> |
| 7 | #include <type_traits> // for std::is_same |
| 8 | |
| 9 | struct A { |
| 10 | const volatile int cv_value = 0; |
| 11 | volatile int v_value = 0; |
| 12 | const int c_value = 0; |
| 13 | int value = 0; |
| 14 | |
| 15 | const volatile int& cv_ref; |
| 16 | volatile int& v_ref; |
| 17 | const int& c_ref; |
| 18 | int& ref; |
| 19 | |
| 20 | const volatile int&& cv_rref; |
| 21 | volatile int&& v_rref; |
| 22 | const int&& c_rref; |
| 23 | int&& rref; |
| 24 | }; |
| 25 | |
| 26 | int main() { |
| 27 | #if BOOST_PFR_USE_CPP17 |
| 28 | const volatile int cv_value = 0; |
| 29 | volatile int v_value = 0; |
| 30 | const int c_value = 0; |
| 31 | int value = 0; |
| 32 | |
| 33 | typedef boost::pfr::detail::size_t_<12> fields_count_tag; |
| 34 | |
| 35 | { |
| 36 | A a {.cv_value: cv_value, .v_value: v_value, .c_value: c_value, .value: value, |
| 37 | .cv_ref: cv_value, .v_ref: v_value, .c_ref: c_value, .ref: value, |
| 38 | .cv_rref: std::move(cv_value), .v_rref: std::move(v_value), .c_rref: std::move(c_value), .rref: std::move(value)}; |
| 39 | |
| 40 | const auto t = boost::pfr::detail::tie_as_tuple(val&: a, fields_count_tag{}); |
| 41 | |
| 42 | static_assert(std::is_same<decltype(boost::pfr::detail::sequence_tuple::get<0>(t)), int const volatile&>()); |
| 43 | static_assert(std::is_same<decltype(boost::pfr::detail::sequence_tuple::get<1>(t)), int volatile&>()); |
| 44 | static_assert(std::is_same<decltype(boost::pfr::detail::sequence_tuple::get<2>(t)), int const&>()); |
| 45 | static_assert(std::is_same<decltype(boost::pfr::detail::sequence_tuple::get<3>(t)), int&>()); |
| 46 | static_assert(std::is_same<decltype(boost::pfr::detail::sequence_tuple::get<4>(t)), int const volatile&>()); |
| 47 | static_assert(std::is_same<decltype(boost::pfr::detail::sequence_tuple::get<5>(t)), int volatile&>()); |
| 48 | static_assert(std::is_same<decltype(boost::pfr::detail::sequence_tuple::get<6>(t)), int const&>()); |
| 49 | static_assert(std::is_same<decltype(boost::pfr::detail::sequence_tuple::get<7>(t)), int&>()); |
| 50 | // FIXME implement rvalue references as a field support |
| 51 | // static_assert(std::is_same<decltype(boost::pfr::detail::sequence_tuple::get<8>(t)), int const volatile&&>()); |
| 52 | // static_assert(std::is_same<decltype(boost::pfr::detail::sequence_tuple::get<9>(t)), int volatile&&>()); |
| 53 | // static_assert(std::is_same<decltype(boost::pfr::detail::sequence_tuple::get<10>(t)), int const&&>()); |
| 54 | // static_assert(std::is_same<decltype(boost::pfr::detail::sequence_tuple::get<11>(t)), int&&>()); |
| 55 | } |
| 56 | |
| 57 | { |
| 58 | const A a {.cv_value: cv_value, .v_value: v_value, .c_value: c_value, .value: value, |
| 59 | .cv_ref: cv_value, .v_ref: v_value, .c_ref: c_value, .ref: value, |
| 60 | .cv_rref: std::move(cv_value), .v_rref: std::move(v_value), .c_rref: std::move(c_value), .rref: std::move(value)}; |
| 61 | |
| 62 | const auto t = boost::pfr::detail::tie_as_tuple(val: a, fields_count_tag{}); |
| 63 | |
| 64 | static_assert(std::is_same<decltype(boost::pfr::detail::sequence_tuple::get<0>(t)), int const volatile&>()); |
| 65 | static_assert(std::is_same<decltype(boost::pfr::detail::sequence_tuple::get<1>(t)), int const volatile&>()); |
| 66 | static_assert(std::is_same<decltype(boost::pfr::detail::sequence_tuple::get<2>(t)), int const&>()); |
| 67 | static_assert(std::is_same<decltype(boost::pfr::detail::sequence_tuple::get<3>(t)), int const&>()); |
| 68 | static_assert(std::is_same<decltype(boost::pfr::detail::sequence_tuple::get<4>(t)), int const volatile&>()); |
| 69 | static_assert(std::is_same<decltype(boost::pfr::detail::sequence_tuple::get<5>(t)), int volatile&>()); |
| 70 | static_assert(std::is_same<decltype(boost::pfr::detail::sequence_tuple::get<6>(t)), int const&>()); |
| 71 | static_assert(std::is_same<decltype(boost::pfr::detail::sequence_tuple::get<7>(t)), int&>()); |
| 72 | // FIXME implement rvalue references as a field support |
| 73 | // static_assert(std::is_same<decltype(boost::pfr::detail::sequence_tuple::get<8>(t)), int const volatile&&>()); |
| 74 | // static_assert(std::is_same<decltype(boost::pfr::detail::sequence_tuple::get<9>(t)), int volatile&&>()); |
| 75 | // static_assert(std::is_same<decltype(boost::pfr::detail::sequence_tuple::get<10>(t)), int const&&>()); |
| 76 | // static_assert(std::is_same<decltype(boost::pfr::detail::sequence_tuple::get<11>(t)), int&&>()); |
| 77 | } |
| 78 | |
| 79 | { |
| 80 | volatile A a {.cv_value: cv_value, .v_value: v_value, .c_value: c_value, .value: value, |
| 81 | .cv_ref: cv_value, .v_ref: v_value, .c_ref: c_value, .ref: value, |
| 82 | .cv_rref: std::move(cv_value), .v_rref: std::move(v_value), .c_rref: std::move(c_value), .rref: std::move(value)}; |
| 83 | |
| 84 | const auto t = boost::pfr::detail::tie_as_tuple(val&: a, fields_count_tag{}); |
| 85 | |
| 86 | static_assert(std::is_same<decltype(boost::pfr::detail::sequence_tuple::get<0>(t)), int const volatile&>()); |
| 87 | static_assert(std::is_same<decltype(boost::pfr::detail::sequence_tuple::get<1>(t)), int volatile&>()); |
| 88 | static_assert(std::is_same<decltype(boost::pfr::detail::sequence_tuple::get<2>(t)), int const volatile&>()); |
| 89 | static_assert(std::is_same<decltype(boost::pfr::detail::sequence_tuple::get<3>(t)), int volatile&>()); |
| 90 | static_assert(std::is_same<decltype(boost::pfr::detail::sequence_tuple::get<4>(t)), int const volatile&>()); |
| 91 | static_assert(std::is_same<decltype(boost::pfr::detail::sequence_tuple::get<5>(t)), int volatile&>()); |
| 92 | static_assert(std::is_same<decltype(boost::pfr::detail::sequence_tuple::get<6>(t)), int const&>()); |
| 93 | static_assert(std::is_same<decltype(boost::pfr::detail::sequence_tuple::get<7>(t)), int&>()); |
| 94 | // FIXME implement rvalue references as a field support |
| 95 | // static_assert(std::is_same<decltype(boost::pfr::detail::sequence_tuple::get<8>(t)), int const volatile&&>()); |
| 96 | // static_assert(std::is_same<decltype(boost::pfr::detail::sequence_tuple::get<9>(t)), int volatile&&>()); |
| 97 | // static_assert(std::is_same<decltype(boost::pfr::detail::sequence_tuple::get<10>(t)), int const&&>()); |
| 98 | // static_assert(std::is_same<decltype(boost::pfr::detail::sequence_tuple::get<11>(t)), int&&>()); |
| 99 | } |
| 100 | |
| 101 | { |
| 102 | const volatile A a {.cv_value: cv_value, .v_value: v_value, .c_value: c_value, .value: value, |
| 103 | .cv_ref: cv_value, .v_ref: v_value, .c_ref: c_value, .ref: value, |
| 104 | .cv_rref: std::move(cv_value), .v_rref: std::move(v_value), .c_rref: std::move(c_value), .rref: std::move(value)}; |
| 105 | |
| 106 | const auto t = boost::pfr::detail::tie_as_tuple(val: a, fields_count_tag{}); |
| 107 | |
| 108 | static_assert(std::is_same<decltype(boost::pfr::detail::sequence_tuple::get<0>(t)), int const volatile&>()); |
| 109 | static_assert(std::is_same<decltype(boost::pfr::detail::sequence_tuple::get<1>(t)), int const volatile&>()); |
| 110 | static_assert(std::is_same<decltype(boost::pfr::detail::sequence_tuple::get<2>(t)), int const volatile&>()); |
| 111 | static_assert(std::is_same<decltype(boost::pfr::detail::sequence_tuple::get<3>(t)), int const volatile&>()); |
| 112 | static_assert(std::is_same<decltype(boost::pfr::detail::sequence_tuple::get<4>(t)), int const volatile&>()); |
| 113 | static_assert(std::is_same<decltype(boost::pfr::detail::sequence_tuple::get<5>(t)), int volatile&>()); |
| 114 | static_assert(std::is_same<decltype(boost::pfr::detail::sequence_tuple::get<6>(t)), int const&>()); |
| 115 | static_assert(std::is_same<decltype(boost::pfr::detail::sequence_tuple::get<7>(t)), int&>()); |
| 116 | // FIXME implement rvalue references as a field support |
| 117 | // static_assert(std::is_same<decltype(boost::pfr::detail::sequence_tuple::get<8>(t)), int const volatile&&>()); |
| 118 | // static_assert(std::is_same<decltype(boost::pfr::detail::sequence_tuple::get<9>(t)), int volatile&&>()); |
| 119 | // static_assert(std::is_same<decltype(boost::pfr::detail::sequence_tuple::get<10>(t)), int const&&>()); |
| 120 | // static_assert(std::is_same<decltype(boost::pfr::detail::sequence_tuple::get<11>(t)), int&&>()); |
| 121 | } |
| 122 | |
| 123 | #endif |
| 124 | } |
| 125 | |
| 126 | |