diff --git a/README.md b/README.md index 3d79803a..843c5ce9 100644 --- a/README.md +++ b/README.md @@ -301,7 +301,6 @@ const auto view = rfl::to_view(lisa); view.apply([](const auto& f) { // f is a an rfl::Field pointing to the original field. - // f.name() is a compile-time constant. std::cout << f.name() << ": " << rfl::json::write(*f.value()) << std::endl; }); ``` diff --git a/docs/named_tuple.md b/docs/named_tuple.md index d1f99e5c..0785f92b 100644 --- a/docs/named_tuple.md +++ b/docs/named_tuple.md @@ -102,11 +102,13 @@ auto person = rfl::Field<"first_name", std::string>("Bart") * rfl::Field<"last_name", std::string>("Simpson"); person.apply([](const auto& f) { - constexpr auto field_name = f.name(); + auto field_name = f.name(); const auto& value = *f.value(); }); person.apply([](Field& f) { + // The field name can also be obtained as a compile-time constant. + constexpr auto field_name = Field::name(); using field_pointer_type = typename Field::Type; field_pointer_type* value = f.value(); }); diff --git a/tests/json/test_view.cpp b/tests/json/test_view.cpp index b9e6a292..b09622c7 100644 --- a/tests/json/test_view.cpp +++ b/tests/json/test_view.cpp @@ -34,15 +34,15 @@ void test() { view.apply([](const Field& field) { using field_type = std::remove_pointer_t; - if constexpr (field.name() == "age") { + if constexpr (Field::name() == "age") { static_assert(std::is_same_v); } else { static_assert(std::is_same_v); } }); - rfl::to_view(lisa).apply([](auto&& field) { - if constexpr (field.name() == "first_name") { + rfl::to_view(lisa).apply([](auto field) { + if constexpr (decltype(field)::name() == "first_name") { *field.value() = "Bart"; } });