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