| 1 | // Copyright (c) 2019 Ilya Kiselev |
|---|---|
| 2 | // Copyright (c) 2019-2024 Antony Polukhin |
| 3 | // |
| 4 | // Distributed under the Boost Software License, Version 1.0. (See accompanying |
| 5 | // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) |
| 6 | |
| 7 | #include <boost/pfr/detail/offset_based_getter.hpp> |
| 8 | #include <boost/pfr/detail/sequence_tuple.hpp> |
| 9 | |
| 10 | #include <boost/core/lightweight_test.hpp> |
| 11 | |
| 12 | struct user_type { |
| 13 | char c; |
| 14 | double d; |
| 15 | }; |
| 16 | |
| 17 | int main() { |
| 18 | using pfr_tuple = boost::pfr::detail::sequence_tuple::tuple<char, double>; |
| 19 | using getter = boost::pfr::detail::offset_based_getter<user_type, pfr_tuple>; |
| 20 | using boost::pfr::detail::size_t_; |
| 21 | using boost::pfr::detail::sequence_tuple::get; |
| 22 | |
| 23 | user_type value{}; |
| 24 | auto begin = reinterpret_cast<char*>(&value); |
| 25 | auto native_offset = reinterpret_cast<char*>(&value.d) - begin; |
| 26 | |
| 27 | auto getter_offset = reinterpret_cast<char*>(&getter{}.get(u&: value, size_t_<1>{})) - begin; |
| 28 | BOOST_TEST_EQ(native_offset, getter_offset); |
| 29 | |
| 30 | pfr_tuple pfr_value{}; |
| 31 | auto pfr_tuple_offset = ( |
| 32 | reinterpret_cast<char*>(&get<1>(t&: pfr_value)) - reinterpret_cast<char*>(&get<0>(t&: pfr_value)) |
| 33 | ); |
| 34 | BOOST_TEST_EQ(native_offset, pfr_tuple_offset); |
| 35 | |
| 36 | return boost::report_errors(); |
| 37 | } |
| 38 |
