Skip to content

Commit 187bac7

Browse files
var-consttstellar
authored andcommitted
[libc++][ranges][NFC] Make sure all implemented algorithms are enabled in "robust" tests.
Also fix `std::find_first_of` (which accidentally copied the predicate in the implementation). Differential Revision: https://reviews.llvm.org/D131235 (cherry picked from commit 8ac015c)
1 parent db9c521 commit 187bac7

File tree

7 files changed

+18
-17
lines changed

7 files changed

+18
-17
lines changed

libcxx/include/__algorithm/find_first_of.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,8 @@ template <class _ForwardIterator1, class _ForwardIterator2, class _BinaryPredica
2424
_LIBCPP_CONSTEXPR_AFTER_CXX11 _ForwardIterator1 __find_first_of_ce(_ForwardIterator1 __first1,
2525
_ForwardIterator1 __last1,
2626
_ForwardIterator2 __first2,
27-
_ForwardIterator2 __last2, _BinaryPredicate __pred) {
27+
_ForwardIterator2 __last2,
28+
_BinaryPredicate&& __pred) {
2829
for (; __first1 != __last1; ++__first1)
2930
for (_ForwardIterator2 __j = __first2; __j != __last2; ++__j)
3031
if (__pred(*__first1, *__j))

libcxx/test/libcxx/algorithms/ranges_robust_against_copying_comparators.pass.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -121,9 +121,9 @@ constexpr bool all_the_algorithms()
121121
(void)std::ranges::for_each(first, last, UnaryVoid(&copies)); assert(copies == 1); copies = 0;
122122
(void)std::ranges::for_each(a, UnaryVoid(&copies)); assert(copies == 1); copies = 0;
123123
(void)std::ranges::for_each_n(first, count, UnaryVoid(&copies)); assert(copies == 1); copies = 0;
124-
//(void)std::ranges::generate(first, last, NullaryValue(&copies)); assert(copies == 0);
125-
//(void)std::ranges::generate(a, NullaryValue(&copies)); assert(copies == 0);
126-
//(void)std::ranges::generate_n(first, count, NullaryValue(&copies)); assert(copies == 0);
124+
(void)std::ranges::generate(first, last, NullaryValue(&copies)); assert(copies == 0);
125+
(void)std::ranges::generate(a, NullaryValue(&copies)); assert(copies == 0);
126+
(void)std::ranges::generate_n(first, count, NullaryValue(&copies)); assert(copies == 0);
127127
(void)std::ranges::includes(first, last, first2, last2, Less(&copies)); assert(copies == 0);
128128
(void)std::ranges::includes(a, b, Less(&copies)); assert(copies == 0);
129129
(void)std::ranges::is_heap(first, last, Less(&copies)); assert(copies == 0);

libcxx/test/libcxx/algorithms/robust_against_copying_comparators.pass.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ TEST_CONSTEXPR_CXX20 bool all_the_algorithms()
120120
#endif
121121
(void)std::equal_range(first, last, value, Less<T>(&copies)); assert(copies == 0);
122122
(void)std::find_end(first, last, first2, mid2, Equal<T>(&copies)); assert(copies == 0);
123-
//(void)std::find_first_of(first, last, first2, last2, Equal(&copies)); assert(copies == 0);
123+
(void)std::find_first_of(first, last, first2, last2, Equal<T>(&copies)); assert(copies == 0);
124124
(void)std::find_if(first, last, UnaryTrue<T>(&copies)); assert(copies == 0);
125125
(void)std::find_if_not(first, last, UnaryTrue<T>(&copies)); assert(copies == 0);
126126
(void)std::for_each(first, last, UnaryVoid<T>(&copies)); assert(copies == 1); copies = 0;

libcxx/test/std/algorithms/ranges_result_alias_declarations.compile.pass.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,8 @@ static_assert(std::is_same_v<in_out_result<int, long>, remove_copy_result<int, l
3636
static_assert(std::is_same_v<in_out_result<int, long>, remove_copy_if_result<int, long>>);
3737
static_assert(std::is_same_v<in_out_result<int, long>, replace_copy_result<int, long>>);
3838
static_assert(std::is_same_v<in_out_result<int, long>, replace_copy_if_result<int, long>>);
39-
// static_assert(std::is_same_v<in_out_result<int, long>, reverse_copy_result<int, long>>);
40-
// static_assert(std::is_same_v<in_out_result<int, long>, rotate_copy_result<int, long>>);
39+
static_assert(std::is_same_v<in_out_result<int, long>, reverse_copy_result<int, long>>);
40+
static_assert(std::is_same_v<in_out_result<int, long>, rotate_copy_result<int, long>>);
4141
static_assert(std::is_same_v<in_out_result<int, long>, set_difference_result<int, long>>);
4242
static_assert(std::is_same_v<in_out_result<int, long>, unary_transform_result<int, long>>);
4343
static_assert(std::is_same_v<in_out_result<int, long>, uninitialized_copy_result<int, long>>);

libcxx/test/std/algorithms/ranges_robust_against_dangling.pass.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,8 +76,10 @@ constexpr bool test_all() {
7676
using std::ranges::mismatch_result;
7777
using std::ranges::move_result;
7878
using std::ranges::move_backward_result;
79+
using std::ranges::next_permutation_result;
7980
using std::ranges::partial_sort_copy_result;
8081
using std::ranges::partition_copy_result;
82+
using std::ranges::prev_permutation_result;
8183
using std::ranges::remove_copy_result;
8284
using std::ranges::remove_copy_if_result;
8385
using std::ranges::replace_copy_result;
@@ -199,8 +201,8 @@ constexpr bool test_all() {
199201
dangling_1st(std::ranges::push_heap, in);
200202
dangling_1st(std::ranges::pop_heap, in);
201203
dangling_1st(std::ranges::sort_heap, in);
202-
//dangling_1st(std::ranges::prev_permutation, in);
203-
//dangling_1st(std::ranges::next_permutation, in);
204+
dangling_1st<prev_permutation_result<dangling>>(std::ranges::prev_permutation, in);
205+
dangling_1st<next_permutation_result<dangling>>(std::ranges::next_permutation, in);
204206

205207
return true;
206208
}

libcxx/test/std/algorithms/ranges_robust_against_proxy_iterators.pass.cpp

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,6 @@ constexpr void run_tests() {
6969
int count = 1;
7070

7171
auto unary_pred = [](const Proxy<T&>&) { return true; };
72-
//auto binary_pred = [](const Proxy<T>&, const Proxy<T>&) { return return false; };
7372
auto binary_func = [](const Proxy<T>&, const Proxy<T>&) -> Proxy<T> { return Proxy<T>(T()); };
7473
auto gen = [] { return Proxy<T>(T{42}); };
7574

@@ -87,7 +86,7 @@ constexpr void run_tests() {
8786
test(std::ranges::partition_point, in, unary_pred);
8887
test(std::ranges::lower_bound, in, x);
8988
test(std::ranges::upper_bound, in, x);
90-
//test(std::ranges::equal_range, in, x);
89+
test(std::ranges::equal_range, in, x);
9190
test(std::ranges::binary_search, in, x);
9291

9392
test(std::ranges::min_element, in);
@@ -169,8 +168,8 @@ constexpr void run_tests() {
169168
test(std::ranges::push_heap, in);
170169
test(std::ranges::pop_heap, in);
171170
test(std::ranges::sort_heap, in);
172-
//test(std::ranges::prev_permutation, in);
173-
//test(std::ranges::next_permutation, in);
171+
test(std::ranges::prev_permutation, in);
172+
test(std::ranges::next_permutation, in);
174173

175174
// The algorithms that work on uninitialized memory have constraints that prevent proxy iterators from being used with
176175
// them.

libcxx/test/std/library/description/conventions/customization.point.object/niebloid.compile.pass.cpp

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,6 @@ int a[10];
5656
auto odd = [](int x) { return x % 2 != 0; };
5757
auto triple = [](int x) { return 3*x; };
5858
auto gen = [] { return 42; };
59-
//auto plus = [](int x, int y) { return x == y; };
6059
std::mt19937 g;
6160

6261
// [algorithm.syn]
@@ -79,7 +78,7 @@ static_assert(test(std::ranges::fill, a, 42));
7978
static_assert(test(std::ranges::fill_n, a, 10, 42));
8079
static_assert(test(std::ranges::find, a, 42));
8180
static_assert(test(std::ranges::find_end, a, a));
82-
//static_assert(test(std::ranges::find_first_of, a, a));
81+
static_assert(test(std::ranges::find_first_of, a, a));
8382
static_assert(test(std::ranges::find_if, a, odd));
8483
static_assert(test(std::ranges::find_if_not, a, odd));
8584
static_assert(test(std::ranges::for_each, a, odd));
@@ -107,7 +106,7 @@ static_assert(test(std::ranges::minmax_element, a));
107106
static_assert(test(std::ranges::mismatch, a, a));
108107
static_assert(test(std::ranges::move, a, a));
109108
static_assert(test(std::ranges::move_backward, a, a));
110-
//static_assert(test(std::ranges::next_permutation, a));
109+
static_assert(test(std::ranges::next_permutation, a));
111110
static_assert(test(std::ranges::none_of, a, odd));
112111
static_assert(test(std::ranges::nth_element, a, a+5));
113112
static_assert(test(std::ranges::partial_sort, a, a+5));
@@ -116,7 +115,7 @@ static_assert(test(std::ranges::partition, a, odd));
116115
static_assert(test(std::ranges::partition_copy, a, a, a, odd));
117116
static_assert(test(std::ranges::partition_point, a, odd));
118117
static_assert(test(std::ranges::pop_heap, a));
119-
//static_assert(test(std::ranges::prev_permutation, a));
118+
static_assert(test(std::ranges::prev_permutation, a));
120119
static_assert(test(std::ranges::push_heap, a));
121120
static_assert(test(std::ranges::remove, a, 42));
122121
static_assert(test(std::ranges::remove_copy, a, a, 42));

0 commit comments

Comments
 (0)