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