diff --git a/include/boost/pfr/core.hpp b/include/boost/pfr/core.hpp index 555e1654..263b1ecb 100644 --- a/include/boost/pfr/core.hpp +++ b/include/boost/pfr/core.hpp @@ -13,7 +13,7 @@ #include #include -#include +#include #include #include @@ -223,24 +223,7 @@ constexpr auto structure_tie(T&&, std::enable_if_t< std::is_rvalue_reference constexpr void for_each_field(T&& value, F&& func) { - 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{} - ); + return ::boost::pfr::detail::for_each_field(std::forward(value), std::forward(func)); } /// \brief std::tie-like function that allows assigning to tied values from aggregates. diff --git a/include/boost/pfr/detail/core_name20_static.hpp b/include/boost/pfr/detail/core_name20_static.hpp index 40804fc5..931de004 100644 --- a/include/boost/pfr/detail/core_name20_static.hpp +++ b/include/boost/pfr/detail/core_name20_static.hpp @@ -12,14 +12,15 @@ #define BOOST_PFR_DETAIL_CORE_NAME20_STATIC_HPP #pragma once -#include #include + #include -#include -#include +#include #include +#include +#include +#include #include -#include #ifdef BOOST_PFR_HAS_STD_MODULE import std; @@ -244,7 +245,7 @@ constexpr auto tie_as_names_tuple() noexcept { template constexpr void for_each_field_with_name(T&& value, F&& func) { - return boost::pfr::for_each_field( + return boost::pfr::detail::for_each_field( std::forward(value), [f = std::forward(func)](auto&& field, auto index) mutable { using IndexType = decltype(index); diff --git a/include/boost/pfr/detail/for_each_field.hpp b/include/boost/pfr/detail/for_each_field.hpp new file mode 100644 index 00000000..14f417df --- /dev/null +++ b/include/boost/pfr/detail/for_each_field.hpp @@ -0,0 +1,50 @@ +// Copyright (c) 2016-2024 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 + +#ifdef BOOST_PFR_HAS_STD_MODULE +import std; +#else +#include // metaprogramming stuff +#endif + +#include +#include +#include +#include + +namespace boost { namespace pfr { namespace detail { + +template +constexpr void for_each_field(T&& value, F&& func) { + 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{} + ); +} + +}}} // namespace boost::pfr::detail + + +#endif // BOOST_PFR_DETAIL_FOR_EACH_FIELD_HPP