1 //===----------------------------------------------------------------------===//
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
7 //===----------------------------------------------------------------------===//
9 // UNSUPPORTED: c++03, c++11, c++14, c++17
11 #include "test_macros.h"
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"
17 // constexpr auto end() const;
18 // constexpr iterator end() const requires same_as<W, Bound>;
26 template<class T
, class U
>
27 constexpr void testType(U u
) {
29 std::ranges::iota_view
<T
, U
> io(T(0), u
);
30 assert(std::ranges::next(io
.begin(), 10) == io
.end());
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());
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());
43 const std::ranges::iota_view
<T
, U
> io(T(10), u
);
44 assert(io
.begin() == io
.end());
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());
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());
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));
79 int main(int, char**) {
81 static_assert(test());