Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1 | // -*- C++ -*- |
Louis Dionne | 9bd9388 | 2021-11-17 16:25:01 -0500 | [diff] [blame] | 2 | //===----------------------------------------------------------------------===// |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3 | // |
Chandler Carruth | d201210 | 2019-01-19 10:56:40 +0000 | [diff] [blame] | 4 | // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. |
| 5 | // See https://llvm.org/LICENSE.txt for license information. |
| 6 | // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 7 | // |
| 8 | //===----------------------------------------------------------------------===// |
| 9 | |
| 10 | #ifndef _LIBCPP_ITERATOR |
| 11 | #define _LIBCPP_ITERATOR |
| 12 | |
| 13 | /* |
| 14 | iterator synopsis |
| 15 | |
Christopher Di Bella | 490fe40 | 2021-03-23 03:55:52 +0000 | [diff] [blame] | 16 | #include <concepts> |
| 17 | |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 18 | namespace std |
| 19 | { |
Christopher Di Bella | e00eebc | 2021-03-23 20:48:41 +0000 | [diff] [blame] | 20 | template<class> struct incrementable_traits; // since C++20 |
Christopher Di Bella | a3a1006 | 2021-04-20 18:56:08 +0000 | [diff] [blame] | 21 | template<class T> |
| 22 | using iter_difference_t = see below; // since C++20 |
| 23 | |
Christopher Di Bella | e00eebc | 2021-03-23 20:48:41 +0000 | [diff] [blame] | 24 | template<class> struct indirectly_readable_traits; // since C++20 |
Christopher Di Bella | a3a1006 | 2021-04-20 18:56:08 +0000 | [diff] [blame] | 25 | template<class T> |
| 26 | using iter_value_t = see below; // since C++20 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 27 | |
| 28 | template<class Iterator> |
zoecarver | 9f1e297 | 2021-04-20 08:50:11 -0400 | [diff] [blame] | 29 | struct iterator_traits; |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 30 | |
| 31 | template<class T> |
zoecarver | 9f1e297 | 2021-04-20 08:50:11 -0400 | [diff] [blame] | 32 | requires is_object_v<T> // since C++20 |
| 33 | struct iterator_traits<T*>; |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 34 | |
Christopher Di Bella | 875636f | 2021-04-04 05:12:46 +0000 | [diff] [blame] | 35 | template<dereferenceable T> |
| 36 | using iter_reference_t = decltype(*declval<T&>()); |
| 37 | |
Louis Dionne | ca989a5 | 2021-04-20 14:40:43 -0400 | [diff] [blame] | 38 | namespace ranges::inline unspecified { |
| 39 | inline constexpr unspecified iter_move = unspecified; // since C++20, nodiscard as an extension |
| 40 | }} |
| 41 | |
| 42 | template<dereferenceable T> |
| 43 | requires ... |
| 44 | using iter_rvalue_reference_t = decltype(ranges::iter_move(declval<T&>())); // since C++20 |
| 45 | |
Louis Dionne | 463afb8 | 2021-04-22 11:05:30 -0400 | [diff] [blame] | 46 | // [iterator.concepts], iterator concepts |
| 47 | // [iterator.concept.readable], concept indirectly_readable |
| 48 | template<class In> |
Louis Dionne | 170a03c | 2021-04-28 15:02:08 -0400 | [diff] [blame] | 49 | concept indirectly_readable = see below; // since C++20 |
| 50 | |
| 51 | template<indirectly_readable T> |
| 52 | using iter_common_reference_t = |
| 53 | common_reference_t<iter_reference_t<T>, iter_value_t<T>&>; // since C++20 |
Louis Dionne | 463afb8 | 2021-04-22 11:05:30 -0400 | [diff] [blame] | 54 | |
| 55 | // [iterator.concept.writable], concept indirectly_writable |
| 56 | template<class Out, class T> |
| 57 | concept indirectly_writable = see below; // since C++20 |
| 58 | |
Mark de Wever | 6639f42 | 2021-04-26 17:53:20 +0200 | [diff] [blame] | 59 | // [iterator.concept.winc], concept weakly_incrementable |
Christopher Di Bella | 54ffc18 | 2021-04-23 18:22:55 -0700 | [diff] [blame] | 60 | template<class I> |
| 61 | concept weakly_incrementable = see below; // since C++20 |
| 62 | |
| 63 | // [iterator.concept.inc], concept incrementable |
| 64 | template<class I> |
| 65 | concept incrementable = see below; // since C++20 |
| 66 | |
Mark de Wever | 6639f42 | 2021-04-26 17:53:20 +0200 | [diff] [blame] | 67 | // [iterator.concept.iterator], concept input_or_output_iterator |
Christopher Di Bella | 0ef5228 | 2021-04-09 02:10:32 +0000 | [diff] [blame] | 68 | template<class I> |
| 69 | concept input_or_output_iterator = see below; // since C++20 |
| 70 | |
Mark de Wever | 6639f42 | 2021-04-26 17:53:20 +0200 | [diff] [blame] | 71 | // [iterator.concept.sentinel], concept sentinel_for |
Christopher Di Bella | 0ef5228 | 2021-04-09 02:10:32 +0000 | [diff] [blame] | 72 | template<class S, class I> |
| 73 | concept sentinel_for = see below; // since C++20 |
| 74 | |
zoecarver | 11391bc | 2021-04-26 09:35:47 -0700 | [diff] [blame] | 75 | // [iterator.concept.sizedsentinel], concept sized_sentinel_for |
| 76 | template<class S, class I> |
| 77 | inline constexpr bool disable_sized_sentinel_for = false; |
| 78 | |
| 79 | template<class S, class I> |
| 80 | concept sized_sentinel_for = see below; |
| 81 | |
Christopher Di Bella | 8250c63 | 2021-04-11 19:04:52 +0000 | [diff] [blame] | 82 | // [iterator.concept.input], concept input_iterator |
| 83 | template<class I> |
| 84 | concept input_iterator = see below; // since C++20 |
| 85 | |
Louis Dionne | b53a0ec | 2021-07-23 15:26:23 -0400 | [diff] [blame] | 86 | // [iterator.concept.output], concept output_iterator |
| 87 | template<class I, class T> |
| 88 | concept output_iterator = see below; // since C++20 |
| 89 | |
Christopher Di Bella | 8f1370d | 2021-04-11 22:11:03 +0000 | [diff] [blame] | 90 | // [iterator.concept.forward], concept forward_iterator |
| 91 | template<class I> |
| 92 | concept forward_iterator = see below; // since C++20 |
| 93 | |
Christopher Di Bella | 10a3147 | 2021-04-12 01:16:45 +0000 | [diff] [blame] | 94 | // [iterator.concept.bidir], concept bidirectional_iterator |
| 95 | template<class I> |
| 96 | concept bidirectional_iterator = see below; // since C++20 |
| 97 | |
zoecarver | 21da57e | 2021-04-23 17:11:44 -0700 | [diff] [blame] | 98 | // [iterator.concept.random.access], concept random_access_iterator |
| 99 | template<class I> |
| 100 | concept random_access_iterator = see below; // since C++20 |
| 101 | |
Louis Dionne | 170a03c | 2021-04-28 15:02:08 -0400 | [diff] [blame] | 102 | // [indirectcallable] |
| 103 | // [indirectcallable.indirectinvocable] |
| 104 | template<class F, class I> |
| 105 | concept indirectly_unary_invocable = see below; // since C++20 |
| 106 | |
| 107 | template<class F, class I> |
| 108 | concept indirectly_regular_unary_invocable = see below; // since C++20 |
| 109 | |
| 110 | template<class F, class I> |
| 111 | concept indirect_unary_predicate = see below; // since C++20 |
| 112 | |
| 113 | template<class F, class I1, class I2> |
| 114 | concept indirect_binary_predicate = see below; // since C++20 |
| 115 | |
| 116 | template<class F, class I1, class I2 = I1> |
| 117 | concept indirect_equivalence_relation = see below; // since C++20 |
| 118 | |
| 119 | template<class F, class I1, class I2 = I1> |
| 120 | concept indirect_strict_weak_order = see below; // since C++20 |
| 121 | |
| 122 | template<class F, class... Is> |
| 123 | using indirect_result_t = see below; // since C++20 |
| 124 | |
| 125 | // [projected], projected |
| 126 | template<indirectly_readable I, indirectly_regular_unary_invocable<I> Proj> |
| 127 | struct projected; // since C++20 |
| 128 | |
| 129 | template<weakly_incrementable I, indirectly_regular_unary_invocable<I> Proj> |
| 130 | struct incrementable_traits<projected<I, Proj>>; // since C++20 |
| 131 | |
zoecarver | 7e38f80 | 2021-05-17 10:30:12 -0700 | [diff] [blame] | 132 | // [alg.req.ind.move], concept indirectly_movable |
| 133 | template<class In, class Out> |
| 134 | concept indirectly_movable = see below; // since C++20 |
| 135 | |
| 136 | template<class In, class Out> |
| 137 | concept indirectly_movable_storable = see below; // since C++20 |
| 138 | |
Konstantin Varlamov | de87b2c | 2022-02-02 13:27:28 -0800 | [diff] [blame] | 139 | // [alg.req.ind.copy], concept indirectly_copyable |
| 140 | template<class In, class Out> |
Konstantin Varlamov | 1755e8d | 2022-02-17 20:15:02 -0800 | [diff] [blame] | 141 | concept indirectly_copyable = see below; // since C++20 |
Konstantin Varlamov | de87b2c | 2022-02-02 13:27:28 -0800 | [diff] [blame] | 142 | |
| 143 | template<class In, class Out> |
Konstantin Varlamov | 1755e8d | 2022-02-17 20:15:02 -0800 | [diff] [blame] | 144 | concept indirectly_copyable_storable = see below; // since C++20 |
Konstantin Varlamov | de87b2c | 2022-02-02 13:27:28 -0800 | [diff] [blame] | 145 | |
zoecarver | e0d9808 | 2021-07-01 11:58:54 -0700 | [diff] [blame] | 146 | // [alg.req.ind.swap], concept indirectly_swappable |
| 147 | template<class I1, class I2 = I1> |
| 148 | concept indirectly_swappable = see below; // since C++20 |
| 149 | |
Nikolas Klauser | 764ac5e | 2022-01-04 19:55:37 +0100 | [diff] [blame] | 150 | template<class I1, class I2, class R, class P1 = identity, |
| 151 | class P2 = identity> |
| 152 | concept indirectly_comparable = |
| 153 | indirect_binary_predicate<R, projected<I1, P1>, projected<I2, P2>>; // since C++20 |
| 154 | |
Konstantin Varlamov | 1755e8d | 2022-02-17 20:15:02 -0800 | [diff] [blame] | 155 | // [alg.req.permutable], concept permutable |
Konstantin Varlamov | 73b5c16 | 2022-02-17 20:11:46 -0800 | [diff] [blame] | 156 | template<class I> |
Konstantin Varlamov | 1755e8d | 2022-02-17 20:15:02 -0800 | [diff] [blame] | 157 | concept permutable = see below; // since C++20 |
Konstantin Varlamov | 73b5c16 | 2022-02-17 20:11:46 -0800 | [diff] [blame] | 158 | |
| 159 | // [alg.req.mergeable], concept mergeable |
| 160 | template<class I1, class I2, class Out, |
| 161 | class R = ranges::less, class P1 = identity, class P2 = identity> |
| 162 | concept mergeable = see below; // since C++20 |
| 163 | |
Konstantin Varlamov | 1755e8d | 2022-02-17 20:15:02 -0800 | [diff] [blame] | 164 | // [alg.req.sortable], concept sortable |
| 165 | template<class I, class R = ranges::less, class P = identity> |
| 166 | concept sortable = see below; // since C++20 |
| 167 | |
zoecarver | 6eb71a9 | 2021-05-27 09:23:19 -0700 | [diff] [blame] | 168 | template<input_or_output_iterator I, sentinel_for<I> S> |
| 169 | requires (!same_as<I, S> && copyable<I>) |
| 170 | class common_iterator; // since C++20 |
| 171 | |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 172 | template<class Category, class T, class Distance = ptrdiff_t, |
| 173 | class Pointer = T*, class Reference = T&> |
Louis Dionne | 8762e2b | 2021-05-25 18:15:58 -0400 | [diff] [blame] | 174 | struct iterator // deprecated in C++17 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 175 | { |
| 176 | typedef T value_type; |
| 177 | typedef Distance difference_type; |
| 178 | typedef Pointer pointer; |
| 179 | typedef Reference reference; |
| 180 | typedef Category iterator_category; |
| 181 | }; |
| 182 | |
| 183 | struct input_iterator_tag {}; |
| 184 | struct output_iterator_tag {}; |
| 185 | struct forward_iterator_tag : public input_iterator_tag {}; |
| 186 | struct bidirectional_iterator_tag : public forward_iterator_tag {}; |
| 187 | struct random_access_iterator_tag : public bidirectional_iterator_tag {}; |
Konstantin Varlamov | 5eda502 | 2022-02-02 12:53:07 -0800 | [diff] [blame] | 188 | struct contiguous_iterator_tag : public random_access_iterator_tag {}; |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 189 | |
Marshall Clow | 75468e7 | 2017-05-17 18:51:36 +0000 | [diff] [blame] | 190 | // 27.4.3, iterator operations |
Louis Dionne | 4576866 | 2020-06-08 16:16:01 -0400 | [diff] [blame] | 191 | template <class InputIterator, class Distance> // constexpr in C++17 |
| 192 | constexpr void advance(InputIterator& i, Distance n); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 193 | |
Marshall Clow | 75468e7 | 2017-05-17 18:51:36 +0000 | [diff] [blame] | 194 | template <class InputIterator> // constexpr in C++17 |
| 195 | constexpr typename iterator_traits<InputIterator>::difference_type |
| 196 | distance(InputIterator first, InputIterator last); |
| 197 | |
| 198 | template <class InputIterator> // constexpr in C++17 |
| 199 | constexpr InputIterator next(InputIterator x, |
| 200 | typename iterator_traits<InputIterator>::difference_type n = 1); |
| 201 | |
| 202 | template <class BidirectionalIterator> // constexpr in C++17 |
| 203 | constexpr BidirectionalIterator prev(BidirectionalIterator x, |
Louis Dionne | 173f29e | 2019-05-29 16:01:36 +0000 | [diff] [blame] | 204 | typename iterator_traits<BidirectionalIterator>::difference_type n = 1); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 205 | |
Christopher Di Bella | c6ead65 | 2021-05-05 07:14:08 +0000 | [diff] [blame] | 206 | // [range.iter.ops], range iterator operations |
| 207 | namespace ranges { |
| 208 | // [range.iter.op.advance], ranges::advance |
| 209 | template<input_or_output_iterator I> |
| 210 | constexpr void advance(I& i, iter_difference_t<I> n); // since C++20 |
| 211 | template<input_or_output_iterator I, sentinel_for<I> S> |
| 212 | constexpr void advance(I& i, S bound); // since C++20 |
| 213 | template<input_or_output_iterator I, sentinel_for<I> S> |
| 214 | constexpr iter_difference_t<I> advance(I& i, iter_difference_t<I> n, S bound); // since C++20 |
| 215 | } |
| 216 | |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 217 | template <class Iterator> |
| 218 | class reverse_iterator |
Louis Dionne | 8762e2b | 2021-05-25 18:15:58 -0400 | [diff] [blame] | 219 | : public iterator<typename iterator_traits<Iterator>::iterator_category, // until C++17 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 220 | typename iterator_traits<Iterator>::value_type, |
| 221 | typename iterator_traits<Iterator>::difference_type, |
| 222 | typename iterator_traits<Iterator>::pointer, |
| 223 | typename iterator_traits<Iterator>::reference> |
| 224 | { |
| 225 | protected: |
| 226 | Iterator current; |
| 227 | public: |
Konstantin Varlamov | b899686 | 2022-03-17 19:57:39 -0700 | [diff] [blame] | 228 | using iterator_type = Iterator; |
| 229 | using iterator_concept = see below; // since C++20 |
| 230 | using iterator_category = typename iterator_traits<Iterator>::iterator_category; // since C++17, until C++20 |
| 231 | using iterator_category = see below; // since C++20 |
| 232 | using value_type = typename iterator_traits<Iterator>::value_type; // since C++17, until C++20 |
| 233 | using value_type = iter_value_t<Iterator>; // since C++20 |
| 234 | using difference_type = typename iterator_traits<Iterator>::difference_type; // until C++20 |
| 235 | using difference_type = iter_difference_t<Iterator>; // since C++20 |
| 236 | using pointer = typename iterator_traits<Iterator>::pointer; |
| 237 | using reference = typename iterator_traits<Iterator>::reference; // until C++20 |
| 238 | using reference = iter_reference_t<Iterator>; // since C++20 |
Howard Hinnant | 3b6579a | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 239 | |
Marshall Clow | 5ace554 | 2016-10-19 15:12:50 +0000 | [diff] [blame] | 240 | constexpr reverse_iterator(); |
| 241 | constexpr explicit reverse_iterator(Iterator x); |
| 242 | template <class U> constexpr reverse_iterator(const reverse_iterator<U>& u); |
| 243 | template <class U> constexpr reverse_iterator& operator=(const reverse_iterator<U>& u); |
| 244 | constexpr Iterator base() const; |
| 245 | constexpr reference operator*() const; |
Konstantin Varlamov | b899686 | 2022-03-17 19:57:39 -0700 | [diff] [blame] | 246 | constexpr pointer operator->() const; // until C++20 |
| 247 | constexpr pointer operator->() const requires see below; // since C++20 |
Marshall Clow | 5ace554 | 2016-10-19 15:12:50 +0000 | [diff] [blame] | 248 | constexpr reverse_iterator& operator++(); |
| 249 | constexpr reverse_iterator operator++(int); |
| 250 | constexpr reverse_iterator& operator--(); |
| 251 | constexpr reverse_iterator operator--(int); |
| 252 | constexpr reverse_iterator operator+ (difference_type n) const; |
| 253 | constexpr reverse_iterator& operator+=(difference_type n); |
| 254 | constexpr reverse_iterator operator- (difference_type n) const; |
| 255 | constexpr reverse_iterator& operator-=(difference_type n); |
Konstantin Varlamov | b899686 | 2022-03-17 19:57:39 -0700 | [diff] [blame] | 256 | constexpr unspecified operator[](difference_type n) const; |
| 257 | |
| 258 | friend constexpr iter_rvalue_reference_t<Iterator> |
| 259 | iter_move(const reverse_iterator& i) noexcept(see below); |
| 260 | template<indirectly_swappable<Iterator> Iterator2> |
| 261 | friend constexpr void |
| 262 | iter_swap(const reverse_iterator& x, |
| 263 | const reverse_iterator<Iterator2>& y) noexcept(see below); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 264 | }; |
| 265 | |
| 266 | template <class Iterator1, class Iterator2> |
Marshall Clow | 5ace554 | 2016-10-19 15:12:50 +0000 | [diff] [blame] | 267 | constexpr bool // constexpr in C++17 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 268 | operator==(const reverse_iterator<Iterator1>& x, const reverse_iterator<Iterator2>& y); |
| 269 | |
| 270 | template <class Iterator1, class Iterator2> |
Marshall Clow | 5ace554 | 2016-10-19 15:12:50 +0000 | [diff] [blame] | 271 | constexpr bool // constexpr in C++17 |
Konstantin Varlamov | b899686 | 2022-03-17 19:57:39 -0700 | [diff] [blame] | 272 | operator!=(const reverse_iterator<Iterator1>& x, const reverse_iterator<Iterator2>& y); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 273 | |
| 274 | template <class Iterator1, class Iterator2> |
Marshall Clow | 5ace554 | 2016-10-19 15:12:50 +0000 | [diff] [blame] | 275 | constexpr bool // constexpr in C++17 |
Konstantin Varlamov | b899686 | 2022-03-17 19:57:39 -0700 | [diff] [blame] | 276 | operator<(const reverse_iterator<Iterator1>& x, const reverse_iterator<Iterator2>& y); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 277 | |
| 278 | template <class Iterator1, class Iterator2> |
Marshall Clow | 5ace554 | 2016-10-19 15:12:50 +0000 | [diff] [blame] | 279 | constexpr bool // constexpr in C++17 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 280 | operator>(const reverse_iterator<Iterator1>& x, const reverse_iterator<Iterator2>& y); |
| 281 | |
| 282 | template <class Iterator1, class Iterator2> |
Marshall Clow | 5ace554 | 2016-10-19 15:12:50 +0000 | [diff] [blame] | 283 | constexpr bool // constexpr in C++17 |
Konstantin Varlamov | b899686 | 2022-03-17 19:57:39 -0700 | [diff] [blame] | 284 | operator<=(const reverse_iterator<Iterator1>& x, const reverse_iterator<Iterator2>& y); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 285 | |
| 286 | template <class Iterator1, class Iterator2> |
Marshall Clow | 5ace554 | 2016-10-19 15:12:50 +0000 | [diff] [blame] | 287 | constexpr bool // constexpr in C++17 |
Konstantin Varlamov | b899686 | 2022-03-17 19:57:39 -0700 | [diff] [blame] | 288 | operator>=(const reverse_iterator<Iterator1>& x, const reverse_iterator<Iterator2>& y); |
| 289 | |
| 290 | template<class Iterator1, three_way_comparable_with<Iterator1> Iterator2> |
| 291 | constexpr compare_three_way_result_t<Iterator1, Iterator2> |
| 292 | operator<=>(const reverse_iterator<Iterator1>& x, |
| 293 | const reverse_iterator<Iterator2>& y); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 294 | |
| 295 | template <class Iterator1, class Iterator2> |
Marshall Clow | 5ace554 | 2016-10-19 15:12:50 +0000 | [diff] [blame] | 296 | constexpr auto |
Marshall Clow | f8fec4e | 2016-07-08 16:54:47 +0000 | [diff] [blame] | 297 | operator-(const reverse_iterator<Iterator1>& x, const reverse_iterator<Iterator2>& y) |
Marshall Clow | 5ace554 | 2016-10-19 15:12:50 +0000 | [diff] [blame] | 298 | -> decltype(__y.base() - __x.base()); // constexpr in C++17 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 299 | |
| 300 | template <class Iterator> |
Marshall Clow | 5ace554 | 2016-10-19 15:12:50 +0000 | [diff] [blame] | 301 | constexpr reverse_iterator<Iterator> |
Louis Dionne | 173f29e | 2019-05-29 16:01:36 +0000 | [diff] [blame] | 302 | operator+(typename reverse_iterator<Iterator>::difference_type n, |
Marshall Clow | 5ace554 | 2016-10-19 15:12:50 +0000 | [diff] [blame] | 303 | const reverse_iterator<Iterator>& x); // constexpr in C++17 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 304 | |
Marshall Clow | 5ace554 | 2016-10-19 15:12:50 +0000 | [diff] [blame] | 305 | template <class Iterator> |
| 306 | constexpr reverse_iterator<Iterator> make_reverse_iterator(Iterator i); // C++14, constexpr in C++17 |
Marshall Clow | 6dbbdc9 | 2014-03-03 01:24:04 +0000 | [diff] [blame] | 307 | |
Konstantin Varlamov | b899686 | 2022-03-17 19:57:39 -0700 | [diff] [blame] | 308 | template<class Iterator1, class Iterator2> |
| 309 | requires (!sized_sentinel_for<Iterator1, Iterator2>) |
| 310 | inline constexpr bool disable_sized_sentinel_for<reverse_iterator<Iterator1>, |
| 311 | reverse_iterator<Iterator2>> = true; |
| 312 | |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 313 | template <class Container> |
| 314 | class back_insert_iterator |
Louis Dionne | 3402c3c | 2021-05-27 12:56:12 -0400 | [diff] [blame] | 315 | : public iterator<output_iterator_tag, void, void, void, void> // until C++17 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 316 | { |
| 317 | protected: |
| 318 | Container* container; |
| 319 | public: |
| 320 | typedef Container container_type; |
| 321 | typedef void value_type; |
Louis Dionne | 3402c3c | 2021-05-27 12:56:12 -0400 | [diff] [blame] | 322 | typedef void difference_type; // until C++20 |
| 323 | typedef ptrdiff_t difference_type; // since C++20 |
Eric Fiselier | 9aeea87 | 2016-06-30 04:40:50 +0000 | [diff] [blame] | 324 | typedef void reference; |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 325 | typedef void pointer; |
| 326 | |
Arthur O'Dwyer | 20638cc | 2021-02-09 19:12:16 -0500 | [diff] [blame] | 327 | explicit back_insert_iterator(Container& x); // constexpr in C++20 |
| 328 | back_insert_iterator& operator=(const typename Container::value_type& value); // constexpr in C++20 |
| 329 | back_insert_iterator& operator*(); // constexpr in C++20 |
| 330 | back_insert_iterator& operator++(); // constexpr in C++20 |
| 331 | back_insert_iterator operator++(int); // constexpr in C++20 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 332 | }; |
| 333 | |
Arthur O'Dwyer | 20638cc | 2021-02-09 19:12:16 -0500 | [diff] [blame] | 334 | template <class Container> back_insert_iterator<Container> back_inserter(Container& x); // constexpr in C++20 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 335 | |
| 336 | template <class Container> |
| 337 | class front_insert_iterator |
Louis Dionne | 3402c3c | 2021-05-27 12:56:12 -0400 | [diff] [blame] | 338 | : public iterator<output_iterator_tag, void, void, void, void> // until C++17 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 339 | { |
| 340 | protected: |
| 341 | Container* container; |
| 342 | public: |
| 343 | typedef Container container_type; |
| 344 | typedef void value_type; |
Louis Dionne | 3402c3c | 2021-05-27 12:56:12 -0400 | [diff] [blame] | 345 | typedef void difference_type; // until C++20 |
| 346 | typedef ptrdiff_t difference_type; // since C++20 |
Eric Fiselier | 9aeea87 | 2016-06-30 04:40:50 +0000 | [diff] [blame] | 347 | typedef void reference; |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 348 | typedef void pointer; |
| 349 | |
Arthur O'Dwyer | 20638cc | 2021-02-09 19:12:16 -0500 | [diff] [blame] | 350 | explicit front_insert_iterator(Container& x); // constexpr in C++20 |
| 351 | front_insert_iterator& operator=(const typename Container::value_type& value); // constexpr in C++20 |
| 352 | front_insert_iterator& operator*(); // constexpr in C++20 |
| 353 | front_insert_iterator& operator++(); // constexpr in C++20 |
| 354 | front_insert_iterator operator++(int); // constexpr in C++20 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 355 | }; |
| 356 | |
Arthur O'Dwyer | 20638cc | 2021-02-09 19:12:16 -0500 | [diff] [blame] | 357 | template <class Container> front_insert_iterator<Container> front_inserter(Container& x); // constexpr in C++20 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 358 | |
| 359 | template <class Container> |
| 360 | class insert_iterator |
Louis Dionne | 3402c3c | 2021-05-27 12:56:12 -0400 | [diff] [blame] | 361 | : public iterator<output_iterator_tag, void, void, void, void> // until C++17 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 362 | { |
| 363 | protected: |
| 364 | Container* container; |
| 365 | typename Container::iterator iter; |
| 366 | public: |
| 367 | typedef Container container_type; |
| 368 | typedef void value_type; |
Louis Dionne | 3402c3c | 2021-05-27 12:56:12 -0400 | [diff] [blame] | 369 | typedef void difference_type; // until C++20 |
| 370 | typedef ptrdiff_t difference_type; // since C++20 |
Eric Fiselier | 9aeea87 | 2016-06-30 04:40:50 +0000 | [diff] [blame] | 371 | typedef void reference; |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 372 | typedef void pointer; |
| 373 | |
Arthur O'Dwyer | 20638cc | 2021-02-09 19:12:16 -0500 | [diff] [blame] | 374 | insert_iterator(Container& x, typename Container::iterator i); // constexpr in C++20 |
| 375 | insert_iterator& operator=(const typename Container::value_type& value); // constexpr in C++20 |
| 376 | insert_iterator& operator*(); // constexpr in C++20 |
| 377 | insert_iterator& operator++(); // constexpr in C++20 |
| 378 | insert_iterator& operator++(int); // constexpr in C++20 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 379 | }; |
| 380 | |
Konstantin Varlamov | eb3faed | 2022-02-10 18:43:43 -0800 | [diff] [blame] | 381 | template <class Container> |
| 382 | insert_iterator<Container> inserter(Container& x, typename Container::iterator i); // until C++20 |
| 383 | template <class Container> |
| 384 | constexpr insert_iterator<Container> inserter(Container& x, ranges::iterator_t<Container> i); // since C++20 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 385 | |
Marshall Clow | f8fec4e | 2016-07-08 16:54:47 +0000 | [diff] [blame] | 386 | template <class Iterator> |
| 387 | class move_iterator { |
| 388 | public: |
Konstantin Varlamov | 2c7e7ba | 2022-05-24 19:56:02 -0700 | [diff] [blame] | 389 | using iterator_type = Iterator; |
| 390 | using iterator_concept = input_iterator_tag; // From C++20 |
| 391 | using iterator_category = see below; // not always present starting from C++20 |
| 392 | using value_type = iter_value_t<Iterator>; // Until C++20, iterator_traits<Iterator>::value_type |
| 393 | using difference_type = iter_difference_t<Iterator>; // Until C++20, iterator_traits<Iterator>::difference_type; |
| 394 | using pointer = Iterator; |
| 395 | using reference = iter_rvalue_reference_t<Iterator>; // Until C++20, value_type&& |
Louis Dionne | 173f29e | 2019-05-29 16:01:36 +0000 | [diff] [blame] | 396 | |
Marshall Clow | b5f9912 | 2016-11-02 15:30:26 +0000 | [diff] [blame] | 397 | constexpr move_iterator(); // all the constexprs are in C++17 |
| 398 | constexpr explicit move_iterator(Iterator i); |
| 399 | template <class U> |
| 400 | constexpr move_iterator(const move_iterator<U>& u); |
| 401 | template <class U> |
| 402 | constexpr move_iterator& operator=(const move_iterator<U>& u); |
Konstantin Varlamov | 2c7e7ba | 2022-05-24 19:56:02 -0700 | [diff] [blame] | 403 | |
| 404 | constexpr iterator_type base() const; // Until C++20 |
| 405 | constexpr const Iterator& base() const & noexcept; // From C++20 |
| 406 | constexpr Iterator base() &&; // From C++20 |
| 407 | |
Marshall Clow | b5f9912 | 2016-11-02 15:30:26 +0000 | [diff] [blame] | 408 | constexpr reference operator*() const; |
Konstantin Varlamov | 2c7e7ba | 2022-05-24 19:56:02 -0700 | [diff] [blame] | 409 | constexpr pointer operator->() const; // Removed in C++20 |
Marshall Clow | b5f9912 | 2016-11-02 15:30:26 +0000 | [diff] [blame] | 410 | constexpr move_iterator& operator++(); |
Konstantin Varlamov | 2c7e7ba | 2022-05-24 19:56:02 -0700 | [diff] [blame] | 411 | constexpr auto operator++(int); // Return type was move_iterator until C++20 |
Marshall Clow | b5f9912 | 2016-11-02 15:30:26 +0000 | [diff] [blame] | 412 | constexpr move_iterator& operator--(); |
| 413 | constexpr move_iterator operator--(int); |
Louis Dionne | 173f29e | 2019-05-29 16:01:36 +0000 | [diff] [blame] | 414 | constexpr move_iterator operator+(difference_type n) const; |
| 415 | constexpr move_iterator& operator+=(difference_type n); |
| 416 | constexpr move_iterator operator-(difference_type n) const; |
| 417 | constexpr move_iterator& operator-=(difference_type n); |
Konstantin Varlamov | 2c7e7ba | 2022-05-24 19:56:02 -0700 | [diff] [blame] | 418 | constexpr reference operator[](difference_type n) const; // Return type unspecified until C++20 |
| 419 | |
| 420 | template<sentinel_for<Iterator> S> |
| 421 | friend constexpr bool |
| 422 | operator==(const move_iterator& x, const move_sentinel<S>& y); // Since C++20 |
| 423 | template<sized_sentinel_for<Iterator> S> |
| 424 | friend constexpr iter_difference_t<Iterator> |
| 425 | operator-(const move_sentinel<S>& x, const move_iterator& y); // Since C++20 |
| 426 | template<sized_sentinel_for<Iterator> S> |
| 427 | friend constexpr iter_difference_t<Iterator> |
| 428 | operator-(const move_iterator& x, const move_sentinel<S>& y); // Since C++20 |
| 429 | friend constexpr iter_rvalue_reference_t<Iterator> |
| 430 | iter_move(const move_iterator& i) |
| 431 | noexcept(noexcept(ranges::iter_move(i.current))); // Since C++20 |
| 432 | template<indirectly_swappable<Iterator> Iterator2> |
| 433 | friend constexpr void |
| 434 | iter_swap(const move_iterator& x, const move_iterator<Iterator2>& y) |
| 435 | noexcept(noexcept(ranges::iter_swap(x.current, y.current))); // Since C++20 |
| 436 | |
Marshall Clow | f8fec4e | 2016-07-08 16:54:47 +0000 | [diff] [blame] | 437 | private: |
| 438 | Iterator current; // exposition only |
| 439 | }; |
| 440 | |
| 441 | template <class Iterator1, class Iterator2> |
Marshall Clow | b5f9912 | 2016-11-02 15:30:26 +0000 | [diff] [blame] | 442 | constexpr bool // constexpr in C++17 |
Marshall Clow | f8fec4e | 2016-07-08 16:54:47 +0000 | [diff] [blame] | 443 | operator==(const move_iterator<Iterator1>& x, const move_iterator<Iterator2>& y); |
| 444 | |
| 445 | template <class Iterator1, class Iterator2> |
Marshall Clow | b5f9912 | 2016-11-02 15:30:26 +0000 | [diff] [blame] | 446 | constexpr bool // constexpr in C++17 |
Marshall Clow | f8fec4e | 2016-07-08 16:54:47 +0000 | [diff] [blame] | 447 | operator!=(const move_iterator<Iterator1>& x, const move_iterator<Iterator2>& y); |
| 448 | |
| 449 | template <class Iterator1, class Iterator2> |
Marshall Clow | b5f9912 | 2016-11-02 15:30:26 +0000 | [diff] [blame] | 450 | constexpr bool // constexpr in C++17 |
Marshall Clow | f8fec4e | 2016-07-08 16:54:47 +0000 | [diff] [blame] | 451 | operator<(const move_iterator<Iterator1>& x, const move_iterator<Iterator2>& y); |
| 452 | |
| 453 | template <class Iterator1, class Iterator2> |
Marshall Clow | b5f9912 | 2016-11-02 15:30:26 +0000 | [diff] [blame] | 454 | constexpr bool // constexpr in C++17 |
Marshall Clow | f8fec4e | 2016-07-08 16:54:47 +0000 | [diff] [blame] | 455 | operator<=(const move_iterator<Iterator1>& x, const move_iterator<Iterator2>& y); |
| 456 | |
| 457 | template <class Iterator1, class Iterator2> |
Marshall Clow | b5f9912 | 2016-11-02 15:30:26 +0000 | [diff] [blame] | 458 | constexpr bool // constexpr in C++17 |
Marshall Clow | f8fec4e | 2016-07-08 16:54:47 +0000 | [diff] [blame] | 459 | operator>(const move_iterator<Iterator1>& x, const move_iterator<Iterator2>& y); |
| 460 | |
| 461 | template <class Iterator1, class Iterator2> |
Marshall Clow | b5f9912 | 2016-11-02 15:30:26 +0000 | [diff] [blame] | 462 | constexpr bool // constexpr in C++17 |
Marshall Clow | f8fec4e | 2016-07-08 16:54:47 +0000 | [diff] [blame] | 463 | operator>=(const move_iterator<Iterator1>& x, const move_iterator<Iterator2>& y); |
| 464 | |
| 465 | template <class Iterator1, class Iterator2> |
Marshall Clow | b5f9912 | 2016-11-02 15:30:26 +0000 | [diff] [blame] | 466 | constexpr auto // constexpr in C++17 |
Marshall Clow | f8fec4e | 2016-07-08 16:54:47 +0000 | [diff] [blame] | 467 | operator-(const move_iterator<Iterator1>& x, |
| 468 | const move_iterator<Iterator2>& y) -> decltype(x.base() - y.base()); |
| 469 | |
| 470 | template <class Iterator> |
Marshall Clow | b5f9912 | 2016-11-02 15:30:26 +0000 | [diff] [blame] | 471 | constexpr move_iterator<Iterator> operator+( // constexpr in C++17 |
Louis Dionne | 173f29e | 2019-05-29 16:01:36 +0000 | [diff] [blame] | 472 | typename move_iterator<Iterator>::difference_type n, |
Marshall Clow | b5f9912 | 2016-11-02 15:30:26 +0000 | [diff] [blame] | 473 | const move_iterator<Iterator>& x); |
Marshall Clow | f8fec4e | 2016-07-08 16:54:47 +0000 | [diff] [blame] | 474 | |
Marshall Clow | b5f9912 | 2016-11-02 15:30:26 +0000 | [diff] [blame] | 475 | template <class Iterator> // constexpr in C++17 |
| 476 | constexpr move_iterator<Iterator> make_move_iterator(const Iterator& i); |
Marshall Clow | f8fec4e | 2016-07-08 16:54:47 +0000 | [diff] [blame] | 477 | |
Konstantin Varlamov | 2c7e7ba | 2022-05-24 19:56:02 -0700 | [diff] [blame] | 478 | template<semiregular S> |
| 479 | class move_sentinel { |
| 480 | public: |
| 481 | constexpr move_sentinel(); |
| 482 | constexpr explicit move_sentinel(S s); |
| 483 | template<class S2> |
| 484 | requires convertible_to<const S2&, S> |
| 485 | constexpr move_sentinel(const move_sentinel<S2>& s); |
| 486 | template<class S2> |
| 487 | requires assignable_from<S&, const S2&> |
| 488 | constexpr move_sentinel& operator=(const move_sentinel<S2>& s); |
| 489 | |
| 490 | constexpr S base() const; |
| 491 | private: |
| 492 | S last; // exposition only |
| 493 | }; |
| 494 | |
zoecarver | 63f1320 | 2021-06-01 12:55:33 -0700 | [diff] [blame] | 495 | // [default.sentinel], default sentinel |
| 496 | struct default_sentinel_t; |
| 497 | inline constexpr default_sentinel_t default_sentinel{}; |
Marshall Clow | f8fec4e | 2016-07-08 16:54:47 +0000 | [diff] [blame] | 498 | |
zoecarver | d3aca59 | 2021-07-13 11:06:10 -0700 | [diff] [blame] | 499 | // [iterators.counted], counted iterators |
| 500 | template<input_or_output_iterator I> class counted_iterator; |
| 501 | |
| 502 | template<input_iterator I> |
| 503 | requires see below |
| 504 | struct iterator_traits<counted_iterator<I>>; |
| 505 | |
zoecarver | 23001f7 | 2021-08-11 11:16:27 -0700 | [diff] [blame] | 506 | // [unreachable.sentinel], unreachable sentinel |
| 507 | struct unreachable_sentinel_t; |
| 508 | inline constexpr unreachable_sentinel_t unreachable_sentinel{}; |
| 509 | |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 510 | template <class T, class charT = char, class traits = char_traits<charT>, class Distance = ptrdiff_t> |
| 511 | class istream_iterator |
Louis Dionne | 8762e2b | 2021-05-25 18:15:58 -0400 | [diff] [blame] | 512 | : public iterator<input_iterator_tag, T, Distance, const T*, const T&> // until C++17 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 513 | { |
| 514 | public: |
Louis Dionne | 3402c3c | 2021-05-27 12:56:12 -0400 | [diff] [blame] | 515 | typedef input_iterator_tag iterator_category; |
| 516 | typedef T value_type; |
| 517 | typedef Distance difference_type; |
| 518 | typedef const T* pointer; |
| 519 | typedef const T& reference; |
| 520 | |
| 521 | typedef charT char_type; |
| 522 | typedef traits traits_type; |
| 523 | typedef basic_istream<charT, traits> istream_type; |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 524 | |
Konstantin Varlamov | 02f89d5 | 2022-02-15 16:59:16 -0800 | [diff] [blame] | 525 | istream_iterator(); // constexpr since C++11 |
| 526 | constexpr istream_iterator(default_sentinel_t); // since C++20 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 527 | istream_iterator(istream_type& s); |
| 528 | istream_iterator(const istream_iterator& x); |
| 529 | ~istream_iterator(); |
| 530 | |
| 531 | const T& operator*() const; |
| 532 | const T* operator->() const; |
| 533 | istream_iterator& operator++(); |
| 534 | istream_iterator operator++(int); |
Konstantin Varlamov | 02f89d5 | 2022-02-15 16:59:16 -0800 | [diff] [blame] | 535 | friend bool operator==(const istream_iterator& i, default_sentinel_t); // since C++20 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 536 | }; |
| 537 | |
| 538 | template <class T, class charT, class traits, class Distance> |
| 539 | bool operator==(const istream_iterator<T,charT,traits,Distance>& x, |
| 540 | const istream_iterator<T,charT,traits,Distance>& y); |
| 541 | template <class T, class charT, class traits, class Distance> |
| 542 | bool operator!=(const istream_iterator<T,charT,traits,Distance>& x, |
Konstantin Varlamov | 02f89d5 | 2022-02-15 16:59:16 -0800 | [diff] [blame] | 543 | const istream_iterator<T,charT,traits,Distance>& y); // until C++20 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 544 | |
| 545 | template <class T, class charT = char, class traits = char_traits<charT> > |
| 546 | class ostream_iterator |
Louis Dionne | 3402c3c | 2021-05-27 12:56:12 -0400 | [diff] [blame] | 547 | : public iterator<output_iterator_tag, void, void, void, void> // until C++17 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 548 | { |
| 549 | public: |
Louis Dionne | 3402c3c | 2021-05-27 12:56:12 -0400 | [diff] [blame] | 550 | typedef output_iterator_tag iterator_category; |
| 551 | typedef void value_type; |
| 552 | typedef void difference_type; // until C++20 |
| 553 | typedef ptrdiff_t difference_type; // since C++20 |
| 554 | typedef void pointer; |
| 555 | typedef void reference; |
| 556 | |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 557 | typedef charT char_type; |
| 558 | typedef traits traits_type; |
| 559 | typedef basic_ostream<charT,traits> ostream_type; |
| 560 | |
| 561 | ostream_iterator(ostream_type& s); |
| 562 | ostream_iterator(ostream_type& s, const charT* delimiter); |
| 563 | ostream_iterator(const ostream_iterator& x); |
| 564 | ~ostream_iterator(); |
| 565 | ostream_iterator& operator=(const T& value); |
| 566 | |
| 567 | ostream_iterator& operator*(); |
| 568 | ostream_iterator& operator++(); |
| 569 | ostream_iterator& operator++(int); |
| 570 | }; |
| 571 | |
| 572 | template<class charT, class traits = char_traits<charT> > |
| 573 | class istreambuf_iterator |
Louis Dionne | 3402c3c | 2021-05-27 12:56:12 -0400 | [diff] [blame] | 574 | : public iterator<input_iterator_tag, charT, traits::off_type, unspecified, charT> // until C++17 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 575 | { |
| 576 | public: |
Louis Dionne | 3402c3c | 2021-05-27 12:56:12 -0400 | [diff] [blame] | 577 | typedef input_iterator_tag iterator_category; |
| 578 | typedef charT value_type; |
| 579 | typedef traits::off_type difference_type; |
| 580 | typedef unspecified pointer; |
| 581 | typedef charT reference; |
| 582 | |
| 583 | typedef charT char_type; |
| 584 | typedef traits traits_type; |
| 585 | typedef traits::int_type int_type; |
| 586 | typedef basic_streambuf<charT, traits> streambuf_type; |
| 587 | typedef basic_istream<charT, traits> istream_type; |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 588 | |
Konstantin Varlamov | 02f89d5 | 2022-02-15 16:59:16 -0800 | [diff] [blame] | 589 | istreambuf_iterator() noexcept; // constexpr since C++11 |
| 590 | constexpr istreambuf_iterator(default_sentinel_t) noexcept; // since C++20 |
Howard Hinnant | 011138d | 2012-07-20 19:36:34 +0000 | [diff] [blame] | 591 | istreambuf_iterator(istream_type& s) noexcept; |
| 592 | istreambuf_iterator(streambuf_type* s) noexcept; |
| 593 | istreambuf_iterator(a-private-type) noexcept; |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 594 | |
| 595 | charT operator*() const; |
| 596 | pointer operator->() const; |
| 597 | istreambuf_iterator& operator++(); |
| 598 | a-private-type operator++(int); |
| 599 | |
| 600 | bool equal(const istreambuf_iterator& b) const; |
Konstantin Varlamov | 02f89d5 | 2022-02-15 16:59:16 -0800 | [diff] [blame] | 601 | friend bool operator==(const istreambuf_iterator& i, default_sentinel_t s); // since C++20 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 602 | }; |
| 603 | |
| 604 | template <class charT, class traits> |
| 605 | bool operator==(const istreambuf_iterator<charT,traits>& a, |
| 606 | const istreambuf_iterator<charT,traits>& b); |
| 607 | template <class charT, class traits> |
| 608 | bool operator!=(const istreambuf_iterator<charT,traits>& a, |
Konstantin Varlamov | 02f89d5 | 2022-02-15 16:59:16 -0800 | [diff] [blame] | 609 | const istreambuf_iterator<charT,traits>& b); // until C++20 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 610 | |
| 611 | template <class charT, class traits = char_traits<charT> > |
| 612 | class ostreambuf_iterator |
Louis Dionne | 8762e2b | 2021-05-25 18:15:58 -0400 | [diff] [blame] | 613 | : public iterator<output_iterator_tag, void, void, void, void> // until C++17 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 614 | { |
| 615 | public: |
Louis Dionne | 3402c3c | 2021-05-27 12:56:12 -0400 | [diff] [blame] | 616 | typedef output_iterator_tag iterator_category; |
| 617 | typedef void value_type; |
| 618 | typedef void difference_type; // until C++20 |
| 619 | typedef ptrdiff_t difference_type; // since C++20 |
| 620 | typedef void pointer; |
| 621 | typedef void reference; |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 622 | |
Louis Dionne | 3402c3c | 2021-05-27 12:56:12 -0400 | [diff] [blame] | 623 | typedef charT char_type; |
| 624 | typedef traits traits_type; |
| 625 | typedef basic_streambuf<charT, traits> streambuf_type; |
| 626 | typedef basic_ostream<charT, traits> ostream_type; |
| 627 | |
Howard Hinnant | 011138d | 2012-07-20 19:36:34 +0000 | [diff] [blame] | 628 | ostreambuf_iterator(ostream_type& s) noexcept; |
| 629 | ostreambuf_iterator(streambuf_type* s) noexcept; |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 630 | ostreambuf_iterator& operator=(charT c); |
| 631 | ostreambuf_iterator& operator*(); |
| 632 | ostreambuf_iterator& operator++(); |
| 633 | ostreambuf_iterator& operator++(int); |
Howard Hinnant | 011138d | 2012-07-20 19:36:34 +0000 | [diff] [blame] | 634 | bool failed() const noexcept; |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 635 | }; |
| 636 | |
Marshall Clow | 99ba002 | 2017-01-04 17:58:17 +0000 | [diff] [blame] | 637 | template <class C> constexpr auto begin(C& c) -> decltype(c.begin()); |
| 638 | template <class C> constexpr auto begin(const C& c) -> decltype(c.begin()); |
| 639 | template <class C> constexpr auto end(C& c) -> decltype(c.end()); |
| 640 | template <class C> constexpr auto end(const C& c) -> decltype(c.end()); |
| 641 | template <class T, size_t N> constexpr T* begin(T (&array)[N]); |
| 642 | template <class T, size_t N> constexpr T* end(T (&array)[N]); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 643 | |
Marshall Clow | 99ba002 | 2017-01-04 17:58:17 +0000 | [diff] [blame] | 644 | template <class C> auto constexpr cbegin(const C& c) -> decltype(std::begin(c)); // C++14 |
| 645 | template <class C> auto constexpr cend(const C& c) -> decltype(std::end(c)); // C++14 |
| 646 | template <class C> auto constexpr rbegin(C& c) -> decltype(c.rbegin()); // C++14 |
| 647 | template <class C> auto constexpr rbegin(const C& c) -> decltype(c.rbegin()); // C++14 |
| 648 | template <class C> auto constexpr rend(C& c) -> decltype(c.rend()); // C++14 |
| 649 | template <class C> constexpr auto rend(const C& c) -> decltype(c.rend()); // C++14 |
| 650 | template <class E> reverse_iterator<const E*> constexpr rbegin(initializer_list<E> il); // C++14 |
| 651 | template <class E> reverse_iterator<const E*> constexpr rend(initializer_list<E> il); // C++14 |
| 652 | template <class T, size_t N> reverse_iterator<T*> constexpr rbegin(T (&array)[N]); // C++14 |
| 653 | template <class T, size_t N> reverse_iterator<T*> constexpr rend(T (&array)[N]); // C++14 |
| 654 | template <class C> constexpr auto crbegin(const C& c) -> decltype(std::rbegin(c)); // C++14 |
| 655 | template <class C> constexpr auto crend(const C& c) -> decltype(std::rend(c)); // C++14 |
Marshall Clow | b278e9c | 2013-08-30 01:17:07 +0000 | [diff] [blame] | 656 | |
Marshall Clow | ef35727 | 2014-11-19 19:43:23 +0000 | [diff] [blame] | 657 | // 24.8, container access: |
| 658 | template <class C> constexpr auto size(const C& c) -> decltype(c.size()); // C++17 |
| 659 | template <class T, size_t N> constexpr size_t size(const T (&array)[N]) noexcept; // C++17 |
Marshall Clow | 3c5363e | 2019-02-27 02:58:56 +0000 | [diff] [blame] | 660 | |
| 661 | template <class C> constexpr auto ssize(const C& c) |
Arthur O'Dwyer | 2fc9b5d | 2021-04-17 17:03:20 -0400 | [diff] [blame] | 662 | -> common_type_t<ptrdiff_t, make_signed_t<decltype(c.size())>>; // C++20 |
Marshall Clow | 3c5363e | 2019-02-27 02:58:56 +0000 | [diff] [blame] | 663 | template <class T, ptrdiff_t> constexpr ptrdiff_t ssize(const T (&array)[N]) noexcept; // C++20 |
| 664 | |
Marshall Clow | ef35727 | 2014-11-19 19:43:23 +0000 | [diff] [blame] | 665 | template <class C> constexpr auto empty(const C& c) -> decltype(c.empty()); // C++17 |
| 666 | template <class T, size_t N> constexpr bool empty(const T (&array)[N]) noexcept; // C++17 |
| 667 | template <class E> constexpr bool empty(initializer_list<E> il) noexcept; // C++17 |
| 668 | template <class C> constexpr auto data(C& c) -> decltype(c.data()); // C++17 |
| 669 | template <class C> constexpr auto data(const C& c) -> decltype(c.data()); // C++17 |
| 670 | template <class T, size_t N> constexpr T* data(T (&array)[N]) noexcept; // C++17 |
| 671 | template <class E> constexpr const E* data(initializer_list<E> il) noexcept; // C++17 |
| 672 | |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 673 | } // std |
| 674 | |
| 675 | */ |
| 676 | |
Louis Dionne | b4fce35 | 2022-03-25 12:55:36 -0400 | [diff] [blame] | 677 | #include <__assert> // all public C++ headers provide the assertion handler |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 678 | #include <__config> |
Arthur O'Dwyer | a2f99ee | 2021-04-29 17:40:17 -0400 | [diff] [blame] | 679 | #include <__debug> |
Christopher Di Bella | c7674cd | 2021-06-29 02:32:59 +0000 | [diff] [blame] | 680 | #include <__iterator/access.h> |
Christopher Di Bella | c6ead65 | 2021-05-05 07:14:08 +0000 | [diff] [blame] | 681 | #include <__iterator/advance.h> |
Louis Dionne | 7724952 | 2021-06-11 09:55:11 -0400 | [diff] [blame] | 682 | #include <__iterator/back_insert_iterator.h> |
zoecarver | 6eb71a9 | 2021-05-27 09:23:19 -0700 | [diff] [blame] | 683 | #include <__iterator/common_iterator.h> |
Louis Dionne | 463afb8 | 2021-04-22 11:05:30 -0400 | [diff] [blame] | 684 | #include <__iterator/concepts.h> |
zoecarver | d3aca59 | 2021-07-13 11:06:10 -0700 | [diff] [blame] | 685 | #include <__iterator/counted_iterator.h> |
Christopher Di Bella | c7674cd | 2021-06-29 02:32:59 +0000 | [diff] [blame] | 686 | #include <__iterator/data.h> |
zoecarver | 63f1320 | 2021-06-01 12:55:33 -0700 | [diff] [blame] | 687 | #include <__iterator/default_sentinel.h> |
Christopher Di Bella | c7674cd | 2021-06-29 02:32:59 +0000 | [diff] [blame] | 688 | #include <__iterator/distance.h> |
| 689 | #include <__iterator/empty.h> |
| 690 | #include <__iterator/erase_if_container.h> |
Louis Dionne | 7724952 | 2021-06-11 09:55:11 -0400 | [diff] [blame] | 691 | #include <__iterator/front_insert_iterator.h> |
zoecarver | 61ae1dc | 2021-04-19 14:28:27 -0400 | [diff] [blame] | 692 | #include <__iterator/incrementable_traits.h> |
Nikolas Klauser | 764ac5e | 2022-01-04 19:55:37 +0100 | [diff] [blame] | 693 | #include <__iterator/indirectly_comparable.h> |
Louis Dionne | 7724952 | 2021-06-11 09:55:11 -0400 | [diff] [blame] | 694 | #include <__iterator/insert_iterator.h> |
Christopher Di Bella | c7674cd | 2021-06-29 02:32:59 +0000 | [diff] [blame] | 695 | #include <__iterator/istream_iterator.h> |
Arthur O'Dwyer | 65077c0 | 2022-01-07 09:45:05 -0500 | [diff] [blame] | 696 | #include <__iterator/istreambuf_iterator.h> |
Louis Dionne | ca989a5 | 2021-04-20 14:40:43 -0400 | [diff] [blame] | 697 | #include <__iterator/iter_move.h> |
zoecarver | 31f4f5d | 2021-05-18 16:18:18 -0700 | [diff] [blame] | 698 | #include <__iterator/iter_swap.h> |
Arthur O'Dwyer | 65077c0 | 2022-01-07 09:45:05 -0500 | [diff] [blame] | 699 | #include <__iterator/iterator.h> |
| 700 | #include <__iterator/iterator_traits.h> |
Konstantin Varlamov | 73b5c16 | 2022-02-17 20:11:46 -0800 | [diff] [blame] | 701 | #include <__iterator/mergeable.h> |
Louis Dionne | 7724952 | 2021-06-11 09:55:11 -0400 | [diff] [blame] | 702 | #include <__iterator/move_iterator.h> |
Arthur O'Dwyer | 6b240aa | 2022-01-19 06:26:52 -0500 | [diff] [blame] | 703 | #include <__iterator/move_sentinel.h> |
Christopher Di Bella | 9c0adab | 2021-05-08 05:02:43 +0000 | [diff] [blame] | 704 | #include <__iterator/next.h> |
Christopher Di Bella | c7674cd | 2021-06-29 02:32:59 +0000 | [diff] [blame] | 705 | #include <__iterator/ostream_iterator.h> |
Arthur O'Dwyer | 65077c0 | 2022-01-07 09:45:05 -0500 | [diff] [blame] | 706 | #include <__iterator/ostreambuf_iterator.h> |
Konstantin Varlamov | ea9734e | 2022-02-09 20:32:56 -0800 | [diff] [blame] | 707 | #include <__iterator/permutable.h> |
Christopher Di Bella | b8e2104 | 2021-05-16 01:39:22 +0000 | [diff] [blame] | 708 | #include <__iterator/prev.h> |
Louis Dionne | 170a03c | 2021-04-28 15:02:08 -0400 | [diff] [blame] | 709 | #include <__iterator/projected.h> |
zoecarver | 61ae1dc | 2021-04-19 14:28:27 -0400 | [diff] [blame] | 710 | #include <__iterator/readable_traits.h> |
Christopher Di Bella | c7674cd | 2021-06-29 02:32:59 +0000 | [diff] [blame] | 711 | #include <__iterator/reverse_access.h> |
Louis Dionne | 7724952 | 2021-06-11 09:55:11 -0400 | [diff] [blame] | 712 | #include <__iterator/reverse_iterator.h> |
Christopher Di Bella | c7674cd | 2021-06-29 02:32:59 +0000 | [diff] [blame] | 713 | #include <__iterator/size.h> |
Konstantin Varlamov | 1755e8d | 2022-02-17 20:15:02 -0800 | [diff] [blame] | 714 | #include <__iterator/sortable.h> |
zoecarver | 23001f7 | 2021-08-11 11:16:27 -0700 | [diff] [blame] | 715 | #include <__iterator/unreachable_sentinel.h> |
Louis Dionne | 7724952 | 2021-06-11 09:55:11 -0400 | [diff] [blame] | 716 | #include <__iterator/wrap_iter.h> |
Louis Dionne | 735bc46 | 2021-04-14 13:59:03 -0400 | [diff] [blame] | 717 | #include <__memory/addressof.h> |
Arthur O'Dwyer | 1ac9f09 | 2021-01-15 12:59:56 -0500 | [diff] [blame] | 718 | #include <__memory/pointer_traits.h> |
Arthur O'Dwyer | a2f99ee | 2021-04-29 17:40:17 -0400 | [diff] [blame] | 719 | #include <compare> |
| 720 | #include <concepts> // Mandated by the Standard. |
| 721 | #include <cstddef> |
| 722 | #include <initializer_list> |
Arthur O'Dwyer | a2f99ee | 2021-04-29 17:40:17 -0400 | [diff] [blame] | 723 | #include <type_traits> |
Marshall Clow | 0a1e750 | 2018-09-12 19:41:40 +0000 | [diff] [blame] | 724 | #include <version> |
Howard Hinnant | 48fd5d5 | 2012-11-14 21:17:15 +0000 | [diff] [blame] | 725 | |
Howard Hinnant | aaaa52b | 2011-10-17 20:05:10 +0000 | [diff] [blame] | 726 | #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) |
Arthur O'Dwyer | 6eeaa00 | 2022-02-01 20:16:40 -0500 | [diff] [blame] | 727 | # pragma GCC system_header |
Howard Hinnant | aaaa52b | 2011-10-17 20:05:10 +0000 | [diff] [blame] | 728 | #endif |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 729 | |
Louis Dionne | 2b1ceaa | 2021-04-20 12:03:32 -0400 | [diff] [blame] | 730 | #endif // _LIBCPP_ITERATOR |