Skip to content

Commit

Permalink
extracted common code from sequential uninitialized_copy and uninitia…
Browse files Browse the repository at this point in the history
…lized_copy_sent
  • Loading branch information
Jedi18 committed Jun 26, 2021
1 parent 4ac158f commit 825e7bd
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 37 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -236,48 +236,18 @@ namespace hpx { namespace parallel { inline namespace v1 {
namespace detail {
/// \cond NOINTERNAL

// provide our own implementation of std::uninitialized_copy as some
// versions of MSVC horribly fail at compiling it for some types T
template <typename InIter1, typename Sent, typename InIter2>
util::in_out_result<InIter1, InIter2> std_uninitialized_copy(
InIter1 first, Sent last, InIter2 d_first)
{
using value_type =
typename std::iterator_traits<InIter2>::value_type;

InIter2 current = d_first;
try
{
for (/* */; first != last; (void) ++first, ++current)
{
::new (std::addressof(*current)) value_type(*first);
}
return util::in_out_result<InIter1, InIter2>{first, current};
}
catch (...)
{
for (/* */; d_first != current; ++d_first)
{
(*d_first).~value_type();
}
throw;
}
}

///////////////////////////////////////////////////////////////////////
template <typename InIter1, typename Sent1, typename FwdIter2,
typename Sent2>
util::in_out_result<InIter1, FwdIter2> std_uninitialized_copy_sent(
InIter1 first, Sent1 last, FwdIter2 dest, Sent2 last_d)
template <typename InIter1, typename FwdIter2, typename Cond>
util::in_out_result<InIter1, FwdIter2> sequential_uninitialized_copy(
InIter1 first, FwdIter2 dest, Cond cond)
{
using value_type =
typename std::iterator_traits<FwdIter2>::value_type;

FwdIter2 current = dest;
try
{
for (/* */; !(first == last || current == last_d);
(void) ++first, ++current)
for (/* */; cond(first, current); (void) ++first, ++current)
{
::new (std::addressof(*current)) value_type(*first);
}
Expand Down Expand Up @@ -381,7 +351,10 @@ namespace hpx { namespace parallel { inline namespace v1 {
static util::in_out_result<InIter1, FwdIter2> sequential(
ExPolicy, InIter1 first, Sent last, FwdIter2 dest)
{
return std_uninitialized_copy(first, last, dest);
return sequential_uninitialized_copy(
first, dest, [last](InIter1 first, FwdIter2) -> bool {
return first != last;
});
}

template <typename ExPolicy, typename Iter, typename Sent,
Expand Down Expand Up @@ -445,7 +418,10 @@ namespace hpx { namespace parallel { inline namespace v1 {
static util::in_out_result<InIter1, FwdIter2> sequential(ExPolicy,
InIter1 first, Sent1 last, FwdIter2 dest, Sent2 last_d)
{
return std_uninitialized_copy_sent(first, last, dest, last_d);
return sequential_uninitialized_copy(first, dest,
[last, last_d](InIter1 first, FwdIter2 current) -> bool {
return !(first == last || current == last_d);
});
}

template <typename ExPolicy, typename Iter, typename Sent1,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,5 @@

#include <hpx/parallel/memory.hpp>

#include <hpx/parallel/container_algorithms/uninitialized_copy.hpp>
#include <hpx/parallel/container_algorithms/destroy.hpp>
#include <hpx/parallel/container_algorithms/uninitialized_copy.hpp>

0 comments on commit 825e7bd

Please sign in to comment.