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
16struct nonconstexpr {
17 nonconstexpr() {};
18};
19
20struct Aggregate {
21 int member1;
22 nonconstexpr this_is_a_name;
23 std::reference_wrapper<char> c;
24 std::string Forth;
25};
26
27static_assert(boost::pfr::get_name<0, Aggregate>() == "member1");
28static_assert(boost::pfr::get_name<1, Aggregate>() == "this_is_a_name");
29static_assert(boost::pfr::get_name<2, Aggregate>() == "c");
30static_assert(boost::pfr::get_name<3, Aggregate>() == "Forth");
31
32constexpr auto names_array = boost::pfr::names_as_array<Aggregate>();
33static_assert(names_array.size() == 4);
34static_assert(names_array[0] == "member1");
35static_assert(names_array[1] == "this_is_a_name");
36static_assert(names_array[2] == "c");
37static_assert(names_array[3] == "Forth");
38
39int main() {}
40
41

source code of boost/libs/pfr/test/core_name/run/fields_names_constexpr.cpp