From 9e52541c8974f21f913664d742d74a4669c59879 Mon Sep 17 00:00:00 2001 From: isidorostsa Date: Fri, 13 Oct 2023 12:59:58 +0300 Subject: [PATCH] fix returned value of in_out results --- .../algorithms/uninitialized_relocate.hpp | 34 ++++++---- .../uninitialized_relocate_n_primitive.hpp | 65 ++++++++++--------- 2 files changed, 57 insertions(+), 42 deletions(-) diff --git a/libs/core/algorithms/include/hpx/parallel/algorithms/uninitialized_relocate.hpp b/libs/core/algorithms/include/hpx/parallel/algorithms/uninitialized_relocate.hpp index 1f8a858b6f53..ff43ff778a28 100644 --- a/libs/core/algorithms/include/hpx/parallel/algorithms/uninitialized_relocate.hpp +++ b/libs/core/algorithms/include/hpx/parallel/algorithms/uninitialized_relocate.hpp @@ -329,11 +329,13 @@ namespace hpx::parallel { InIter part_source = get<0>(iters); FwdIter part_dest = get<1>(iters); - // returns (dest begin, dest end) - return std::make_pair(part_dest, + auto [part_source_advanced, part_dest_advanced] = hpx::experimental::util:: uninitialized_relocate_n_primitive( - part_source, part_size, part_dest)); + part_source, part_size, part_dest); + + // returns (dest begin, dest end) + return std::make_pair(part_dest, part_dest_advanced); }, // finalize, called once if no error occurred [first, dest, count](auto&& data) mutable @@ -382,9 +384,12 @@ namespace hpx::parallel { experimental::util::detail::relocation_traits::is_noexcept_relocatable_v) { - return util::in_out_result{first, + auto [first_advanced, dest_advanced] = hpx::experimental::util::uninitialized_relocate_n_primitive( - first, count, dest)}; + first, count, dest); + + return util::in_out_result{ + first_advanced, dest_advanced}; } // clang-format off @@ -437,9 +442,11 @@ namespace hpx::parallel { FwdIter dest) noexcept(hpx::experimental::util::detail::relocation_traits< InIter1, FwdIter>::is_noexcept_relocatable_v) { - return util::in_out_result{first, + auto [first_advanced, dest_advanced] = hpx::experimental::util::uninitialized_relocate_primitive( - first, last, dest)}; + first, last, dest); + + return util::in_out_result{first_advanced, dest_advanced}; } template && - hpx::traits::is_bidirectional_iterator_v&& + hpx::is_sequenced_execution_policy_v && + hpx::traits::is_bidirectional_iterator_v && hpx::traits::is_bidirectional_iterator_v )> // clang-format on @@ -495,9 +502,12 @@ namespace hpx::parallel { BiIter2 dest_last) noexcept(hpx::experimental::util::detail:: relocation_traits::is_noexcept_relocatable_v) { - return util::in_out_result{first, - hpx::experimental::util::uninitialized_relocate_backward_primitive( - first, last, dest_last)}; + auto [last_advanced, dest_last_advanced] = + hpx::experimental::util::uninitialized_relocate_backward_primitive( + first, last, dest_last); + + return util::in_out_result{last_advanced, dest_last_advanced + }; } template #include -#include +#include // for memmove #include -#if defined(__cpp_lib_trivially_relocatable) +#include + +#if defined(HPX_HAVE_P1144_RELOCATE_AT) #include #endif @@ -84,7 +86,7 @@ namespace hpx::experimental::util { // uninitialized_relocate_n // ////////////////////////////// template - FwdIter uninitialized_relocate_n_primitive_helper( + std::tuple uninitialized_relocate_n_primitive_helper( InIter first, Size n, FwdIter dst, buffer_memcpy_tag) noexcept { if (n != 0) @@ -106,13 +108,13 @@ namespace hpx::experimental::util { dst += n; } - return dst; + return {first, dst}; } template // Either the buffer is not contiguous or the types are no-throw // move constructible but not trivially relocatable - FwdIter uninitialized_relocate_n_primitive_helper( + std::tuple uninitialized_relocate_n_primitive_helper( InIter first, Size n, FwdIter dst, for_loop_nothrow_tag) noexcept { for (Size i = 0; i < n; ++first, ++dst, ++i) @@ -123,11 +125,11 @@ namespace hpx::experimental::util { std::addressof(*first), std::addressof(*dst)); } - return dst; + return {first, dst}; } template - FwdIter uninitialized_relocate_n_primitive_helper( + std::tuple uninitialized_relocate_n_primitive_helper( InIter first, Size n, FwdIter dst, for_loop_try_catch_tag) { FwdIter original_dst = dst; @@ -158,14 +160,14 @@ namespace hpx::experimental::util { } } - return dst; + return {first, dst}; } //////////////////////////// // uninitialized_relocate // //////////////////////////// template - FwdIter uninitialized_relocate_primitive_helper( + std::tuple uninitialized_relocate_primitive_helper( InIter first, Sent last, FwdIter dst, buffer_memcpy_tag) noexcept { return uninitialized_relocate_n_primitive_helper( @@ -175,7 +177,7 @@ namespace hpx::experimental::util { template // Either the buffer is not contiguous or the types are no-throw // move constructible but not trivially relocatable - FwdIter uninitialized_relocate_primitive_helper( + std::tuple uninitialized_relocate_primitive_helper( InIter first, Sent last, FwdIter dst, for_loop_nothrow_tag) noexcept { for (; first != last; ++first, ++dst) @@ -186,11 +188,11 @@ namespace hpx::experimental::util { std::addressof(*first), std::addressof(*dst)); } - return dst; + return {first, dst}; } template - FwdIter uninitialized_relocate_primitive_helper( + std::tuple uninitialized_relocate_primitive_helper( InIter first, Sent last, FwdIter dst, for_loop_try_catch_tag) { FwdIter original_dst = dst; @@ -218,14 +220,15 @@ namespace hpx::experimental::util { } } - return dst; + return {first, dst}; } ///////////////////////////////////// // uninitialized_relocate_backward // ///////////////////////////////////// template - BiIter2 uninitialized_relocate_backward_primitive_helper(BiIter1 first, + std::tuple + uninitialized_relocate_backward_primitive_helper(BiIter1 first, BiIter1 last, BiIter2 dst_last, buffer_memcpy_tag) noexcept { // Here we know the iterators are contiguous @@ -242,7 +245,8 @@ namespace hpx::experimental::util { // Either the buffer is not contiguous or the types are no-throw // move constructible but not trivially relocatable // dst_last is one past the last element of the destination - BiIter2 uninitialized_relocate_backward_primitive_helper(BiIter1 first, + std::tuple + uninitialized_relocate_backward_primitive_helper(BiIter1 first, BiIter1 last, BiIter2 dst_last, for_loop_nothrow_tag) noexcept { while (first != last) @@ -255,14 +259,15 @@ namespace hpx::experimental::util { std::addressof(*last), std::addressof(*dst_last)); } - return dst_last; + return {last, dst_last}; } - template - FwdIter uninitialized_relocate_backward_primitive_helper( - InIter first, Sent last, FwdIter dst_last, for_loop_try_catch_tag) + template + std::tuple + uninitialized_relocate_backward_primitive_helper(BiIter1 first, + BiIter1 last, BiIter2 dst_last, for_loop_try_catch_tag) { - FwdIter original_dst_last = dst_last; + BiIter2 original_dst_last = dst_last; while (first != last) { @@ -289,7 +294,7 @@ namespace hpx::experimental::util { } } - return dst_last; + return {last, dst_last}; } } // namespace detail @@ -300,7 +305,7 @@ namespace hpx::experimental::util { template // clang-format off - FwdIter uninitialized_relocate_n_primitive(InIter first, Size n, + std::tuple uninitialized_relocate_n_primitive(InIter first, Size n, FwdIter dst, iterators_are_contiguous_t) noexcept( detail::relocation_traits::is_noexcept_relocatable_v) // clang-format on @@ -317,8 +322,8 @@ namespace hpx::experimental::util { } template - FwdIter uninitialized_relocate_n_primitive(InIter first, Size n, - FwdIter dst) noexcept(detail::relocation_traits uninitialized_relocate_n_primitive(InIter first, + Size n, FwdIter dst) noexcept(detail::relocation_traits::is_noexcept_relocatable_v) { using iterators_are_contiguous_default_t = @@ -335,7 +340,7 @@ namespace hpx::experimental::util { template // clang-format off - FwdIter uninitialized_relocate_primitive(InIter first, Sent last, + std::tuple uninitialized_relocate_primitive(InIter first, Sent last, FwdIter dst, iterators_are_contiguous_t) noexcept( detail::relocation_traits::is_noexcept_relocatable_v) // clang-format on @@ -353,8 +358,8 @@ namespace hpx::experimental::util { } template - FwdIter uninitialized_relocate_primitive(InIter first, Sent last, - FwdIter dst) noexcept(detail::relocation_traits uninitialized_relocate_primitive(InIter first, + Sent last, FwdIter dst) noexcept(detail::relocation_traits::is_noexcept_relocatable_v) { using iterators_are_contiguous_default_t = @@ -371,7 +376,7 @@ namespace hpx::experimental::util { template // clang-format off - BiIter2 uninitialized_relocate_backward_primitive(BiIter1 first, BiIter1 last, + std::tuple uninitialized_relocate_backward_primitive(BiIter1 first, BiIter1 last, BiIter2 dst_last, iterators_are_contiguous_t) noexcept( detail::relocation_traits::is_noexcept_relocatable_v) // clang-format on @@ -389,8 +394,8 @@ namespace hpx::experimental::util { } template - BiIter2 uninitialized_relocate_backward_primitive(BiIter1 first, - BiIter1 last, + std::tuple uninitialized_relocate_backward_primitive( + BiIter1 first, BiIter1 last, BiIter2 dst_last) noexcept(detail::relocation_traits::is_noexcept_relocatable_v) {