| 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 iterator begin() const; |
| 12 | |
| 13 | #include <ranges> |
| 14 | #include <cassert> |
| 15 | #include <concepts> |
| 16 | |
| 17 | constexpr bool test() { |
| 18 | // Test unbound && non-const view |
| 19 | { |
| 20 | std::ranges::repeat_view<int> rv(0); |
| 21 | std::same_as<std::ranges::iterator_t<decltype(rv)>> decltype(auto) iter = rv.begin(); |
| 22 | assert(*iter == 0); |
| 23 | } |
| 24 | |
| 25 | // Test unbound && const view |
| 26 | { |
| 27 | const std::ranges::repeat_view<int> rv(0); |
| 28 | std::same_as<std::ranges::iterator_t<decltype(rv)>> decltype(auto) iter = rv.begin(); |
| 29 | assert(*iter == 0); |
| 30 | } |
| 31 | |
| 32 | // Test bound && non-const view |
| 33 | { |
| 34 | std::ranges::repeat_view<int, int> rv(1024, 10); |
| 35 | std::same_as<std::ranges::iterator_t<decltype(rv)>> decltype(auto) iter = rv.begin(); |
| 36 | assert(*iter == 1024); |
| 37 | } |
| 38 | |
| 39 | // Test bound && const view |
| 40 | { |
| 41 | const std::ranges::repeat_view<int, long long> rv(1024, 10); |
| 42 | std::same_as<std::ranges::iterator_t<decltype(rv)>> decltype(auto) iter = rv.begin(); |
| 43 | assert(*iter == 1024); |
| 44 | } |
| 45 | |
| 46 | return true; |
| 47 | } |
| 48 | |
| 49 | int main(int, char**) { |
| 50 | test(); |
| 51 | static_assert(test()); |
| 52 | |
| 53 | return 0; |
| 54 | } |
| 55 | |