From 0cf44d634e7e33f1ed53ea50fb0aeaa94efe926e Mon Sep 17 00:00:00 2001 From: Antony Polukhin Date: Wed, 6 Sep 2017 21:57:22 +0300 Subject: [PATCH] Reduce instantiations count by dropping some of the rvalue overloads of internal methods; reduce detail stuff used for public functions; reduced includes count --- include/boost/pfr/detail/core14_classic.hpp | 29 ++++++++++++------- include/boost/pfr/detail/core14_loophole.hpp | 5 ---- include/boost/pfr/detail/core17_generated.hpp | 3 -- .../boost/pfr/detail/for_each_field_impl.hpp | 3 ++ include/boost/pfr/precise/core.hpp | 11 +++---- include/boost/pfr/precise/functors.hpp | 6 +++- misc/generate_cpp17.py | 3 -- 7 files changed, 31 insertions(+), 29 deletions(-) diff --git a/include/boost/pfr/detail/core14_classic.hpp b/include/boost/pfr/detail/core14_classic.hpp index 80a303f..1764776 100644 --- a/include/boost/pfr/detail/core14_classic.hpp +++ b/include/boost/pfr/detail/core14_classic.hpp @@ -15,7 +15,6 @@ #include #include #include -#include #include #include @@ -528,24 +527,34 @@ constexpr bool is_flat_refelectable(std::index_sequence) noexcept { template auto tie_as_flat_tuple(T&& val) noexcept { typedef internal_tuple_with_same_alignment_t> tuple_type; - auto&& t = cast_to_layout_compatible(std::forward(val)); - return make_flat_tuple_of_references(std::forward(t), size_t_<0>{}, size_t_{}); + auto& t = cast_to_layout_compatible(std::forward(val)); + return make_flat_tuple_of_references(t, size_t_<0>{}, size_t_{}); } +#if !BOOST_PFR_USE_CPP17 + template -auto tie_as_tuple(T&& val) noexcept { - typedef std::remove_reference_t type; +auto tie_as_tuple(T& val) noexcept { + typedef T type; static_assert( boost::pfr::detail::is_flat_refelectable( std::make_index_sequence()>{} ), "Not possible in C++14 to represent that type without loosing information. Use boost::pfr::flat_ version, or change type definition, or enable C++17" ); - return tie_as_flat_tuple(std::forward(val)); + return tie_as_flat_tuple(val); } + template -using tie_as_tuple_t = decltype( ::boost::pfr::detail::tie_as_tuple(std::declval()) ); - +auto tie_as_tuple(const T& val) noexcept { + typedef T type; + static_assert( + boost::pfr::detail::is_flat_refelectable( std::make_index_sequence()>{} ), + "Not possible in C++14 to represent that type without loosing information. Use boost::pfr::flat_ version, or change type definition, or enable C++17" + ); + return tie_as_flat_tuple(val); +} +#endif // #if !BOOST_PFR_USE_CPP17 ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// @@ -609,9 +618,9 @@ void for_each_field_in_depth(T&& t, F&& f, std::index_sequence, identi template void for_each_field_in_depth(T&& t, F&& f, std::index_sequence<>, identity...) { - auto&& tuple = cast_to_layout_compatible< ::boost::pfr::detail::sequence_tuple::tuple >(std::forward(t)); + auto& tuple = cast_to_layout_compatible< ::boost::pfr::detail::sequence_tuple::tuple >(std::forward(t)); std::forward(f)( - make_flat_tuple_of_references(std::forward(tuple), size_t_<0>{}, size_t_{}) + make_flat_tuple_of_references(tuple, size_t_<0>{}, size_t_{}) ); } diff --git a/include/boost/pfr/detail/core14_loophole.hpp b/include/boost/pfr/detail/core14_loophole.hpp index ec16c76..90bd0dc 100644 --- a/include/boost/pfr/detail/core14_loophole.hpp +++ b/include/boost/pfr/detail/core14_loophole.hpp @@ -28,7 +28,6 @@ #include #include #include -#include #include #include @@ -123,10 +122,6 @@ auto tie_as_flat_tuple(T& t) { ); } - -template -using tie_as_tuple_t = decltype( ::boost::pfr::detail::tie_as_tuple(std::declval()) ); - }}} // namespace boost::pfr::detail #pragma GCC diagnostic pop diff --git a/include/boost/pfr/detail/core17_generated.hpp b/include/boost/pfr/detail/core17_generated.hpp index 7706a8d..3136dbc 100644 --- a/include/boost/pfr/detail/core17_generated.hpp +++ b/include/boost/pfr/detail/core17_generated.hpp @@ -1038,9 +1038,6 @@ constexpr auto tie_as_tuple(T& val) noexcept { return boost::pfr::detail::tie_as_tuple(val, fields_count_tag{}); } -template -using tie_as_tuple_t = decltype( ::boost::pfr::detail::tie_as_tuple(std::declval()) ); - }}} // namespace boost::pfr::detail #endif // BOOST_PFR_DETAIL_CORE17_GENERATED_HPP diff --git a/include/boost/pfr/detail/for_each_field_impl.hpp b/include/boost/pfr/detail/for_each_field_impl.hpp index ff20284..fe5e998 100644 --- a/include/boost/pfr/detail/for_each_field_impl.hpp +++ b/include/boost/pfr/detail/for_each_field_impl.hpp @@ -15,6 +15,9 @@ namespace boost { namespace pfr { namespace detail { +template +using size_t_ = std::integral_constant; + template ()(std::declval(), I{}))> void for_each_field_impl(T&& v, F&& f, I i, long) { std::forward(f)(std::forward(v), i); diff --git a/include/boost/pfr/precise/core.hpp b/include/boost/pfr/precise/core.hpp index 000b557..116453f 100644 --- a/include/boost/pfr/precise/core.hpp +++ b/include/boost/pfr/precise/core.hpp @@ -14,6 +14,7 @@ #include #include +#include #include #if BOOST_PFR_USE_CPP17 @@ -59,7 +60,7 @@ constexpr decltype(auto) get(T& val) noexcept { /// std::vector< boost::pfr::tuple_element<0, my_structure>::type > v; /// \endcode template -using tuple_element = detail::sequence_tuple::tuple_element >; +using tuple_element = detail::sequence_tuple::tuple_element()) ) >; /// \brief Type of a field with index `I` in aggregate `T`. @@ -89,11 +90,9 @@ using tuple_element_t = typename tuple_element::type; /// \endcode template constexpr auto structure_to_tuple(const T& val) noexcept { - typedef detail::tie_as_tuple_t internal_tuple_t; - return detail::make_stdtuple_from_tietuple( detail::tie_as_tuple(val), - std::make_index_sequence< internal_tuple_t::size_v >() + std::make_index_sequence< tuple_size_v >() ); } @@ -113,11 +112,9 @@ constexpr auto structure_to_tuple(const T& val) noexcept { /// \endcode template constexpr auto structure_tie(T& val) noexcept { - typedef detail::tie_as_tuple_t internal_tuple_t; - return detail::make_stdtiedtuple_from_tietuple( detail::tie_as_tuple(val), - std::make_index_sequence< internal_tuple_t::size_v >() + std::make_index_sequence< tuple_size_v >() ); } diff --git a/include/boost/pfr/precise/functors.hpp b/include/boost/pfr/precise/functors.hpp index 4b03ef7..c8095cc 100644 --- a/include/boost/pfr/precise/functors.hpp +++ b/include/boost/pfr/precise/functors.hpp @@ -10,7 +10,11 @@ #include #include -#include +#if BOOST_PFR_USE_CPP17 +# include +#else +# include +#endif /// \file boost/pfr/functors.hpp /// Contains functors that are close to the Standard Library ones. diff --git a/misc/generate_cpp17.py b/misc/generate_cpp17.py index cd6131f..5795ca0 100644 --- a/misc/generate_cpp17.py +++ b/misc/generate_cpp17.py @@ -78,9 +78,6 @@ constexpr auto tie_as_tuple(T& val) noexcept { return boost::pfr::detail::tie_as_tuple(val, fields_count_tag{}); } -template -using tie_as_tuple_t = decltype( ::boost::pfr::detail::tie_as_tuple(std::declval()) ); - }}} // namespace boost::pfr::detail #endif // BOOST_PFR_DETAIL_CORE17_GENERATED_HPP