Skip to content

Commit

Permalink
Better headers organization (#180)
Browse files Browse the repository at this point in the history
  • Loading branch information
apolukhin authored Sep 13, 2024
1 parent 6591a86 commit e4cbbc7
Show file tree
Hide file tree
Showing 3 changed files with 58 additions and 24 deletions.
21 changes: 2 additions & 19 deletions include/boost/pfr/core.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@

#include <boost/pfr/detail/sequence_tuple.hpp>
#include <boost/pfr/detail/stdtuple.hpp>
#include <boost/pfr/detail/for_each_field_impl.hpp>
#include <boost/pfr/detail/for_each_field.hpp>
#include <boost/pfr/detail/make_integer_sequence.hpp>
#include <boost/pfr/detail/tie_from_structure_tuple.hpp>

Expand Down Expand Up @@ -223,24 +223,7 @@ constexpr auto structure_tie(T&&, std::enable_if_t< std::is_rvalue_reference<T&&
/// \endcode
template <class T, class F>
constexpr void for_each_field(T&& value, F&& func) {
constexpr std::size_t fields_count_val = boost::pfr::detail::fields_count<std::remove_reference_t<T>>();

::boost::pfr::detail::for_each_field_dispatcher(
value,
[f = std::forward<F>(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<std::remove_reference_t<T>>();

::boost::pfr::detail::for_each_field_impl(
t,
std::forward<F>(f),
detail::make_index_sequence<fields_count_val_in_lambda>{},
std::is_rvalue_reference<T&&>{}
);
},
detail::make_index_sequence<fields_count_val>{}
);
return ::boost::pfr::detail::for_each_field(std::forward<T>(value), std::forward<F>(func));
}

/// \brief std::tie-like function that allows assigning to tied values from aggregates.
Expand Down
11 changes: 6 additions & 5 deletions include/boost/pfr/detail/core_name20_static.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,15 @@
#define BOOST_PFR_DETAIL_CORE_NAME20_STATIC_HPP
#pragma once

#include <boost/pfr/core.hpp>
#include <boost/pfr/detail/config.hpp>

#include <boost/pfr/detail/core.hpp>
#include <boost/pfr/detail/sequence_tuple.hpp>
#include <boost/pfr/detail/make_integer_sequence.hpp>
#include <boost/pfr/detail/fake_object.hpp>
#include <boost/pfr/detail/fields_count.hpp>
#include <boost/pfr/detail/for_each_field.hpp>
#include <boost/pfr/detail/make_integer_sequence.hpp>
#include <boost/pfr/detail/sequence_tuple.hpp>
#include <boost/pfr/detail/stdarray.hpp>
#include <boost/pfr/detail/fake_object.hpp>

#ifdef BOOST_PFR_HAS_STD_MODULE
import std;
Expand Down Expand Up @@ -244,7 +245,7 @@ constexpr auto tie_as_names_tuple() noexcept {

template <class T, class F>
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<T>(value),
[f = std::forward<F>(func)](auto&& field, auto index) mutable {
using IndexType = decltype(index);
Expand Down
50 changes: 50 additions & 0 deletions include/boost/pfr/detail/for_each_field.hpp
Original file line number Diff line number Diff line change
@@ -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 <boost/pfr/detail/config.hpp>

#ifdef BOOST_PFR_HAS_STD_MODULE
import std;
#else
#include <type_traits> // metaprogramming stuff
#endif

#include <boost/pfr/detail/core.hpp>
#include <boost/pfr/detail/fields_count.hpp>
#include <boost/pfr/detail/for_each_field_impl.hpp>
#include <boost/pfr/detail/make_integer_sequence.hpp>

namespace boost { namespace pfr { namespace detail {

template <class T, class F>
constexpr void for_each_field(T&& value, F&& func) {
constexpr std::size_t fields_count_val = boost::pfr::detail::fields_count<std::remove_reference_t<T>>();

::boost::pfr::detail::for_each_field_dispatcher(
value,
[f = std::forward<F>(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<std::remove_reference_t<T>>();

::boost::pfr::detail::for_each_field_impl(
t,
std::forward<F>(f),
detail::make_index_sequence<fields_count_val_in_lambda>{},
std::is_rvalue_reference<T&&>{}
);
},
detail::make_index_sequence<fields_count_val>{}
);
}

}}} // namespace boost::pfr::detail


#endif // BOOST_PFR_DETAIL_FOR_EACH_FIELD_HPP

0 comments on commit e4cbbc7

Please sign in to comment.