diff --git a/libcxx/test/std/iterators/iterator.primitives/range.iter.ops/range.iter.ops.advance/iterator_count.pass.cpp b/libcxx/test/std/iterators/iterator.primitives/range.iter.ops/range.iter.ops.advance/iterator_count.pass.cpp index 60fc2a302e7d..be4d9b61401d 100644 --- a/libcxx/test/std/iterators/iterator.primitives/range.iter.ops/range.iter.ops.advance/iterator_count.pass.cpp +++ b/libcxx/test/std/iterators/iterator.primitives/range.iter.ops/range.iter.ops.advance/iterator_count.pass.cpp @@ -24,14 +24,14 @@ static_assert(is_function_like()); using range_t = std::array; -template +template constexpr void check_move_forward(std::ptrdiff_t const n) { auto range = range_t{0, 1, 2, 3, 4, 5, 6, 7, 8, 9}; - auto first = stride_counting_iterator(I(range.begin())); + auto first = stride_counting_iterator(It(range.begin())); std::ranges::advance(first, n); assert(first.base().base() == range.begin() + n); - if constexpr (std::random_access_iterator) { + if constexpr (std::random_access_iterator) { assert(first.stride_count() == 0 || first.stride_count() == 1); assert(first.stride_displacement() == 1); } else { @@ -40,14 +40,14 @@ constexpr void check_move_forward(std::ptrdiff_t const n) { } } -template +template constexpr void check_move_backward(std::ptrdiff_t const n) { auto range = range_t{0, 1, 2, 3, 4, 5, 6, 7, 8, 9}; - auto first = stride_counting_iterator(I(range.begin() + n)); + auto first = stride_counting_iterator(It(range.begin() + n)); std::ranges::advance(first, -n); assert(first.base().base() == range.begin()); - if constexpr (std::random_access_iterator) { + if constexpr (std::random_access_iterator) { assert(first.stride_count() == 0 || first.stride_count() == 1); assert(first.stride_displacement() == 1); } else { @@ -83,7 +83,7 @@ constexpr bool test() { } int main(int, char**) { - static_assert(test()); assert(test()); + static_assert(test()); return 0; } diff --git a/libcxx/test/std/iterators/iterator.primitives/range.iter.ops/range.iter.ops.advance/iterator_count_sentinel.pass.cpp b/libcxx/test/std/iterators/iterator.primitives/range.iter.ops/range.iter.ops.advance/iterator_count_sentinel.pass.cpp index 128d298b4994..29af3a100832 100644 --- a/libcxx/test/std/iterators/iterator.primitives/range.iter.ops/range.iter.ops.advance/iterator_count_sentinel.pass.cpp +++ b/libcxx/test/std/iterators/iterator.primitives/range.iter.ops/range.iter.ops.advance/iterator_count_sentinel.pass.cpp @@ -53,14 +53,15 @@ struct expected_t { std::ptrdiff_t result; }; -template -constexpr void check_forward_sized_sentinel(std::ptrdiff_t const n, expected_t const expected, range_t& range) { - auto current = stride_counting_iterator(I(range.begin())); - auto const result = std::ranges::advance(current, n, distance_apriori_sentinel(range.size())); +template +constexpr void check_forward_sized_sentinel(std::ptrdiff_t n, expected_t expected, range_t& range) { + using Difference = std::iter_difference_t; + auto current = stride_counting_iterator(It(range.begin())); + Difference const result = std::ranges::advance(current, n, distance_apriori_sentinel(range.size())); assert(current.base().base() == expected.coordinate); assert(result == expected.result); - if constexpr (std::random_access_iterator) { + if constexpr (std::random_access_iterator) { assert(current.stride_count() == 0 || current.stride_count() == 1); assert(current.stride_displacement() == current.stride_count()); } else { @@ -69,10 +70,11 @@ constexpr void check_forward_sized_sentinel(std::ptrdiff_t const n, expected_t c } } -template -constexpr void check_backward_sized_sentinel(std::ptrdiff_t const n, expected_t const expected, range_t& range) { - auto current = stride_counting_iterator(I(range.end())); - auto const result = std::ranges::advance(current, -n, stride_counting_iterator(I(range.begin()))); +template +constexpr void check_backward_sized_sentinel(std::ptrdiff_t n, expected_t expected, range_t& range) { + using Difference = std::iter_difference_t; + auto current = stride_counting_iterator(It(range.end())); + Difference const result = std::ranges::advance(current, -n, stride_counting_iterator(It(range.begin()))); assert(current.base().base() == expected.coordinate); assert(result == expected.result); @@ -80,19 +82,21 @@ constexpr void check_backward_sized_sentinel(std::ptrdiff_t const n, expected_t assert(current.stride_displacement() == current.stride_count()); } -template -constexpr void check_forward(std::ptrdiff_t const n, expected_t const expected, range_t& range) { - auto current = stride_counting_iterator(I(range.begin())); - auto const result = std::ranges::advance(current, n, sentinel_wrapper(I(range.end()))); +template +constexpr void check_forward(std::ptrdiff_t n, expected_t expected, range_t& range) { + using Difference = std::iter_difference_t; + auto current = stride_counting_iterator(It(range.begin())); + Difference const result = std::ranges::advance(current, n, sentinel_wrapper(It(range.end()))); assert(current.base().base() == expected.coordinate); assert(result == expected.result); assert(current.stride_count() == n - result); } -template -constexpr void check_backward(std::ptrdiff_t const n, expected_t const expected, range_t& range) { - auto current = stride_counting_iterator(I(range.end())); - auto const result = std::ranges::advance(current, -n, stride_counting_iterator(I(range.begin()))); +template +constexpr void check_backward(std::ptrdiff_t n, expected_t expected, range_t& range) { + using Difference = std::iter_difference_t; + auto current = stride_counting_iterator(It(range.end())); + Difference const result = std::ranges::advance(current, -n, stride_counting_iterator(It(range.begin()))); assert(current.base().base() == expected.coordinate); assert(result == expected.result); assert(current.stride_count() == n + result); @@ -139,7 +143,7 @@ constexpr bool test() { } int main(int, char**) { - static_assert(test()); assert(test()); + static_assert(test()); return 0; } diff --git a/libcxx/test/std/iterators/iterator.primitives/range.iter.ops/range.iter.ops.advance/iterator_sentinel.pass.cpp b/libcxx/test/std/iterators/iterator.primitives/range.iter.ops/range.iter.ops.advance/iterator_sentinel.pass.cpp index 1a740665f0c6..902e7d2b5d58 100644 --- a/libcxx/test/std/iterators/iterator.primitives/range.iter.ops/range.iter.ops.advance/iterator_sentinel.pass.cpp +++ b/libcxx/test/std/iterators/iterator.primitives/range.iter.ops/range.iter.ops.advance/iterator_sentinel.pass.cpp @@ -48,23 +48,23 @@ private: std::ptrdiff_t count_ = 0; }; -template S = I> +template Sent = It> constexpr void check_assignable_case(std::ptrdiff_t const n) { auto range = range_t{0, 1, 2, 3, 4, 5, 6, 7, 8, 9}; - auto first = stride_counting_iterator(I(range.begin())); - std::ranges::advance(first, stride_counting_iterator(S(I(range.begin() + n)))); + auto first = stride_counting_iterator(It(range.begin())); + std::ranges::advance(first, stride_counting_iterator(Sent(It(range.begin() + n)))); assert(first.base().base() == range.begin() + n); assert(first.stride_count() == 0); // because we got here by assigning from last, not by incrementing } -template +template constexpr void check_sized_sentinel_case(std::ptrdiff_t const n) { auto range = range_t{0, 1, 2, 3, 4, 5, 6, 7, 8, 9}; - auto first = stride_counting_iterator(I(range.begin())); + auto first = stride_counting_iterator(It(range.begin())); std::ranges::advance(first, distance_apriori_sentinel(n)); assert(first.base().base() == range.begin() + n); - if constexpr (std::random_access_iterator) { + if constexpr (std::random_access_iterator) { assert(first.stride_count() == 1); assert(first.stride_displacement() == 1); } else { @@ -73,11 +73,11 @@ constexpr void check_sized_sentinel_case(std::ptrdiff_t const n) { } } -template +template constexpr void check_sentinel_case(std::ptrdiff_t const n) { auto range = range_t{0, 1, 2, 3, 4, 5, 6, 7, 8, 9}; - auto first = stride_counting_iterator(I(range.begin())); - auto const last = I(range.begin() + n); + auto first = stride_counting_iterator(It(range.begin())); + auto const last = It(range.begin() + n); std::ranges::advance(first, sentinel_wrapper(last)); assert(first.base() == last); assert(first.stride_count() == n); @@ -107,7 +107,7 @@ constexpr bool test() { } int main(int, char**) { - static_assert(test()); assert(test()); + static_assert(test()); return 0; } diff --git a/libcxx/test/std/iterators/iterator.primitives/range.iter.ops/range.iter.ops.next/constraints.compile.pass.cpp b/libcxx/test/std/iterators/iterator.primitives/range.iter.ops/range.iter.ops.next/constraints.compile.pass.cpp index 8c65059a66b7..19379e3f1525 100644 --- a/libcxx/test/std/iterators/iterator.primitives/range.iter.ops/range.iter.ops.next/constraints.compile.pass.cpp +++ b/libcxx/test/std/iterators/iterator.primitives/range.iter.ops/range.iter.ops.next/constraints.compile.pass.cpp @@ -18,9 +18,10 @@ #include #include #include +#include "test_iterators.h" template -concept has_ranges_next = requires (Args ...args) { +concept has_ranges_next = requires (Args&& ...args) { { std::ranges::next(std::forward(args)...) }; }; @@ -31,4 +32,7 @@ static_assert(!has_ranges_next); static_assert(!has_ranges_next); // Test the test -static_assert(has_ranges_next); +using It2 = forward_iterator; +static_assert(has_ranges_next); +static_assert(has_ranges_next); +static_assert(has_ranges_next); diff --git a/libcxx/test/std/iterators/iterator.primitives/range.iter.ops/range.iter.ops.next/iterator.pass.cpp b/libcxx/test/std/iterators/iterator.primitives/range.iter.ops/range.iter.ops.next/iterator.pass.cpp index 5e69ffd723fe..4f74e85f67d7 100644 --- a/libcxx/test/std/iterators/iterator.primitives/range.iter.ops/range.iter.ops.next/iterator.pass.cpp +++ b/libcxx/test/std/iterators/iterator.primitives/range.iter.ops/range.iter.ops.next/iterator.pass.cpp @@ -40,7 +40,7 @@ constexpr bool test() { } int main(int, char**) { - static_assert(test()); test(); + static_assert(test()); return 0; } diff --git a/libcxx/test/std/iterators/iterator.primitives/range.iter.ops/range.iter.ops.next/iterator_count.pass.cpp b/libcxx/test/std/iterators/iterator.primitives/range.iter.ops/range.iter.ops.next/iterator_count.pass.cpp index 01217704ca10..9e5bc7300478 100644 --- a/libcxx/test/std/iterators/iterator.primitives/range.iter.ops/range.iter.ops.next/iterator_count.pass.cpp +++ b/libcxx/test/std/iterators/iterator.primitives/range.iter.ops/range.iter.ops.next/iterator_count.pass.cpp @@ -19,19 +19,19 @@ #include "test_iterators.h" -template -constexpr void check_steps(I it, std::ptrdiff_t n, int const* expected) { +template +constexpr void check_steps(It it, std::ptrdiff_t n, int const* expected) { { - auto result = std::ranges::next(std::move(it), n); + It result = std::ranges::next(std::move(it), n); assert(&*result == expected); } // Count the number of operations { stride_counting_iterator strided_it(std::move(it)); - auto result = std::ranges::next(std::move(strided_it), n); + stride_counting_iterator result = std::ranges::next(std::move(strided_it), n); assert(&*result == expected); - if constexpr (std::random_access_iterator) { + if constexpr (std::random_access_iterator) { assert(result.stride_count() == 1); // uses += exactly once assert(result.stride_displacement() == 1); } else { @@ -68,7 +68,7 @@ constexpr bool test() { } int main(int, char**) { - static_assert(test()); test(); + static_assert(test()); return 0; } diff --git a/libcxx/test/std/iterators/iterator.primitives/range.iter.ops/range.iter.ops.next/iterator_count_sentinel.pass.cpp b/libcxx/test/std/iterators/iterator.primitives/range.iter.ops/range.iter.ops.next/iterator_count_sentinel.pass.cpp index 6da7149ce38d..29067c8eab44 100644 --- a/libcxx/test/std/iterators/iterator.primitives/range.iter.ops/range.iter.ops.next/iterator_count_sentinel.pass.cpp +++ b/libcxx/test/std/iterators/iterator.primitives/range.iter.ops/range.iter.ops.next/iterator_count_sentinel.pass.cpp @@ -17,26 +17,27 @@ #include "test_iterators.h" -template -constexpr void check(I it, std::ptrdiff_t n, I last) { +template +constexpr void check(It it, std::ptrdiff_t n, It last) { { - auto result = std::ranges::next(it, n, last); + It result = std::ranges::next(it, n, last); assert(result == last); } // Count the number of operations { - stride_counting_iterator strided_it(it), strided_last(last); - auto result = std::ranges::next(strided_it, n, strided_last); + stride_counting_iterator strided_it(it); + stride_counting_iterator strided_last(last); + stride_counting_iterator result = std::ranges::next(strided_it, n, strided_last); assert(result == strided_last); - if constexpr (std::random_access_iterator) { + if constexpr (std::random_access_iterator) { if (n == 0 || n >= (last - it)) { assert(result.stride_count() == 0); // uses the assign-from-sentinel codepath } else { assert(result.stride_count() == 1); // uses += exactly once } } else { - auto const abs_n = n < 0 ? -n : n; + std::ptrdiff_t const abs_n = n < 0 ? -n : n; assert(result.stride_count() == abs_n); assert(result.stride_displacement() == n); } @@ -65,8 +66,7 @@ constexpr bool test() { } int main(int, char**) { - static_assert(test()); assert(test()); - + static_assert(test()); return 0; } diff --git a/libcxx/test/std/iterators/iterator.primitives/range.iter.ops/range.iter.ops.next/iterator_sentinel.pass.cpp b/libcxx/test/std/iterators/iterator.primitives/range.iter.ops/range.iter.ops.next/iterator_sentinel.pass.cpp index c33a145d73f2..ef28113dbf7e 100644 --- a/libcxx/test/std/iterators/iterator.primitives/range.iter.ops/range.iter.ops.next/iterator_sentinel.pass.cpp +++ b/libcxx/test/std/iterators/iterator.primitives/range.iter.ops/range.iter.ops.next/iterator_sentinel.pass.cpp @@ -46,10 +46,10 @@ private: std::ptrdiff_t count_ = 0; }; -template -constexpr void check_assignable(I it, I last, int const* expected) { +template +constexpr void check_assignable(It it, It last, int const* expected) { { - auto result = std::ranges::next(std::move(it), std::move(last)); + It result = std::ranges::next(std::move(it), std::move(last)); assert(&*result == expected); } @@ -63,8 +63,8 @@ constexpr void check_assignable(I it, I last, int const* expected) { } } -template -constexpr void check_sized_sentinel(I it, I last, int const* expected) { +template +constexpr void check_sized_sentinel(It it, It last, int const* expected) { auto n = (last.base() - it.base()); { @@ -80,7 +80,7 @@ constexpr void check_sized_sentinel(I it, I last, int const* expected) { auto result = std::ranges::next(std::move(strided_it), sent); assert(&*result == expected); - if constexpr (std::random_access_iterator) { + if constexpr (std::random_access_iterator) { assert(result.stride_count() == 1); // should have used exactly one += assert(result.stride_displacement() == 1); } else { @@ -90,13 +90,13 @@ constexpr void check_sized_sentinel(I it, I last, int const* expected) { } } -template -constexpr void check_sentinel(I it, I last, int const* expected) { +template +constexpr void check_sentinel(It it, It last, int const* expected) { auto n = (last.base() - it.base()); { auto sent = sentinel_wrapper(last); - auto result = std::ranges::next(std::move(it), sent); + It result = std::ranges::next(std::move(it), sent); assert(&*result == expected); } @@ -104,7 +104,7 @@ constexpr void check_sentinel(I it, I last, int const* expected) { { auto strided_it = stride_counting_iterator(it); auto sent = sentinel_wrapper(stride_counting_iterator(last)); - auto result = std::ranges::next(std::move(strided_it), sent); + stride_counting_iterator result = std::ranges::next(std::move(strided_it), sent); assert(&*result == expected); assert(result.stride_count() == n); // must have used ++ until it hit the sentinel } @@ -136,7 +136,7 @@ constexpr bool test() { } int main(int, char**) { - static_assert(test()); test(); + static_assert(test()); return 0; } diff --git a/libcxx/test/std/iterators/iterator.primitives/range.iter.ops/range.iter.ops.prev/constraints.compile.pass.cpp b/libcxx/test/std/iterators/iterator.primitives/range.iter.ops/range.iter.ops.prev/constraints.compile.pass.cpp index 78265299340c..05e49b56db8e 100644 --- a/libcxx/test/std/iterators/iterator.primitives/range.iter.ops/range.iter.ops.prev/constraints.compile.pass.cpp +++ b/libcxx/test/std/iterators/iterator.primitives/range.iter.ops/range.iter.ops.prev/constraints.compile.pass.cpp @@ -20,7 +20,7 @@ #include "test_iterators.h" template -concept has_ranges_prev = requires (Args ...args) { +concept has_ranges_prev = requires (Args&& ...args) { { std::ranges::prev(std::forward(args)...) }; }; @@ -30,4 +30,7 @@ static_assert(!has_ranges_prev); static_assert(!has_ranges_prev); // Test the test -static_assert(has_ranges_prev); +using It2 = bidirectional_iterator; +static_assert(has_ranges_prev); +static_assert(has_ranges_prev); +static_assert(has_ranges_prev); diff --git a/libcxx/test/std/iterators/iterator.primitives/range.iter.ops/range.iter.ops.prev/iterator.pass.cpp b/libcxx/test/std/iterators/iterator.primitives/range.iter.ops/range.iter.ops.prev/iterator.pass.cpp index 4bc642437224..a8d6b47dd591 100644 --- a/libcxx/test/std/iterators/iterator.primitives/range.iter.ops/range.iter.ops.prev/iterator.pass.cpp +++ b/libcxx/test/std/iterators/iterator.primitives/range.iter.ops/range.iter.ops.prev/iterator.pass.cpp @@ -20,9 +20,11 @@ template constexpr void check() { int range[] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9}; + assert(std::ranges::prev(It(&range[1])) == It(&range[0])); assert(std::ranges::prev(It(&range[4])) == It(&range[3])); assert(std::ranges::prev(It(&range[5])) == It(&range[4])); assert(std::ranges::prev(It(&range[6])) == It(&range[5])); + assert(std::ranges::prev(It(&range[10])) == It(&range[9])); } constexpr bool test() { @@ -34,7 +36,7 @@ constexpr bool test() { } int main(int, char**) { - static_assert(test()); test(); + static_assert(test()); return 0; } diff --git a/libcxx/test/std/iterators/iterator.primitives/range.iter.ops/range.iter.ops.prev/iterator_count.pass.cpp b/libcxx/test/std/iterators/iterator.primitives/range.iter.ops/range.iter.ops.prev/iterator_count.pass.cpp index e8f7beb99ac0..c089bb5d07c4 100644 --- a/libcxx/test/std/iterators/iterator.primitives/range.iter.ops/range.iter.ops.prev/iterator_count.pass.cpp +++ b/libcxx/test/std/iterators/iterator.primitives/range.iter.ops/range.iter.ops.prev/iterator_count.pass.cpp @@ -18,17 +18,17 @@ #include "test_iterators.h" -template -constexpr void check(I it, std::ptrdiff_t n, int const* expected) { - auto result = std::ranges::prev(stride_counting_iterator(std::move(it)), n); +template +constexpr void check(It it, std::ptrdiff_t n, int const* expected) { + stride_counting_iterator result = std::ranges::prev(stride_counting_iterator(std::move(it)), n); assert(result.base().base() == expected); - if constexpr (std::random_access_iterator) { + if constexpr (std::random_access_iterator) { assert(result.stride_count() <= 1); // we can't say anything about the stride displacement, cause we could be using -= or +=. } else { - auto const distance = n < 0 ? -n : n; - assert(result.stride_count() == distance); + std::ptrdiff_t const abs_n = n < 0 ? -n : n; + assert(result.stride_count() == abs_n); assert(result.stride_displacement() == -n); } } @@ -51,7 +51,7 @@ constexpr bool test() { } int main(int, char**) { - static_assert(test()); test(); + static_assert(test()); return 0; } diff --git a/libcxx/test/std/iterators/iterator.primitives/range.iter.ops/range.iter.ops.prev/iterator_count_sentinel.pass.cpp b/libcxx/test/std/iterators/iterator.primitives/range.iter.ops/range.iter.ops.prev/iterator_count_sentinel.pass.cpp index 5e1734b572a4..bf61d243ff1b 100644 --- a/libcxx/test/std/iterators/iterator.primitives/range.iter.ops/range.iter.ops.prev/iterator_count_sentinel.pass.cpp +++ b/libcxx/test/std/iterators/iterator.primitives/range.iter.ops/range.iter.ops.prev/iterator_count_sentinel.pass.cpp @@ -17,21 +17,22 @@ #include "test_iterators.h" -template -constexpr void check(I it, std::ptrdiff_t n, I last) { +template +constexpr void check(It it, std::ptrdiff_t n, It last) { auto abs = [](auto x) { return x < 0 ? -x : x; }; { - auto result = std::ranges::prev(it, n, last); + It result = std::ranges::prev(it, n, last); assert(result == last); } // Count the number of operations { - stride_counting_iterator strided_it(it), strided_last(last); - auto result = std::ranges::prev(strided_it, n, strided_last); + stride_counting_iterator strided_it(it); + stride_counting_iterator strided_last(last); + stride_counting_iterator result = std::ranges::prev(strided_it, n, strided_last); assert(result == strided_last); - if constexpr (std::random_access_iterator) { + if constexpr (std::random_access_iterator) { if (n == 0 || abs(n) >= abs(last - it)) { assert(result.stride_count() == 0); // uses the assign-from-sentinel codepath } else { @@ -62,8 +63,7 @@ constexpr bool test() { } int main(int, char**) { - static_assert(test()); assert(test()); - + static_assert(test()); return 0; } diff --git a/libcxx/test/support/test_iterators.h b/libcxx/test/support/test_iterators.h index 3ab759358336..51627178e6d3 100644 --- a/libcxx/test/support/test_iterators.h +++ b/libcxx/test/support/test_iterators.h @@ -663,9 +663,9 @@ struct cpp20_input_iterator { constexpr void operator++(int) { ++base_; } - [[nodiscard]] constexpr I const& base() const& { return base_; } + constexpr I const& base() const& { return base_; } - [[nodiscard]] constexpr I base() && { return std::move(base_); } + constexpr I base() && { return std::move(base_); } private: I base_ = I();