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 // constexpr explicit iota_view(W value);
15 #include <type_traits>
17 #include "test_macros.h"
20 struct SomeIntComparable
{
21 using difference_type
= int;
24 constexpr SomeIntComparable() : value_(SomeInt(10)) {}
26 friend constexpr bool operator==(SomeIntComparable lhs
, SomeIntComparable rhs
) {
27 return lhs
.value_
== rhs
.value_
;
29 friend constexpr bool operator==(SomeIntComparable lhs
, SomeInt rhs
) {
30 return lhs
.value_
== rhs
;
32 friend constexpr bool operator==(SomeInt lhs
, SomeIntComparable rhs
) {
33 return lhs
== rhs
.value_
;
36 friend constexpr difference_type
operator-(SomeIntComparable lhs
, SomeIntComparable rhs
) {
37 return lhs
.value_
- rhs
.value_
;
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; }
45 constexpr bool test() {
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
>);
55 std::ranges::iota_view
<SomeInt
, SomeIntComparable
> io(SomeInt(0));
56 assert(std::ranges::next(io
.begin(), 10) == io
.end());
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
>);
66 int main(int, char**) {
68 static_assert(test());