Skip to content

Commit 7b5ef42

Browse files
Add CallOnMembers-variant to pass member index and member type
Signed-off-by: Christian Parpart <[email protected]>
1 parent b93b641 commit 7b5ef42

File tree

1 file changed

+9
-0
lines changed

1 file changed

+9
-0
lines changed

include/reflection-cpp/reflection.hpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -697,6 +697,15 @@ void CallOnMembers(Object& object, Callable&& callable)
697697
[&]<auto I>() { callable(Reflection::MemberNameOf<I, Object>, std::get<I>(Reflection::ToTuple(object))); });
698698
}
699699

700+
/// Calls a callable on each member of an object with the index of the member as the first argument.
701+
/// and the member's default-constructed value as the second argument.
702+
template <typename Object, typename Callable>
703+
void CallOnMembersWithIndex(Object& object, Callable&& callable)
704+
{
705+
template_for<0, Reflection::CountMembers<Object>>(
706+
[&]<auto I>() { callable(I, std::get<I>(Reflection::ToTuple(object))); });
707+
}
708+
700709
/// Folds over the members of a type without an object of it.
701710
///
702711
/// @param initialValue The initial value to fold with

0 commit comments

Comments
 (0)