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 // constexpr explicit iota_view(W value); 13 14 #include <ranges> 15 #include <cassert> 16 17 #include "test_macros.h" 18 #include "types.h" 19 20 struct SomeIntComparable { 21 using difference_type = int; 22 23 SomeInt value_; 24 constexpr SomeIntComparable() : value_(SomeInt(10)) {} 25 26 friend constexpr bool operator==(SomeIntComparable lhs, SomeIntComparable rhs) { 27 return lhs.value_ == rhs.value_; 28 } 29 friend constexpr bool operator==(SomeIntComparable lhs, SomeInt rhs) { 30 return lhs.value_ == rhs; 31 } 32 friend constexpr bool operator==(SomeInt lhs, SomeIntComparable rhs) { 33 return lhs == rhs.value_; 34 } 35 36 friend constexpr difference_type operator-(SomeIntComparable lhs, SomeIntComparable rhs) { 37 return lhs.value_ - rhs.value_; 38 } 39 40 constexpr SomeIntComparable& operator++() { ++value_; return *this; } 41 constexpr SomeIntComparable operator++(int) { auto tmp = *this; ++value_; return tmp; } 42 constexpr SomeIntComparable operator--() { --value_; return *this; } 43 }; 44 45 constexpr bool test() { 46 { 47 std::ranges::iota_view<SomeInt> io(SomeInt(42)); 48 assert((*io.begin()).value_ == 42); 49 // Check that end returns std::unreachable_sentinel. 50 assert(io.end() != io.begin()); 51 static_assert(std::same_as<decltype(io.end()), std::unreachable_sentinel_t>); 52 } 53 54 { 55 std::ranges::iota_view<SomeInt, SomeIntComparable> io(SomeInt(0)); 56 assert(std::ranges::next(io.begin(), 10) == io.end()); 57 } 58 { 59 static_assert(!std::is_convertible_v<std::ranges::iota_view<SomeInt>, SomeInt>); 60 static_assert( std::is_constructible_v<std::ranges::iota_view<SomeInt>, SomeInt>); 61 } 62 63 return true; 64 } 65 66 int main(int, char**) { 67 test(); 68 static_assert(test()); 69 70 return 0; 71 } 72