]> git.ipfire.org Git - thirdparty/gcc.git/blame - libstdc++-v3/testsuite/24_iterators/move_iterator/rel_ops_c++20.cc
Update copyright years.
[thirdparty/gcc.git] / libstdc++-v3 / testsuite / 24_iterators / move_iterator / rel_ops_c++20.cc
CommitLineData
7adcbafe 1// Copyright (C) 2020-2022 Free Software Foundation, Inc.
81a8d137
JW
2//
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)
7// any later version.
8
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.
13
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/>.
17
18// { dg-options "-std=gnu++2a" }
19// { dg-do compile { target c++2a } }
20
21#include <iterator>
22
23template<int>
24struct Iter
25{
26 using iterator_category = std::random_access_iterator_tag;
27 using value_type = int;
28 using pointer = int*;
29 using reference = int&;
30 using difference_type = std::ptrdiff_t;
31
32 Iter();
33
34 Iter& operator++();
35 Iter operator++(int);
36 Iter& operator--();
37 Iter operator--(int);
38 int& operator*() const;
39 int* operator->() const;
40
41 int& operator[](difference_type) const;
42
43 Iter& operator+=(difference_type);
44 Iter& operator-=(difference_type);
45
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>);
50
b8a28a06
JW
51 template<int N> friend bool operator==(Iter<N>, Iter<N>);
52 template<int N> friend std::weak_ordering operator<=>(Iter<N>, Iter<N>);
81a8d137
JW
53};
54
81a8d137
JW
55static_assert( std::random_access_iterator<Iter<0>> );
56
57int operator==(Iter<0>, long*);
58void* operator< (Iter<1>, long*);
59bool& operator< (long*, Iter<2>);
60
61using std::move_iterator;
62
63static_assert( std::three_way_comparable<move_iterator<Iter<0>>> );
64
65move_iterator<Iter<0>> l0{Iter<0>()};
66move_iterator<Iter<1>> l1{Iter<1>()};
67move_iterator<Iter<2>> l2{Iter<2>()};
68move_iterator<long*> r{nullptr};
69
70bool b0 = l0 == r;
71bool b1 = l0 != r;
72bool b2 = l1 < r;
73bool b3 = l2 > r;
74bool b4 = l2 <= r;
75bool b5 = l1 >= r;
76
77template<int N>
78 concept has_eq
79 = requires (move_iterator<Iter<N>> l, move_iterator<long*> r)
80 { l == r; };
81
82template<int N>
83 concept has_ne
84 = requires (move_iterator<Iter<N>> l, move_iterator<long*> r)
85 { l != r; };
86
87template<int N>
88 concept has_lt
89 = requires (move_iterator<Iter<N>> l, move_iterator<long*> r)
90 { l < r; };
91
92template<int N>
93 concept has_gt
94 = requires (move_iterator<Iter<N>> l, move_iterator<long*> r)
95 { l > r; };
96
97template<int N>
98 concept has_le
99 = requires (move_iterator<Iter<N>> l, move_iterator<long*> r)
100 { l <= r; };
101
102template<int N>
103 concept has_ge
104 = requires (move_iterator<Iter<N>> l, move_iterator<long*> r)
105 { l >= r; };
106
107static_assert( has_eq<0> );
108static_assert( ! has_eq<1> );
109static_assert( ! has_eq<2> );
110
111static_assert( has_ne<0> ); // uses synthesized operator!=
112static_assert( ! has_ne<1> );
113static_assert( ! has_ne<2> );
114
115static_assert( ! has_lt<0> );
116static_assert( has_lt<1> );
117static_assert( ! has_lt<2> );
118
119static_assert( ! has_gt<0> );
120static_assert( ! has_gt<1> );
121static_assert( has_gt<2> );
122
123static_assert( ! has_le<0> );
124static_assert( ! has_le<1> );
125static_assert( has_le<2> );
126
127static_assert( ! has_ge<0> );
128static_assert( has_ge<1> );
129static_assert( ! has_ge<2> );
42cda3ba
JW
130
131int arr[3] = { 1, 2, 3 };
132constexpr std::move_iterator<int*> beg{std::begin(arr)};
133constexpr std::move_iterator<const int*> cbeg{std::cbegin(arr)};
134static_assert( beg == cbeg );
135static_assert( beg <= cbeg );
136static_assert( beg >= cbeg );
137static_assert( std::is_eq(beg <=> cbeg) );
138constexpr std::move_iterator<const int*> cend{std::cend(arr)};
139static_assert( beg != cend );
140static_assert( beg < cend );
141static_assert( cend > beg );
142static_assert( beg <= cend );
143static_assert( cend >= beg );
144static_assert( std::is_lt(beg <=> cend) );