diff --git a/include/boost/pfr/detail/core14.hpp b/include/boost/pfr/detail/core14.hpp index 812c5c9..9db3f13 100644 --- a/include/boost/pfr/detail/core14.hpp +++ b/include/boost/pfr/detail/core14.hpp @@ -526,14 +526,14 @@ constexpr bool is_flat_refelectable(std::index_sequence) noexcept { } template -decltype(auto) tie_as_flat_tuple(T&& val) noexcept { +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_{}); } template -decltype(auto) tie_as_tuple(T&& val) noexcept { +auto tie_as_tuple(T&& val) noexcept { typedef std::remove_reference_t type; static_assert( boost::pfr::detail::is_flat_refelectable( std::make_index_sequence()>{} ), diff --git a/include/boost/pfr/detail/core14_loophole.hpp b/include/boost/pfr/detail/core14_loophole.hpp index 26c9611..8740342 100644 --- a/include/boost/pfr/detail/core14_loophole.hpp +++ b/include/boost/pfr/detail/core14_loophole.hpp @@ -100,8 +100,8 @@ void for_each_field_dispatcher(T&& t, F&& f, std::index_sequence) { ); } -template -void tie_as_flat_tuple(T&& t) { +template +decltype(auto) tie_as_flat_tuple(T&& t) { return flatten_tuple_recursively( tie_as_tuple(std::forward(t)) ); diff --git a/include/boost/pfr/detail/flatten_tuple_recursively.hpp b/include/boost/pfr/detail/flatten_tuple_recursively.hpp index 7a84d52..b400f7b 100644 --- a/include/boost/pfr/detail/flatten_tuple_recursively.hpp +++ b/include/boost/pfr/detail/flatten_tuple_recursively.hpp @@ -16,30 +16,32 @@ namespace boost { namespace pfr { namespace detail { // Forward declarations: -template decltype(auto) flatten_tuple_recursively(T&& val) noexcept; +template auto flatten_tuple_recursively(T&& val) noexcept; template decltype(auto) tie_as_tuple(T&& val) noexcept; template -decltype(auto) tie_or_value(T&& val, std::enable_if_t >::value>* = 0) noexcept { - return flatten_tuple(std::forward(val)); +auto tie_or_value(T&& val, std::enable_if_t >::value>* = 0) noexcept { + return flatten_tuple_recursively( + tie_as_tuple(std::forward(val)) + ); } template -decltype(auto) tie_or_value(T&& val, std::enable_if_t >::value>* = 0) noexcept { +decltype(auto) tie_or_value(T&& val, std::enable_if_t >::value && !std::is_array< std::remove_reference_t >::value>* = 0) noexcept { return std::forward(val); } template -decltype(auto) flatten_tuple_recursively_impl(T&& tup, std::index_sequence ) noexcept { +auto flatten_tuple_recursively_impl(T&& tup, std::index_sequence ) noexcept { return sequence_tuple::tuple< decltype(tie_or_value(sequence_tuple::get(std::forward(tup))))... >{tie_or_value(sequence_tuple::get(std::forward(tup)))...}; } template -decltype(auto) flatten_tuple_recursively(T&& tup) noexcept { +auto flatten_tuple_recursively(T&& tup) noexcept { using indexes = std::make_index_sequence; - return flatten_tuple_impl(std::forward(tup), indexes{}); + return flatten_tuple_recursively_impl(std::forward(tup), indexes{}); } }}} // namespace boost::pfr::detail diff --git a/misc/generate_cpp17.py b/misc/generate_cpp17.py index b59d314..cd6131f 100644 --- a/misc/generate_cpp17.py +++ b/misc/generate_cpp17.py @@ -44,19 +44,19 @@ constexpr auto make_tuple_of_references(Args&&... args) noexcept { } template -constexpr auto as_tuple_impl(T&& /*val*/, size_t_<0>) noexcept { +constexpr auto tie_as_tuple(T&& /*val*/, size_t_<0>) noexcept { return sequence_tuple::tuple<>{}; } template -constexpr auto as_tuple_impl(T&& val, size_t_<1>, std::enable_if_t> >::value>* = 0) noexcept { +constexpr auto tie_as_tuple(T&& val, size_t_<1>, std::enable_if_t> >::value>* = 0) noexcept { auto& [a] = std::forward(val); return ::boost::pfr::detail::make_tuple_of_references(a); } template -constexpr auto as_tuple_impl(T&& val, size_t_<1>, std::enable_if_t> >::value>* = 0) noexcept { +constexpr auto tie_as_tuple(T&& val, size_t_<1>, std::enable_if_t> >::value>* = 0) noexcept { return ::boost::pfr::detail::make_tuple_of_references( std::forward(val) ); } @@ -67,19 +67,19 @@ EPILOGUE = """ //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// template -constexpr auto as_tuple(const T& val) noexcept { +constexpr auto tie_as_tuple(const T& val) noexcept { typedef size_t_()> fields_count_tag; - return boost::pfr::detail::as_tuple_impl(val, fields_count_tag{}); + return boost::pfr::detail::tie_as_tuple(val, fields_count_tag{}); } template -constexpr auto as_tuple(T& val) noexcept { +constexpr auto tie_as_tuple(T& val) noexcept { typedef size_t_()> fields_count_tag; - return boost::pfr::detail::as_tuple_impl(val, fields_count_tag{}); + return boost::pfr::detail::tie_as_tuple(val, fields_count_tag{}); } template -using as_tuple_t = decltype( ::boost::pfr::detail::as_tuple(std::declval()) ); +using tie_as_tuple_t = decltype( ::boost::pfr::detail::tie_as_tuple(std::declval()) ); }}} // namespace boost::pfr::detail @@ -93,8 +93,8 @@ generate_sfinae_attempts = False if generate_sfinae_attempts: print """ template - constexpr auto as_tuple_impl(T&& val, size_t_) noexcept { - return as_tuple_impl( std::forward(val), size_t_{}); + constexpr auto tie_as_tuple(T&& val, size_t_) noexcept { + return tie_as_tuple( std::forward(val), size_t_{}); } """ @@ -114,7 +114,7 @@ for i in xrange(1, funcs_count): indexes += ascii_letters[i % max_args_on_a_line] print "template " - print "constexpr auto as_tuple_impl(T&& val, size_t_<" + str(i + 1) + ">) noexcept {" + print "constexpr auto tie_as_tuple(T&& val, size_t_<" + str(i + 1) + ">) noexcept {" if i < max_args_on_a_line: print " auto& [" + indexes.strip() + "] = std::forward(val);" print " return ::boost::pfr::detail::make_tuple_of_references(" + indexes.strip() + ");" @@ -131,8 +131,8 @@ for i in xrange(1, funcs_count): if generate_sfinae_attempts: print "template " - print "constexpr auto as_tuple_impl(T&& val, size_t_<" + str(i + 1) + "> v) noexcept" - print " ->decltype( ::boost::pfr::detail::as_tuple_impl0(std::forward(val), v) )" - print "{ return ::boost::pfr::detail::as_tuple_impl0(std::forward(val), v); }\n" + print "constexpr auto tie_as_tuple(T&& val, size_t_<" + str(i + 1) + "> v) noexcept" + print " ->decltype( ::boost::pfr::detail::tie_as_tuple0(std::forward(val), v) )" + print "{ return ::boost::pfr::detail::tie_as_tuple0(std::forward(val), v); }\n" print EPILOGUE