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
10 // UNSUPPORTED: libcpp-no-concepts
11 // UNSUPPORTED: libcpp-has-no-incomplete-ranges
12 
13 // constexpr W operator[](difference_type n) const
14 //   requires advanceable<W>;
15 
16 #include <ranges>
17 #include <cassert>
18 
19 #include "test_macros.h"
20 #include "../types.h"
21 
22 template<class T>
23 constexpr void testType() {
24   {
25     std::ranges::iota_view<T> io(T(0));
26     auto iter = io.begin();
27     for (int i = 0; i < 100; ++i)
28       assert(iter[i] == T(i));
29   }
30   {
31     std::ranges::iota_view<T> io(T(10));
32     auto iter = io.begin();
33     for (int i = 0; i < 100; ++i)
34       assert(iter[i] == T(i + 10));
35   }
36   {
37     const std::ranges::iota_view<T> io(T(0));
38     auto iter = io.begin();
39     for (int i = 0; i < 100; ++i)
40       assert(iter[i] == T(i));
41   }
42   {
43     const std::ranges::iota_view<T> io(T(10));
44     auto iter = io.begin();
45     for (int i = 0; i < 100; ++i)
46       assert(iter[i] == T(i + 10));
47   }
48 }
49 
50 constexpr bool test() {
51   testType<SomeInt>();
52   testType<signed long>();
53   testType<unsigned long>();
54   testType<int>();
55   testType<unsigned>();
56   testType<short>();
57   testType<unsigned short>();
58 
59   return true;
60 }
61 
62 int main(int, char**) {
63   test();
64   static_assert(test());
65 
66   return 0;
67 }
68