Skip to content

Commit

Permalink
[avnd] Add a function to iterate fields with their index
Browse files Browse the repository at this point in the history
  • Loading branch information
jcelerier committed Apr 6, 2024
1 parent 56b89e5 commit dba0807
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions include/avnd/common/struct_reflection.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,21 @@ struct fields_introspection
#endif
}

template <typename F>
static constexpr void for_all_n(type& fields, F&& func) noexcept
{
#if AVND_USE_BOOST_PFR
if constexpr(size > 0)
{
avnd::for_each_field_ref_n(fields, std::forward<F>(func));
}
#else
// FIXME pass it the avnd::field_index<I>
auto&& [... elts] = fields;
(func(elts), ...);
#endif
}

static constexpr void for_nth(type& fields, int n, auto&& func) noexcept
{
// TODO maybe there is some dirty hack to do here with offsetof computations...
Expand Down

0 comments on commit dba0807

Please sign in to comment.