From dba080715258700aa657834dc0af3a351a62751b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jean-Micha=C3=ABl=20Celerier?= Date: Sat, 6 Apr 2024 12:15:15 -0400 Subject: [PATCH] [avnd] Add a function to iterate fields with their index --- include/avnd/common/struct_reflection.hpp | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/include/avnd/common/struct_reflection.hpp b/include/avnd/common/struct_reflection.hpp index 884b9c9c..050c53a2 100644 --- a/include/avnd/common/struct_reflection.hpp +++ b/include/avnd/common/struct_reflection.hpp @@ -71,6 +71,21 @@ struct fields_introspection #endif } + template + 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(func)); + } +#else + // FIXME pass it the avnd::field_index + 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...