Skip to content

Commit

Permalink
fix returned value of in_out results
Browse files Browse the repository at this point in the history
  • Loading branch information
isidorostsa committed Oct 13, 2023
1 parent 3916299 commit 9e52541
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 42 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -382,9 +384,12 @@ namespace hpx::parallel {
experimental::util::detail::relocation_traits<InIter,
FwdIter>::is_noexcept_relocatable_v)
{
return util::in_out_result<InIter, FwdIter>{first,
auto [first_advanced, dest_advanced] =
hpx::experimental::util::uninitialized_relocate_n_primitive(
first, count, dest)};
first, count, dest);

return util::in_out_result<InIter, FwdIter>{
first_advanced, dest_advanced};
}

// clang-format off
Expand Down Expand Up @@ -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<InIter1, FwdIter>{first,
auto [first_advanced, dest_advanced] =
hpx::experimental::util::uninitialized_relocate_primitive(
first, last, dest)};
first, last, dest);

return util::in_out_result<InIter1, FwdIter>{first_advanced, dest_advanced};
}

template <typename ExPolicy, typename InIter1, typename InIter2,
Expand Down Expand Up @@ -485,8 +492,8 @@ namespace hpx::parallel {
template <typename ExPolicy, typename BiIter1, typename BiIter2,
// clang-format off
HPX_CONCEPT_REQUIRES_(
hpx::is_sequenced_execution_policy_v<ExPolicy>&&
hpx::traits::is_bidirectional_iterator_v<BiIter1>&&
hpx::is_sequenced_execution_policy_v<ExPolicy> &&
hpx::traits::is_bidirectional_iterator_v<BiIter1> &&
hpx::traits::is_bidirectional_iterator_v<BiIter2>
)>
// clang-format on
Expand All @@ -495,9 +502,12 @@ namespace hpx::parallel {
BiIter2 dest_last) noexcept(hpx::experimental::util::detail::
relocation_traits<BiIter1, BiIter2>::is_noexcept_relocatable_v)
{
return util::in_out_result<BiIter1, BiIter2>{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<BiIter1, BiIter2>{last_advanced, dest_last_advanced
};
}

template <typename ExPolicy, typename BiIter1, typename BiIter2,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,12 @@
#include <hpx/type_support/is_trivially_relocatable.hpp>
#include <hpx/type_support/relocate_at.hpp>

#include <cstring>
#include <cstring> // for memmove
#include <type_traits>

#if defined(__cpp_lib_trivially_relocatable)
#include <tuple>

#if defined(HPX_HAVE_P1144_RELOCATE_AT)
#include <memory>
#endif

Expand Down Expand Up @@ -84,7 +86,7 @@ namespace hpx::experimental::util {
// uninitialized_relocate_n //
//////////////////////////////
template <typename InIter, typename Size, typename FwdIter>
FwdIter uninitialized_relocate_n_primitive_helper(
std::tuple<InIter, FwdIter> uninitialized_relocate_n_primitive_helper(
InIter first, Size n, FwdIter dst, buffer_memcpy_tag) noexcept
{
if (n != 0)
Expand All @@ -106,13 +108,13 @@ namespace hpx::experimental::util {
dst += n;
}

return dst;
return {first, dst};
}

template <typename InIter, typename Size, typename FwdIter>
// 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<InIter, FwdIter> 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)
Expand All @@ -123,11 +125,11 @@ namespace hpx::experimental::util {
std::addressof(*first), std::addressof(*dst));
}

return dst;
return {first, dst};
}

template <typename InIter, typename Size, typename FwdIter>
FwdIter uninitialized_relocate_n_primitive_helper(
std::tuple<InIter, FwdIter> uninitialized_relocate_n_primitive_helper(
InIter first, Size n, FwdIter dst, for_loop_try_catch_tag)
{
FwdIter original_dst = dst;
Expand Down Expand Up @@ -158,14 +160,14 @@ namespace hpx::experimental::util {
}
}

return dst;
return {first, dst};
}

////////////////////////////
// uninitialized_relocate //
////////////////////////////
template <typename InIter, typename Sent, typename FwdIter>
FwdIter uninitialized_relocate_primitive_helper(
std::tuple<InIter, FwdIter> uninitialized_relocate_primitive_helper(
InIter first, Sent last, FwdIter dst, buffer_memcpy_tag) noexcept
{
return uninitialized_relocate_n_primitive_helper(
Expand All @@ -175,7 +177,7 @@ namespace hpx::experimental::util {
template <typename InIter, typename Sent, typename FwdIter>
// 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<InIter, FwdIter> uninitialized_relocate_primitive_helper(
InIter first, Sent last, FwdIter dst, for_loop_nothrow_tag) noexcept
{
for (; first != last; ++first, ++dst)
Expand All @@ -186,11 +188,11 @@ namespace hpx::experimental::util {
std::addressof(*first), std::addressof(*dst));
}

return dst;
return {first, dst};
}

template <typename InIter, typename Sent, typename FwdIter>
FwdIter uninitialized_relocate_primitive_helper(
std::tuple<InIter, FwdIter> uninitialized_relocate_primitive_helper(
InIter first, Sent last, FwdIter dst, for_loop_try_catch_tag)
{
FwdIter original_dst = dst;
Expand Down Expand Up @@ -218,14 +220,15 @@ namespace hpx::experimental::util {
}
}

return dst;
return {first, dst};
}

/////////////////////////////////////
// uninitialized_relocate_backward //
/////////////////////////////////////
template <typename BiIter1, typename BiIter2>
BiIter2 uninitialized_relocate_backward_primitive_helper(BiIter1 first,
std::tuple<BiIter1, BiIter2>
uninitialized_relocate_backward_primitive_helper(BiIter1 first,
BiIter1 last, BiIter2 dst_last, buffer_memcpy_tag) noexcept
{
// Here we know the iterators are contiguous
Expand All @@ -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<BiIter1, BiIter2>
uninitialized_relocate_backward_primitive_helper(BiIter1 first,
BiIter1 last, BiIter2 dst_last, for_loop_nothrow_tag) noexcept
{
while (first != last)
Expand All @@ -255,14 +259,15 @@ namespace hpx::experimental::util {
std::addressof(*last), std::addressof(*dst_last));
}

return dst_last;
return {last, dst_last};
}

template <typename InIter, typename Sent, typename FwdIter>
FwdIter uninitialized_relocate_backward_primitive_helper(
InIter first, Sent last, FwdIter dst_last, for_loop_try_catch_tag)
template <typename BiIter1, typename BiIter2>
std::tuple<BiIter1, BiIter2>
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)
{
Expand All @@ -289,7 +294,7 @@ namespace hpx::experimental::util {
}
}

return dst_last;
return {last, dst_last};
}

} // namespace detail
Expand All @@ -300,7 +305,7 @@ namespace hpx::experimental::util {
template <typename InIter, typename FwdIter, typename Size,
typename iterators_are_contiguous_t>
// clang-format off
FwdIter uninitialized_relocate_n_primitive(InIter first, Size n,
std::tuple<InIter, FwdIter> uninitialized_relocate_n_primitive(InIter first, Size n,
FwdIter dst, iterators_are_contiguous_t) noexcept(
detail::relocation_traits<InIter, FwdIter>::is_noexcept_relocatable_v)
// clang-format on
Expand All @@ -317,8 +322,8 @@ namespace hpx::experimental::util {
}

template <typename InIter, typename Size, typename FwdIter>
FwdIter uninitialized_relocate_n_primitive(InIter first, Size n,
FwdIter dst) noexcept(detail::relocation_traits<InIter,
std::tuple<InIter, FwdIter> uninitialized_relocate_n_primitive(InIter first,
Size n, FwdIter dst) noexcept(detail::relocation_traits<InIter,
FwdIter>::is_noexcept_relocatable_v)
{
using iterators_are_contiguous_default_t =
Expand All @@ -335,7 +340,7 @@ namespace hpx::experimental::util {
template <typename InIter, typename Sent, typename FwdIter,
typename iterators_are_contiguous_t>
// clang-format off
FwdIter uninitialized_relocate_primitive(InIter first, Sent last,
std::tuple<InIter, FwdIter> uninitialized_relocate_primitive(InIter first, Sent last,
FwdIter dst, iterators_are_contiguous_t) noexcept(
detail::relocation_traits<InIter, FwdIter>::is_noexcept_relocatable_v)
// clang-format on
Expand All @@ -353,8 +358,8 @@ namespace hpx::experimental::util {
}

template <typename InIter, typename Sent, typename FwdIter>
FwdIter uninitialized_relocate_primitive(InIter first, Sent last,
FwdIter dst) noexcept(detail::relocation_traits<InIter,
std::tuple<InIter, FwdIter> uninitialized_relocate_primitive(InIter first,
Sent last, FwdIter dst) noexcept(detail::relocation_traits<InIter,
FwdIter>::is_noexcept_relocatable_v)
{
using iterators_are_contiguous_default_t =
Expand All @@ -371,7 +376,7 @@ namespace hpx::experimental::util {
template <typename BiIter1, typename BiIter2,
typename iterators_are_contiguous_t>
// clang-format off
BiIter2 uninitialized_relocate_backward_primitive(BiIter1 first, BiIter1 last,
std::tuple<BiIter1, BiIter2> uninitialized_relocate_backward_primitive(BiIter1 first, BiIter1 last,
BiIter2 dst_last, iterators_are_contiguous_t) noexcept(
detail::relocation_traits<BiIter1, BiIter2>::is_noexcept_relocatable_v)
// clang-format on
Expand All @@ -389,8 +394,8 @@ namespace hpx::experimental::util {
}

template <typename BiIter1, typename BiIter2>
BiIter2 uninitialized_relocate_backward_primitive(BiIter1 first,
BiIter1 last,
std::tuple<BiIter1, BiIter2> uninitialized_relocate_backward_primitive(
BiIter1 first, BiIter1 last,
BiIter2 dst_last) noexcept(detail::relocation_traits<BiIter1,
BiIter2>::is_noexcept_relocatable_v)
{
Expand Down

0 comments on commit 9e52541

Please sign in to comment.