@@ -639,29 +639,6 @@ constexpr void template_for(F&& f)
639639 }(std::make_integer_sequence<t, E - B> {});
640640}
641641
642- // / Folds over the members of a type
643- // /
644- // / @param initialValue The initial value to fold with
645- // / @param callable The callable to fold with. The parameters are the member name,
646- // / the member's default value and the current result of the fold.
647- // /
648- // / @return The result of the fold
649- template <typename Object, typename Callable, typename ResultType>
650- constexpr ResultType FoldType (ResultType initialValue, Callable const & callable)
651- {
652- // clang-format off
653- ResultType result = initialValue;
654- template_for<0 , Reflection::CountMembers<Object>>(
655- [&]<size_t I>() {
656- result = callable (Reflection::MemberNameOf<I, Object>,
657- std::get<I>(Reflection::ToTuple (Object {})),
658- result);
659- }
660- );
661- // clang-format on
662- return result;
663- }
664-
665642template <auto P>
666643 requires (std::is_member_pointer_v<decltype (P)>)
667644consteval std::string_view GetName ()
@@ -719,6 +696,29 @@ void CallOnMembers(Object& object, Callable&& callable)
719696 [&]<auto I>() { callable (Reflection::MemberNameOf<I, Object>, std::get<I>(Reflection::ToTuple (object))); });
720697}
721698
699+ // / Folds over the members of a type without an object of it.
700+ // /
701+ // / @param initialValue The initial value to fold with
702+ // / @param callable The callable to fold with. The parameters are the member name,
703+ // / the member's default value and the current result of the fold.
704+ // /
705+ // / @return The result of the fold
706+ template <typename Object, typename Callable, typename ResultType>
707+ constexpr ResultType FoldMembers (ResultType initialValue, Callable const & callable)
708+ {
709+ // clang-format off
710+ ResultType result = initialValue;
711+ template_for<0 , Reflection::CountMembers<Object>>(
712+ [&]<size_t I>() {
713+ result = callable (Reflection::MemberNameOf<I, Object>,
714+ std::get<I>(Reflection::ToTuple (Object {})),
715+ result);
716+ }
717+ );
718+ // clang-format on
719+ return result;
720+ }
721+
722722// / Folds over the members of an object
723723// /
724724// / @param object The object to fold over
0 commit comments