From ba10f9bc94115aab1963039a44f914a2402ae06f Mon Sep 17 00:00:00 2001 From: Denis Mikhailov Date: Wed, 20 Jul 2022 15:27:28 +0600 Subject: [PATCH] Update core14_classic.hpp --- include/boost/pfr/detail/core14_classic.hpp | 24 ++++++++++----------- 1 file changed, 11 insertions(+), 13 deletions(-) diff --git a/include/boost/pfr/detail/core14_classic.hpp b/include/boost/pfr/detail/core14_classic.hpp index a27d081..b8be1d3 100644 --- a/include/boost/pfr/detail/core14_classic.hpp +++ b/include/boost/pfr/detail/core14_classic.hpp @@ -599,13 +599,20 @@ struct ubiq_constructor_constexpr_copy { ///////////////////// template -struct is_constexpr_aggregate_initializable { // TODO: try to fix it - template +struct is_constexpr_aggregate_initializable { + template + static constexpr void* constexpr_aggregate_initializer() { + const auto t = T2{ ubiq_constructor_constexpr_copy{I2}... }; + (void)t; + return nullptr; + } + + template () > static std::true_type test(long) noexcept; static std::false_type test(...) noexcept; - static constexpr decltype( test(0) ) value{}; + static constexpr bool value = decltype(test(0)){}; }; @@ -676,16 +683,7 @@ void for_each_field_dispatcher(T& t, F&& f, std::index_sequence) { !std::is_union::value, "====================> Boost.PFR: For safety reasons it is forbidden to reflect unions. See `Reflection of unions` section in the docs for more info." ); - - /// Compile time error at this point means that you have called `for_each_field` or some other non-flat function or operator for a - /// type that is not constexpr aggregate initializable. - /// - /// Make sure that all the fields of your type have constexpr default construtors and trivial destructors. - /// Or compile in C++17 mode. - constexpr T tmp{ ubiq_constructor_constexpr_copy{I}... }; - (void)tmp; - - //static_assert(is_constexpr_aggregate_initializable::value, "====================> Boost.PFR: T must be a constexpr initializable type"); + static_assert(is_constexpr_aggregate_initializable::value, "====================> Boost.PFR: T must be a constexpr initializable type"); constexpr bool is_flat_refelectable_val = detail::is_flat_refelectable( std::index_sequence{} ); detail::for_each_field_dispatcher_1(