From 3cfee3f62ddf64f8066984d88a7e16113f29dbe2 Mon Sep 17 00:00:00 2001 From: stu Date: Thu, 21 Mar 2024 12:11:06 +0000 Subject: [PATCH 1/2] revert change of F&& to const F& --- include/rfl/NamedTuple.hpp | 4 ++-- tests/json/test_apply.cpp | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/include/rfl/NamedTuple.hpp b/include/rfl/NamedTuple.hpp index 1edd4d73..c2d38d73 100644 --- a/include/rfl/NamedTuple.hpp +++ b/include/rfl/NamedTuple.hpp @@ -199,7 +199,7 @@ class NamedTuple { /// Invokes a callable object once for each field in order. template - void apply(const F& _f) { + void apply(F&& _f) { const auto apply_to_field = [&_f](AFields&&... fields) { ((_f(std::forward(fields))), ...); @@ -209,7 +209,7 @@ class NamedTuple { /// Invokes a callable object once for each field in order. template - void apply(const F& _f) const { + void apply(F&& _f) const { const auto apply_to_field = [&_f](const auto&... fields) { ((_f(fields)), ...); }; diff --git a/tests/json/test_apply.cpp b/tests/json/test_apply.cpp index 3f80e843..bcb97db7 100644 --- a/tests/json/test_apply.cpp +++ b/tests/json/test_apply.cpp @@ -38,7 +38,7 @@ void test() { } }); - rfl::to_view(lisa).apply([](auto field) { + rfl::to_view(lisa).apply([](auto field) mutable { if constexpr (decltype(field)::name() == "first_name") { *field.value() = "Bart"; } From 270d27d3967ad0f49582cb09a16926f5d9f28850 Mon Sep 17 00:00:00 2001 From: stu Date: Thu, 21 Mar 2024 12:42:53 +0000 Subject: [PATCH 2/2] also for empty named tuple --- include/rfl/NamedTuple.hpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/rfl/NamedTuple.hpp b/include/rfl/NamedTuple.hpp index c2d38d73..ba9619be 100644 --- a/include/rfl/NamedTuple.hpp +++ b/include/rfl/NamedTuple.hpp @@ -602,7 +602,7 @@ class NamedTuple<> { /// Does nothing at all. template - void apply(const F& _f) const {} + void apply(F&& _f) const {} /// Returns an empty tuple. auto fields() const { return std::tuple(); }