1 // Copyright (C) 2020-2022 Free Software Foundation, Inc.
3 // This file is part of the GNU ISO C++ Library. This library is free
4 // software; you can redistribute it and/or modify it under the
5 // terms of the GNU General Public License as published by the
6 // Free Software Foundation; either version 3, or (at your option)
9 // This library is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 // GNU General Public License for more details.
14 // You should have received a copy of the GNU General Public License along
15 // with this library; see the file COPYING3. If not see
16 // <http://www.gnu.org/licenses/>.
18 // { dg-options "-std=gnu++2a" }
19 // { dg-do compile { target c++2a } }
26 using iterator_category
= std::random_access_iterator_tag
;
27 using value_type
= int;
29 using reference
= int&;
30 using difference_type
= std::ptrdiff_t;
38 int& operator*() const;
39 int* operator->() const;
41 int& operator[](difference_type
) const;
43 Iter
& operator+=(difference_type
);
44 Iter
& operator-=(difference_type
);
46 template<int N
> friend Iter
operator+(Iter
<N
>, difference_type
);
47 template<int N
> friend Iter
operator+(difference_type
, Iter
<N
>);
48 template<int N
> friend Iter
operator-(Iter
<N
>, difference_type
);
49 template<int N
> friend difference_type
operator-(Iter
<N
>, Iter
<N
>);
51 template<int N
> friend bool operator==(Iter
<N
>, Iter
<N
>);
52 template<int N
> friend std::weak_ordering
operator<=>(Iter
<N
>, Iter
<N
>);
55 static_assert( std::random_access_iterator
<Iter
<0>> );
57 int operator==(Iter
<0>, long*);
58 void* operator< (Iter
<1>, long*);
59 bool& operator< (long*, Iter
<2>);
61 using std::move_iterator
;
63 static_assert( std::three_way_comparable
<move_iterator
<Iter
<0>>> );
65 move_iterator
<Iter
<0>> l0
{Iter
<0>()};
66 move_iterator
<Iter
<1>> l1
{Iter
<1>()};
67 move_iterator
<Iter
<2>> l2
{Iter
<2>()};
68 move_iterator
<long*> r
{nullptr};
79 = requires (move_iterator
<Iter
<N
>> l
, move_iterator
<long*> r
)
84 = requires (move_iterator
<Iter
<N
>> l
, move_iterator
<long*> r
)
89 = requires (move_iterator
<Iter
<N
>> l
, move_iterator
<long*> r
)
94 = requires (move_iterator
<Iter
<N
>> l
, move_iterator
<long*> r
)
99 = requires (move_iterator
<Iter
<N
>> l
, move_iterator
<long*> r
)
104 = requires (move_iterator
<Iter
<N
>> l
, move_iterator
<long*> r
)
107 static_assert( has_eq
<0> );
108 static_assert( ! has_eq
<1> );
109 static_assert( ! has_eq
<2> );
111 static_assert( has_ne
<0> ); // uses synthesized operator!=
112 static_assert( ! has_ne
<1> );
113 static_assert( ! has_ne
<2> );
115 static_assert( ! has_lt
<0> );
116 static_assert( has_lt
<1> );
117 static_assert( ! has_lt
<2> );
119 static_assert( ! has_gt
<0> );
120 static_assert( ! has_gt
<1> );
121 static_assert( has_gt
<2> );
123 static_assert( ! has_le
<0> );
124 static_assert( ! has_le
<1> );
125 static_assert( has_le
<2> );
127 static_assert( ! has_ge
<0> );
128 static_assert( has_ge
<1> );
129 static_assert( ! has_ge
<2> );
131 int arr
[3] = { 1, 2, 3 };
132 constexpr std::move_iterator
<int*> beg
{std::begin(arr
)};
133 constexpr std::move_iterator
<const int*> cbeg
{std::cbegin(arr
)};
134 static_assert( beg
== cbeg
);
135 static_assert( beg
<= cbeg
);
136 static_assert( beg
>= cbeg
);
137 static_assert( std::is_eq(beg
<=> cbeg
) );
138 constexpr std::move_iterator
<const int*> cend
{std::cend(arr
)};
139 static_assert( beg
!= cend
);
140 static_assert( beg
< cend
);
141 static_assert( cend
> beg
);
142 static_assert( beg
<= cend
);
143 static_assert( cend
>= beg
);
144 static_assert( std::is_lt(beg
<=> cend
) );