[libcxx-commits] [pstl] [ptsl] passed iterators directly to invoke_on_all_policies to avoid u… (PR #85679)
via libcxx-commits
libcxx-commits at lists.llvm.org
Mon Mar 18 11:35:14 PDT 2024
https://github.com/matrixication created https://github.com/llvm/llvm-project/pull/85679
…nnecessary copies.
>From 538172e305df9ab872cbe3adf482a3899c8e9e24 Mon Sep 17 00:00:00 2001
From: Matrix <163585062+matrixication at users.noreply.github.com>
Date: Mon, 18 Mar 2024 18:31:25 +0000
Subject: [PATCH] [ptsl] passed iterators directly to invoke_on_all_policies to
avoid unnecessary copies.
---
.../algorithms/alg.sorting/is_sorted.pass.cpp | 70 +++++++++----------
1 file changed, 32 insertions(+), 38 deletions(-)
diff --git a/pstl/test/std/algorithms/alg.sorting/is_sorted.pass.cpp b/pstl/test/std/algorithms/alg.sorting/is_sorted.pass.cpp
index d4c6fe291ed849..e1ef61dafc893d 100644
--- a/pstl/test/std/algorithms/alg.sorting/is_sorted.pass.cpp
+++ b/pstl/test/std/algorithms/alg.sorting/is_sorted.pass.cpp
@@ -21,79 +21,73 @@ using namespace TestUtils;
struct test_is_sorted
{
template <typename Policy, typename Iterator>
- void
- operator()(Policy&& exec, Iterator first, Iterator last, bool exam)
+ void operator()(Policy&& exec, Iterator first, Iterator last, bool exam)
{
using namespace std;
typedef typename std::iterator_traits<Iterator>::value_type T;
- //try random-access iterator
+ // try random-access iterator
bool res = is_sorted(exec, first, last);
EXPECT_TRUE(exam == res, "is_sorted wrong result for random-access iterator");
+
auto iexam = is_sorted_until(first, last);
auto ires = is_sorted_until(exec, first, last);
EXPECT_TRUE(iexam == ires, "is_sorted_until wrong result for random-access iterator");
- //try random-access iterator with a predicate
- res = is_sorted(exec, first, last, std::less<T>());
+ // try random-access iterator with a predicate
+ res = is_sorted(exec, first, last, std::less<>());
EXPECT_TRUE(exam == res, "is_sorted wrong result for random-access iterator");
- iexam = is_sorted_until(first, last, std::less<T>());
- ires = is_sorted_until(exec, first, last, std::less<T>());
+
+ iexam = is_sorted_until(first, last, std::less<>());
+ ires = is_sorted_until(exec, first, last, std::less<>());
EXPECT_TRUE(iexam == ires, "is_sorted_until wrong result for random-access iterator");
}
};
template <typename T>
-void
-test_is_sorted_by_type()
+void test_is_sorted_by_type()
{
-
- Sequence<T> in(99999, [](size_t v) -> T { return T(v); }); //fill 0..n
-
- invoke_on_all_policies(test_is_sorted(), in.begin(), in.end(), std::is_sorted(in.begin(), in.end()));
- invoke_on_all_policies(test_is_sorted(), in.cbegin(), in.cend(), std::is_sorted(in.begin(), in.end()));
+ Sequence<T> in(99999, [](size_t v) -> T { return T(v); });
+ // fill 0..n
+ invoke_on_all_policies(test_is_sorted<T>(), in.begin(), in.end(), std::is_sorted(in.begin(), in.end()));
+ invoke_on_all_policies(test_is_sorted<T>(), in.cbegin(), in.cend(), std::is_sorted(in.begin(), in.end()));
in[in.size() / 2] = -1;
- invoke_on_all_policies(test_is_sorted(), in.begin(), in.end(), std::is_sorted(in.begin(), in.end()));
- invoke_on_all_policies(test_is_sorted(), in.cbegin(), in.cend(), std::is_sorted(in.begin(), in.end()));
+ invoke_on_all_policies(test_is_sorted<T>(), in.begin(), in.end(), std::is_sorted(in.begin(), in.end()));
+ invoke_on_all_policies(test_is_sorted<T>(), in.cbegin(), in.cend(), std::is_sorted(in.begin(), in.end()));
in[1] = -1;
- invoke_on_all_policies(test_is_sorted(), in.begin(), in.end(), std::is_sorted(in.begin(), in.end()));
- invoke_on_all_policies(test_is_sorted(), in.cbegin(), in.cend(), std::is_sorted(in.begin(), in.end()));
+ invoke_on_all_policies(test_is_sorted<T>(), in.begin(), in.end(), std::is_sorted(in.begin(), in.end()));
+ invoke_on_all_policies(test_is_sorted<T>(), in.cbegin(), in.cend(), std::is_sorted(in.begin(), in.end()));
- //an empty container
+ // an empty container
Sequence<T> in0(0);
- invoke_on_all_policies(test_is_sorted(), in0.begin(), in0.end(), std::is_sorted(in0.begin(), in0.end()));
- invoke_on_all_policies(test_is_sorted(), in0.cbegin(), in0.cend(), std::is_sorted(in0.begin(), in0.end()));
+ invoke_on_all_policies(test_is_sorted<T>(), in0.begin(), in0.end(), std::is_sorted(in0.begin(), in0.end()));
+ invoke_on_all_policies(test_is_sorted<T>(), in0.cbegin(), in0.cend(), std::is_sorted(in0.begin(), in0.end()));
- //non-descending order
+ // non-descending order
Sequence<T> in1(9, [](size_t) -> T { return T(0); });
- invoke_on_all_policies(test_is_sorted(), in1.begin(), in1.end(), std::is_sorted(in1.begin(), in1.end()));
- invoke_on_all_policies(test_is_sorted(), in1.cbegin(), in1.cend(), std::is_sorted(in1.begin(), in1.end()));
+ invoke_on_all_policies(test_is_sorted<T>(), in1.begin(), in1.end(), std::is_sorted(in1.begin(), in1.end()));
+ invoke_on_all_policies(test_is_sorted<T>(), in1.cbegin(), in1.cend(), std::is_sorted(in1.begin(), in1.end()));
}
-template <typename T>
+template <typename Iterator>
struct test_non_const
{
- template <typename Policy, typename Iterator>
- void
- operator()(Policy&& exec, Iterator iter)
+ template <typename Policy>
+ void operator()(Policy&& exec, Iterator iter)
{
- is_sorted(exec, iter, iter, std::less<T>());
- is_sorted_until(exec, iter, iter, std::less<T>());
+ is_sorted(exec, iter, iter, std::less<>());
+ is_sorted_until(exec, iter, iter, std::less<>());
}
};
-int
-main()
+int main()
{
+ test_is_sorted_by_type<int>();
+ test_is_sorted_by_type<double>();
- test_is_sorted_by_type<int32_t>();
- test_is_sorted_by_type<float64_t>();
-
- test_is_sorted_by_type<Wrapper<int32_t>>();
-
- test_algo_basic_single<int32_t>(run_for_rnd_fw<test_non_const<int32_t>>());
+ test_algo_basic_single(run_for_rnd_fw<test_non_const>());
std::cout << done() << std::endl;
return 0;
More information about the libcxx-commits
mailing list