Skip to content

Commit

Permalink
Merge pull request #4884 from STEllAR-GROUP/mismatch_cpos
Browse files Browse the repository at this point in the history
Adapting mismatch to C++20
  • Loading branch information
hkaiser committed Aug 8, 2020
2 parents 60ad7e9 + c80acf6 commit eca2139
Show file tree
Hide file tree
Showing 25 changed files with 2,888 additions and 392 deletions.
1 change: 1 addition & 0 deletions libs/algorithms/CMakeLists.txt
Expand Up @@ -90,6 +90,7 @@ set(algorithms_headers
hpx/parallel/container_algorithms/is_heap.hpp
hpx/parallel/container_algorithms/merge.hpp
hpx/parallel/container_algorithms/minmax.hpp
hpx/parallel/container_algorithms/mismatch.hpp
hpx/parallel/container_algorithms/move.hpp
hpx/parallel/container_algorithms/partition.hpp
hpx/parallel/container_algorithms/reduce.hpp
Expand Down
740 changes: 533 additions & 207 deletions libs/algorithms/include/hpx/parallel/algorithms/mismatch.hpp

Large diffs are not rendered by default.

Expand Up @@ -20,6 +20,7 @@
#include <hpx/parallel/container_algorithms/is_heap.hpp>
#include <hpx/parallel/container_algorithms/merge.hpp>
#include <hpx/parallel/container_algorithms/minmax.hpp>
#include <hpx/parallel/container_algorithms/mismatch.hpp>
#include <hpx/parallel/container_algorithms/move.hpp>
#include <hpx/parallel/container_algorithms/partition.hpp>
#include <hpx/parallel/container_algorithms/reduce.hpp>
Expand Down
Expand Up @@ -215,6 +215,7 @@ namespace hpx { namespace ranges {

#include <hpx/algorithms/traits/projected.hpp>
#include <hpx/algorithms/traits/projected_range.hpp>
#include <hpx/execution/algorithms/detail/predicates.hpp>
#include <hpx/parallel/algorithms/equal.hpp>
#include <hpx/parallel/util/invoke_projected.hpp>
#include <hpx/parallel/util/projection_identity.hpp>
Expand All @@ -224,8 +225,6 @@ namespace hpx { namespace ranges {

namespace hpx { namespace ranges {

using equal_to = hpx::parallel::v1::detail::equal_to;

///////////////////////////////////////////////////////////////////////////
// CPO for hpx::equal
HPX_INLINE_CONSTEXPR_VARIABLE struct equal_t final
Expand Down
405 changes: 405 additions & 0 deletions libs/algorithms/include/hpx/parallel/container_algorithms/mismatch.hpp

Large diffs are not rendered by default.

96 changes: 93 additions & 3 deletions libs/algorithms/include/hpx/parallel/util/compare_projected.hpp
@@ -1,4 +1,4 @@
// Copyright (c) 2016-2017 Hartmut Kaiser
// Copyright (c) 2016-2020 Hartmut Kaiser
// Copyright (c) 2018 Christopher Ogle
//
// SPDX-License-Identifier: BSL-1.0
Expand All @@ -10,13 +10,17 @@
#include <hpx/config.hpp>
#include <hpx/functional/invoke.hpp>

#include <hpx/parallel/util/projection_identity.hpp>

#include <utility>

namespace hpx { namespace parallel { namespace util {

///////////////////////////////////////////////////////////////////////////
template <typename Compare, typename... Proj>
struct compare_projected;

///////////////////////////////////////////////////////////////////////////
template <typename Compare, typename Proj>
struct compare_projected<Compare, Proj>
{
Expand All @@ -28,7 +32,7 @@ namespace hpx { namespace parallel { namespace util {
}

template <typename T1, typename T2>
inline bool operator()(T1&& t1, T2&& t2) const
inline constexpr bool operator()(T1&& t1, T2&& t2) const
{
return hpx::util::invoke(comp_,
hpx::util::invoke(proj_, std::forward<T1>(t1)),
Expand All @@ -39,6 +43,26 @@ namespace hpx { namespace parallel { namespace util {
Proj proj_;
};

template <typename Compare>
struct compare_projected<Compare, util::projection_identity>
{
template <typename Compare_>
compare_projected(Compare_&& comp, util::projection_identity)
: comp_(std::forward<Compare_>(comp))
{
}

template <typename T1, typename T2>
inline constexpr bool operator()(T1&& t1, T2&& t2) const
{
return hpx::util::invoke(
comp_, std::forward<T1>(t1), std::forward<T2>(t2));
}

Compare comp_;
};

///////////////////////////////////////////////////////////////////////////
template <typename Compare, typename Proj1, typename Proj2>
struct compare_projected<Compare, Proj1, Proj2>
{
Expand All @@ -51,7 +75,7 @@ namespace hpx { namespace parallel { namespace util {
}

template <typename T1, typename T2>
inline bool operator()(T1&& t1, T2&& t2) const
inline constexpr bool operator()(T1&& t1, T2&& t2) const
{
return hpx::util::invoke(comp_,
hpx::util::invoke(proj1_, std::forward<T1>(t1)),
Expand All @@ -62,4 +86,70 @@ namespace hpx { namespace parallel { namespace util {
Proj1 proj1_;
Proj2 proj2_;
};

template <typename Compare, typename Proj2>
struct compare_projected<Compare, util::projection_identity, Proj2>
{
template <typename Compare_, typename Proj2_>
compare_projected(
Compare_&& comp, util::projection_identity, Proj2_&& proj2)
: comp_(std::forward<Compare_>(comp))
, proj2_(std::forward<Proj2_>(proj2))
{
}

template <typename T1, typename T2>
inline constexpr bool operator()(T1&& t1, T2&& t2) const
{
return hpx::util::invoke(comp_, std::forward<T1>(t1),
hpx::util::invoke(proj2_, std::forward<T2>(t2)));
}

Compare comp_;
Proj2 proj2_;
};

template <typename Compare, typename Proj1>
struct compare_projected<Compare, Proj1, util::projection_identity>
{
template <typename Compare_, typename Proj1_>
compare_projected(
Compare_&& comp, Proj1_&& proj1, util::projection_identity)
: comp_(std::forward<Compare_>(comp))
, proj1_(std::forward<Proj1_>(proj1))
{
}

template <typename T1, typename T2>
inline constexpr bool operator()(T1&& t1, T2&& t2) const
{
return hpx::util::invoke(comp_,
hpx::util::invoke(proj1_, std::forward<T1>(t1)),
std::forward<T2>(t2));
}

Compare comp_;
Proj1 proj1_;
};

template <typename Compare>
struct compare_projected<Compare, util::projection_identity,
util::projection_identity>
{
template <typename Compare_>
compare_projected(Compare_&& comp, util::projection_identity,
util::projection_identity)
: comp_(std::forward<Compare_>(comp))
{
}

template <typename T1, typename T2>
inline constexpr bool operator()(T1&& t1, T2&& t2) const
{
return hpx::util::invoke(
comp_, std::forward<T1>(t1), std::forward<T2>(t2));
}

Compare comp_;
};
}}} // namespace hpx::parallel::util
@@ -1,4 +1,4 @@
// Copyright (c) 2015-2016 Hartmut Kaiser
// Copyright (c) 2015-2020 Hartmut Kaiser
//
// SPDX-License-Identifier: BSL-1.0
// Distributed under the Boost Software License, Version 1.0. (See accompanying
Expand All @@ -15,7 +15,7 @@ namespace hpx { namespace parallel { namespace util {
struct projection_identity
{
template <typename T>
HPX_HOST_DEVICE HPX_FORCEINLINE T&& operator()(T&& val) const
HPX_HOST_DEVICE HPX_FORCEINLINE constexpr T&& operator()(T&& val) const
{
return std::forward<T>(val);
}
Expand Down
34 changes: 34 additions & 0 deletions libs/algorithms/include/hpx/parallel/util/result_types.hpp
Expand Up @@ -17,6 +17,40 @@

namespace hpx { namespace parallel { namespace util {

///////////////////////////////////////////////////////////////////////////
template <typename I1, typename I2>
struct in_in_result
{
HPX_NO_UNIQUE_ADDRESS I1 in1;
HPX_NO_UNIQUE_ADDRESS I2 in2;

template <typename II1, typename II2,
typename Enable = typename std::enable_if<
std::is_convertible<I1 const&, II1&>::value &&
std::is_convertible<I2 const&, II2&>::value>::type>
constexpr operator in_in_result<II1, II2>() const&
{
return {in1, in2};
}

template <typename II1, typename II2,
typename Enable =
typename std::enable_if<std::is_convertible<I1, II1>::value &&
std::is_convertible<I2, II2>::value>::type>
constexpr operator in_in_result<II1, II2>() &&
{
return {std::move(in1), std::move(in2)};
}

template <typename Archive>
void serialize(Archive& ar, unsigned)
{
// clang-format off
ar & in1 & in2;
// clang-format on
}
};

///////////////////////////////////////////////////////////////////////////
template <typename I, typename O>
struct in_out_result
Expand Down
10 changes: 10 additions & 0 deletions libs/algorithms/tests/performance/benchmark_unique.cpp
Expand Up @@ -64,6 +64,11 @@ struct vector_type
return vec_ == t.vec_;
}

bool operator!=(vector_type const& t) const
{
return vec_ != t.vec_;
}

std::vector<int> vec_;
static const std::size_t vec_size_{30};
};
Expand All @@ -82,6 +87,11 @@ struct array_type
return arr_ == t.arr_;
}

bool operator!=(array_type const& t) const
{
return arr_ != t.arr_;
}

static const std::size_t arr_size_{30};
std::array<int, arr_size_> arr_;
};
Expand Down

0 comments on commit eca2139

Please sign in to comment.