Skip to content

Commit

Permalink
Adapt is_partitioned to C++20
Browse files Browse the repository at this point in the history
  • Loading branch information
msimberg committed Oct 15, 2020
1 parent 39ad34e commit 1798a76
Show file tree
Hide file tree
Showing 12 changed files with 1,878 additions and 102 deletions.
3 changes: 2 additions & 1 deletion docs/sphinx/api/public_api.rst
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ Functions
- :cpp:func:`hpx::inplace_merge`
- :cpp:func:`hpx::is_heap`
- :cpp:func:`hpx::is_heap_until`
- :cpp:func:`hpx::parallel::v1::is_partitioned`
- :cpp:func:`hpx::is_partitioned`
- :cpp:func:`hpx::parallel::v1::is_sorted`
- :cpp:func:`hpx::parallel::v1::is_sorted_until`
- :cpp:func:`hpx::parallel::v1::lexicographical_compare`
Expand Down Expand Up @@ -121,6 +121,7 @@ Functions
- :cpp:func:`hpx::ranges::inplace_merge`
- :cpp:func:`hpx::ranges::is_heap`
- :cpp:func:`hpx::ranges::is_heap_until`
- :cpp:func:`hpx::ranges::is_partitioned`
- :cpp:func:`hpx::ranges::make_heap`
- :cpp:func:`hpx::ranges::merge`
- :cpp:func:`hpx::ranges::move`
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -610,7 +610,7 @@ Parallel algorithms
* Description
* In header
* Algorithm page at cppreference.com
* * :cpp:func:`hpx::parallel::v1::is_partitioned`
* * :cpp:func:`hpx::is_partitioned`
* Returns ``true`` if each true element for a predicate precedes the false elements in a range.
* ``<hpx/algorithm.hpp>``
* :cppreference-algorithm:`is_partitioned`
Expand Down
1 change: 0 additions & 1 deletion libs/full/include/include/hpx/algorithm.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@

