Open invexed opened 3 years ago
boost::hana::zip_with
and std::forward_as_tuple
would prevent unnecessary copies occurring when constructing the inner tuples.
pfr::structure_tie
with parameter pack will cause an "internal compiler error" in the current latest MSVC, for those who are having this problem or don't want to use hana
, the following workaround also works:
template <size_t index = 0, class ...Args>
void ForEachMultipleFields(const auto &callback, Args &&...args)
{
callback(pfr::get<index>(args)...);
constexpr size_t size = pfr::detail::fields_count<
std::decay_t<std::tuple_element_t<0, std::tuple<Args...>>>
>();
if constexpr (index + 1 != size) {
ForEachMultipleFields<index + 1>(callback, std::forward<Args>(args)...);
}
}
Multiple visitation is easy enough to achieve with a library like Boost.Hana (see below), but I think it would be useful functionality for
for_each_field
to support directly.Example on Compiler Explorer