| 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 const W & operator[](difference_type n) const noexcept; |
| 12 | |
| 13 | #include <ranges> |
| 14 | #include <cassert> |
| 15 | #include <concepts> |
| 16 | #include <algorithm> |
| 17 | |
| 18 | constexpr bool test() { |
| 19 | // unbound |
| 20 | { |
| 21 | std::ranges::repeat_view<int> v(31); |
| 22 | auto iter = v.begin(); |
| 23 | assert(std::ranges::all_of(std::views::iota(0, 100), [&v](int i) { return v[i] == 31; })); |
| 24 | |
| 25 | static_assert(noexcept(iter[0])); |
| 26 | static_assert(std::same_as<decltype(iter[0]), const int&>); |
| 27 | } |
| 28 | |
| 29 | // bound |
| 30 | { |
| 31 | std::ranges::repeat_view<int, int> v(32); |
| 32 | auto iter = v.begin(); |
| 33 | assert(std::ranges::all_of(v, [](int i) { return i == 32; })); |
| 34 | static_assert(noexcept(iter[0])); |
| 35 | static_assert(std::same_as<decltype(iter[0]), const int&>); |
| 36 | } |
| 37 | return true; |
| 38 | } |
| 39 | |
| 40 | int main(int, char**) { |
| 41 | test(); |
| 42 | static_assert(test()); |
| 43 | |
| 44 | return 0; |
| 45 | } |
| 46 | |