Skip to content

Commit 950a034

Browse files
authored
Fix ranges_rotate.pass.cpp complexity checks
The complexity is "at most N swaps" _for each invocation of `rotate`_, but the tests currently assert that the total number of swaps for N calls is at most N. The standard allows that to be N squared, so the test is either requiring more than the standard (and the comment in the test) promises, or somebody just forgot to reset the counter on each iteration. If the intent really is to verify the libc++ guarantee, not the standard one, then shouldn't `expected` be set to N/2 i.e. 5, since that's what libc++ actually does? Either way, to be portable to other implementations, swaps should be reset on each loop. If you want to guard that with `#ifndef _LIBCPP_VERSION` it would not change the test for libc++.
1 parent 73e64e5 commit 950a034

File tree

1 file changed

+2
-0
lines changed

1 file changed

+2
-0
lines changed

libcxx/test/std/algorithms/alg.modifying.operations/alg.rotate/ranges_rotate.pass.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -173,6 +173,7 @@ constexpr bool test() {
173173
auto end = adl::Iterator::TrackSwaps(in.data() + in.size(), swaps);
174174

175175
for (std::size_t mid = 0; mid != input.size(); ++mid) {
176+
swaps = 0;
176177
std::ranges::rotate(begin, begin + mid, end);
177178
assert(swaps <= expected);
178179
}
@@ -186,6 +187,7 @@ constexpr bool test() {
186187
auto range = std::ranges::subrange(begin, end);
187188

188189
for (std::size_t mid = 0; mid != input.size(); ++mid) {
190+
swaps = 0;
189191
std::ranges::rotate(range, begin + mid);
190192
assert(swaps <= expected);
191193
}

0 commit comments

Comments
 (0)