Skip to content

Commit

Permalink
Merge c64e423 into 616ed17
Browse files Browse the repository at this point in the history
  • Loading branch information
hkaiser authored Nov 10, 2021
2 parents 616ed17 + c64e423 commit 71d8dbe
Show file tree
Hide file tree
Showing 7 changed files with 232 additions and 152 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,9 @@ namespace hpx { namespace segmented {
return *(it_.get_data()->begin() + it_.get_local_index());
}

template <typename T_>
template <typename T_,
typename Enable = std::enable_if_t<!std::is_same_v<
std::decay_t<T_>, local_vector_value_proxy>>>
local_vector_value_proxy& operator=(T_&& value)
{
if (!it_.get_data())
Expand Down Expand Up @@ -214,7 +216,9 @@ namespace hpx { namespace segmented {
return v_.get_value(launch::sync, index_);
}

template <typename T_>
template <typename T_,
typename Enable = std::enable_if_t<
!std::is_same_v<std::decay_t<T_>, vector_value_proxy>>>
vector_value_proxy& operator=(T_&& value)
{
v_.set_value(launch::sync, index_, std::forward<T_>(value));
Expand Down Expand Up @@ -1230,8 +1234,21 @@ namespace hpx { namespace traits {
};

template <typename T, typename Data>
struct is_value_proxy<hpx::segmented::detail::vector_value_proxy<T, Data>>
struct proxy_value<
hpx::segmented::detail::local_vector_value_proxy<T, Data>>
: std::true_type
{
};

template <typename T, typename Data>
struct is_value_proxy<hpx::segmented::detail::vector_value_proxy<T, Data>>
{
using type = T;
};

template <typename T, typename Data>
struct proxy_value<hpx::segmented::detail::vector_value_proxy<T, Data>>
{
using type = T;
};
}} // namespace hpx::traits
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,22 @@
#include <type_traits>

namespace hpx { namespace traits {

template <typename T>
struct is_value_proxy : std::false_type
{
};

template <typename T>
HPX_INLINE_CONSTEXPR_VARIABLE bool is_value_proxy_v =
is_value_proxy<T>::value;

template <typename T>
struct proxy_value
{
using type = T;
};

template <typename T>
using proxy_value_t = typename proxy_value<T>::type;
}} // namespace hpx::traits
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,7 @@ namespace hpx {
#include <hpx/iterator_support/zip_iterator.hpp>

#include <hpx/executors/execution_policy.hpp>
#include <hpx/algorithms/traits/is_value_proxy.hpp>
#include <hpx/parallel/algorithms/detail/adjacent_difference.hpp>
#include <hpx/parallel/algorithms/detail/dispatch.hpp>
#include <hpx/parallel/algorithms/detail/distance.hpp>
Expand Down Expand Up @@ -199,20 +200,25 @@ namespace hpx { namespace parallel { inline namespace v1 {
parallel(ExPolicy&& policy, FwdIter1 first, Sent last,
FwdIter2 dest, Op&& op)
{
typedef hpx::util::zip_iterator<FwdIter1, FwdIter1, FwdIter2>
zip_iterator;
typedef util::detail::algorithm_result<ExPolicy, FwdIter2>
result;
typedef typename std::iterator_traits<FwdIter1>::difference_type
difference_type;
using zip_iterator =
hpx::util::zip_iterator<FwdIter1, FwdIter1, FwdIter2>;
using result =
util::detail::algorithm_result<ExPolicy, FwdIter2>;
using difference_type =
typename std::iterator_traits<FwdIter1>::difference_type;

if (first == last)
{
return result::get(std::move(dest));
}

difference_type count = detail::distance(first, last) - 1;

FwdIter1 prev = first;
*dest++ = *first++;
hpx::traits::proxy_value_t<
typename std::iterator_traits<FwdIter1>::value_type>
tmp = *first++;
*dest++ = std::move(tmp);

if (count == 0)
{
Expand Down Expand Up @@ -255,10 +261,10 @@ namespace hpx { namespace parallel { inline namespace v1 {
HPX_DEPRECATED_V(1, 8,
"hpx::parallel::adjacent_difference is deprecated, use "
"hpx::adjacent_difference instead")
inline typename std::enable_if<hpx::is_execution_policy<ExPolicy>::value,
typename util::detail::algorithm_result<ExPolicy, FwdIter2>::type>::type
adjacent_difference(
ExPolicy&& policy, FwdIter1 first, FwdIter1 last, FwdIter2 dest)
inline std::enable_if_t<hpx::is_execution_policy_v<ExPolicy>,
util::detail::algorithm_result_t<ExPolicy,
FwdIter2>> adjacent_difference(ExPolicy&& policy, FwdIter1 first,
FwdIter1 last, FwdIter2 dest)
{
#if defined(HPX_GCC_VERSION) && HPX_GCC_VERSION >= 100000
#pragma GCC diagnostic push
Expand All @@ -276,10 +282,10 @@ namespace hpx { namespace parallel { inline namespace v1 {
HPX_DEPRECATED_V(1, 8,
"hpx::parallel::adjacent_difference is deprecated, use "
"hpx::adjacent_difference instead")
inline typename std::enable_if<hpx::is_execution_policy<ExPolicy>::value,
typename util::detail::algorithm_result<ExPolicy, FwdIter2>::type>::type
adjacent_difference(ExPolicy&& policy, FwdIter1 first, FwdIter1 last,
FwdIter2 dest, Op&& op)
inline std::enable_if_t<hpx::is_execution_policy_v<ExPolicy>,
util::detail::algorithm_result_t<ExPolicy,
FwdIter2>> adjacent_difference(ExPolicy&& policy, FwdIter1 first,
FwdIter1 last, FwdIter2 dest, Op&& op)
{
return detail::adjacent_difference<FwdIter2>().call(
std::forward<ExPolicy>(policy), first, last, dest,
Expand All @@ -297,13 +303,16 @@ namespace hpx {
private:
template <typename FwdIter1, typename FwdIter2,
HPX_CONCEPT_REQUIRES_(
hpx::traits::is_iterator<FwdIter1>::value
hpx::traits::is_iterator_v<FwdIter1> &&
hpx::traits::is_iterator_v<FwdIter2>
)>
// clang-format on
friend FwdIter2 tag_fallback_invoke(hpx::adjacent_difference_t,
FwdIter1 first, FwdIter1 last, FwdIter2 dest)
{
static_assert((hpx::traits::is_forward_iterator<FwdIter1>::value),
static_assert(hpx::traits::is_forward_iterator_v<FwdIter1>,
"Required at least forward iterator.");
static_assert(hpx::traits::is_forward_iterator_v<FwdIter2>,
"Required at least forward iterator.");

return hpx::parallel::v1::detail::adjacent_difference<FwdIter2>()
Expand All @@ -314,16 +323,19 @@ namespace hpx {
// clang-format off
template <typename ExPolicy, typename FwdIter1, typename FwdIter2,
HPX_CONCEPT_REQUIRES_(
parallel::execution::is_execution_policy<ExPolicy>::value &&
hpx::traits::is_iterator<FwdIter2>::value
hpx::is_execution_policy_v<ExPolicy> &&
hpx::traits::is_iterator_v<FwdIter1> &&
hpx::traits::is_iterator_v<FwdIter2>
)>
// clang-format on
friend typename parallel::util::detail::algorithm_result<ExPolicy,
FwdIter2>::type
friend hpx::parallel::util::detail::algorithm_result_t<ExPolicy,
FwdIter2>
tag_fallback_invoke(hpx::adjacent_difference_t, ExPolicy&& policy,
FwdIter1 first, FwdIter1 last, FwdIter2 dest)
{
static_assert((hpx::traits::is_forward_iterator<FwdIter2>::value),
static_assert(hpx::traits::is_forward_iterator_v<FwdIter1>,
"Required at least forward iterator.");
static_assert(hpx::traits::is_forward_iterator_v<FwdIter2>,
"Required at least forward iterator.");

return hpx::parallel::v1::detail::adjacent_difference<FwdIter2>()
Expand All @@ -334,13 +346,16 @@ namespace hpx {
// clang-format off
template <typename FwdIter1, typename FwdIter2, typename Op,
HPX_CONCEPT_REQUIRES_(
hpx::traits::is_iterator<FwdIter1>::value
hpx::traits::is_iterator_v<FwdIter1> &&
hpx::traits::is_iterator_v<FwdIter2>
)>
// clang-format on
friend FwdIter2 tag_fallback_invoke(hpx::adjacent_difference_t,
FwdIter1 first, FwdIter1 last, FwdIter2 dest, Op&& op)
{
static_assert((hpx::traits::is_forward_iterator<FwdIter1>::value),
static_assert(hpx::traits::is_forward_iterator_v<FwdIter1>,
"Required at least forward iterator.");
static_assert(hpx::traits::is_forward_iterator_v<FwdIter2>,
"Required at least forward iterator.");

return hpx::parallel::v1::detail::adjacent_difference<FwdIter2>()
Expand All @@ -351,16 +366,19 @@ namespace hpx {
// clang-format off
template <typename ExPolicy, typename FwdIter1, typename FwdIter2, typename Op,
HPX_CONCEPT_REQUIRES_(
parallel::execution::is_execution_policy<ExPolicy>::value &&
hpx::traits::is_iterator<FwdIter2>::value
hpx::is_execution_policy_v<ExPolicy> &&
hpx::traits::is_iterator_v<FwdIter1> &&
hpx::traits::is_iterator_v<FwdIter2>
)>
// clang-format on
friend typename parallel::util::detail::algorithm_result<ExPolicy,
FwdIter2>::type
friend hpx::parallel::util::detail::algorithm_result_t<ExPolicy,
FwdIter2>
tag_fallback_invoke(hpx::adjacent_difference_t, ExPolicy&& policy,
FwdIter1 first, FwdIter1 last, FwdIter2 dest, Op&& op)
{
static_assert((hpx::traits::is_forward_iterator<FwdIter2>::value),
static_assert(hpx::traits::is_forward_iterator_v<FwdIter1>,
"Required at least forward iterator.");
static_assert(hpx::traits::is_forward_iterator_v<FwdIter2>,
"Required at least forward iterator.");

return hpx::parallel::v1::detail::adjacent_difference<FwdIter2>()
Expand Down
Loading

0 comments on commit 71d8dbe

Please sign in to comment.