1 | //===----------------------------------------------------------------------===// |
2 | // |
3 | // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. |
4 | // See https://llvm.org/LICENSE.txt for license information. |
5 | // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception |
6 | // |
7 | //===----------------------------------------------------------------------===// |
8 | |
9 | // UNSUPPORTED: c++03, c++11, c++14, c++17, c++20 |
10 | |
11 | // constexpr unreachable_sentinel_t end() const noexcept; |
12 | // constexpr iterator end() const requires (!same_as<Bound, unreachable_sentinel_t>); |
13 | |
14 | #include <ranges> |
15 | #include <cassert> |
16 | #include <concepts> |
17 | #include <iterator> |
18 | |
19 | constexpr bool test() { |
20 | // bound |
21 | { |
22 | std::ranges::repeat_view<int, int> rv(0, 10); |
23 | assert(rv.begin() + 10 == rv.end()); |
24 | std::same_as<std::ranges::iterator_t<decltype(rv)>> decltype(auto) iter = rv.end(); |
25 | static_assert(std::same_as<decltype(*iter), const int&>); |
26 | for (const auto& i : rv) { |
27 | assert(i == 0); |
28 | } |
29 | } |
30 | |
31 | // unbound |
32 | { |
33 | std::ranges::repeat_view<int> rv(0); |
34 | assert(rv.begin() + 10 != rv.end()); |
35 | static_assert(std::same_as<decltype(rv.end()), std::unreachable_sentinel_t>); |
36 | static_assert(noexcept(rv.end())); |
37 | for (const auto& i : rv | std::views::take(10)) { |
38 | assert(i == 0); |
39 | } |
40 | } |
41 | return true; |
42 | } |
43 | |
44 | int main(int, char**) { |
45 | test(); |
46 | static_assert(test()); |
47 | |
48 | return 0; |
49 | } |
50 | |