-
-
Notifications
You must be signed in to change notification settings - Fork 428
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add stable_partition sequential implementation and add advance_and_ge…
…t_distance
- Loading branch information
Showing
7 changed files
with
225 additions
and
136 deletions.
There are no files selected for viewing
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
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
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
53 changes: 53 additions & 0 deletions
53
...arallelism/algorithms/include/hpx/parallel/algorithms/detail/advance_and_get_distance.hpp
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
// Copyright (c) 2019 Hartmut Kaiser | ||
// Copyright (c) 2021 Akhil J Nair | ||
// | ||
// SPDX-License-Identifier: BSL-1.0 | ||
// Distributed under the Boost Software License, Version 1.0. (See accompanying | ||
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) | ||
|
||
#pragma once | ||
|
||
#include <hpx/config.hpp> | ||
#include <hpx/iterator_support/traits/is_iterator.hpp> | ||
#include <hpx/iterator_support/traits/is_sentinel_for.hpp> | ||
|
||
#include <iterator> | ||
#include <type_traits> | ||
|
||
namespace hpx { namespace parallel { inline namespace v1 { namespace detail { | ||
// helper facility to both advance the iterator to the sentinel and return the | ||
// distance | ||
template <typename Iter, typename Sent> | ||
constexpr inline typename std::iterator_traits<Iter>::difference_type | ||
advance_and_get_distance(Iter& first, Sent last) | ||
{ | ||
using difference_type = | ||
typename std::iterator_traits<Iter>::difference_type; | ||
|
||
// we add this since passing in random access iterators | ||
// as begin and end might not pass the sized sentinel check | ||
if constexpr (std::is_same_v<Iter, Sent> && | ||
hpx::traits::is_random_access_iterator_v<Iter>) | ||
{ | ||
difference_type offset = last - first; | ||
first = last; | ||
return offset; | ||
} | ||
|
||
if constexpr (hpx::traits::is_sized_sentinel_for_v<Sent, Iter>) | ||
{ | ||
difference_type offset = last - first; | ||
std::advance(first, offset); | ||
return offset; | ||
} | ||
else | ||
{ | ||
difference_type offset = 0; | ||
for (/**/; first != last; ++first) | ||
{ | ||
++offset; | ||
} | ||
return offset; | ||
} | ||
} | ||
}}}} // namespace hpx::parallel::v1::detail |
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
Oops, something went wrong.