namespace hpx {
using hpx::parallel::adjacent_find;
using hpx::parallel::is_partitioned;
using hpx::parallel::is_sorted;
using hpx::parallel::is_sorted_until;
using hpx::parallel::lexicographical_compare;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,4 @@
#pragma once

#include <hpx/parallel/algorithms/is_partitioned.hpp>
#include <hpx/parallel/container_algorithms/is_partitioned.hpp>
1 change: 1 addition & 0 deletions libs/parallelism/algorithms/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ set(algorithms_headers
hpx/parallel/container_algorithms.hpp
hpx/parallel/container_algorithms/includes.hpp
hpx/parallel/container_algorithms/is_heap.hpp
hpx/parallel/container_algorithms/is_partitioned.hpp
hpx/parallel/container_algorithms/make_heap.hpp
hpx/parallel/container_algorithms/merge.hpp
hpx/parallel/container_algorithms/minmax.hpp
Expand Down

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
#include <hpx/parallel/container_algorithms/generate.hpp>
#include <hpx/parallel/container_algorithms/includes.hpp>
#include <hpx/parallel/container_algorithms/is_heap.hpp>
#include <hpx/parallel/container_algorithms/is_partitioned.hpp>
#include <hpx/parallel/container_algorithms/make_heap.hpp>
#include <hpx/parallel/container_algorithms/merge.hpp>
#include <hpx/parallel/container_algorithms/minmax.hpp>
Expand Down

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ void test_partitioned1(ExPolicy policy, IteratorTag)
std::fill(std::begin(c), std::begin(c) + c.size() / 2, 2 * (dis(gen)));
std::fill(std::begin(c) + c.size() / 2, std::end(c), 2 * (dis(gen)) + 1);

bool parted = hpx::parallel::is_partitioned(policy, iterator(std::begin(c)),
bool parted = hpx::is_partitioned(policy, iterator(std::begin(c)),
iterator(std::end(c)), [](std::size_t n) { return n % 2 == 0; });

HPX_TEST(parted);
Expand All @@ -56,9 +56,8 @@ void test_partitioned1_async(ExPolicy p, IteratorTag)
std::fill(std::begin(c), std::begin(c) + c.size() / 2, 2 * (dis(gen)));
std::fill(std::begin(c) + c.size() / 2, std::end(c), 2 * (dis(gen)) + 1);

hpx::future<bool> f =
hpx::parallel::is_partitioned(p, iterator(std::begin(c)),
iterator(std::end(c)), [](std::size_t n) { return n % 2 == 0; });
hpx::future<bool> f = hpx::is_partitioned(p, iterator(std::begin(c)),
iterator(std::end(c)), [](std::size_t n) { return n % 2 == 0; });
f.wait();

HPX_TEST(f.get());
Expand Down Expand Up @@ -97,14 +96,12 @@ void test_partitioned2(ExPolicy policy, IteratorTag)
std::fill(std::begin(c_odd), std::end(c_odd), 2 * (dis(gen)) + 1);
std::vector<std::size_t> c_even(10007);
//fill all of array with evens
std::fill(std::begin(c_odd), std::end(c_odd), 2 * (dis(gen)));
std::fill(std::begin(c_even), std::end(c_even), 2 * (dis(gen)));

bool parted_odd = hpx::parallel::is_partitioned(policy,
iterator(std::begin(c_odd)), iterator(std::end(c_odd)),
[](std::size_t n) { return n % 2 == 0; });
bool parted_even = hpx::parallel::is_partitioned(policy,
iterator(std::begin(c_even)), iterator(std::end(c_even)),
[](std::size_t n) { return n % 2 == 0; });
bool parted_odd = hpx::is_partitioned(policy, iterator(std::begin(c_odd)),
iterator(std::end(c_odd)), [](std::size_t n) { return n % 2 == 0; });
bool parted_even = hpx::is_partitioned(policy, iterator(std::begin(c_even)),
iterator(std::end(c_even)), [](std::size_t n) { return n % 2 == 0; });

HPX_TEST(parted_odd);
HPX_TEST(parted_even);
Expand All @@ -121,12 +118,12 @@ void test_partitioned2_async(ExPolicy p, IteratorTag)
std::fill(std::begin(c_odd), std::end(c_odd), 2 * (dis(gen)) + 1);
std::vector<std::size_t> c_even(10007);
//fill all of array with evens
std::fill(std::begin(c_odd), std::end(c_odd), 2 * (dis(gen)));
std::fill(std::begin(c_even), std::end(c_even), 2 * (dis(gen)));

hpx::future<bool> f_odd = hpx::parallel::is_partitioned(p,
hpx::future<bool> f_odd = hpx::is_partitioned(p,
iterator(std::begin(c_odd)), iterator(std::end(c_odd)),
[](std::size_t n) { return n % 2 == 0; });
hpx::future<bool> f_even = hpx::parallel::is_partitioned(p,
hpx::future<bool> f_even = hpx::is_partitioned(p,
iterator(std::begin(c_even)), iterator(std::end(c_even)),
[](std::size_t n) { return n % 2 == 0; });

Expand Down Expand Up @@ -177,12 +174,10 @@ void test_partitioned3(ExPolicy policy, IteratorTag)
//add even number to end
c_end[c_end.size() - 1] -= 1;

bool parted1 = hpx::parallel::is_partitioned(policy,
iterator(std::begin(c_beg)), iterator(std::end(c_beg)),
[](std::size_t n) { return n % 2 == 0; });
bool parted2 = hpx::parallel::is_partitioned(policy,
iterator(std::begin(c_end)), iterator(std::end(c_end)),
[](std::size_t n) { return n % 2 == 0; });
bool parted1 = hpx::is_partitioned(policy, iterator(std::begin(c_beg)),
iterator(std::end(c_beg)), [](std::size_t n) { return n % 2 == 0; });
bool parted2 = hpx::is_partitioned(policy, iterator(std::begin(c_end)),
iterator(std::end(c_end)), [](std::size_t n) { return n % 2 == 0; });

HPX_TEST(!parted1);
HPX_TEST(!parted2);
Expand Down Expand Up @@ -213,10 +208,10 @@ void test_partitioned3_async(ExPolicy p, IteratorTag)
//add even number to end
c_end[c_end.size() - 1] -= 1;

hpx::future<bool> f_beg = hpx::parallel::is_partitioned(p,
hpx::future<bool> f_beg = hpx::is_partitioned(p,
iterator(std::begin(c_beg)), iterator(std::end(c_beg)),
[](std::size_t n) { return n % 2 == 0; });
hpx::future<bool> f_end = hpx::parallel::is_partitioned(p,
hpx::future<bool> f_end = hpx::is_partitioned(p,
iterator(std::begin(c_end)), iterator(std::end(c_end)),
[](std::size_t n) { return n % 2 == 0; });

Expand Down Expand Up @@ -264,7 +259,7 @@ void test_partitioned_exception(ExPolicy policy, IteratorTag)
bool caught_exception = false;
try
{
hpx::parallel::is_partitioned(policy,
hpx::is_partitioned(policy,
decorated_iterator(
std::begin(c), []() { throw std::runtime_error("test"); }),
decorated_iterator(
Expand Down Expand Up @@ -300,7 +295,7 @@ void test_partitioned_async_exception(ExPolicy p, IteratorTag)
bool caught_exception = false;
try
{
hpx::future<bool> f = hpx::parallel::is_partitioned(p,
hpx::future<bool> f = hpx::is_partitioned(p,
decorated_iterator(
std::begin(c), []() { throw std::runtime_error("test"); }),
decorated_iterator(
Expand Down Expand Up @@ -363,7 +358,7 @@ void test_partitioned_bad_alloc(ExPolicy policy, IteratorTag)
bool caught_bad_alloc = false;
try
{
hpx::parallel::is_partitioned(policy,
hpx::is_partitioned(policy,
decorated_iterator(std::begin(c), []() { throw std::bad_alloc(); }),
decorated_iterator(std::end(c), []() { throw std::bad_alloc(); }),
[](std::size_t n) { return n % 2 == 0; });
Expand Down Expand Up @@ -397,7 +392,7 @@ void test_partitioned_async_bad_alloc(ExPolicy p, IteratorTag)
bool caught_bad_alloc = false;
try
{
hpx::future<bool> f = hpx::parallel::is_partitioned(p,
hpx::future<bool> f = hpx::is_partitioned(p,
decorated_iterator(std::begin(c), []() { throw std::bad_alloc(); }),
decorated_iterator(std::end(c), []() { throw std::bad_alloc(); }),
[](std::size_t n) { return n % 2 == 0; });
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@ set(tests
inplace_merge_range
is_heap_range
is_heap_until_range
is_partitioned_range
is_partitioned_projection_range
make_heap_range
max_element_range
merge_range
Expand Down
Loading

0 comments on commit 1798a76

Please sign in to comment.