-
Notifications
You must be signed in to change notification settings - Fork 1
Add tests and concepts for some functions #13
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -715,6 +715,7 @@ constexpr void EnumerateMembers(Callable&& callable) | |
| } | ||
|
|
||
| template <typename Object, typename Callable> | ||
| requires std::same_as<void, std::invoke_result_t<Callable, std::string, MemberTypeOf<1, Object>>> | ||
| void CallOnMembers(Object& object, Callable&& callable) | ||
| { | ||
| EnumerateMembers<Object>(object, | ||
|
|
@@ -751,6 +752,7 @@ constexpr ResultType FoldMembers(ResultType initialValue, Callable const& callab | |
| /// | ||
| /// @return The result of the fold | ||
| template <typename Object, typename Callable, typename ResultType> | ||
| requires std::same_as<ResultType, std::invoke_result_t<Callable, std::string, MemberTypeOf<1, Object>, ResultType>> | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. why
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. callable is called in the following way: so it must take |
||
| constexpr ResultType FoldMembers(Object& object, ResultType initialValue, Callable const& callable) | ||
| { | ||
| // clang-format off | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -68,6 +68,56 @@ TEST_CASE("nested", "[reflection]") | |
| CHECK(result == R"(a=1 b=2 c=3 d="hello" e={name="John Doe" email="[email protected]" age=42})"); | ||
| } | ||
|
|
||
| TEST_CASE("EnumerateMembers.index_and_value", "[reflection]") | ||
| { | ||
| auto ps = Person { "John Doe", "[email protected]", 42 }; | ||
| Reflection::EnumerateMembers(ps, []<size_t I>(auto&& value) { | ||
| if constexpr (I == 0) | ||
| { | ||
| CHECK(value == "John Doe"); | ||
| } | ||
| else if constexpr (I == 1) | ||
| { | ||
| CHECK(value == "[email protected]"); | ||
| } | ||
| else if constexpr (I == 2) | ||
| { | ||
| CHECK(value == 42); | ||
| } | ||
| }); | ||
| } | ||
|
|
||
| TEST_CASE("EnumerateMembers.index_and_type", "[reflection]") | ||
| { | ||
| Reflection::EnumerateMembers<Person>([]<auto I, typename T>() { | ||
| if constexpr (I == 0) | ||
| { | ||
| static_assert(std::same_as<T,std::string_view>); | ||
| } | ||
| if constexpr (I == 1) | ||
| { | ||
| static_assert(std::same_as<T,std::string>); | ||
| } | ||
| if constexpr (I == 2) | ||
| { | ||
| static_assert(std::same_as<T,int>); | ||
| } | ||
| }); | ||
| } | ||
|
|
||
| TEST_CASE("CallOnMembers", "[reflection]") | ||
| { | ||
| auto ps = Person { "John Doe", "[email protected]", 42 }; | ||
| std::string result; | ||
| Reflection::CallOnMembers(ps, [&result](auto&& name, auto&& value) { | ||
| result += name; | ||
| result += "="; | ||
| result += std::format("{}", value); | ||
| result += " "; | ||
| }); | ||
| CHECK(result == R"(name=John Doe [email protected] age=42 )"); | ||
| } | ||
|
|
||
| TEST_CASE("FoldMembers.type", "[reflection]") | ||
| { | ||
| // clang-format off | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
same question here as I asked below (sorry) :-)