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 #include "test_macros.h"
12
13 TEST_CLANG_DIAGNOSTIC_IGNORED("-Wsign-compare")
14 TEST_GCC_DIAGNOSTIC_IGNORED("-Wsign-compare")
15 TEST_MSVC_DIAGNOSTIC_IGNORED(4018 4389) // various "signed/unsigned mismatch"
16
17 // constexpr auto end() const;
18 // constexpr iterator end() const requires same_as<W, Bound>;
19
20 #include <cassert>
21 #include <ranges>
22 #include <utility>
23
24 #include "types.h"
25
26 template<class T, class U>
testType(U u)27 constexpr void testType(U u) {
28 {
29 std::ranges::iota_view<T, U> io(T(0), u);
30 assert(std::ranges::next(io.begin(), 10) == io.end());
31 }
32 {
33 std::ranges::iota_view<T, U> io(T(10), u);
34 assert(io.begin() == io.end());
35 assert(io.begin() == std::move(io).end());
36 }
37 {
38 const std::ranges::iota_view<T, U> io(T(0), u);
39 assert(std::ranges::next(io.begin(), 10) == io.end());
40 assert(std::ranges::next(io.begin(), 10) == std::move(io).end());
41 }
42 {
43 const std::ranges::iota_view<T, U> io(T(10), u);
44 assert(io.begin() == io.end());
45 }
46
47 {
48 std::ranges::iota_view<T> io(T(0), std::unreachable_sentinel);
49 assert(io.begin() != io.end());
50 assert(std::ranges::next(io.begin()) != io.end());
51 assert(std::ranges::next(io.begin(), 10) != io.end());
52 }
53 {
54 const std::ranges::iota_view<T> io(T(0), std::unreachable_sentinel);
55 assert(io.begin() != io.end());
56 assert(std::ranges::next(io.begin()) != io.end());
57 assert(std::ranges::next(io.begin(), 10) != io.end());
58 }
59 }
60
test()61 constexpr bool test() {
62 testType<SomeInt>(SomeInt(10));
63 testType<SomeInt>(IntComparableWith(SomeInt(10)));
64 testType<signed long>(IntComparableWith<signed long>(10));
65 testType<unsigned long>(IntComparableWith<unsigned long>(10));
66 testType<int>(IntComparableWith<int>(10));
67 testType<int>(int(10));
68 testType<int>(unsigned(10));
69 testType<unsigned>(unsigned(10));
70 testType<unsigned>(int(10));
71 testType<unsigned>(IntComparableWith<unsigned>(10));
72 testType<short>(short(10));
73 testType<short>(IntComparableWith<short>(10));
74 testType<unsigned short>(IntComparableWith<unsigned short>(10));
75
76 return true;
77 }
78
main(int,char **)79 int main(int, char**) {
80 test();
81 static_assert(test());
82
83 return 0;
84 }
85