| 1 | // Copyright (c) 2023 Bela Schaum, X-Ryl669, 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 | |
| 7 | // Initial implementation by Bela Schaum, https://github.com/schaumb |
| 8 | // The way to make it union and UB free by X-Ryl669, https://github.com/X-Ryl669 |
| 9 | // |
| 10 | |
| 11 | #include <boost/pfr/core_name.hpp> |
| 12 | |
| 13 | #include <functional> |
| 14 | #include <string> |
| 15 | |
| 16 | struct nonconstexpr { |
| 17 | nonconstexpr() {}; |
| 18 | }; |
| 19 | |
| 20 | struct Aggregate { |
| 21 | int member1; |
| 22 | nonconstexpr this_is_a_name; |
| 23 | std::reference_wrapper<char> c; |
| 24 | std::string Forth; |
| 25 | }; |
| 26 | |
| 27 | static_assert(boost::pfr::get_name<0, Aggregate>() == "member1" ); |
| 28 | static_assert(boost::pfr::get_name<1, Aggregate>() == "this_is_a_name" ); |
| 29 | static_assert(boost::pfr::get_name<2, Aggregate>() == "c" ); |
| 30 | static_assert(boost::pfr::get_name<3, Aggregate>() == "Forth" ); |
| 31 | |
| 32 | constexpr auto names_array = boost::pfr::names_as_array<Aggregate>(); |
| 33 | static_assert(names_array.size() == 4); |
| 34 | static_assert(names_array[0] == "member1" ); |
| 35 | static_assert(names_array[1] == "this_is_a_name" ); |
| 36 | static_assert(names_array[2] == "c" ); |
| 37 | static_assert(names_array[3] == "Forth" ); |
| 38 | |
| 39 | int main() {} |
| 40 | |
| 41 | |