69 lines · cpp
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-exception6//7//===----------------------------------------------------------------------===//8 9// UNSUPPORTED: c++03, c++11, c++14, c++17, c++2010 11// constexpr const W & operator*() const noexcept;12 13#include <ranges>14#include <cassert>15#include <concepts>16 17constexpr bool test() {18 // unbound19 {20 std::ranges::repeat_view<int> v(31);21 auto iter = v.begin();22 23 const int& val = *iter;24 for (int i = 0; i < 100; ++i, ++iter) {25 assert(*iter == 31);26 assert(&*iter == &val);27 }28 29 static_assert(noexcept(*iter));30 static_assert(std::same_as<decltype(*iter), const int&>);31 }32 33 // bound && one element34 {35 std::ranges::repeat_view<int, int> v(31, 1);36 auto iter = v.begin();37 assert(*iter == 31);38 static_assert(noexcept(*iter));39 static_assert(std::same_as<decltype(*iter), const int&>);40 }41 42 // bound && several elements43 {44 std::ranges::repeat_view<int, int> v(31, 100);45 auto iter = v.begin();46 47 const int& val = *iter;48 for (int i = 0; i < 100; ++i, ++iter) {49 assert(*iter == 31);50 assert(&*iter == &val);51 }52 }53 54 // bound && foreach55 {56 for (const auto& val : std::views::repeat(31, 100))57 assert(val == 31);58 }59 60 return true;61}62 63int main(int, char**) {64 test();65 static_assert(test());66 67 return 0;68}69