File tree Expand file tree Collapse file tree
include/rfl/internal/cpp26
tests/json_c_arrays_and_inheritance Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -35,19 +35,31 @@ consteval auto get_field_names_impl() {
3535
3636template <auto _i, auto _j>
3737consteval bool is_same () {
38- static_assert (_i == _j, " Mismatched types " );
38+ static_assert (_i == _j, " Mismatched lengths " );
3939 return _i == _j;
4040}
4141
42+ template <class Type >
43+ consteval std::vector<std::meta::info> get_members () {
44+ constexpr auto ctx = std::meta::access_context::current ();
45+
46+ std::vector<std::meta::info> members;
47+
48+ constexpr auto nonstatic_members = std::define_static_array (
49+ std::meta::nonstatic_data_members_of (^^Type, ctx));
50+
51+ template for (auto member : nonstatic_members) { members.push_back (member); }
52+
53+ return members;
54+ }
55+
4256template <class T >
4357consteval auto get_field_names () {
4458 using Type = std::remove_cvref_t <T>;
4559 if constexpr (std::is_pointer_v<Type>) {
4660 return get_field_names<std::remove_pointer_t <Type>>();
4761 } else {
48- constexpr auto members =
49- std::define_static_array (std::meta::nonstatic_data_members_of (
50- ^^Type, std::meta::access_context::current ()));
62+ constexpr auto members = std::define_static_array (get_members<Type>());
5163
5264 using TupleT = decltype (bind_to_tuple (std::declval<Type&>()));
5365
Original file line number Diff line number Diff line change 1+ #ifdef REFLECTCPP_USE_CPP_REFLECTION
2+
3+ // Only supported with C++26 reflection
4+
5+ #include < gtest/gtest.h>
6+
7+ #include < cassert>
8+ #include < rfl.hpp>
9+
10+ #include " rfl/num_fields.hpp"
11+
12+ namespace test_inheritance3 {
13+
14+ struct Base {
15+ int x;
16+ };
17+
18+ struct Derived : public Base {
19+ int y;
20+ };
21+
22+ TEST (json, test_inheritance3) {
23+ Derived derived;
24+ const auto derived_view = rfl::to_view (derived);
25+
26+ constexpr auto name_x =
27+ rfl::tuple_element_t <0 , typename rfl::named_tuple_t <T>::Fields>::name ();
28+ constexpr auto name_y =
29+ rfl::tuple_element_t <1 , typename rfl::named_tuple_t <T>::Fields>::name ();
30+
31+ static_assert (name_x == " x" );
32+ static_assert (name_y == " y" );
33+
34+ EXPECT_TRUE (true );
35+ }
36+
37+ } // namespace test_inheritance3
38+
39+ #endif
You can’t perform that action at this time.
0 commit comments