// Copyright (c) 2016-2025 Antony Polukhin // // Distributed under the Boost Software License, Version 1.0. (See accompanying // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) #ifndef BOOST_PFR_DETAIL_FOR_EACH_FIELD_HPP #define BOOST_PFR_DETAIL_FOR_EACH_FIELD_HPP #pragma once #include #include #include #include #include #if !defined(BOOST_PFR_INTERFACE_UNIT) #include // metaprogramming stuff #include // forward_like #endif namespace boost { namespace pfr { namespace detail { template constexpr void for_each_field(T&& value, F&& func) { #if BOOST_PFR_USE_CPP26 using no_ref = std::remove_reference_t; if constexpr (std::is_aggregate_v || std::is_bounded_array_v) { auto &&[... members] = value; ::boost::pfr::detail::for_each_field_impl(value, std::forward(func), std::make_index_sequence{}, std::is_rvalue_reference{}); } else { ::boost::pfr::detail::for_each_field_impl(value, std::forward(func), std::make_index_sequence<1>{}, std::is_rvalue_reference{}); } #else constexpr std::size_t fields_count_val = boost::pfr::detail::fields_count>(); ::boost::pfr::detail::for_each_field_dispatcher( value, [f = std::forward(func)](auto&& t) mutable { // MSVC related workaround. Its lambdas do not capture constexprs. constexpr std::size_t fields_count_val_in_lambda = boost::pfr::detail::fields_count>(); ::boost::pfr::detail::for_each_field_impl( t, std::forward(f), detail::make_index_sequence{}, std::is_rvalue_reference{} ); }, detail::make_index_sequence{} ); #endif } }}} // namespace boost::pfr::detail #endif // BOOST_PFR_DETAIL_FOR_EACH_FIELD_HPP