Skip to content

Commit a0145e3

Browse files
sidhikumari5hkaiser
authored andcommitted
Updated async_distributed, collectives, segmented_algorithms to use c++20 concepts
Signed-off-by: Hartmut Kaiser <hartmut.kaiser@gmail.com>
1 parent ec532ac commit a0145e3

20 files changed

Lines changed: 345 additions & 610 deletions

File tree

libs/core/type_support/include/hpx/type_support/relocate_at.hpp

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -89,21 +89,21 @@ namespace hpx::experimental {
8989

9090
// P1144 also proposes a version of relocate that does not call the
9191
// move constructor and instead memmoves the bytes of src to dest.
92-
//
92+
//
9393
// Giving an interface like:
94-
//
94+
//
9595
// T dest = relocate(std::addressof(src));
96-
//
96+
//
9797
// That results in a valid T object (dest) without calling any
9898
// constructor or destructor.
99-
//
99+
//
100100
// This is not possible to do with the current C++ standard.
101-
//
101+
//
102102
// One of the proposed ways to implement this uses a hypothetical
103103
// attribute "do_not_construct" and NRVO.
104-
//
104+
//
105105
// Implementation:
106-
//
106+
//
107107
// template <class T, std::enable_if_t<relocate_using_memmove<T>, int> = 0>
108108
// T relocate(T* source)
109109
// {

libs/full/async_distributed/include/hpx/async_distributed/dataflow.hpp

Lines changed: 5 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright (c) 2007-2022 Hartmut Kaiser
1+
// Copyright (c) 2007-2025 Hartmut Kaiser
22
//
33
// SPDX-License-Identifier: BSL-1.0
44
// Distributed under the Boost Software License, Version 1.0. (See accompanying
@@ -115,12 +115,8 @@ namespace hpx { namespace lcos { namespace detail {
115115
///////////////////////////////////////////////////////////////////////////////
116116
namespace hpx {
117117

118-
// clang-format off
119-
template <typename Action, typename F, typename... Ts,
120-
HPX_CONCEPT_REQUIRES_(
121-
traits::is_action_v<Action> &&
122-
!traits::is_launch_policy_v<F>
123-
)>
118+
template <typename Action, typename F, typename... Ts>
119+
requires(traits::is_action_v<Action> && !traits::is_launch_policy_v<F>)
124120
HPX_DEPRECATED_V(1, 9,
125121
"hpx::dataflow<Action>(...) is deprecated, use hpx::dataflow(Action{}, "
126122
"...) instead")
@@ -132,12 +128,8 @@ namespace hpx {
132128
HPX_FORWARD(Ts, ts)...);
133129
}
134130

135-
// clang-format off
136-
template <typename Action, typename F, typename... Ts,
137-
HPX_CONCEPT_REQUIRES_(
138-
traits::is_action_v<Action> &&
139-
traits::is_launch_policy_v<F>
140-
)>
131+
template <typename Action, typename F, typename... Ts>
132+
requires(traits::is_action_v<Action> && traits::is_launch_policy_v<F>)
141133
HPX_DEPRECATED_V(1, 9,
142134
"hpx::dataflow<Action>(policy, ...) is deprecated, use "
143135
"hpx::dataflow(policy, Action{}, ...) instead")

libs/full/collectives/include/hpx/collectives/exclusive_scan.hpp

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -283,6 +283,7 @@ namespace hpx { namespace collectives {
283283
#include <hpx/modules/futures.hpp>
284284
#include <hpx/modules/type_support.hpp>
285285

286+
#include <concepts>
286287
#include <cstddef>
287288
#include <type_traits>
288289
#include <utility>
@@ -356,7 +357,7 @@ namespace hpx::traits {
356357
std::vector<T_> dest;
357358
dest.resize(data.size());
358359

359-
if constexpr (!std::is_same_v<T_, bool>)
360+
if constexpr (!std::same_as<T_, bool>)
360361
{
361362
collectives::detail::exclusive_scan<T_>(
362363
data.begin(), data.end(), dest.begin(),
@@ -409,7 +410,7 @@ namespace hpx::traits {
409410
std::vector<T_> dest;
410411
dest.resize(data.size());
411412

412-
if constexpr (!std::is_same_v<T_, bool>)
413+
if constexpr (!std::same_as<T_, bool>)
413414
{
414415
hpx::exclusive_scan(data.begin(), data.end(),
415416
dest.begin(), HPX_FORWARD(Init, init),
@@ -557,7 +558,7 @@ namespace hpx::collectives {
557558
////////////////////////////////////////////////////////////////////////////
558559
// Version of exclusive scan that takes an initial value for element 0.
559560
template <typename T, typename Init, typename F>
560-
requires(!std::is_same_v<this_site_arg, std::decay_t<F>>)
561+
requires(!std::same_as<this_site_arg, std::decay_t<F>>)
561562
hpx::future<std::decay_t<T>> exclusive_scan(communicator fid,
562563
T&& local_result, Init&& init, F&& op,
563564
this_site_arg this_site = this_site_arg(),
@@ -621,7 +622,7 @@ namespace hpx::collectives {
621622
}
622623

623624
template <typename T, typename Init, typename F>
624-
requires(!std::is_same_v<generation_arg, std::decay_t<F>>)
625+
requires(!std::same_as<generation_arg, std::decay_t<F>>)
625626
hpx::future<std::decay_t<T>> exclusive_scan(communicator fid,
626627
T&& local_result, Init&& init, F&& op, generation_arg generation,
627628
this_site_arg this_site = this_site_arg())
@@ -631,7 +632,7 @@ namespace hpx::collectives {
631632
}
632633

633634
template <typename T, typename Init, typename F>
634-
requires(!std::is_same_v<num_sites_arg, std::decay_t<F>>)
635+
requires(!std::same_as<num_sites_arg, std::decay_t<F>>)
635636
hpx::future<std::decay_t<T>> exclusive_scan(char const* basename,
636637
T&& local_result, Init&& init, F&& op,
637638
num_sites_arg const num_sites = num_sites_arg(),
@@ -646,7 +647,7 @@ namespace hpx::collectives {
646647
}
647648

648649
template <typename T, typename Init, typename F>
649-
requires(!std::is_same_v<this_site_arg, std::decay_t<F>>)
650+
requires(!std::same_as<this_site_arg, std::decay_t<F>>)
650651
decltype(auto) exclusive_scan(hpx::launch::sync_policy, communicator fid,
651652
T&& local_result, Init&& init, F&& op,
652653
this_site_arg const this_site = this_site_arg(),
@@ -658,7 +659,7 @@ namespace hpx::collectives {
658659
}
659660

660661
template <typename T, typename Init, typename F>
661-
requires(!std::is_same_v<generation_arg, std::decay_t<F>>)
662+
requires(!std::same_as<generation_arg, std::decay_t<F>>)
662663
decltype(auto) exclusive_scan(hpx::launch::sync_policy, communicator fid,
663664
T&& local_result, Init&& init, F&& op, generation_arg const generation,
664665
this_site_arg const this_site = this_site_arg())
@@ -669,7 +670,7 @@ namespace hpx::collectives {
669670
}
670671

671672
template <typename T, typename Init, typename F>
672-
requires(!std::is_same_v<num_sites_arg, std::decay_t<F>>)
673+
requires(!std::same_as<num_sites_arg, std::decay_t<F>>)
673674
decltype(auto) exclusive_scan(hpx::launch::sync_policy,
674675
char const* basename, T&& local_result, Init&& init, F&& op,
675676
num_sites_arg const num_sites = num_sites_arg(),

libs/full/collectives/include/hpx/collectives/spmd_block.hpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -336,8 +336,8 @@ namespace hpx { namespace lcos {
336336
};
337337
} // namespace detail
338338

339-
template <typename F, typename... Args,
340-
HPX_CONCEPT_REQUIRES_(hpx::traits::is_action<F>::value)>
339+
template <typename F, typename... Args>
340+
requires(hpx::traits::is_action_v<F>)
341341
hpx::future<void> define_spmd_block(std::string&& name,
342342
std::size_t images_per_locality, F&& /* f */, Args&&... args)
343343
{
@@ -370,4 +370,5 @@ namespace hpx { namespace lcos {
370370
HPX_FORWARD(Args, args)...);
371371
}
372372
}} // namespace hpx::lcos
373+
373374
#endif

libs/full/segmented_algorithms/include/hpx/parallel/segmented_algorithms/adjacent_difference.hpp

Lines changed: 7 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// Copyright (c) 2017 Ajai V George
22
// Copyright (c) 2021 Karame M.Shokooh
3-
// Copyright (c) 2024 Hartmut Kaiser
3+
// Copyright (c) 2024-2025 Hartmut Kaiser
44
//
55
// SPDX-License-Identifier: BSL-1.0
66
// Distributed under the Boost Software License, Version 1.0. (See accompanying
@@ -246,17 +246,13 @@ namespace hpx::parallel {
246246
// The segmented iterators we support all live in namespace hpx::segmented
247247
namespace hpx::segmented {
248248

249-
// clang-format off
250249
template <typename ExPolicy, typename FwdIter1, typename FwdIter2,
251-
typename Op,
252-
HPX_CONCEPT_REQUIRES_(
253-
hpx::is_execution_policy_v<ExPolicy> &&
250+
typename Op>
251+
requires(hpx::is_execution_policy_v<ExPolicy> &&
254252
hpx::traits::is_iterator_v<FwdIter1> &&
255253
hpx::traits::is_segmented_iterator_v<FwdIter1> &&
256254
hpx::traits::is_iterator_v<FwdIter2> &&
257-
hpx::traits::is_segmented_iterator_v<FwdIter2>
258-
)>
259-
// clang-format on
255+
hpx::traits::is_segmented_iterator_v<FwdIter2>)
260256
hpx::parallel::util::detail::algorithm_result_t<ExPolicy, FwdIter2>
261257
tag_invoke(hpx::adjacent_difference_t, ExPolicy&& policy, FwdIter1 first,
262258
FwdIter1 last, FwdIter2 dest, Op&& op)
@@ -284,15 +280,11 @@ namespace hpx::segmented {
284280
HPX_FORWARD(Op, op), is_seq());
285281
}
286282

287-
// clang-format off
288-
template <typename InIter1, typename InIter2, typename Op,
289-
HPX_CONCEPT_REQUIRES_(
290-
hpx::traits::is_iterator_v<InIter1> &&
283+
template <typename InIter1, typename InIter2, typename Op>
284+
requires(hpx::traits::is_iterator_v<InIter1> &&
291285
hpx::traits::is_segmented_iterator_v<InIter1> &&
292286
hpx::traits::is_iterator_v<InIter2> &&
293-
hpx::traits::is_segmented_iterator_v<InIter2>
294-
)>
295-
// clang-format on
287+
hpx::traits::is_segmented_iterator_v<InIter2>)
296288
InIter2 tag_invoke(hpx::adjacent_difference_t, InIter1 first, InIter1 last,
297289
InIter2 dest, Op&& op)
298290
{

libs/full/segmented_algorithms/include/hpx/parallel/segmented_algorithms/adjacent_find.hpp

Lines changed: 10 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
// Copyright (c) 2017 Ajai V George
2+
// Copyright (c) 2025 Hartmut Kaiser
23
//
34
// SPDX-License-Identifier: BSL-1.0
45
// Distributed under the Boost Software License, Version 1.0. (See accompanying
@@ -274,18 +275,13 @@ namespace hpx::parallel {
274275
// The segmented iterators we support all live in namespace hpx::segmented
275276
namespace hpx::segmented {
276277

277-
// clang-format off
278-
template<typename InIter,
279-
typename Pred,
280-
HPX_CONCEPT_REQUIRES_(
281-
hpx::traits::is_iterator<InIter>::value &&
282-
hpx::traits::is_segmented_iterator<InIter>::value
283-
)>
284-
// clang-format on
278+
template <typename InIter, typename Pred>
279+
requires(hpx::traits::is_iterator_v<InIter> &&
280+
hpx::traits::is_segmented_iterator_v<InIter>)
285281
InIter tag_invoke(
286282
hpx::adjacent_find_t, InIter first, InIter last, Pred&& pred = Pred())
287283
{
288-
static_assert((hpx::traits::is_input_iterator<InIter>::value),
284+
static_assert((hpx::traits::is_input_iterator_v<InIter>),
289285
"Requires at least input iterator.");
290286

291287
if (first == last)
@@ -303,21 +299,15 @@ namespace hpx::segmented {
303299
hpx::identity_v, std::true_type());
304300
}
305301

306-
// clang-format off
307-
template<typename ExPolicy, typename SegIter,
308-
typename Pred,
309-
HPX_CONCEPT_REQUIRES_(
310-
hpx::is_execution_policy_v<ExPolicy> &&
302+
template <typename ExPolicy, typename SegIter, typename Pred>
303+
requires(hpx::is_execution_policy_v<ExPolicy> &&
311304
hpx::traits::is_iterator_v<SegIter> &&
312-
hpx::traits::is_segmented_iterator_v<SegIter>
313-
)>
314-
// clang-format on
315-
typename hpx::parallel::util::detail::algorithm_result<ExPolicy,
316-
SegIter>::type
305+
hpx::traits::is_segmented_iterator_v<SegIter>)
306+
hpx::parallel::util::detail::algorithm_result_t<ExPolicy, SegIter>
317307
tag_invoke(hpx::adjacent_find_t, ExPolicy&& policy, SegIter first,
318308
SegIter last, Pred&& pred)
319309
{
320-
static_assert((hpx::traits::is_forward_iterator<SegIter>::value),
310+
static_assert((hpx::traits::is_forward_iterator_v<SegIter>),
321311
"Requires at least forward iterator.");
322312

323313
using is_seq = hpx::is_sequenced_execution_policy<ExPolicy>;

0 commit comments

Comments
 (0)