diff --git a/CMakeLists.txt b/CMakeLists.txt index 1d11f79..815be91 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,5 +1,5 @@ cmake_minimum_required(VERSION 3.10) -project(reflection-cpp VERSION 0.3.0 LANGUAGES CXX) +project(reflection-cpp VERSION 0.3.1 LANGUAGES CXX) list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake") set(CMAKE_EXPORT_COMPILE_COMMANDS ON) diff --git a/include/reflection-cpp/reflection.hpp b/include/reflection-cpp/reflection.hpp index 81f85f6..0b7c857 100644 --- a/include/reflection-cpp/reflection.hpp +++ b/include/reflection-cpp/reflection.hpp @@ -1264,12 +1264,18 @@ constexpr void EnumerateMembers(Callable&& callable) } template - requires std::same_as>> + requires std::is_invocable_v> void CallOnMembers(Object& object, Callable&& callable) { EnumerateMembers(object, [&](T&& value) { callable(MemberNameOf, value); }); } +template +void CallOnMembersWithoutName(Object& object, Callable&& callable) +{ + EnumerateMembers(object, [&](T&& value) { callable.template operator()(value); }); +} + /// Folds over the members of a type without an object of it. /// /// @param initialValue The initial value to fold with diff --git a/test-reflection-cpp.cpp b/test-reflection-cpp.cpp index 4bab11e..58e1ccd 100644 --- a/test-reflection-cpp.cpp +++ b/test-reflection-cpp.cpp @@ -78,6 +78,7 @@ TEST_CASE("single value record", "[reflection]") CHECK(name == "value"); CHECK(value == 42); }); + } TEST_CASE("core", "[reflection]") @@ -181,6 +182,12 @@ TEST_CASE("CallOnMembers", "[reflection]") result += " "; }); CHECK(result == R"(name=John Doe email=john@doe.com age=42 )"); + + std::string resultAnother; + Reflection::CallOnMembersWithoutName(ps, [&resultAnother](FieldType const& value) { + resultAnother += std::format("{}", value); + }); + CHECK(resultAnother == R"(John Doejohn@doe.com42)"); } TEST_CASE("FoldMembers.type", "[reflection]")