-
-
Save hkaiser/26bced03497017f481dbb9ee7d0df67c to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
diff --git a/libs/core/algorithms/include/hpx/parallel/algorithms/contains.hpp b/libs/core/algorithms/include/hpx/parallel/algorithms/contains.hpp | |
index fe6d6ba..8198096 100644 | |
--- a/libs/core/algorithms/include/hpx/parallel/algorithms/contains.hpp | |
+++ b/libs/core/algorithms/include/hpx/parallel/algorithms/contains.hpp | |
@@ -1,20 +1,20 @@ | |
#pragma once | |
#include <hpx/config.hpp> | |
+#include <hpx/coroutines/thread_enums.hpp> | |
#include <hpx/execution/algorithms/detail/predicates.hpp> | |
#include <hpx/executors/execution_policy.hpp> | |
#include <hpx/iterator_support/traits/is_iterator.hpp> | |
+#include <hpx/parallel/algorithms/detail/contains.hpp> | |
#include <hpx/parallel/algorithms/detail/dispatch.hpp> | |
#include <hpx/parallel/algorithms/detail/distance.hpp> | |
+#include <hpx/parallel/util/adapt_placement_mode.hpp> | |
+#include <hpx/parallel/util/cancellation_token.hpp> | |
#include <hpx/parallel/util/detail/algorithm_result.hpp> | |
#include <hpx/parallel/util/loop.hpp> | |
-#include <hpx/type_support/identity.hpp> | |
-#include <hpx/parallel/util/cancellation_token.hpp> | |
#include <hpx/parallel/util/partitioner.hpp> | |
#include <hpx/parallel/util/zip_iterator.hpp> | |
-#include <hpx/coroutines/thread_enums.hpp> | |
-#include <hpx/parallel/util/adapt_placement_mode.hpp> | |
-#include <hpx/parallel/algorithms/detail/contains.hpp> | |
+#include <hpx/type_support/identity.hpp> | |
#include <algorithm> | |
#include <cstddef> | |
@@ -22,78 +22,68 @@ | |
#include <type_traits> | |
#include <utility> | |
-namespace hpx::parallel { | |
- namespace detail { | |
- struct contains : public algorithm<contains, bool> | |
+namespace hpx::parallel { namespace detail { | |
+ struct contains : public algorithm<contains, bool> | |
+ { | |
+ constexpr contains() noexcept | |
+ : algorithm("contains") | |
{ | |
- constexpr contains() noexcept | |
- : algorithm("contains") | |
- { | |
- | |
- } | |
- | |
- template <typename ExPolicy, typename Iterator, typename Sentinel, | |
- typename T, typename Proj> | |
- static constexpr bool sequential(ExPolicy, Iterator first, | |
- Sentinel last, const T& val, Proj&& proj) | |
- { | |
- return sequential_contains<std::decay<ExPolicy>>(first, last, | |
- val, HPX_FORWARD(Proj, proj)); | |
- } | |
- | |
- template <typename ExPolicy, typename Iterator, typename Sentinel, | |
- typename T, typename Proj> | |
- static util::detail::algorithm_result_t<ExPolicy, bool> parallel( | |
- ExPolicy&& orgpolicy, Iterator first, Sentinel last, const T& val, | |
- Proj&& proj) | |
- { | |
- const std::size_t count = detail::distance(first, last); | |
- if (count <= 0) | |
- return util::detail::algorithm_result<ExPolicy, bool>::get( | |
- false); | |
- | |
- decltype(auto) policy = parallel::util::adapt_placement_mode( | |
- HPX_FORWARD(ExPolicy, orgpolicy), | |
- hpx::threads::thread_placement_hint::breadth_first); | |
- | |
- using policy_type = std::decay_t<decltype(policy)>; | |
- util::cancellation_token<> tok; | |
- auto f1 = [val, tok, proj] | |
- (Iterator first, std::size_t count) | |
- { | |
- sequential_contains<policy_type>(first, val, count, tok, proj); | |
- return tok.was_cancelled(); | |
- }; | |
- | |
- auto f2 = [](auto&& results) | |
- { | |
- return std::any_of(hpx::util::begin(results), | |
- hpx::util::end(results), | |
- [](hpx::future<bool>& val) { return val.get();}); | |
- }; | |
- | |
- return util::partitioner<policy_type, bool>::call( | |
- HPX_FORWARD(decltype(policy), policy), first, count, | |
- HPX_MOVE(f1), HPX_MOVE(f2) | |
- ); | |
- } | |
- }; | |
- } | |
-} | |
+ } | |
+ | |
+ template <typename ExPolicy, typename Iterator, typename Sentinel, | |
+ typename T, typename Proj> | |
+ static constexpr bool sequential( | |
+ ExPolicy, Iterator first, Sentinel last, const T& val, Proj&& proj) | |
+ { | |
+ return sequential_contains<std::decay<ExPolicy>>( | |
+ first, last, val, HPX_FORWARD(Proj, proj)); | |
+ } | |
+ | |
+ template <typename ExPolicy, typename Iterator, typename Sentinel, | |
+ typename T, typename Proj> | |
+ static util::detail::algorithm_result_t<ExPolicy, bool> parallel( | |
+ ExPolicy&& orgpolicy, Iterator first, Sentinel last, const T& val, | |
+ Proj&& proj) | |
+ { | |
+ const std::size_t count = detail::distance(first, last); | |
+ if (count <= 0) | |
+ return util::detail::algorithm_result<ExPolicy, bool>::get( | |
+ false); | |
+ | |
+ decltype(auto) policy = parallel::util::adapt_placement_mode( | |
+ HPX_FORWARD(ExPolicy, orgpolicy), | |
+ hpx::threads::thread_placement_hint::breadth_first); | |
+ | |
+ using policy_type = std::decay_t<decltype(policy)>; | |
+ util::cancellation_token<> tok; | |
+ auto f1 = [val, tok, proj](Iterator first, std::size_t count) { | |
+ sequential_contains<policy_type>(first, val, count, tok, proj); | |
+ return tok.was_cancelled(); | |
+ }; | |
+ | |
+ auto f2 = [](auto&& results) { | |
+ return std::any_of(hpx::util::begin(results), | |
+ hpx::util::end(results), | |
+ [](hpx::future<bool>& val) { return val.get(); }); | |
+ }; | |
+ | |
+ return util::partitioner<policy_type, bool>::call( | |
+ HPX_FORWARD(decltype(policy), policy), first, count, | |
+ HPX_MOVE(f1), HPX_MOVE(f2)); | |
+ } | |
+ }; | |
+}} // namespace hpx::parallel::detail | |
namespace hpx { | |
inline constexpr struct contains_t final | |
: hpx::functional::detail::tag_fallback<contains_t> | |
{ | |
private: | |
- template <typename Iterator, typename Sentinel, | |
- typename T, typename Proj = hpx::identity, | |
- HPX_CONCEPT_REQUIRES_( | |
- hpx::traits::is_iterator_v<Iterator> && | |
- hpx::traits::is_iterator_v<Iterator> && | |
- hpx::is_invocable_v<Proj, | |
- typename std::iterator_traits<Iterator>::value_type> | |
- )> | |
+ template <typename Iterator, typename Sentinel, typename T, | |
+ typename Proj = hpx::identity, | |
+ HPX_CONCEPT_REQUIRES_(hpx::traits::is_iterator_v<Iterator>&& hpx:: | |
+ traits::is_iterator_v<Iterator>&& hpx::is_invocable_v<Proj, | |
+ typename std::iterator_traits<Iterator>::value_type>)> | |
friend bool tag_fallback_invoke(hpx::contains_t, Iterator first, | |
Sentinel last, const T& val, Proj&& proj = Proj()) | |
@@ -104,17 +94,16 @@ namespace hpx { | |
static_assert(hpx::traits::is_input_iterator_v<Sentinel>, | |
"Required at least input iterator."); | |
- return hpx::parallel::detail::contains().call(hpx::execution::seq, | |
- first, last, val, proj); | |
+ return hpx::parallel::detail::contains().call( | |
+ hpx::execution::seq, first, last, val, proj); | |
} | |
template <typename ExPolicy, typename Iterator, typename Sentinel, | |
- typename T, typename Proj = hpx::identity, HPX_CONCEPT_REQUIRES_( | |
- hpx::is_execution_policy_v<ExPolicy> && | |
- hpx::traits::is_iterator_v<Iterator> && | |
- hpx::traits::is_iterator_v<Iterator> && | |
- hpx::is_invocable_v<Proj, | |
- typename std::iterator_traits<Iterator>::value_type>)> | |
+ typename T, typename Proj = hpx::identity, | |
+ HPX_CONCEPT_REQUIRES_(hpx::is_execution_policy_v< | |
+ ExPolicy>&& hpx::traits::is_iterator_v<Iterator>&& hpx::traits:: | |
+ is_iterator_v<Iterator>&& hpx::is_invocable_v<Proj, | |
+ typename std::iterator_traits<Iterator>::value_type>)> | |
friend typename parallel::util::detail::algorithm_result<ExPolicy, | |
bool>::type | |
@@ -133,4 +122,4 @@ namespace hpx { | |
} | |
} contains{}; | |
-} | |
\ No newline at end of file | |
+} // namespace hpx | |
\ No newline at end of file | |
diff --git a/libs/core/algorithms/include/hpx/parallel/algorithms/detail/contains.hpp b/libs/core/algorithms/include/hpx/parallel/algorithms/detail/contains.hpp | |
index 411d302..eed49d5 100644 | |
--- a/libs/core/algorithms/include/hpx/parallel/algorithms/detail/contains.hpp | |
+++ b/libs/core/algorithms/include/hpx/parallel/algorithms/detail/contains.hpp | |
@@ -10,15 +10,15 @@ | |
#include <type_traits> | |
#include <utility> | |
- | |
namespace hpx::parallel::detail { | |
template <typename ExPolicy> | |
struct sequential_contains_t final | |
- : hpx::functional::detail::tag_fallback<sequential_contains_t<ExPolicy>> | |
+ : hpx::functional::detail::tag_fallback<sequential_contains_t<ExPolicy>> | |
{ | |
private: | |
- template <typename Iterator, typename Sentinel, typename T, typename Proj> | |
+ template <typename Iterator, typename Sentinel, typename T, | |
+ typename Proj> | |
friend constexpr bool tag_fallback_invoke(sequential_contains_t, | |
Iterator first, Sentinel last, const T& val, Proj&& proj) | |
{ | |
@@ -26,21 +26,22 @@ namespace hpx::parallel::detail { | |
if (distance <= 0) | |
return false; | |
- const auto itr = util::loop_pred< | |
- std::decay_t<hpx::execution::sequenced_policy>>(first, last, | |
- [&val, &proj] (const auto& cur) | |
- { return HPX_INVOKE(proj, *cur) == val; }); | |
+ const auto itr = | |
+ util::loop_pred<std::decay_t<hpx::execution::sequenced_policy>>( | |
+ first, last, [&val, &proj](const auto& cur) { | |
+ return HPX_INVOKE(proj, *cur) == val; | |
+ }); | |
return itr != last; | |
} | |
template <typename Iterator, typename T, typename Token, typename Proj> | |
friend constexpr void tag_fallback_invoke(sequential_contains_t, | |
- Iterator first, T const& val, std::size_t count, Token& tok, Proj&& proj) | |
+ Iterator first, T const& val, std::size_t count, Token& tok, | |
+ Proj&& proj) | |
{ | |
- util::loop_n<ExPolicy>(first, count, tok, | |
- [&val, &tok, &proj] (const auto& cur) | |
- { | |
+ util::loop_n<ExPolicy>( | |
+ first, count, tok, [&val, &tok, &proj](const auto& cur) { | |
if (HPX_INVOKE(proj, *cur) == val) | |
{ | |
tok.cancel(); | |
@@ -48,10 +49,8 @@ namespace hpx::parallel::detail { | |
} | |
}); | |
} | |
- | |
- | |
}; | |
template <typename ExPolicy> | |
inline constexpr sequential_contains_t<ExPolicy> sequential_contains = | |
sequential_contains_t<ExPolicy>{}; | |
-} //namespace hpx::parallel::detail | |
\ No newline at end of file | |
+} //namespace hpx::parallel::detail | |
\ No newline at end of file |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment