[C++20] to_tuple with names
twitter.com
twitter.com
It uses extern combined with source_location to get the field name.
Example
struct foo {
int first_field;
int second_field;
};
constexpr auto t = to_tuple(foo{.first_field = 42, .second_field = 87});
static_assert("first_field"sv == std::get<0>(t).name and 42 == std::get<0>(t).value);
static_assert("second_field"sv == std::get<1>(t).name and 87 == std::get<1>(t).value);
100 LOC example
- https://godbolt.org/z/sEMPxjGfP