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-has-no-incomplete-ranges
11
12 #include "test_macros.h"
13
14 TEST_CLANG_DIAGNOSTIC_IGNORED("-Wsign-compare")
15 TEST_GCC_DIAGNOSTIC_IGNORED("-Wsign-compare")
16 TEST_MSVC_DIAGNOSTIC_IGNORED(4018 4389) // various "signed/unsigned mismatch"
17
18 // constexpr iota_view(type_identity_t<W> value, type_identity_t<Bound> bound);
19
20 #include <ranges>
21 #include <cassert>
22
23 #include "types.h"
24
test()25 constexpr bool test() {
26 {
27 std::ranges::iota_view<SomeInt, SomeInt> io(SomeInt(0), SomeInt(10));
28 assert(std::ranges::next(io.begin(), 10) == io.end());
29 }
30
31 {
32 std::ranges::iota_view<SomeInt> io(SomeInt(0), std::unreachable_sentinel);
33 assert(std::ranges::next(io.begin(), 10) != io.end());
34 }
35
36 {
37 std::ranges::iota_view<SomeInt, IntComparableWith<SomeInt>> io(SomeInt(0), IntComparableWith(SomeInt(10)));
38 assert(std::ranges::next(io.begin(), 10) == io.end());
39 }
40
41 {
42 // This is allowed only when using the constructor (not the deduction guide).
43 std::ranges::iota_view<int, unsigned> signedUnsigned(0, 10);
44 assert(std::ranges::next(signedUnsigned.begin(), 10) == signedUnsigned.end());
45 }
46
47 {
48 // This is allowed only when using the constructor (not the deduction guide).
49 std::ranges::iota_view<unsigned, int> signedUnsigned(0, 10);
50 assert(std::ranges::next(signedUnsigned.begin(), 10) == signedUnsigned.end());
51 }
52
53 return true;
54 }
55
main(int,char **)56 int main(int, char**) {
57 test();
58 static_assert(test());
59
60 return 0;
61 }
62