Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1 | // -*- C++ -*- |
| 2 | //===-------------------------- iterator ----------------------------------===// |
| 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 | |
Christopher Di Bella | 8f1370d | 2021-04-11 22:11:03 +0000 | [diff] [blame] | 86 | // [iterator.concept.forward], concept forward_iterator |
| 87 | template<class I> |
| 88 | concept forward_iterator = see below; // since C++20 |
| 89 | |
Christopher Di Bella | 10a3147 | 2021-04-12 01:16:45 +0000 | [diff] [blame] | 90 | // [iterator.concept.bidir], concept bidirectional_iterator |
| 91 | template<class I> |
| 92 | concept bidirectional_iterator = see below; // since C++20 |
| 93 | |
zoecarver | 21da57e | 2021-04-23 17:11:44 -0700 | [diff] [blame] | 94 | // [iterator.concept.random.access], concept random_access_iterator |
| 95 | template<class I> |
| 96 | concept random_access_iterator = see below; // since C++20 |
| 97 | |
Louis Dionne | 170a03c | 2021-04-28 15:02:08 -0400 | [diff] [blame] | 98 | // [indirectcallable] |
| 99 | // [indirectcallable.indirectinvocable] |
| 100 | template<class F, class I> |
| 101 | concept indirectly_unary_invocable = see below; // since C++20 |
| 102 | |
| 103 | template<class F, class I> |
| 104 | concept indirectly_regular_unary_invocable = see below; // since C++20 |
| 105 | |
| 106 | template<class F, class I> |
| 107 | concept indirect_unary_predicate = see below; // since C++20 |
| 108 | |
| 109 | template<class F, class I1, class I2> |
| 110 | concept indirect_binary_predicate = see below; // since C++20 |
| 111 | |
| 112 | template<class F, class I1, class I2 = I1> |
| 113 | concept indirect_equivalence_relation = see below; // since C++20 |
| 114 | |
| 115 | template<class F, class I1, class I2 = I1> |
| 116 | concept indirect_strict_weak_order = see below; // since C++20 |
| 117 | |
| 118 | template<class F, class... Is> |
| 119 | using indirect_result_t = see below; // since C++20 |
| 120 | |
| 121 | // [projected], projected |
| 122 | template<indirectly_readable I, indirectly_regular_unary_invocable<I> Proj> |
| 123 | struct projected; // since C++20 |
| 124 | |
| 125 | template<weakly_incrementable I, indirectly_regular_unary_invocable<I> Proj> |
| 126 | struct incrementable_traits<projected<I, Proj>>; // since C++20 |
| 127 | |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 128 | template<class Category, class T, class Distance = ptrdiff_t, |
| 129 | class Pointer = T*, class Reference = T&> |
Louis Dionne | 8762e2b | 2021-05-25 18:15:58 -0400 | [diff] [blame] | 130 | struct iterator // deprecated in C++17 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 131 | { |
| 132 | typedef T value_type; |
| 133 | typedef Distance difference_type; |
| 134 | typedef Pointer pointer; |
| 135 | typedef Reference reference; |
| 136 | typedef Category iterator_category; |
| 137 | }; |
| 138 | |
| 139 | struct input_iterator_tag {}; |
| 140 | struct output_iterator_tag {}; |
| 141 | struct forward_iterator_tag : public input_iterator_tag {}; |
| 142 | struct bidirectional_iterator_tag : public forward_iterator_tag {}; |
| 143 | struct random_access_iterator_tag : public bidirectional_iterator_tag {}; |
| 144 | |
Marshall Clow | 75468e7 | 2017-05-17 18:51:36 +0000 | [diff] [blame] | 145 | // 27.4.3, iterator operations |
Louis Dionne | 4576866 | 2020-06-08 16:16:01 -0400 | [diff] [blame] | 146 | template <class InputIterator, class Distance> // constexpr in C++17 |
| 147 | constexpr void advance(InputIterator& i, Distance n); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 148 | |
Marshall Clow | 75468e7 | 2017-05-17 18:51:36 +0000 | [diff] [blame] | 149 | template <class InputIterator> // constexpr in C++17 |
| 150 | constexpr typename iterator_traits<InputIterator>::difference_type |
| 151 | distance(InputIterator first, InputIterator last); |
| 152 | |
| 153 | template <class InputIterator> // constexpr in C++17 |
| 154 | constexpr InputIterator next(InputIterator x, |
| 155 | typename iterator_traits<InputIterator>::difference_type n = 1); |
| 156 | |
| 157 | template <class BidirectionalIterator> // constexpr in C++17 |
| 158 | constexpr BidirectionalIterator prev(BidirectionalIterator x, |
Louis Dionne | 173f29e | 2019-05-29 16:01:36 +0000 | [diff] [blame] | 159 | typename iterator_traits<BidirectionalIterator>::difference_type n = 1); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 160 | |
Christopher Di Bella | c6ead65 | 2021-05-05 07:14:08 +0000 | [diff] [blame] | 161 | // [range.iter.ops], range iterator operations |
| 162 | namespace ranges { |
| 163 | // [range.iter.op.advance], ranges::advance |
| 164 | template<input_or_output_iterator I> |
| 165 | constexpr void advance(I& i, iter_difference_t<I> n); // since C++20 |
| 166 | template<input_or_output_iterator I, sentinel_for<I> S> |
| 167 | constexpr void advance(I& i, S bound); // since C++20 |
| 168 | template<input_or_output_iterator I, sentinel_for<I> S> |
| 169 | constexpr iter_difference_t<I> advance(I& i, iter_difference_t<I> n, S bound); // since C++20 |
| 170 | } |
| 171 | |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 172 | template <class Iterator> |
| 173 | class reverse_iterator |
Louis Dionne | 8762e2b | 2021-05-25 18:15:58 -0400 | [diff] [blame] | 174 | : public iterator<typename iterator_traits<Iterator>::iterator_category, // until C++17 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 175 | typename iterator_traits<Iterator>::value_type, |
| 176 | typename iterator_traits<Iterator>::difference_type, |
| 177 | typename iterator_traits<Iterator>::pointer, |
| 178 | typename iterator_traits<Iterator>::reference> |
| 179 | { |
| 180 | protected: |
| 181 | Iterator current; |
| 182 | public: |
| 183 | typedef Iterator iterator_type; |
| 184 | typedef typename iterator_traits<Iterator>::difference_type difference_type; |
| 185 | typedef typename iterator_traits<Iterator>::reference reference; |
| 186 | typedef typename iterator_traits<Iterator>::pointer pointer; |
Howard Hinnant | 3b6579a | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 187 | |
Marshall Clow | 5ace554 | 2016-10-19 15:12:50 +0000 | [diff] [blame] | 188 | constexpr reverse_iterator(); |
| 189 | constexpr explicit reverse_iterator(Iterator x); |
| 190 | template <class U> constexpr reverse_iterator(const reverse_iterator<U>& u); |
| 191 | template <class U> constexpr reverse_iterator& operator=(const reverse_iterator<U>& u); |
| 192 | constexpr Iterator base() const; |
| 193 | constexpr reference operator*() const; |
| 194 | constexpr pointer operator->() const; |
| 195 | constexpr reverse_iterator& operator++(); |
| 196 | constexpr reverse_iterator operator++(int); |
| 197 | constexpr reverse_iterator& operator--(); |
| 198 | constexpr reverse_iterator operator--(int); |
| 199 | constexpr reverse_iterator operator+ (difference_type n) const; |
| 200 | constexpr reverse_iterator& operator+=(difference_type n); |
| 201 | constexpr reverse_iterator operator- (difference_type n) const; |
| 202 | constexpr reverse_iterator& operator-=(difference_type n); |
| 203 | constexpr reference operator[](difference_type n) const; |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 204 | }; |
| 205 | |
| 206 | template <class Iterator1, class Iterator2> |
Marshall Clow | 5ace554 | 2016-10-19 15:12:50 +0000 | [diff] [blame] | 207 | constexpr bool // constexpr in C++17 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 208 | operator==(const reverse_iterator<Iterator1>& x, const reverse_iterator<Iterator2>& y); |
| 209 | |
| 210 | template <class Iterator1, class Iterator2> |
Marshall Clow | 5ace554 | 2016-10-19 15:12:50 +0000 | [diff] [blame] | 211 | constexpr bool // constexpr in C++17 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 212 | operator<(const reverse_iterator<Iterator1>& x, const reverse_iterator<Iterator2>& y); |
| 213 | |
| 214 | template <class Iterator1, class Iterator2> |
Marshall Clow | 5ace554 | 2016-10-19 15:12:50 +0000 | [diff] [blame] | 215 | constexpr bool // constexpr in C++17 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 216 | operator!=(const reverse_iterator<Iterator1>& x, const reverse_iterator<Iterator2>& y); |
| 217 | |
| 218 | template <class Iterator1, class Iterator2> |
Marshall Clow | 5ace554 | 2016-10-19 15:12:50 +0000 | [diff] [blame] | 219 | constexpr bool // constexpr in C++17 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 220 | operator>(const reverse_iterator<Iterator1>& x, const reverse_iterator<Iterator2>& y); |
| 221 | |
| 222 | template <class Iterator1, class Iterator2> |
Marshall Clow | 5ace554 | 2016-10-19 15:12:50 +0000 | [diff] [blame] | 223 | constexpr bool // constexpr in C++17 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 224 | operator>=(const reverse_iterator<Iterator1>& x, const reverse_iterator<Iterator2>& y); |
| 225 | |
| 226 | template <class Iterator1, class Iterator2> |
Marshall Clow | 5ace554 | 2016-10-19 15:12:50 +0000 | [diff] [blame] | 227 | constexpr bool // constexpr in C++17 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 228 | operator<=(const reverse_iterator<Iterator1>& x, const reverse_iterator<Iterator2>& y); |
| 229 | |
| 230 | template <class Iterator1, class Iterator2> |
Marshall Clow | 5ace554 | 2016-10-19 15:12:50 +0000 | [diff] [blame] | 231 | constexpr auto |
Marshall Clow | f8fec4e | 2016-07-08 16:54:47 +0000 | [diff] [blame] | 232 | operator-(const reverse_iterator<Iterator1>& x, const reverse_iterator<Iterator2>& y) |
Marshall Clow | 5ace554 | 2016-10-19 15:12:50 +0000 | [diff] [blame] | 233 | -> decltype(__y.base() - __x.base()); // constexpr in C++17 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 234 | |
| 235 | template <class Iterator> |
Marshall Clow | 5ace554 | 2016-10-19 15:12:50 +0000 | [diff] [blame] | 236 | constexpr reverse_iterator<Iterator> |
Louis Dionne | 173f29e | 2019-05-29 16:01:36 +0000 | [diff] [blame] | 237 | operator+(typename reverse_iterator<Iterator>::difference_type n, |
Marshall Clow | 5ace554 | 2016-10-19 15:12:50 +0000 | [diff] [blame] | 238 | const reverse_iterator<Iterator>& x); // constexpr in C++17 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 239 | |
Marshall Clow | 5ace554 | 2016-10-19 15:12:50 +0000 | [diff] [blame] | 240 | template <class Iterator> |
| 241 | 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] | 242 | |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 243 | template <class Container> |
| 244 | class back_insert_iterator |
Louis Dionne | 3402c3c | 2021-05-27 12:56:12 -0400 | [diff] [blame^] | 245 | : public iterator<output_iterator_tag, void, void, void, void> // until C++17 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 246 | { |
| 247 | protected: |
| 248 | Container* container; |
| 249 | public: |
| 250 | typedef Container container_type; |
| 251 | typedef void value_type; |
Louis Dionne | 3402c3c | 2021-05-27 12:56:12 -0400 | [diff] [blame^] | 252 | typedef void difference_type; // until C++20 |
| 253 | typedef ptrdiff_t difference_type; // since C++20 |
Eric Fiselier | 9aeea87 | 2016-06-30 04:40:50 +0000 | [diff] [blame] | 254 | typedef void reference; |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 255 | typedef void pointer; |
| 256 | |
Louis Dionne | 3402c3c | 2021-05-27 12:56:12 -0400 | [diff] [blame^] | 257 | constexpr back_insert_iterator() noexcept = default; // since C++20 |
Arthur O'Dwyer | 20638cc | 2021-02-09 19:12:16 -0500 | [diff] [blame] | 258 | explicit back_insert_iterator(Container& x); // constexpr in C++20 |
| 259 | back_insert_iterator& operator=(const typename Container::value_type& value); // constexpr in C++20 |
| 260 | back_insert_iterator& operator*(); // constexpr in C++20 |
| 261 | back_insert_iterator& operator++(); // constexpr in C++20 |
| 262 | back_insert_iterator operator++(int); // constexpr in C++20 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 263 | }; |
| 264 | |
Arthur O'Dwyer | 20638cc | 2021-02-09 19:12:16 -0500 | [diff] [blame] | 265 | 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] | 266 | |
| 267 | template <class Container> |
| 268 | class front_insert_iterator |
Louis Dionne | 3402c3c | 2021-05-27 12:56:12 -0400 | [diff] [blame^] | 269 | : public iterator<output_iterator_tag, void, void, void, void> // until C++17 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 270 | { |
| 271 | protected: |
| 272 | Container* container; |
| 273 | public: |
| 274 | typedef Container container_type; |
| 275 | typedef void value_type; |
Louis Dionne | 3402c3c | 2021-05-27 12:56:12 -0400 | [diff] [blame^] | 276 | typedef void difference_type; // until C++20 |
| 277 | typedef ptrdiff_t difference_type; // since C++20 |
Eric Fiselier | 9aeea87 | 2016-06-30 04:40:50 +0000 | [diff] [blame] | 278 | typedef void reference; |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 279 | typedef void pointer; |
| 280 | |
Louis Dionne | 3402c3c | 2021-05-27 12:56:12 -0400 | [diff] [blame^] | 281 | constexpr front_insert_iterator() noexcept = default; // since C++20 |
Arthur O'Dwyer | 20638cc | 2021-02-09 19:12:16 -0500 | [diff] [blame] | 282 | explicit front_insert_iterator(Container& x); // constexpr in C++20 |
| 283 | front_insert_iterator& operator=(const typename Container::value_type& value); // constexpr in C++20 |
| 284 | front_insert_iterator& operator*(); // constexpr in C++20 |
| 285 | front_insert_iterator& operator++(); // constexpr in C++20 |
| 286 | front_insert_iterator operator++(int); // constexpr in C++20 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 287 | }; |
| 288 | |
Arthur O'Dwyer | 20638cc | 2021-02-09 19:12:16 -0500 | [diff] [blame] | 289 | 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] | 290 | |
| 291 | template <class Container> |
| 292 | class insert_iterator |
Louis Dionne | 3402c3c | 2021-05-27 12:56:12 -0400 | [diff] [blame^] | 293 | : public iterator<output_iterator_tag, void, void, void, void> // until C++17 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 294 | { |
| 295 | protected: |
| 296 | Container* container; |
| 297 | typename Container::iterator iter; |
| 298 | public: |
| 299 | typedef Container container_type; |
| 300 | typedef void value_type; |
Louis Dionne | 3402c3c | 2021-05-27 12:56:12 -0400 | [diff] [blame^] | 301 | typedef void difference_type; // until C++20 |
| 302 | typedef ptrdiff_t difference_type; // since C++20 |
Eric Fiselier | 9aeea87 | 2016-06-30 04:40:50 +0000 | [diff] [blame] | 303 | typedef void reference; |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 304 | typedef void pointer; |
| 305 | |
Louis Dionne | 3402c3c | 2021-05-27 12:56:12 -0400 | [diff] [blame^] | 306 | insert_iterator() = default; // since C++20 |
Arthur O'Dwyer | 20638cc | 2021-02-09 19:12:16 -0500 | [diff] [blame] | 307 | insert_iterator(Container& x, typename Container::iterator i); // constexpr in C++20 |
| 308 | insert_iterator& operator=(const typename Container::value_type& value); // constexpr in C++20 |
| 309 | insert_iterator& operator*(); // constexpr in C++20 |
| 310 | insert_iterator& operator++(); // constexpr in C++20 |
| 311 | insert_iterator& operator++(int); // constexpr in C++20 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 312 | }; |
| 313 | |
| 314 | template <class Container, class Iterator> |
Arthur O'Dwyer | 20638cc | 2021-02-09 19:12:16 -0500 | [diff] [blame] | 315 | insert_iterator<Container> inserter(Container& x, Iterator i); // constexpr in C++20 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 316 | |
Marshall Clow | f8fec4e | 2016-07-08 16:54:47 +0000 | [diff] [blame] | 317 | template <class Iterator> |
| 318 | class move_iterator { |
| 319 | public: |
| 320 | typedef Iterator iterator_type; |
| 321 | typedef typename iterator_traits<Iterator>::difference_type difference_type; |
| 322 | typedef Iterator pointer; |
| 323 | typedef typename iterator_traits<Iterator>::value_type value_type; |
| 324 | typedef typename iterator_traits<Iterator>::iterator_category iterator_category; |
| 325 | typedef value_type&& reference; |
Louis Dionne | 173f29e | 2019-05-29 16:01:36 +0000 | [diff] [blame] | 326 | |
Marshall Clow | b5f9912 | 2016-11-02 15:30:26 +0000 | [diff] [blame] | 327 | constexpr move_iterator(); // all the constexprs are in C++17 |
| 328 | constexpr explicit move_iterator(Iterator i); |
| 329 | template <class U> |
| 330 | constexpr move_iterator(const move_iterator<U>& u); |
| 331 | template <class U> |
| 332 | constexpr move_iterator& operator=(const move_iterator<U>& u); |
| 333 | constexpr iterator_type base() const; |
| 334 | constexpr reference operator*() const; |
| 335 | constexpr pointer operator->() const; |
| 336 | constexpr move_iterator& operator++(); |
| 337 | constexpr move_iterator operator++(int); |
| 338 | constexpr move_iterator& operator--(); |
| 339 | constexpr move_iterator operator--(int); |
Louis Dionne | 173f29e | 2019-05-29 16:01:36 +0000 | [diff] [blame] | 340 | constexpr move_iterator operator+(difference_type n) const; |
| 341 | constexpr move_iterator& operator+=(difference_type n); |
| 342 | constexpr move_iterator operator-(difference_type n) const; |
| 343 | constexpr move_iterator& operator-=(difference_type n); |
Marshall Clow | b5f9912 | 2016-11-02 15:30:26 +0000 | [diff] [blame] | 344 | constexpr unspecified operator[](difference_type n) const; |
Marshall Clow | f8fec4e | 2016-07-08 16:54:47 +0000 | [diff] [blame] | 345 | private: |
| 346 | Iterator current; // exposition only |
| 347 | }; |
| 348 | |
| 349 | template <class Iterator1, class Iterator2> |
Marshall Clow | b5f9912 | 2016-11-02 15:30:26 +0000 | [diff] [blame] | 350 | constexpr bool // constexpr in C++17 |
Marshall Clow | f8fec4e | 2016-07-08 16:54:47 +0000 | [diff] [blame] | 351 | operator==(const move_iterator<Iterator1>& x, const move_iterator<Iterator2>& y); |
| 352 | |
| 353 | template <class Iterator1, class Iterator2> |
Marshall Clow | b5f9912 | 2016-11-02 15:30:26 +0000 | [diff] [blame] | 354 | constexpr bool // constexpr in C++17 |
Marshall Clow | f8fec4e | 2016-07-08 16:54:47 +0000 | [diff] [blame] | 355 | operator!=(const move_iterator<Iterator1>& x, const move_iterator<Iterator2>& y); |
| 356 | |
| 357 | template <class Iterator1, class Iterator2> |
Marshall Clow | b5f9912 | 2016-11-02 15:30:26 +0000 | [diff] [blame] | 358 | constexpr bool // constexpr in C++17 |
Marshall Clow | f8fec4e | 2016-07-08 16:54:47 +0000 | [diff] [blame] | 359 | operator<(const move_iterator<Iterator1>& x, const move_iterator<Iterator2>& y); |
| 360 | |
| 361 | template <class Iterator1, class Iterator2> |
Marshall Clow | b5f9912 | 2016-11-02 15:30:26 +0000 | [diff] [blame] | 362 | constexpr bool // constexpr in C++17 |
Marshall Clow | f8fec4e | 2016-07-08 16:54:47 +0000 | [diff] [blame] | 363 | operator<=(const move_iterator<Iterator1>& x, const move_iterator<Iterator2>& y); |
| 364 | |
| 365 | template <class Iterator1, class Iterator2> |
Marshall Clow | b5f9912 | 2016-11-02 15:30:26 +0000 | [diff] [blame] | 366 | constexpr bool // constexpr in C++17 |
Marshall Clow | f8fec4e | 2016-07-08 16:54:47 +0000 | [diff] [blame] | 367 | operator>(const move_iterator<Iterator1>& x, const move_iterator<Iterator2>& y); |
| 368 | |
| 369 | template <class Iterator1, class Iterator2> |
Marshall Clow | b5f9912 | 2016-11-02 15:30:26 +0000 | [diff] [blame] | 370 | constexpr bool // constexpr in C++17 |
Marshall Clow | f8fec4e | 2016-07-08 16:54:47 +0000 | [diff] [blame] | 371 | operator>=(const move_iterator<Iterator1>& x, const move_iterator<Iterator2>& y); |
| 372 | |
| 373 | template <class Iterator1, class Iterator2> |
Marshall Clow | b5f9912 | 2016-11-02 15:30:26 +0000 | [diff] [blame] | 374 | constexpr auto // constexpr in C++17 |
Marshall Clow | f8fec4e | 2016-07-08 16:54:47 +0000 | [diff] [blame] | 375 | operator-(const move_iterator<Iterator1>& x, |
| 376 | const move_iterator<Iterator2>& y) -> decltype(x.base() - y.base()); |
| 377 | |
| 378 | template <class Iterator> |
Marshall Clow | b5f9912 | 2016-11-02 15:30:26 +0000 | [diff] [blame] | 379 | constexpr move_iterator<Iterator> operator+( // constexpr in C++17 |
Louis Dionne | 173f29e | 2019-05-29 16:01:36 +0000 | [diff] [blame] | 380 | typename move_iterator<Iterator>::difference_type n, |
Marshall Clow | b5f9912 | 2016-11-02 15:30:26 +0000 | [diff] [blame] | 381 | const move_iterator<Iterator>& x); |
Marshall Clow | f8fec4e | 2016-07-08 16:54:47 +0000 | [diff] [blame] | 382 | |
Marshall Clow | b5f9912 | 2016-11-02 15:30:26 +0000 | [diff] [blame] | 383 | template <class Iterator> // constexpr in C++17 |
| 384 | constexpr move_iterator<Iterator> make_move_iterator(const Iterator& i); |
Marshall Clow | f8fec4e | 2016-07-08 16:54:47 +0000 | [diff] [blame] | 385 | |
| 386 | |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 387 | template <class T, class charT = char, class traits = char_traits<charT>, class Distance = ptrdiff_t> |
| 388 | class istream_iterator |
Louis Dionne | 8762e2b | 2021-05-25 18:15:58 -0400 | [diff] [blame] | 389 | : 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] | 390 | { |
| 391 | public: |
Louis Dionne | 3402c3c | 2021-05-27 12:56:12 -0400 | [diff] [blame^] | 392 | typedef input_iterator_tag iterator_category; |
| 393 | typedef T value_type; |
| 394 | typedef Distance difference_type; |
| 395 | typedef const T* pointer; |
| 396 | typedef const T& reference; |
| 397 | |
| 398 | typedef charT char_type; |
| 399 | typedef traits traits_type; |
| 400 | typedef basic_istream<charT, traits> istream_type; |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 401 | |
Marshall Clow | 0735e4e | 2015-04-16 21:36:54 +0000 | [diff] [blame] | 402 | constexpr istream_iterator(); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 403 | istream_iterator(istream_type& s); |
| 404 | istream_iterator(const istream_iterator& x); |
| 405 | ~istream_iterator(); |
| 406 | |
| 407 | const T& operator*() const; |
| 408 | const T* operator->() const; |
| 409 | istream_iterator& operator++(); |
| 410 | istream_iterator operator++(int); |
| 411 | }; |
| 412 | |
| 413 | template <class T, class charT, class traits, class Distance> |
| 414 | bool operator==(const istream_iterator<T,charT,traits,Distance>& x, |
| 415 | const istream_iterator<T,charT,traits,Distance>& y); |
| 416 | template <class T, class charT, class traits, class Distance> |
| 417 | bool operator!=(const istream_iterator<T,charT,traits,Distance>& x, |
| 418 | const istream_iterator<T,charT,traits,Distance>& y); |
| 419 | |
| 420 | template <class T, class charT = char, class traits = char_traits<charT> > |
| 421 | class ostream_iterator |
Louis Dionne | 3402c3c | 2021-05-27 12:56:12 -0400 | [diff] [blame^] | 422 | : public iterator<output_iterator_tag, void, void, void, void> // until C++17 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 423 | { |
| 424 | public: |
Louis Dionne | 3402c3c | 2021-05-27 12:56:12 -0400 | [diff] [blame^] | 425 | typedef output_iterator_tag iterator_category; |
| 426 | typedef void value_type; |
| 427 | typedef void difference_type; // until C++20 |
| 428 | typedef ptrdiff_t difference_type; // since C++20 |
| 429 | typedef void pointer; |
| 430 | typedef void reference; |
| 431 | |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 432 | typedef charT char_type; |
| 433 | typedef traits traits_type; |
| 434 | typedef basic_ostream<charT,traits> ostream_type; |
| 435 | |
Louis Dionne | 3402c3c | 2021-05-27 12:56:12 -0400 | [diff] [blame^] | 436 | constexpr ostream_iterator() noexcept = default; // since C++20 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 437 | ostream_iterator(ostream_type& s); |
| 438 | ostream_iterator(ostream_type& s, const charT* delimiter); |
| 439 | ostream_iterator(const ostream_iterator& x); |
| 440 | ~ostream_iterator(); |
| 441 | ostream_iterator& operator=(const T& value); |
| 442 | |
| 443 | ostream_iterator& operator*(); |
| 444 | ostream_iterator& operator++(); |
| 445 | ostream_iterator& operator++(int); |
| 446 | }; |
| 447 | |
| 448 | template<class charT, class traits = char_traits<charT> > |
| 449 | class istreambuf_iterator |
Louis Dionne | 3402c3c | 2021-05-27 12:56:12 -0400 | [diff] [blame^] | 450 | : 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] | 451 | { |
| 452 | public: |
Louis Dionne | 3402c3c | 2021-05-27 12:56:12 -0400 | [diff] [blame^] | 453 | typedef input_iterator_tag iterator_category; |
| 454 | typedef charT value_type; |
| 455 | typedef traits::off_type difference_type; |
| 456 | typedef unspecified pointer; |
| 457 | typedef charT reference; |
| 458 | |
| 459 | typedef charT char_type; |
| 460 | typedef traits traits_type; |
| 461 | typedef traits::int_type int_type; |
| 462 | typedef basic_streambuf<charT, traits> streambuf_type; |
| 463 | typedef basic_istream<charT, traits> istream_type; |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 464 | |
Howard Hinnant | 011138d | 2012-07-20 19:36:34 +0000 | [diff] [blame] | 465 | istreambuf_iterator() noexcept; |
| 466 | istreambuf_iterator(istream_type& s) noexcept; |
| 467 | istreambuf_iterator(streambuf_type* s) noexcept; |
| 468 | istreambuf_iterator(a-private-type) noexcept; |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 469 | |
| 470 | charT operator*() const; |
| 471 | pointer operator->() const; |
| 472 | istreambuf_iterator& operator++(); |
| 473 | a-private-type operator++(int); |
| 474 | |
| 475 | bool equal(const istreambuf_iterator& b) const; |
| 476 | }; |
| 477 | |
| 478 | template <class charT, class traits> |
| 479 | bool operator==(const istreambuf_iterator<charT,traits>& a, |
| 480 | const istreambuf_iterator<charT,traits>& b); |
| 481 | template <class charT, class traits> |
| 482 | bool operator!=(const istreambuf_iterator<charT,traits>& a, |
| 483 | const istreambuf_iterator<charT,traits>& b); |
| 484 | |
| 485 | template <class charT, class traits = char_traits<charT> > |
| 486 | class ostreambuf_iterator |
Louis Dionne | 8762e2b | 2021-05-25 18:15:58 -0400 | [diff] [blame] | 487 | : public iterator<output_iterator_tag, void, void, void, void> // until C++17 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 488 | { |
| 489 | public: |
Louis Dionne | 3402c3c | 2021-05-27 12:56:12 -0400 | [diff] [blame^] | 490 | typedef output_iterator_tag iterator_category; |
| 491 | typedef void value_type; |
| 492 | typedef void difference_type; // until C++20 |
| 493 | typedef ptrdiff_t difference_type; // since C++20 |
| 494 | typedef void pointer; |
| 495 | typedef void reference; |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 496 | |
Louis Dionne | 3402c3c | 2021-05-27 12:56:12 -0400 | [diff] [blame^] | 497 | typedef charT char_type; |
| 498 | typedef traits traits_type; |
| 499 | typedef basic_streambuf<charT, traits> streambuf_type; |
| 500 | typedef basic_ostream<charT, traits> ostream_type; |
| 501 | |
| 502 | constexpr ostreambuf_iterator() noexcept = default; // since C++20 |
Howard Hinnant | 011138d | 2012-07-20 19:36:34 +0000 | [diff] [blame] | 503 | ostreambuf_iterator(ostream_type& s) noexcept; |
| 504 | ostreambuf_iterator(streambuf_type* s) noexcept; |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 505 | ostreambuf_iterator& operator=(charT c); |
| 506 | ostreambuf_iterator& operator*(); |
| 507 | ostreambuf_iterator& operator++(); |
| 508 | ostreambuf_iterator& operator++(int); |
Howard Hinnant | 011138d | 2012-07-20 19:36:34 +0000 | [diff] [blame] | 509 | bool failed() const noexcept; |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 510 | }; |
| 511 | |
Marshall Clow | 99ba002 | 2017-01-04 17:58:17 +0000 | [diff] [blame] | 512 | template <class C> constexpr auto begin(C& c) -> decltype(c.begin()); |
| 513 | template <class C> constexpr auto begin(const C& c) -> decltype(c.begin()); |
| 514 | template <class C> constexpr auto end(C& c) -> decltype(c.end()); |
| 515 | template <class C> constexpr auto end(const C& c) -> decltype(c.end()); |
| 516 | template <class T, size_t N> constexpr T* begin(T (&array)[N]); |
| 517 | template <class T, size_t N> constexpr T* end(T (&array)[N]); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 518 | |
Marshall Clow | 99ba002 | 2017-01-04 17:58:17 +0000 | [diff] [blame] | 519 | template <class C> auto constexpr cbegin(const C& c) -> decltype(std::begin(c)); // C++14 |
| 520 | template <class C> auto constexpr cend(const C& c) -> decltype(std::end(c)); // C++14 |
| 521 | template <class C> auto constexpr rbegin(C& c) -> decltype(c.rbegin()); // C++14 |
| 522 | template <class C> auto constexpr rbegin(const C& c) -> decltype(c.rbegin()); // C++14 |
| 523 | template <class C> auto constexpr rend(C& c) -> decltype(c.rend()); // C++14 |
| 524 | template <class C> constexpr auto rend(const C& c) -> decltype(c.rend()); // C++14 |
| 525 | template <class E> reverse_iterator<const E*> constexpr rbegin(initializer_list<E> il); // C++14 |
| 526 | template <class E> reverse_iterator<const E*> constexpr rend(initializer_list<E> il); // C++14 |
| 527 | template <class T, size_t N> reverse_iterator<T*> constexpr rbegin(T (&array)[N]); // C++14 |
| 528 | template <class T, size_t N> reverse_iterator<T*> constexpr rend(T (&array)[N]); // C++14 |
| 529 | template <class C> constexpr auto crbegin(const C& c) -> decltype(std::rbegin(c)); // C++14 |
| 530 | 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] | 531 | |
Marshall Clow | ef35727 | 2014-11-19 19:43:23 +0000 | [diff] [blame] | 532 | // 24.8, container access: |
| 533 | template <class C> constexpr auto size(const C& c) -> decltype(c.size()); // C++17 |
| 534 | 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] | 535 | |
| 536 | template <class C> constexpr auto ssize(const C& c) |
Arthur O'Dwyer | 2fc9b5d | 2021-04-17 17:03:20 -0400 | [diff] [blame] | 537 | -> 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] | 538 | template <class T, ptrdiff_t> constexpr ptrdiff_t ssize(const T (&array)[N]) noexcept; // C++20 |
| 539 | |
Marshall Clow | ef35727 | 2014-11-19 19:43:23 +0000 | [diff] [blame] | 540 | template <class C> constexpr auto empty(const C& c) -> decltype(c.empty()); // C++17 |
| 541 | template <class T, size_t N> constexpr bool empty(const T (&array)[N]) noexcept; // C++17 |
| 542 | template <class E> constexpr bool empty(initializer_list<E> il) noexcept; // C++17 |
| 543 | template <class C> constexpr auto data(C& c) -> decltype(c.data()); // C++17 |
| 544 | template <class C> constexpr auto data(const C& c) -> decltype(c.data()); // C++17 |
| 545 | template <class T, size_t N> constexpr T* data(T (&array)[N]) noexcept; // C++17 |
| 546 | template <class E> constexpr const E* data(initializer_list<E> il) noexcept; // C++17 |
| 547 | |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 548 | } // std |
| 549 | |
| 550 | */ |
| 551 | |
| 552 | #include <__config> |
Arthur O'Dwyer | a2f99ee | 2021-04-29 17:40:17 -0400 | [diff] [blame] | 553 | #include <__debug> |
Marshall Clow | 3dc0550 | 2014-02-27 02:11:50 +0000 | [diff] [blame] | 554 | #include <__functional_base> |
Christopher Di Bella | c6ead65 | 2021-05-05 07:14:08 +0000 | [diff] [blame] | 555 | #include <__iterator/advance.h> |
Louis Dionne | 463afb8 | 2021-04-22 11:05:30 -0400 | [diff] [blame] | 556 | #include <__iterator/concepts.h> |
zoecarver | 61ae1dc | 2021-04-19 14:28:27 -0400 | [diff] [blame] | 557 | #include <__iterator/incrementable_traits.h> |
Louis Dionne | 170a03c | 2021-04-28 15:02:08 -0400 | [diff] [blame] | 558 | #include <__iterator/indirect_concepts.h> |
Louis Dionne | ca989a5 | 2021-04-20 14:40:43 -0400 | [diff] [blame] | 559 | #include <__iterator/iter_move.h> |
zoecarver | 5d41ff5 | 2021-04-19 14:44:42 -0700 | [diff] [blame] | 560 | #include <__iterator/iterator_traits.h> |
Christopher Di Bella | 9c0adab | 2021-05-08 05:02:43 +0000 | [diff] [blame] | 561 | #include <__iterator/next.h> |
Christopher Di Bella | b8e2104 | 2021-05-16 01:39:22 +0000 | [diff] [blame] | 562 | #include <__iterator/prev.h> |
Louis Dionne | 170a03c | 2021-04-28 15:02:08 -0400 | [diff] [blame] | 563 | #include <__iterator/projected.h> |
zoecarver | 61ae1dc | 2021-04-19 14:28:27 -0400 | [diff] [blame] | 564 | #include <__iterator/readable_traits.h> |
Louis Dionne | 735bc46 | 2021-04-14 13:59:03 -0400 | [diff] [blame] | 565 | #include <__memory/addressof.h> |
Arthur O'Dwyer | 1ac9f09 | 2021-01-15 12:59:56 -0500 | [diff] [blame] | 566 | #include <__memory/pointer_traits.h> |
Arthur O'Dwyer | a2f99ee | 2021-04-29 17:40:17 -0400 | [diff] [blame] | 567 | #include <compare> |
| 568 | #include <concepts> // Mandated by the Standard. |
| 569 | #include <cstddef> |
| 570 | #include <initializer_list> |
| 571 | #include <iosfwd> // for forward declarations of vector and string |
| 572 | #include <type_traits> |
Marshall Clow | 0a1e750 | 2018-09-12 19:41:40 +0000 | [diff] [blame] | 573 | #include <version> |
Howard Hinnant | 48fd5d5 | 2012-11-14 21:17:15 +0000 | [diff] [blame] | 574 | |
Howard Hinnant | aaaa52b | 2011-10-17 20:05:10 +0000 | [diff] [blame] | 575 | #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 576 | #pragma GCC system_header |
Howard Hinnant | aaaa52b | 2011-10-17 20:05:10 +0000 | [diff] [blame] | 577 | #endif |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 578 | |
| 579 | _LIBCPP_BEGIN_NAMESPACE_STD |
Christopher Di Bella | 490fe40 | 2021-03-23 03:55:52 +0000 | [diff] [blame] | 580 | |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 581 | template<class _Category, class _Tp, class _Distance = ptrdiff_t, |
| 582 | class _Pointer = _Tp*, class _Reference = _Tp&> |
Louis Dionne | 8762e2b | 2021-05-25 18:15:58 -0400 | [diff] [blame] | 583 | struct _LIBCPP_TEMPLATE_VIS _LIBCPP_DEPRECATED_IN_CXX17 iterator |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 584 | { |
| 585 | typedef _Tp value_type; |
| 586 | typedef _Distance difference_type; |
| 587 | typedef _Pointer pointer; |
| 588 | typedef _Reference reference; |
| 589 | typedef _Category iterator_category; |
| 590 | }; |
| 591 | |
| 592 | template <class _InputIter> |
Marshall Clow | 75468e7 | 2017-05-17 18:51:36 +0000 | [diff] [blame] | 593 | inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 594 | void __advance(_InputIter& __i, |
| 595 | typename iterator_traits<_InputIter>::difference_type __n, input_iterator_tag) |
| 596 | { |
| 597 | for (; __n > 0; --__n) |
| 598 | ++__i; |
| 599 | } |
| 600 | |
| 601 | template <class _BiDirIter> |
Marshall Clow | 75468e7 | 2017-05-17 18:51:36 +0000 | [diff] [blame] | 602 | inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 603 | void __advance(_BiDirIter& __i, |
| 604 | typename iterator_traits<_BiDirIter>::difference_type __n, bidirectional_iterator_tag) |
| 605 | { |
| 606 | if (__n >= 0) |
| 607 | for (; __n > 0; --__n) |
| 608 | ++__i; |
| 609 | else |
| 610 | for (; __n < 0; ++__n) |
| 611 | --__i; |
| 612 | } |
| 613 | |
| 614 | template <class _RandIter> |
Marshall Clow | 75468e7 | 2017-05-17 18:51:36 +0000 | [diff] [blame] | 615 | inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 616 | void __advance(_RandIter& __i, |
| 617 | typename iterator_traits<_RandIter>::difference_type __n, random_access_iterator_tag) |
| 618 | { |
| 619 | __i += __n; |
| 620 | } |
| 621 | |
Christopher Di Bella | c6ead65 | 2021-05-05 07:14:08 +0000 | [diff] [blame] | 622 | template <class _InputIter, class _Distance, |
| 623 | class = typename enable_if<is_integral<decltype(_VSTD::__convert_to_integral(declval<_Distance>()))>::value>::type> |
Marshall Clow | 75468e7 | 2017-05-17 18:51:36 +0000 | [diff] [blame] | 624 | inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 |
Louis Dionne | 4576866 | 2020-06-08 16:16:01 -0400 | [diff] [blame] | 625 | void advance(_InputIter& __i, _Distance __orig_n) |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 626 | { |
Arthur O'Dwyer | 6e9069c | 2020-12-07 23:42:47 -0500 | [diff] [blame] | 627 | typedef decltype(_VSTD::__convert_to_integral(__orig_n)) _IntegralSize; |
Louis Dionne | 4576866 | 2020-06-08 16:16:01 -0400 | [diff] [blame] | 628 | _IntegralSize __n = __orig_n; |
Arthur O'Dwyer | ca13391 | 2021-04-20 15:59:22 -0400 | [diff] [blame] | 629 | _LIBCPP_ASSERT(__n >= 0 || __is_cpp17_bidirectional_iterator<_InputIter>::value, |
| 630 | "Attempt to advance(it, n) with negative n on a non-bidirectional iterator"); |
Arthur O'Dwyer | 6e9069c | 2020-12-07 23:42:47 -0500 | [diff] [blame] | 631 | _VSTD::__advance(__i, __n, typename iterator_traits<_InputIter>::iterator_category()); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 632 | } |
| 633 | |
| 634 | template <class _InputIter> |
Marshall Clow | 75468e7 | 2017-05-17 18:51:36 +0000 | [diff] [blame] | 635 | inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 636 | typename iterator_traits<_InputIter>::difference_type |
| 637 | __distance(_InputIter __first, _InputIter __last, input_iterator_tag) |
| 638 | { |
| 639 | typename iterator_traits<_InputIter>::difference_type __r(0); |
| 640 | for (; __first != __last; ++__first) |
| 641 | ++__r; |
| 642 | return __r; |
| 643 | } |
| 644 | |
| 645 | template <class _RandIter> |
Marshall Clow | 75468e7 | 2017-05-17 18:51:36 +0000 | [diff] [blame] | 646 | inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 647 | typename iterator_traits<_RandIter>::difference_type |
| 648 | __distance(_RandIter __first, _RandIter __last, random_access_iterator_tag) |
| 649 | { |
| 650 | return __last - __first; |
| 651 | } |
| 652 | |
| 653 | template <class _InputIter> |
Marshall Clow | 75468e7 | 2017-05-17 18:51:36 +0000 | [diff] [blame] | 654 | inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 655 | typename iterator_traits<_InputIter>::difference_type |
| 656 | distance(_InputIter __first, _InputIter __last) |
| 657 | { |
Arthur O'Dwyer | 6e9069c | 2020-12-07 23:42:47 -0500 | [diff] [blame] | 658 | return _VSTD::__distance(__first, __last, typename iterator_traits<_InputIter>::iterator_category()); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 659 | } |
| 660 | |
Marshall Clow | 990c70d | 2015-11-07 17:48:49 +0000 | [diff] [blame] | 661 | template <class _InputIter> |
Marshall Clow | 75468e7 | 2017-05-17 18:51:36 +0000 | [diff] [blame] | 662 | inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 |
Rachel Craik | 2048d82 | 2017-07-24 22:17:05 +0000 | [diff] [blame] | 663 | typename enable_if |
| 664 | < |
Eric Fiselier | cd5a677 | 2019-11-18 01:46:58 -0500 | [diff] [blame] | 665 | __is_cpp17_input_iterator<_InputIter>::value, |
Rachel Craik | 2048d82 | 2017-07-24 22:17:05 +0000 | [diff] [blame] | 666 | _InputIter |
| 667 | >::type |
Marshall Clow | 990c70d | 2015-11-07 17:48:49 +0000 | [diff] [blame] | 668 | next(_InputIter __x, |
Rachel Craik | 2048d82 | 2017-07-24 22:17:05 +0000 | [diff] [blame] | 669 | typename iterator_traits<_InputIter>::difference_type __n = 1) |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 670 | { |
Eric Fiselier | cd5a677 | 2019-11-18 01:46:58 -0500 | [diff] [blame] | 671 | _LIBCPP_ASSERT(__n >= 0 || __is_cpp17_bidirectional_iterator<_InputIter>::value, |
Louis Dionne | 4576866 | 2020-06-08 16:16:01 -0400 | [diff] [blame] | 672 | "Attempt to next(it, n) with negative n on a non-bidirectional iterator"); |
Marshall Clow | 3d43521 | 2019-03-22 22:32:20 +0000 | [diff] [blame] | 673 | |
Howard Hinnant | b1ad5a8 | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 674 | _VSTD::advance(__x, __n); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 675 | return __x; |
| 676 | } |
| 677 | |
Marshall Clow | 3d43521 | 2019-03-22 22:32:20 +0000 | [diff] [blame] | 678 | template <class _InputIter> |
Marshall Clow | 75468e7 | 2017-05-17 18:51:36 +0000 | [diff] [blame] | 679 | inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 |
Rachel Craik | 2048d82 | 2017-07-24 22:17:05 +0000 | [diff] [blame] | 680 | typename enable_if |
| 681 | < |
Eric Fiselier | cd5a677 | 2019-11-18 01:46:58 -0500 | [diff] [blame] | 682 | __is_cpp17_input_iterator<_InputIter>::value, |
Marshall Clow | 3d43521 | 2019-03-22 22:32:20 +0000 | [diff] [blame] | 683 | _InputIter |
Rachel Craik | 2048d82 | 2017-07-24 22:17:05 +0000 | [diff] [blame] | 684 | >::type |
Marshall Clow | 3d43521 | 2019-03-22 22:32:20 +0000 | [diff] [blame] | 685 | prev(_InputIter __x, |
| 686 | typename iterator_traits<_InputIter>::difference_type __n = 1) |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 687 | { |
Eric Fiselier | cd5a677 | 2019-11-18 01:46:58 -0500 | [diff] [blame] | 688 | _LIBCPP_ASSERT(__n <= 0 || __is_cpp17_bidirectional_iterator<_InputIter>::value, |
Louis Dionne | 4576866 | 2020-06-08 16:16:01 -0400 | [diff] [blame] | 689 | "Attempt to prev(it, n) with a positive n on a non-bidirectional iterator"); |
Howard Hinnant | b1ad5a8 | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 690 | _VSTD::advance(__x, -__n); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 691 | return __x; |
| 692 | } |
| 693 | |
Eric Fiselier | 883af11 | 2017-04-13 02:54:13 +0000 | [diff] [blame] | 694 | |
| 695 | template <class _Tp, class = void> |
| 696 | struct __is_stashing_iterator : false_type {}; |
| 697 | |
| 698 | template <class _Tp> |
| 699 | struct __is_stashing_iterator<_Tp, typename __void_t<typename _Tp::__stashing_iterator_tag>::type> |
| 700 | : true_type {}; |
| 701 | |
Louis Dionne | 8762e2b | 2021-05-25 18:15:58 -0400 | [diff] [blame] | 702 | _LIBCPP_SUPPRESS_DEPRECATED_PUSH |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 703 | template <class _Iter> |
Eric Fiselier | b5eb1bf | 2017-01-04 23:56:00 +0000 | [diff] [blame] | 704 | class _LIBCPP_TEMPLATE_VIS reverse_iterator |
Louis Dionne | 8762e2b | 2021-05-25 18:15:58 -0400 | [diff] [blame] | 705 | #if _LIBCPP_STD_VER <= 14 || !defined(_LIBCPP_ABI_NO_ITERATOR_BASES) |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 706 | : public iterator<typename iterator_traits<_Iter>::iterator_category, |
| 707 | typename iterator_traits<_Iter>::value_type, |
| 708 | typename iterator_traits<_Iter>::difference_type, |
| 709 | typename iterator_traits<_Iter>::pointer, |
| 710 | typename iterator_traits<_Iter>::reference> |
Louis Dionne | 8762e2b | 2021-05-25 18:15:58 -0400 | [diff] [blame] | 711 | #endif |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 712 | { |
Louis Dionne | 8762e2b | 2021-05-25 18:15:58 -0400 | [diff] [blame] | 713 | _LIBCPP_SUPPRESS_DEPRECATED_POP |
Marshall Clow | 0ad029e | 2014-03-11 22:05:31 +0000 | [diff] [blame] | 714 | private: |
Louis Dionne | 8762e2b | 2021-05-25 18:15:58 -0400 | [diff] [blame] | 715 | #ifndef _LIBCPP_ABI_NO_ITERATOR_BASES |
| 716 | _Iter __t; // no longer used as of LWG #2360, not removed due to ABI break |
| 717 | #endif |
Eric Fiselier | 883af11 | 2017-04-13 02:54:13 +0000 | [diff] [blame] | 718 | |
| 719 | static_assert(!__is_stashing_iterator<_Iter>::value, |
| 720 | "The specified iterator type cannot be used with reverse_iterator; " |
| 721 | "Using stashing iterators with reverse_iterator causes undefined behavior"); |
| 722 | |
Marshall Clow | 1f61f0a | 2014-03-12 01:19:36 +0000 | [diff] [blame] | 723 | protected: |
| 724 | _Iter current; |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 725 | public: |
| 726 | typedef _Iter iterator_type; |
| 727 | typedef typename iterator_traits<_Iter>::difference_type difference_type; |
| 728 | typedef typename iterator_traits<_Iter>::reference reference; |
| 729 | typedef typename iterator_traits<_Iter>::pointer pointer; |
Arthur O'Dwyer | 1ac9f09 | 2021-01-15 12:59:56 -0500 | [diff] [blame] | 730 | typedef _If<__is_cpp17_random_access_iterator<_Iter>::value, |
| 731 | random_access_iterator_tag, |
| 732 | typename iterator_traits<_Iter>::iterator_category> iterator_category; |
Louis Dionne | 8762e2b | 2021-05-25 18:15:58 -0400 | [diff] [blame] | 733 | typedef typename iterator_traits<_Iter>::value_type value_type; |
| 734 | |
Arthur O'Dwyer | 1ac9f09 | 2021-01-15 12:59:56 -0500 | [diff] [blame] | 735 | #if _LIBCPP_STD_VER > 17 |
| 736 | typedef _If<__is_cpp17_random_access_iterator<_Iter>::value, |
| 737 | random_access_iterator_tag, |
| 738 | bidirectional_iterator_tag> iterator_concept; |
| 739 | #endif |
Howard Hinnant | 3b6579a | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 740 | |
Louis Dionne | 8762e2b | 2021-05-25 18:15:58 -0400 | [diff] [blame] | 741 | #ifndef _LIBCPP_ABI_NO_ITERATOR_BASES |
Marshall Clow | 5ace554 | 2016-10-19 15:12:50 +0000 | [diff] [blame] | 742 | _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 |
| 743 | reverse_iterator() : __t(), current() {} |
| 744 | _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 |
| 745 | explicit reverse_iterator(_Iter __x) : __t(__x), current(__x) {} |
| 746 | template <class _Up> |
| 747 | _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 |
| 748 | reverse_iterator(const reverse_iterator<_Up>& __u) : __t(__u.base()), current(__u.base()) {} |
| 749 | template <class _Up> |
| 750 | _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 |
| 751 | reverse_iterator& operator=(const reverse_iterator<_Up>& __u) |
| 752 | { __t = current = __u.base(); return *this; } |
Louis Dionne | 8762e2b | 2021-05-25 18:15:58 -0400 | [diff] [blame] | 753 | #else |
| 754 | _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 |
| 755 | reverse_iterator() : current() {} |
| 756 | _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 |
| 757 | explicit reverse_iterator(_Iter __x) : current(__x) {} |
| 758 | template <class _Up> |
| 759 | _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 |
| 760 | reverse_iterator(const reverse_iterator<_Up>& __u) : current(__u.base()) {} |
| 761 | template <class _Up> |
| 762 | _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 |
| 763 | reverse_iterator& operator=(const reverse_iterator<_Up>& __u) |
| 764 | { current = __u.base(); return *this; } |
| 765 | #endif |
Marshall Clow | 5ace554 | 2016-10-19 15:12:50 +0000 | [diff] [blame] | 766 | _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 |
| 767 | _Iter base() const {return current;} |
| 768 | _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 |
| 769 | reference operator*() const {_Iter __tmp = current; return *--__tmp;} |
| 770 | _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 |
| 771 | pointer operator->() const {return _VSTD::addressof(operator*());} |
| 772 | _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 |
| 773 | reverse_iterator& operator++() {--current; return *this;} |
| 774 | _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 |
| 775 | reverse_iterator operator++(int) {reverse_iterator __tmp(*this); --current; return __tmp;} |
| 776 | _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 |
| 777 | reverse_iterator& operator--() {++current; return *this;} |
| 778 | _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 |
| 779 | reverse_iterator operator--(int) {reverse_iterator __tmp(*this); ++current; return __tmp;} |
| 780 | _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 |
| 781 | reverse_iterator operator+ (difference_type __n) const {return reverse_iterator(current - __n);} |
| 782 | _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 |
| 783 | reverse_iterator& operator+=(difference_type __n) {current -= __n; return *this;} |
| 784 | _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 |
| 785 | reverse_iterator operator- (difference_type __n) const {return reverse_iterator(current + __n);} |
| 786 | _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 |
| 787 | reverse_iterator& operator-=(difference_type __n) {current += __n; return *this;} |
| 788 | _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 |
| 789 | reference operator[](difference_type __n) const {return *(*this + __n);} |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 790 | }; |
| 791 | |
| 792 | template <class _Iter1, class _Iter2> |
Marshall Clow | 5ace554 | 2016-10-19 15:12:50 +0000 | [diff] [blame] | 793 | inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 794 | bool |
| 795 | operator==(const reverse_iterator<_Iter1>& __x, const reverse_iterator<_Iter2>& __y) |
| 796 | { |
| 797 | return __x.base() == __y.base(); |
| 798 | } |
| 799 | |
| 800 | template <class _Iter1, class _Iter2> |
Marshall Clow | 5ace554 | 2016-10-19 15:12:50 +0000 | [diff] [blame] | 801 | inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 802 | bool |
| 803 | operator<(const reverse_iterator<_Iter1>& __x, const reverse_iterator<_Iter2>& __y) |
| 804 | { |
| 805 | return __x.base() > __y.base(); |
| 806 | } |
| 807 | |
| 808 | template <class _Iter1, class _Iter2> |
Marshall Clow | 5ace554 | 2016-10-19 15:12:50 +0000 | [diff] [blame] | 809 | inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 810 | bool |
| 811 | operator!=(const reverse_iterator<_Iter1>& __x, const reverse_iterator<_Iter2>& __y) |
| 812 | { |
| 813 | return __x.base() != __y.base(); |
| 814 | } |
| 815 | |
| 816 | template <class _Iter1, class _Iter2> |
Marshall Clow | 5ace554 | 2016-10-19 15:12:50 +0000 | [diff] [blame] | 817 | inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 818 | bool |
| 819 | operator>(const reverse_iterator<_Iter1>& __x, const reverse_iterator<_Iter2>& __y) |
| 820 | { |
| 821 | return __x.base() < __y.base(); |
| 822 | } |
| 823 | |
| 824 | template <class _Iter1, class _Iter2> |
Marshall Clow | 5ace554 | 2016-10-19 15:12:50 +0000 | [diff] [blame] | 825 | inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 826 | bool |
| 827 | operator>=(const reverse_iterator<_Iter1>& __x, const reverse_iterator<_Iter2>& __y) |
| 828 | { |
| 829 | return __x.base() <= __y.base(); |
| 830 | } |
| 831 | |
| 832 | template <class _Iter1, class _Iter2> |
Marshall Clow | 5ace554 | 2016-10-19 15:12:50 +0000 | [diff] [blame] | 833 | inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 834 | bool |
| 835 | operator<=(const reverse_iterator<_Iter1>& __x, const reverse_iterator<_Iter2>& __y) |
| 836 | { |
| 837 | return __x.base() >= __y.base(); |
| 838 | } |
| 839 | |
Marshall Clow | 476d3f4 | 2016-07-18 13:19:00 +0000 | [diff] [blame] | 840 | #ifndef _LIBCPP_CXX03_LANG |
Marshall Clow | f8fec4e | 2016-07-08 16:54:47 +0000 | [diff] [blame] | 841 | template <class _Iter1, class _Iter2> |
Marshall Clow | 5ace554 | 2016-10-19 15:12:50 +0000 | [diff] [blame] | 842 | inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 |
Marshall Clow | f8fec4e | 2016-07-08 16:54:47 +0000 | [diff] [blame] | 843 | auto |
| 844 | operator-(const reverse_iterator<_Iter1>& __x, const reverse_iterator<_Iter2>& __y) |
| 845 | -> decltype(__y.base() - __x.base()) |
| 846 | { |
| 847 | return __y.base() - __x.base(); |
| 848 | } |
| 849 | #else |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 850 | template <class _Iter1, class _Iter2> |
| 851 | inline _LIBCPP_INLINE_VISIBILITY |
| 852 | typename reverse_iterator<_Iter1>::difference_type |
| 853 | operator-(const reverse_iterator<_Iter1>& __x, const reverse_iterator<_Iter2>& __y) |
| 854 | { |
| 855 | return __y.base() - __x.base(); |
| 856 | } |
Marshall Clow | f8fec4e | 2016-07-08 16:54:47 +0000 | [diff] [blame] | 857 | #endif |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 858 | |
| 859 | template <class _Iter> |
Marshall Clow | 5ace554 | 2016-10-19 15:12:50 +0000 | [diff] [blame] | 860 | inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 861 | reverse_iterator<_Iter> |
| 862 | operator+(typename reverse_iterator<_Iter>::difference_type __n, const reverse_iterator<_Iter>& __x) |
| 863 | { |
| 864 | return reverse_iterator<_Iter>(__x.base() - __n); |
| 865 | } |
| 866 | |
Marshall Clow | 6dbbdc9 | 2014-03-03 01:24:04 +0000 | [diff] [blame] | 867 | #if _LIBCPP_STD_VER > 11 |
| 868 | template <class _Iter> |
Marshall Clow | 5ace554 | 2016-10-19 15:12:50 +0000 | [diff] [blame] | 869 | inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 |
Marshall Clow | 6dbbdc9 | 2014-03-03 01:24:04 +0000 | [diff] [blame] | 870 | reverse_iterator<_Iter> make_reverse_iterator(_Iter __i) |
| 871 | { |
| 872 | return reverse_iterator<_Iter>(__i); |
| 873 | } |
| 874 | #endif |
| 875 | |
Louis Dionne | 8762e2b | 2021-05-25 18:15:58 -0400 | [diff] [blame] | 876 | _LIBCPP_SUPPRESS_DEPRECATED_PUSH |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 877 | template <class _Container> |
Eric Fiselier | b5eb1bf | 2017-01-04 23:56:00 +0000 | [diff] [blame] | 878 | class _LIBCPP_TEMPLATE_VIS back_insert_iterator |
Louis Dionne | 8762e2b | 2021-05-25 18:15:58 -0400 | [diff] [blame] | 879 | #if _LIBCPP_STD_VER <= 14 || !defined(_LIBCPP_ABI_NO_ITERATOR_BASES) |
| 880 | : public iterator<output_iterator_tag, void, void, void, void> |
| 881 | #endif |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 882 | { |
Louis Dionne | 8762e2b | 2021-05-25 18:15:58 -0400 | [diff] [blame] | 883 | _LIBCPP_SUPPRESS_DEPRECATED_POP |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 884 | protected: |
| 885 | _Container* container; |
| 886 | public: |
Louis Dionne | 8762e2b | 2021-05-25 18:15:58 -0400 | [diff] [blame] | 887 | typedef output_iterator_tag iterator_category; |
| 888 | typedef void value_type; |
Louis Dionne | 3402c3c | 2021-05-27 12:56:12 -0400 | [diff] [blame^] | 889 | #if _LIBCPP_STD_VER > 17 |
| 890 | typedef ptrdiff_t difference_type; |
| 891 | #else |
Louis Dionne | 8762e2b | 2021-05-25 18:15:58 -0400 | [diff] [blame] | 892 | typedef void difference_type; |
Louis Dionne | 3402c3c | 2021-05-27 12:56:12 -0400 | [diff] [blame^] | 893 | #endif |
Louis Dionne | 8762e2b | 2021-05-25 18:15:58 -0400 | [diff] [blame] | 894 | typedef void pointer; |
| 895 | typedef void reference; |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 896 | typedef _Container container_type; |
| 897 | |
Louis Dionne | 3402c3c | 2021-05-27 12:56:12 -0400 | [diff] [blame^] | 898 | #if _LIBCPP_STD_VER > 17 |
| 899 | _LIBCPP_INLINE_VISIBILITY constexpr back_insert_iterator() noexcept = default; |
| 900 | #endif |
Arthur O'Dwyer | 20638cc | 2021-02-09 19:12:16 -0500 | [diff] [blame] | 901 | _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 explicit back_insert_iterator(_Container& __x) : container(_VSTD::addressof(__x)) {} |
| 902 | _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 back_insert_iterator& operator=(const typename _Container::value_type& __value_) |
Howard Hinnant | bf07402 | 2011-10-22 20:59:45 +0000 | [diff] [blame] | 903 | {container->push_back(__value_); return *this;} |
Eric Fiselier | f07d88c | 2017-04-19 01:34:08 +0000 | [diff] [blame] | 904 | #ifndef _LIBCPP_CXX03_LANG |
Arthur O'Dwyer | 20638cc | 2021-02-09 19:12:16 -0500 | [diff] [blame] | 905 | _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 back_insert_iterator& operator=(typename _Container::value_type&& __value_) |
Howard Hinnant | bf07402 | 2011-10-22 20:59:45 +0000 | [diff] [blame] | 906 | {container->push_back(_VSTD::move(__value_)); return *this;} |
Louis Dionne | 2b1ceaa | 2021-04-20 12:03:32 -0400 | [diff] [blame] | 907 | #endif // _LIBCPP_CXX03_LANG |
Arthur O'Dwyer | 20638cc | 2021-02-09 19:12:16 -0500 | [diff] [blame] | 908 | _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 back_insert_iterator& operator*() {return *this;} |
| 909 | _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 back_insert_iterator& operator++() {return *this;} |
| 910 | _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 back_insert_iterator operator++(int) {return *this;} |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 911 | }; |
| 912 | |
| 913 | template <class _Container> |
Arthur O'Dwyer | 20638cc | 2021-02-09 19:12:16 -0500 | [diff] [blame] | 914 | inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 915 | back_insert_iterator<_Container> |
| 916 | back_inserter(_Container& __x) |
| 917 | { |
| 918 | return back_insert_iterator<_Container>(__x); |
| 919 | } |
| 920 | |
Louis Dionne | 8762e2b | 2021-05-25 18:15:58 -0400 | [diff] [blame] | 921 | _LIBCPP_SUPPRESS_DEPRECATED_PUSH |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 922 | template <class _Container> |
Eric Fiselier | b5eb1bf | 2017-01-04 23:56:00 +0000 | [diff] [blame] | 923 | class _LIBCPP_TEMPLATE_VIS front_insert_iterator |
Louis Dionne | 8762e2b | 2021-05-25 18:15:58 -0400 | [diff] [blame] | 924 | #if _LIBCPP_STD_VER <= 14 || !defined(_LIBCPP_ABI_NO_ITERATOR_BASES) |
| 925 | : public iterator<output_iterator_tag, void, void, void, void> |
| 926 | #endif |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 927 | { |
Louis Dionne | 8762e2b | 2021-05-25 18:15:58 -0400 | [diff] [blame] | 928 | _LIBCPP_SUPPRESS_DEPRECATED_POP |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 929 | protected: |
| 930 | _Container* container; |
| 931 | public: |
Louis Dionne | 8762e2b | 2021-05-25 18:15:58 -0400 | [diff] [blame] | 932 | typedef output_iterator_tag iterator_category; |
| 933 | typedef void value_type; |
Louis Dionne | 3402c3c | 2021-05-27 12:56:12 -0400 | [diff] [blame^] | 934 | #if _LIBCPP_STD_VER > 17 |
| 935 | typedef ptrdiff_t difference_type; |
| 936 | #else |
Louis Dionne | 8762e2b | 2021-05-25 18:15:58 -0400 | [diff] [blame] | 937 | typedef void difference_type; |
Louis Dionne | 3402c3c | 2021-05-27 12:56:12 -0400 | [diff] [blame^] | 938 | #endif |
Louis Dionne | 8762e2b | 2021-05-25 18:15:58 -0400 | [diff] [blame] | 939 | typedef void pointer; |
| 940 | typedef void reference; |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 941 | typedef _Container container_type; |
| 942 | |
Louis Dionne | 3402c3c | 2021-05-27 12:56:12 -0400 | [diff] [blame^] | 943 | #if _LIBCPP_STD_VER > 17 |
| 944 | _LIBCPP_INLINE_VISIBILITY constexpr front_insert_iterator() noexcept = default; |
| 945 | #endif |
Arthur O'Dwyer | 20638cc | 2021-02-09 19:12:16 -0500 | [diff] [blame] | 946 | _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 explicit front_insert_iterator(_Container& __x) : container(_VSTD::addressof(__x)) {} |
| 947 | _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 front_insert_iterator& operator=(const typename _Container::value_type& __value_) |
Howard Hinnant | bf07402 | 2011-10-22 20:59:45 +0000 | [diff] [blame] | 948 | {container->push_front(__value_); return *this;} |
Eric Fiselier | f07d88c | 2017-04-19 01:34:08 +0000 | [diff] [blame] | 949 | #ifndef _LIBCPP_CXX03_LANG |
Arthur O'Dwyer | 20638cc | 2021-02-09 19:12:16 -0500 | [diff] [blame] | 950 | _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 front_insert_iterator& operator=(typename _Container::value_type&& __value_) |
Howard Hinnant | bf07402 | 2011-10-22 20:59:45 +0000 | [diff] [blame] | 951 | {container->push_front(_VSTD::move(__value_)); return *this;} |
Louis Dionne | 2b1ceaa | 2021-04-20 12:03:32 -0400 | [diff] [blame] | 952 | #endif // _LIBCPP_CXX03_LANG |
Arthur O'Dwyer | 20638cc | 2021-02-09 19:12:16 -0500 | [diff] [blame] | 953 | _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 front_insert_iterator& operator*() {return *this;} |
| 954 | _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 front_insert_iterator& operator++() {return *this;} |
| 955 | _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 front_insert_iterator operator++(int) {return *this;} |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 956 | }; |
| 957 | |
| 958 | template <class _Container> |
Arthur O'Dwyer | 20638cc | 2021-02-09 19:12:16 -0500 | [diff] [blame] | 959 | inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 960 | front_insert_iterator<_Container> |
| 961 | front_inserter(_Container& __x) |
| 962 | { |
| 963 | return front_insert_iterator<_Container>(__x); |
| 964 | } |
| 965 | |
Louis Dionne | 8762e2b | 2021-05-25 18:15:58 -0400 | [diff] [blame] | 966 | _LIBCPP_SUPPRESS_DEPRECATED_PUSH |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 967 | template <class _Container> |
Eric Fiselier | b5eb1bf | 2017-01-04 23:56:00 +0000 | [diff] [blame] | 968 | class _LIBCPP_TEMPLATE_VIS insert_iterator |
Louis Dionne | 8762e2b | 2021-05-25 18:15:58 -0400 | [diff] [blame] | 969 | #if _LIBCPP_STD_VER <= 14 || !defined(_LIBCPP_ABI_NO_ITERATOR_BASES) |
| 970 | : public iterator<output_iterator_tag, void, void, void, void> |
| 971 | #endif |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 972 | { |
Louis Dionne | 8762e2b | 2021-05-25 18:15:58 -0400 | [diff] [blame] | 973 | _LIBCPP_SUPPRESS_DEPRECATED_POP |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 974 | protected: |
| 975 | _Container* container; |
| 976 | typename _Container::iterator iter; |
| 977 | public: |
Louis Dionne | 8762e2b | 2021-05-25 18:15:58 -0400 | [diff] [blame] | 978 | typedef output_iterator_tag iterator_category; |
| 979 | typedef void value_type; |
Louis Dionne | 3402c3c | 2021-05-27 12:56:12 -0400 | [diff] [blame^] | 980 | #if _LIBCPP_STD_VER > 17 |
| 981 | typedef ptrdiff_t difference_type; |
| 982 | #else |
Louis Dionne | 8762e2b | 2021-05-25 18:15:58 -0400 | [diff] [blame] | 983 | typedef void difference_type; |
Louis Dionne | 3402c3c | 2021-05-27 12:56:12 -0400 | [diff] [blame^] | 984 | #endif |
Louis Dionne | 8762e2b | 2021-05-25 18:15:58 -0400 | [diff] [blame] | 985 | typedef void pointer; |
| 986 | typedef void reference; |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 987 | typedef _Container container_type; |
| 988 | |
Louis Dionne | 3402c3c | 2021-05-27 12:56:12 -0400 | [diff] [blame^] | 989 | #if _LIBCPP_STD_VER > 17 |
| 990 | _LIBCPP_INLINE_VISIBILITY insert_iterator() = default; |
| 991 | #endif |
Arthur O'Dwyer | 20638cc | 2021-02-09 19:12:16 -0500 | [diff] [blame] | 992 | _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 insert_iterator(_Container& __x, typename _Container::iterator __i) |
Marshall Clow | cef3168 | 2014-03-03 19:20:40 +0000 | [diff] [blame] | 993 | : container(_VSTD::addressof(__x)), iter(__i) {} |
Arthur O'Dwyer | 20638cc | 2021-02-09 19:12:16 -0500 | [diff] [blame] | 994 | _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 insert_iterator& operator=(const typename _Container::value_type& __value_) |
Howard Hinnant | bf07402 | 2011-10-22 20:59:45 +0000 | [diff] [blame] | 995 | {iter = container->insert(iter, __value_); ++iter; return *this;} |
Eric Fiselier | f07d88c | 2017-04-19 01:34:08 +0000 | [diff] [blame] | 996 | #ifndef _LIBCPP_CXX03_LANG |
Arthur O'Dwyer | 20638cc | 2021-02-09 19:12:16 -0500 | [diff] [blame] | 997 | _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 insert_iterator& operator=(typename _Container::value_type&& __value_) |
Howard Hinnant | bf07402 | 2011-10-22 20:59:45 +0000 | [diff] [blame] | 998 | {iter = container->insert(iter, _VSTD::move(__value_)); ++iter; return *this;} |
Louis Dionne | 2b1ceaa | 2021-04-20 12:03:32 -0400 | [diff] [blame] | 999 | #endif // _LIBCPP_CXX03_LANG |
Arthur O'Dwyer | 20638cc | 2021-02-09 19:12:16 -0500 | [diff] [blame] | 1000 | _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 insert_iterator& operator*() {return *this;} |
| 1001 | _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 insert_iterator& operator++() {return *this;} |
| 1002 | _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 insert_iterator& operator++(int) {return *this;} |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1003 | }; |
| 1004 | |
| 1005 | template <class _Container> |
Arthur O'Dwyer | 20638cc | 2021-02-09 19:12:16 -0500 | [diff] [blame] | 1006 | inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1007 | insert_iterator<_Container> |
| 1008 | inserter(_Container& __x, typename _Container::iterator __i) |
| 1009 | { |
| 1010 | return insert_iterator<_Container>(__x, __i); |
| 1011 | } |
| 1012 | |
Louis Dionne | 8762e2b | 2021-05-25 18:15:58 -0400 | [diff] [blame] | 1013 | _LIBCPP_SUPPRESS_DEPRECATED_PUSH |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1014 | template <class _Tp, class _CharT = char, |
| 1015 | class _Traits = char_traits<_CharT>, class _Distance = ptrdiff_t> |
Eric Fiselier | b5eb1bf | 2017-01-04 23:56:00 +0000 | [diff] [blame] | 1016 | class _LIBCPP_TEMPLATE_VIS istream_iterator |
Louis Dionne | 8762e2b | 2021-05-25 18:15:58 -0400 | [diff] [blame] | 1017 | #if _LIBCPP_STD_VER <= 14 || !defined(_LIBCPP_ABI_NO_ITERATOR_BASES) |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1018 | : public iterator<input_iterator_tag, _Tp, _Distance, const _Tp*, const _Tp&> |
Louis Dionne | 8762e2b | 2021-05-25 18:15:58 -0400 | [diff] [blame] | 1019 | #endif |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1020 | { |
Louis Dionne | 8762e2b | 2021-05-25 18:15:58 -0400 | [diff] [blame] | 1021 | _LIBCPP_SUPPRESS_DEPRECATED_POP |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1022 | public: |
Louis Dionne | 8762e2b | 2021-05-25 18:15:58 -0400 | [diff] [blame] | 1023 | typedef input_iterator_tag iterator_category; |
| 1024 | typedef _Tp value_type; |
| 1025 | typedef _Distance difference_type; |
| 1026 | typedef const _Tp* pointer; |
| 1027 | typedef const _Tp& reference; |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1028 | typedef _CharT char_type; |
| 1029 | typedef _Traits traits_type; |
| 1030 | typedef basic_istream<_CharT,_Traits> istream_type; |
| 1031 | private: |
| 1032 | istream_type* __in_stream_; |
| 1033 | _Tp __value_; |
| 1034 | public: |
Bruce Mitchener | 170d897 | 2020-11-24 12:53:53 -0500 | [diff] [blame] | 1035 | _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR istream_iterator() : __in_stream_(nullptr), __value_() {} |
Marshall Clow | b774270 | 2016-05-17 17:44:40 +0000 | [diff] [blame] | 1036 | _LIBCPP_INLINE_VISIBILITY istream_iterator(istream_type& __s) : __in_stream_(_VSTD::addressof(__s)) |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1037 | { |
| 1038 | if (!(*__in_stream_ >> __value_)) |
Bruce Mitchener | 170d897 | 2020-11-24 12:53:53 -0500 | [diff] [blame] | 1039 | __in_stream_ = nullptr; |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1040 | } |
| 1041 | |
| 1042 | _LIBCPP_INLINE_VISIBILITY const _Tp& operator*() const {return __value_;} |
Marshall Clow | b774270 | 2016-05-17 17:44:40 +0000 | [diff] [blame] | 1043 | _LIBCPP_INLINE_VISIBILITY const _Tp* operator->() const {return _VSTD::addressof((operator*()));} |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1044 | _LIBCPP_INLINE_VISIBILITY istream_iterator& operator++() |
| 1045 | { |
| 1046 | if (!(*__in_stream_ >> __value_)) |
Bruce Mitchener | 170d897 | 2020-11-24 12:53:53 -0500 | [diff] [blame] | 1047 | __in_stream_ = nullptr; |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1048 | return *this; |
| 1049 | } |
| 1050 | _LIBCPP_INLINE_VISIBILITY istream_iterator operator++(int) |
| 1051 | {istream_iterator __t(*this); ++(*this); return __t;} |
| 1052 | |
Roger Ferrer Ibanez | d16858b | 2017-12-11 13:54:58 +0000 | [diff] [blame] | 1053 | template <class _Up, class _CharU, class _TraitsU, class _DistanceU> |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1054 | friend _LIBCPP_INLINE_VISIBILITY |
Roger Ferrer Ibanez | d16858b | 2017-12-11 13:54:58 +0000 | [diff] [blame] | 1055 | bool |
| 1056 | operator==(const istream_iterator<_Up, _CharU, _TraitsU, _DistanceU>& __x, |
| 1057 | const istream_iterator<_Up, _CharU, _TraitsU, _DistanceU>& __y); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1058 | |
Roger Ferrer Ibanez | d16858b | 2017-12-11 13:54:58 +0000 | [diff] [blame] | 1059 | template <class _Up, class _CharU, class _TraitsU, class _DistanceU> |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1060 | friend _LIBCPP_INLINE_VISIBILITY |
Roger Ferrer Ibanez | d16858b | 2017-12-11 13:54:58 +0000 | [diff] [blame] | 1061 | bool |
| 1062 | operator==(const istream_iterator<_Up, _CharU, _TraitsU, _DistanceU>& __x, |
| 1063 | const istream_iterator<_Up, _CharU, _TraitsU, _DistanceU>& __y); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1064 | }; |
| 1065 | |
Roger Ferrer Ibanez | d16858b | 2017-12-11 13:54:58 +0000 | [diff] [blame] | 1066 | template <class _Tp, class _CharT, class _Traits, class _Distance> |
| 1067 | inline _LIBCPP_INLINE_VISIBILITY |
| 1068 | bool |
| 1069 | operator==(const istream_iterator<_Tp, _CharT, _Traits, _Distance>& __x, |
| 1070 | const istream_iterator<_Tp, _CharT, _Traits, _Distance>& __y) |
| 1071 | { |
| 1072 | return __x.__in_stream_ == __y.__in_stream_; |
| 1073 | } |
| 1074 | |
| 1075 | template <class _Tp, class _CharT, class _Traits, class _Distance> |
| 1076 | inline _LIBCPP_INLINE_VISIBILITY |
| 1077 | bool |
| 1078 | operator!=(const istream_iterator<_Tp, _CharT, _Traits, _Distance>& __x, |
| 1079 | const istream_iterator<_Tp, _CharT, _Traits, _Distance>& __y) |
| 1080 | { |
| 1081 | return !(__x == __y); |
| 1082 | } |
| 1083 | |
Louis Dionne | 8762e2b | 2021-05-25 18:15:58 -0400 | [diff] [blame] | 1084 | _LIBCPP_SUPPRESS_DEPRECATED_PUSH |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1085 | template <class _Tp, class _CharT = char, class _Traits = char_traits<_CharT> > |
Eric Fiselier | b5eb1bf | 2017-01-04 23:56:00 +0000 | [diff] [blame] | 1086 | class _LIBCPP_TEMPLATE_VIS ostream_iterator |
Louis Dionne | 8762e2b | 2021-05-25 18:15:58 -0400 | [diff] [blame] | 1087 | #if _LIBCPP_STD_VER <= 14 || !defined(_LIBCPP_ABI_NO_ITERATOR_BASES) |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1088 | : public iterator<output_iterator_tag, void, void, void, void> |
Louis Dionne | 8762e2b | 2021-05-25 18:15:58 -0400 | [diff] [blame] | 1089 | #endif |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1090 | { |
Louis Dionne | 8762e2b | 2021-05-25 18:15:58 -0400 | [diff] [blame] | 1091 | _LIBCPP_SUPPRESS_DEPRECATED_POP |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1092 | public: |
Louis Dionne | a4d7952 | 2020-09-11 10:15:56 -0400 | [diff] [blame] | 1093 | typedef output_iterator_tag iterator_category; |
| 1094 | typedef void value_type; |
| 1095 | #if _LIBCPP_STD_VER > 17 |
Louis Dionne | 3402c3c | 2021-05-27 12:56:12 -0400 | [diff] [blame^] | 1096 | typedef ptrdiff_t difference_type; |
Louis Dionne | a4d7952 | 2020-09-11 10:15:56 -0400 | [diff] [blame] | 1097 | #else |
| 1098 | typedef void difference_type; |
| 1099 | #endif |
| 1100 | typedef void pointer; |
| 1101 | typedef void reference; |
| 1102 | typedef _CharT char_type; |
| 1103 | typedef _Traits traits_type; |
| 1104 | typedef basic_ostream<_CharT, _Traits> ostream_type; |
| 1105 | |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1106 | private: |
| 1107 | ostream_type* __out_stream_; |
| 1108 | const char_type* __delim_; |
| 1109 | public: |
Louis Dionne | 3402c3c | 2021-05-27 12:56:12 -0400 | [diff] [blame^] | 1110 | #if _LIBCPP_STD_VER > 17 |
| 1111 | _LIBCPP_INLINE_VISIBILITY constexpr ostream_iterator() noexcept = default; |
| 1112 | #endif |
Marshall Clow | 27a8951 | 2016-10-12 16:13:48 +0000 | [diff] [blame] | 1113 | _LIBCPP_INLINE_VISIBILITY ostream_iterator(ostream_type& __s) _NOEXCEPT |
Bruce Mitchener | 170d897 | 2020-11-24 12:53:53 -0500 | [diff] [blame] | 1114 | : __out_stream_(_VSTD::addressof(__s)), __delim_(nullptr) {} |
Marshall Clow | 27a8951 | 2016-10-12 16:13:48 +0000 | [diff] [blame] | 1115 | _LIBCPP_INLINE_VISIBILITY ostream_iterator(ostream_type& __s, const _CharT* __delimiter) _NOEXCEPT |
Marshall Clow | b774270 | 2016-05-17 17:44:40 +0000 | [diff] [blame] | 1116 | : __out_stream_(_VSTD::addressof(__s)), __delim_(__delimiter) {} |
Howard Hinnant | bf07402 | 2011-10-22 20:59:45 +0000 | [diff] [blame] | 1117 | _LIBCPP_INLINE_VISIBILITY ostream_iterator& operator=(const _Tp& __value_) |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1118 | { |
Howard Hinnant | bf07402 | 2011-10-22 20:59:45 +0000 | [diff] [blame] | 1119 | *__out_stream_ << __value_; |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1120 | if (__delim_) |
| 1121 | *__out_stream_ << __delim_; |
| 1122 | return *this; |
| 1123 | } |
| 1124 | |
| 1125 | _LIBCPP_INLINE_VISIBILITY ostream_iterator& operator*() {return *this;} |
| 1126 | _LIBCPP_INLINE_VISIBILITY ostream_iterator& operator++() {return *this;} |
| 1127 | _LIBCPP_INLINE_VISIBILITY ostream_iterator& operator++(int) {return *this;} |
| 1128 | }; |
| 1129 | |
Louis Dionne | 8762e2b | 2021-05-25 18:15:58 -0400 | [diff] [blame] | 1130 | _LIBCPP_SUPPRESS_DEPRECATED_PUSH |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1131 | template<class _CharT, class _Traits> |
Eric Fiselier | b5eb1bf | 2017-01-04 23:56:00 +0000 | [diff] [blame] | 1132 | class _LIBCPP_TEMPLATE_VIS istreambuf_iterator |
Louis Dionne | 8762e2b | 2021-05-25 18:15:58 -0400 | [diff] [blame] | 1133 | #if _LIBCPP_STD_VER <= 14 || !defined(_LIBCPP_ABI_NO_ITERATOR_BASES) |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1134 | : public iterator<input_iterator_tag, _CharT, |
| 1135 | typename _Traits::off_type, _CharT*, |
| 1136 | _CharT> |
Louis Dionne | 8762e2b | 2021-05-25 18:15:58 -0400 | [diff] [blame] | 1137 | #endif |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1138 | { |
Louis Dionne | 8762e2b | 2021-05-25 18:15:58 -0400 | [diff] [blame] | 1139 | _LIBCPP_SUPPRESS_DEPRECATED_POP |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1140 | public: |
Louis Dionne | 8762e2b | 2021-05-25 18:15:58 -0400 | [diff] [blame] | 1141 | typedef input_iterator_tag iterator_category; |
| 1142 | typedef _CharT value_type; |
| 1143 | typedef typename _Traits::off_type difference_type; |
| 1144 | typedef _CharT* pointer; |
| 1145 | typedef _CharT reference; |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1146 | typedef _CharT char_type; |
| 1147 | typedef _Traits traits_type; |
| 1148 | typedef typename _Traits::int_type int_type; |
| 1149 | typedef basic_streambuf<_CharT,_Traits> streambuf_type; |
| 1150 | typedef basic_istream<_CharT,_Traits> istream_type; |
| 1151 | private: |
Howard Hinnant | 3e57b27 | 2012-11-16 22:17:23 +0000 | [diff] [blame] | 1152 | mutable streambuf_type* __sbuf_; |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1153 | |
| 1154 | class __proxy |
| 1155 | { |
| 1156 | char_type __keep_; |
| 1157 | streambuf_type* __sbuf_; |
| 1158 | _LIBCPP_INLINE_VISIBILITY __proxy(char_type __c, streambuf_type* __s) |
| 1159 | : __keep_(__c), __sbuf_(__s) {} |
| 1160 | friend class istreambuf_iterator; |
| 1161 | public: |
| 1162 | _LIBCPP_INLINE_VISIBILITY char_type operator*() const {return __keep_;} |
| 1163 | }; |
| 1164 | |
Howard Hinnant | 756c69b | 2010-09-22 16:48:34 +0000 | [diff] [blame] | 1165 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 3e57b27 | 2012-11-16 22:17:23 +0000 | [diff] [blame] | 1166 | bool __test_for_eof() const |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1167 | { |
| 1168 | if (__sbuf_ && traits_type::eq_int_type(__sbuf_->sgetc(), traits_type::eof())) |
Bruce Mitchener | 170d897 | 2020-11-24 12:53:53 -0500 | [diff] [blame] | 1169 | __sbuf_ = nullptr; |
| 1170 | return __sbuf_ == nullptr; |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1171 | } |
| 1172 | public: |
Bruce Mitchener | 170d897 | 2020-11-24 12:53:53 -0500 | [diff] [blame] | 1173 | _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR istreambuf_iterator() _NOEXCEPT : __sbuf_(nullptr) {} |
Howard Hinnant | 011138d | 2012-07-20 19:36:34 +0000 | [diff] [blame] | 1174 | _LIBCPP_INLINE_VISIBILITY istreambuf_iterator(istream_type& __s) _NOEXCEPT |
Howard Hinnant | b9af8d8 | 2012-12-29 17:45:42 +0000 | [diff] [blame] | 1175 | : __sbuf_(__s.rdbuf()) {} |
Howard Hinnant | 011138d | 2012-07-20 19:36:34 +0000 | [diff] [blame] | 1176 | _LIBCPP_INLINE_VISIBILITY istreambuf_iterator(streambuf_type* __s) _NOEXCEPT |
Howard Hinnant | b9af8d8 | 2012-12-29 17:45:42 +0000 | [diff] [blame] | 1177 | : __sbuf_(__s) {} |
Howard Hinnant | 011138d | 2012-07-20 19:36:34 +0000 | [diff] [blame] | 1178 | _LIBCPP_INLINE_VISIBILITY istreambuf_iterator(const __proxy& __p) _NOEXCEPT |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1179 | : __sbuf_(__p.__sbuf_) {} |
| 1180 | |
Howard Hinnant | 28b2488 | 2011-12-01 20:21:04 +0000 | [diff] [blame] | 1181 | _LIBCPP_INLINE_VISIBILITY char_type operator*() const |
| 1182 | {return static_cast<char_type>(__sbuf_->sgetc());} |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1183 | _LIBCPP_INLINE_VISIBILITY istreambuf_iterator& operator++() |
| 1184 | { |
Howard Hinnant | 3e57b27 | 2012-11-16 22:17:23 +0000 | [diff] [blame] | 1185 | __sbuf_->sbumpc(); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1186 | return *this; |
| 1187 | } |
| 1188 | _LIBCPP_INLINE_VISIBILITY __proxy operator++(int) |
| 1189 | { |
Howard Hinnant | 3e57b27 | 2012-11-16 22:17:23 +0000 | [diff] [blame] | 1190 | return __proxy(__sbuf_->sbumpc(), __sbuf_); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1191 | } |
| 1192 | |
| 1193 | _LIBCPP_INLINE_VISIBILITY bool equal(const istreambuf_iterator& __b) const |
Howard Hinnant | 3e57b27 | 2012-11-16 22:17:23 +0000 | [diff] [blame] | 1194 | {return __test_for_eof() == __b.__test_for_eof();} |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1195 | }; |
| 1196 | |
| 1197 | template <class _CharT, class _Traits> |
| 1198 | inline _LIBCPP_INLINE_VISIBILITY |
| 1199 | bool operator==(const istreambuf_iterator<_CharT,_Traits>& __a, |
| 1200 | const istreambuf_iterator<_CharT,_Traits>& __b) |
| 1201 | {return __a.equal(__b);} |
| 1202 | |
| 1203 | template <class _CharT, class _Traits> |
| 1204 | inline _LIBCPP_INLINE_VISIBILITY |
| 1205 | bool operator!=(const istreambuf_iterator<_CharT,_Traits>& __a, |
| 1206 | const istreambuf_iterator<_CharT,_Traits>& __b) |
| 1207 | {return !__a.equal(__b);} |
| 1208 | |
Louis Dionne | 8762e2b | 2021-05-25 18:15:58 -0400 | [diff] [blame] | 1209 | _LIBCPP_SUPPRESS_DEPRECATED_PUSH |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1210 | template <class _CharT, class _Traits> |
Eric Fiselier | b5eb1bf | 2017-01-04 23:56:00 +0000 | [diff] [blame] | 1211 | class _LIBCPP_TEMPLATE_VIS ostreambuf_iterator |
Louis Dionne | 8762e2b | 2021-05-25 18:15:58 -0400 | [diff] [blame] | 1212 | #if _LIBCPP_STD_VER <= 14 || !defined(_LIBCPP_ABI_NO_ITERATOR_BASES) |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1213 | : public iterator<output_iterator_tag, void, void, void, void> |
Louis Dionne | 8762e2b | 2021-05-25 18:15:58 -0400 | [diff] [blame] | 1214 | #endif |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1215 | { |
Louis Dionne | 8762e2b | 2021-05-25 18:15:58 -0400 | [diff] [blame] | 1216 | _LIBCPP_SUPPRESS_DEPRECATED_POP |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1217 | public: |
Louis Dionne | a4d7952 | 2020-09-11 10:15:56 -0400 | [diff] [blame] | 1218 | typedef output_iterator_tag iterator_category; |
| 1219 | typedef void value_type; |
| 1220 | #if _LIBCPP_STD_VER > 17 |
Louis Dionne | 3402c3c | 2021-05-27 12:56:12 -0400 | [diff] [blame^] | 1221 | typedef ptrdiff_t difference_type; |
Louis Dionne | a4d7952 | 2020-09-11 10:15:56 -0400 | [diff] [blame] | 1222 | #else |
| 1223 | typedef void difference_type; |
| 1224 | #endif |
| 1225 | typedef void pointer; |
| 1226 | typedef void reference; |
| 1227 | typedef _CharT char_type; |
| 1228 | typedef _Traits traits_type; |
| 1229 | typedef basic_streambuf<_CharT, _Traits> streambuf_type; |
| 1230 | typedef basic_ostream<_CharT, _Traits> ostream_type; |
| 1231 | |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1232 | private: |
| 1233 | streambuf_type* __sbuf_; |
| 1234 | public: |
Louis Dionne | 3402c3c | 2021-05-27 12:56:12 -0400 | [diff] [blame^] | 1235 | #if _LIBCPP_STD_VER > 17 |
| 1236 | _LIBCPP_INLINE_VISIBILITY constexpr ostreambuf_iterator() noexcept = default; |
| 1237 | #endif |
Howard Hinnant | 011138d | 2012-07-20 19:36:34 +0000 | [diff] [blame] | 1238 | _LIBCPP_INLINE_VISIBILITY ostreambuf_iterator(ostream_type& __s) _NOEXCEPT |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1239 | : __sbuf_(__s.rdbuf()) {} |
Howard Hinnant | 011138d | 2012-07-20 19:36:34 +0000 | [diff] [blame] | 1240 | _LIBCPP_INLINE_VISIBILITY ostreambuf_iterator(streambuf_type* __s) _NOEXCEPT |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1241 | : __sbuf_(__s) {} |
| 1242 | _LIBCPP_INLINE_VISIBILITY ostreambuf_iterator& operator=(_CharT __c) |
| 1243 | { |
| 1244 | if (__sbuf_ && traits_type::eq_int_type(__sbuf_->sputc(__c), traits_type::eof())) |
Bruce Mitchener | 170d897 | 2020-11-24 12:53:53 -0500 | [diff] [blame] | 1245 | __sbuf_ = nullptr; |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1246 | return *this; |
| 1247 | } |
| 1248 | _LIBCPP_INLINE_VISIBILITY ostreambuf_iterator& operator*() {return *this;} |
| 1249 | _LIBCPP_INLINE_VISIBILITY ostreambuf_iterator& operator++() {return *this;} |
| 1250 | _LIBCPP_INLINE_VISIBILITY ostreambuf_iterator& operator++(int) {return *this;} |
Bruce Mitchener | 170d897 | 2020-11-24 12:53:53 -0500 | [diff] [blame] | 1251 | _LIBCPP_INLINE_VISIBILITY bool failed() const _NOEXCEPT {return __sbuf_ == nullptr;} |
Howard Hinnant | 9795517 | 2012-09-19 19:14:15 +0000 | [diff] [blame] | 1252 | |
| 1253 | template <class _Ch, class _Tr> |
| 1254 | friend |
| 1255 | _LIBCPP_HIDDEN |
| 1256 | ostreambuf_iterator<_Ch, _Tr> |
| 1257 | __pad_and_output(ostreambuf_iterator<_Ch, _Tr> __s, |
| 1258 | const _Ch* __ob, const _Ch* __op, const _Ch* __oe, |
| 1259 | ios_base& __iob, _Ch __fl); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1260 | }; |
| 1261 | |
| 1262 | template <class _Iter> |
Eric Fiselier | b5eb1bf | 2017-01-04 23:56:00 +0000 | [diff] [blame] | 1263 | class _LIBCPP_TEMPLATE_VIS move_iterator |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1264 | { |
| 1265 | private: |
| 1266 | _Iter __i; |
| 1267 | public: |
| 1268 | typedef _Iter iterator_type; |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1269 | typedef typename iterator_traits<iterator_type>::value_type value_type; |
| 1270 | typedef typename iterator_traits<iterator_type>::difference_type difference_type; |
Marshall Clow | d85a056 | 2016-04-11 03:54:53 +0000 | [diff] [blame] | 1271 | typedef iterator_type pointer; |
Arthur O'Dwyer | 1ac9f09 | 2021-01-15 12:59:56 -0500 | [diff] [blame] | 1272 | typedef _If<__is_cpp17_random_access_iterator<_Iter>::value, |
| 1273 | random_access_iterator_tag, |
| 1274 | typename iterator_traits<_Iter>::iterator_category> iterator_category; |
| 1275 | #if _LIBCPP_STD_VER > 17 |
| 1276 | typedef input_iterator_tag iterator_concept; |
| 1277 | #endif |
| 1278 | |
Eric Fiselier | f07d88c | 2017-04-19 01:34:08 +0000 | [diff] [blame] | 1279 | #ifndef _LIBCPP_CXX03_LANG |
Eric Fiselier | 57b8e0e | 2016-04-22 00:49:12 +0000 | [diff] [blame] | 1280 | typedef typename iterator_traits<iterator_type>::reference __reference; |
| 1281 | typedef typename conditional< |
| 1282 | is_reference<__reference>::value, |
| 1283 | typename remove_reference<__reference>::type&&, |
| 1284 | __reference |
| 1285 | >::type reference; |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1286 | #else |
| 1287 | typedef typename iterator_traits<iterator_type>::reference reference; |
| 1288 | #endif |
Howard Hinnant | 3b6579a | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 1289 | |
Marshall Clow | b5f9912 | 2016-11-02 15:30:26 +0000 | [diff] [blame] | 1290 | _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 |
| 1291 | move_iterator() : __i() {} |
| 1292 | _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 |
| 1293 | explicit move_iterator(_Iter __x) : __i(__x) {} |
| 1294 | template <class _Up> |
| 1295 | _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 |
| 1296 | move_iterator(const move_iterator<_Up>& __u) : __i(__u.base()) {} |
| 1297 | _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 _Iter base() const {return __i;} |
Louis Dionne | 173f29e | 2019-05-29 16:01:36 +0000 | [diff] [blame] | 1298 | _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 |
Marshall Clow | b5f9912 | 2016-11-02 15:30:26 +0000 | [diff] [blame] | 1299 | reference operator*() const { return static_cast<reference>(*__i); } |
| 1300 | _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 |
| 1301 | pointer operator->() const { return __i;} |
| 1302 | _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 |
| 1303 | move_iterator& operator++() {++__i; return *this;} |
| 1304 | _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 |
| 1305 | move_iterator operator++(int) {move_iterator __tmp(*this); ++__i; return __tmp;} |
| 1306 | _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 |
| 1307 | move_iterator& operator--() {--__i; return *this;} |
| 1308 | _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 |
| 1309 | move_iterator operator--(int) {move_iterator __tmp(*this); --__i; return __tmp;} |
| 1310 | _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 |
| 1311 | move_iterator operator+ (difference_type __n) const {return move_iterator(__i + __n);} |
| 1312 | _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 |
| 1313 | move_iterator& operator+=(difference_type __n) {__i += __n; return *this;} |
| 1314 | _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 |
| 1315 | move_iterator operator- (difference_type __n) const {return move_iterator(__i - __n);} |
| 1316 | _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 |
| 1317 | move_iterator& operator-=(difference_type __n) {__i -= __n; return *this;} |
| 1318 | _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 |
| 1319 | reference operator[](difference_type __n) const { return static_cast<reference>(__i[__n]); } |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1320 | }; |
| 1321 | |
| 1322 | template <class _Iter1, class _Iter2> |
Marshall Clow | b5f9912 | 2016-11-02 15:30:26 +0000 | [diff] [blame] | 1323 | inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1324 | bool |
| 1325 | operator==(const move_iterator<_Iter1>& __x, const move_iterator<_Iter2>& __y) |
| 1326 | { |
| 1327 | return __x.base() == __y.base(); |
| 1328 | } |
| 1329 | |
| 1330 | template <class _Iter1, class _Iter2> |
Marshall Clow | b5f9912 | 2016-11-02 15:30:26 +0000 | [diff] [blame] | 1331 | inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1332 | bool |
| 1333 | operator<(const move_iterator<_Iter1>& __x, const move_iterator<_Iter2>& __y) |
| 1334 | { |
| 1335 | return __x.base() < __y.base(); |
| 1336 | } |
| 1337 | |
| 1338 | template <class _Iter1, class _Iter2> |
Marshall Clow | b5f9912 | 2016-11-02 15:30:26 +0000 | [diff] [blame] | 1339 | inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1340 | bool |
| 1341 | operator!=(const move_iterator<_Iter1>& __x, const move_iterator<_Iter2>& __y) |
| 1342 | { |
| 1343 | return __x.base() != __y.base(); |
| 1344 | } |
| 1345 | |
| 1346 | template <class _Iter1, class _Iter2> |
Marshall Clow | b5f9912 | 2016-11-02 15:30:26 +0000 | [diff] [blame] | 1347 | inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1348 | bool |
| 1349 | operator>(const move_iterator<_Iter1>& __x, const move_iterator<_Iter2>& __y) |
| 1350 | { |
| 1351 | return __x.base() > __y.base(); |
| 1352 | } |
| 1353 | |
| 1354 | template <class _Iter1, class _Iter2> |
Marshall Clow | b5f9912 | 2016-11-02 15:30:26 +0000 | [diff] [blame] | 1355 | inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1356 | bool |
| 1357 | operator>=(const move_iterator<_Iter1>& __x, const move_iterator<_Iter2>& __y) |
| 1358 | { |
| 1359 | return __x.base() >= __y.base(); |
| 1360 | } |
| 1361 | |
| 1362 | template <class _Iter1, class _Iter2> |
Marshall Clow | b5f9912 | 2016-11-02 15:30:26 +0000 | [diff] [blame] | 1363 | inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1364 | bool |
| 1365 | operator<=(const move_iterator<_Iter1>& __x, const move_iterator<_Iter2>& __y) |
| 1366 | { |
| 1367 | return __x.base() <= __y.base(); |
| 1368 | } |
| 1369 | |
Marshall Clow | 476d3f4 | 2016-07-18 13:19:00 +0000 | [diff] [blame] | 1370 | #ifndef _LIBCPP_CXX03_LANG |
Marshall Clow | f8fec4e | 2016-07-08 16:54:47 +0000 | [diff] [blame] | 1371 | template <class _Iter1, class _Iter2> |
Marshall Clow | b5f9912 | 2016-11-02 15:30:26 +0000 | [diff] [blame] | 1372 | inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 |
Marshall Clow | f8fec4e | 2016-07-08 16:54:47 +0000 | [diff] [blame] | 1373 | auto |
| 1374 | operator-(const move_iterator<_Iter1>& __x, const move_iterator<_Iter2>& __y) |
| 1375 | -> decltype(__x.base() - __y.base()) |
| 1376 | { |
| 1377 | return __x.base() - __y.base(); |
| 1378 | } |
| 1379 | #else |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1380 | template <class _Iter1, class _Iter2> |
| 1381 | inline _LIBCPP_INLINE_VISIBILITY |
| 1382 | typename move_iterator<_Iter1>::difference_type |
| 1383 | operator-(const move_iterator<_Iter1>& __x, const move_iterator<_Iter2>& __y) |
| 1384 | { |
| 1385 | return __x.base() - __y.base(); |
| 1386 | } |
Marshall Clow | f8fec4e | 2016-07-08 16:54:47 +0000 | [diff] [blame] | 1387 | #endif |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1388 | |
| 1389 | template <class _Iter> |
Marshall Clow | b5f9912 | 2016-11-02 15:30:26 +0000 | [diff] [blame] | 1390 | inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1391 | move_iterator<_Iter> |
| 1392 | operator+(typename move_iterator<_Iter>::difference_type __n, const move_iterator<_Iter>& __x) |
| 1393 | { |
| 1394 | return move_iterator<_Iter>(__x.base() + __n); |
| 1395 | } |
| 1396 | |
| 1397 | template <class _Iter> |
Marshall Clow | b5f9912 | 2016-11-02 15:30:26 +0000 | [diff] [blame] | 1398 | inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1399 | move_iterator<_Iter> |
Marshall Clow | 84f90cf | 2013-08-27 13:03:03 +0000 | [diff] [blame] | 1400 | make_move_iterator(_Iter __i) |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1401 | { |
| 1402 | return move_iterator<_Iter>(__i); |
| 1403 | } |
| 1404 | |
| 1405 | // __wrap_iter |
| 1406 | |
| 1407 | template <class _Iter> class __wrap_iter; |
| 1408 | |
| 1409 | template <class _Iter1, class _Iter2> |
Marshall Clow | ae4f831 | 2018-07-13 16:35:26 +0000 | [diff] [blame] | 1410 | _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1411 | bool |
Eric Fiselier | 873b8d3 | 2019-03-18 21:50:12 +0000 | [diff] [blame] | 1412 | operator==(const __wrap_iter<_Iter1>&, const __wrap_iter<_Iter2>&) _NOEXCEPT; |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1413 | |
| 1414 | template <class _Iter1, class _Iter2> |
Marshall Clow | ae4f831 | 2018-07-13 16:35:26 +0000 | [diff] [blame] | 1415 | _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1416 | bool |
Eric Fiselier | 873b8d3 | 2019-03-18 21:50:12 +0000 | [diff] [blame] | 1417 | operator<(const __wrap_iter<_Iter1>&, const __wrap_iter<_Iter2>&) _NOEXCEPT; |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1418 | |
| 1419 | template <class _Iter1, class _Iter2> |
Marshall Clow | ae4f831 | 2018-07-13 16:35:26 +0000 | [diff] [blame] | 1420 | _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1421 | bool |
Eric Fiselier | 873b8d3 | 2019-03-18 21:50:12 +0000 | [diff] [blame] | 1422 | operator!=(const __wrap_iter<_Iter1>&, const __wrap_iter<_Iter2>&) _NOEXCEPT; |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1423 | |
| 1424 | template <class _Iter1, class _Iter2> |
Marshall Clow | ae4f831 | 2018-07-13 16:35:26 +0000 | [diff] [blame] | 1425 | _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1426 | bool |
Eric Fiselier | 873b8d3 | 2019-03-18 21:50:12 +0000 | [diff] [blame] | 1427 | operator>(const __wrap_iter<_Iter1>&, const __wrap_iter<_Iter2>&) _NOEXCEPT; |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1428 | |
| 1429 | template <class _Iter1, class _Iter2> |
Marshall Clow | ae4f831 | 2018-07-13 16:35:26 +0000 | [diff] [blame] | 1430 | _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1431 | bool |
Eric Fiselier | 873b8d3 | 2019-03-18 21:50:12 +0000 | [diff] [blame] | 1432 | operator>=(const __wrap_iter<_Iter1>&, const __wrap_iter<_Iter2>&) _NOEXCEPT; |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1433 | |
| 1434 | template <class _Iter1, class _Iter2> |
Marshall Clow | ae4f831 | 2018-07-13 16:35:26 +0000 | [diff] [blame] | 1435 | _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1436 | bool |
Eric Fiselier | 873b8d3 | 2019-03-18 21:50:12 +0000 | [diff] [blame] | 1437 | operator<=(const __wrap_iter<_Iter1>&, const __wrap_iter<_Iter2>&) _NOEXCEPT; |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1438 | |
Marshall Clow | 476d3f4 | 2016-07-18 13:19:00 +0000 | [diff] [blame] | 1439 | #ifndef _LIBCPP_CXX03_LANG |
Marshall Clow | f8fec4e | 2016-07-08 16:54:47 +0000 | [diff] [blame] | 1440 | template <class _Iter1, class _Iter2> |
Marshall Clow | ae4f831 | 2018-07-13 16:35:26 +0000 | [diff] [blame] | 1441 | _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG |
Marshall Clow | f8fec4e | 2016-07-08 16:54:47 +0000 | [diff] [blame] | 1442 | auto |
Eric Fiselier | 873b8d3 | 2019-03-18 21:50:12 +0000 | [diff] [blame] | 1443 | operator-(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter2>& __y) _NOEXCEPT |
Marshall Clow | f8fec4e | 2016-07-08 16:54:47 +0000 | [diff] [blame] | 1444 | -> decltype(__x.base() - __y.base()); |
| 1445 | #else |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1446 | template <class _Iter1, class _Iter2> |
Howard Hinnant | a54386e | 2012-09-14 00:39:16 +0000 | [diff] [blame] | 1447 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1448 | typename __wrap_iter<_Iter1>::difference_type |
Eric Fiselier | 873b8d3 | 2019-03-18 21:50:12 +0000 | [diff] [blame] | 1449 | operator-(const __wrap_iter<_Iter1>&, const __wrap_iter<_Iter2>&) _NOEXCEPT; |
Marshall Clow | f8fec4e | 2016-07-08 16:54:47 +0000 | [diff] [blame] | 1450 | #endif |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1451 | |
| 1452 | template <class _Iter> |
Marshall Clow | ae4f831 | 2018-07-13 16:35:26 +0000 | [diff] [blame] | 1453 | _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1454 | __wrap_iter<_Iter> |
Eric Fiselier | 873b8d3 | 2019-03-18 21:50:12 +0000 | [diff] [blame] | 1455 | operator+(typename __wrap_iter<_Iter>::difference_type, __wrap_iter<_Iter>) _NOEXCEPT; |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1456 | |
Louis Dionne | 65b433b | 2019-11-06 12:02:41 +0000 | [diff] [blame] | 1457 | template <class _Ip, class _Op> _Op _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 copy(_Ip, _Ip, _Op); |
| 1458 | template <class _B1, class _B2> _B2 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 copy_backward(_B1, _B1, _B2); |
zoecarver | d0279de | 2020-09-14 18:11:08 -0400 | [diff] [blame] | 1459 | template <class _Ip, class _Op> _Op _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 move(_Ip, _Ip, _Op); |
| 1460 | template <class _B1, class _B2> _B2 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 move_backward(_B1, _B1, _B2); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1461 | |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1462 | template <class _Iter> |
| 1463 | class __wrap_iter |
| 1464 | { |
| 1465 | public: |
| 1466 | typedef _Iter iterator_type; |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1467 | typedef typename iterator_traits<iterator_type>::value_type value_type; |
| 1468 | typedef typename iterator_traits<iterator_type>::difference_type difference_type; |
| 1469 | typedef typename iterator_traits<iterator_type>::pointer pointer; |
| 1470 | typedef typename iterator_traits<iterator_type>::reference reference; |
Arthur O'Dwyer | 1ac9f09 | 2021-01-15 12:59:56 -0500 | [diff] [blame] | 1471 | typedef typename iterator_traits<iterator_type>::iterator_category iterator_category; |
| 1472 | #if _LIBCPP_STD_VER > 17 |
Arthur O'Dwyer | 6eb8a5d | 2021-05-19 11:54:31 -0400 | [diff] [blame] | 1473 | typedef contiguous_iterator_tag iterator_concept; |
Arthur O'Dwyer | 1ac9f09 | 2021-01-15 12:59:56 -0500 | [diff] [blame] | 1474 | #endif |
| 1475 | |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1476 | private: |
| 1477 | iterator_type __i; |
| 1478 | public: |
Eric Fiselier | 873b8d3 | 2019-03-18 21:50:12 +0000 | [diff] [blame] | 1479 | _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG __wrap_iter() _NOEXCEPT |
Marshall Clow | 4e7b35b | 2013-08-07 20:48:48 +0000 | [diff] [blame] | 1480 | #if _LIBCPP_STD_VER > 11 |
| 1481 | : __i{} |
| 1482 | #endif |
Howard Hinnant | c90aa63 | 2011-09-16 19:52:23 +0000 | [diff] [blame] | 1483 | { |
Louis Dionne | ba40078 | 2020-10-02 15:02:52 -0400 | [diff] [blame] | 1484 | #if _LIBCPP_DEBUG_LEVEL == 2 |
Howard Hinnant | c90aa63 | 2011-09-16 19:52:23 +0000 | [diff] [blame] | 1485 | __get_db()->__insert_i(this); |
| 1486 | #endif |
| 1487 | } |
Marshall Clow | ae4f831 | 2018-07-13 16:35:26 +0000 | [diff] [blame] | 1488 | template <class _Up> _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG |
| 1489 | __wrap_iter(const __wrap_iter<_Up>& __u, |
Bruce Mitchener | 170d897 | 2020-11-24 12:53:53 -0500 | [diff] [blame] | 1490 | typename enable_if<is_convertible<_Up, iterator_type>::value>::type* = nullptr) _NOEXCEPT |
Marshall Clow | ae4f831 | 2018-07-13 16:35:26 +0000 | [diff] [blame] | 1491 | : __i(__u.base()) |
Howard Hinnant | 27e0e77 | 2011-09-14 18:33:51 +0000 | [diff] [blame] | 1492 | { |
Louis Dionne | ba40078 | 2020-10-02 15:02:52 -0400 | [diff] [blame] | 1493 | #if _LIBCPP_DEBUG_LEVEL == 2 |
Howard Hinnant | 27e0e77 | 2011-09-14 18:33:51 +0000 | [diff] [blame] | 1494 | __get_db()->__iterator_copy(this, &__u); |
| 1495 | #endif |
| 1496 | } |
Louis Dionne | ba40078 | 2020-10-02 15:02:52 -0400 | [diff] [blame] | 1497 | #if _LIBCPP_DEBUG_LEVEL == 2 |
Marshall Clow | ae4f831 | 2018-07-13 16:35:26 +0000 | [diff] [blame] | 1498 | _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG |
Howard Hinnant | 27e0e77 | 2011-09-14 18:33:51 +0000 | [diff] [blame] | 1499 | __wrap_iter(const __wrap_iter& __x) |
| 1500 | : __i(__x.base()) |
| 1501 | { |
| 1502 | __get_db()->__iterator_copy(this, &__x); |
| 1503 | } |
Marshall Clow | ae4f831 | 2018-07-13 16:35:26 +0000 | [diff] [blame] | 1504 | _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG |
Howard Hinnant | 27e0e77 | 2011-09-14 18:33:51 +0000 | [diff] [blame] | 1505 | __wrap_iter& operator=(const __wrap_iter& __x) |
| 1506 | { |
| 1507 | if (this != &__x) |
| 1508 | { |
| 1509 | __get_db()->__iterator_copy(this, &__x); |
| 1510 | __i = __x.__i; |
| 1511 | } |
| 1512 | return *this; |
| 1513 | } |
Marshall Clow | ae4f831 | 2018-07-13 16:35:26 +0000 | [diff] [blame] | 1514 | _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG |
Howard Hinnant | 27e0e77 | 2011-09-14 18:33:51 +0000 | [diff] [blame] | 1515 | ~__wrap_iter() |
| 1516 | { |
| 1517 | __get_db()->__erase_i(this); |
| 1518 | } |
| 1519 | #endif |
Eric Fiselier | 873b8d3 | 2019-03-18 21:50:12 +0000 | [diff] [blame] | 1520 | _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG reference operator*() const _NOEXCEPT |
Howard Hinnant | 27e0e77 | 2011-09-14 18:33:51 +0000 | [diff] [blame] | 1521 | { |
Louis Dionne | ba40078 | 2020-10-02 15:02:52 -0400 | [diff] [blame] | 1522 | #if _LIBCPP_DEBUG_LEVEL == 2 |
Howard Hinnant | 27e0e77 | 2011-09-14 18:33:51 +0000 | [diff] [blame] | 1523 | _LIBCPP_ASSERT(__get_const_db()->__dereferenceable(this), |
| 1524 | "Attempted to dereference a non-dereferenceable iterator"); |
Howard Hinnant | a47c6d5 | 2011-09-16 17:29:17 +0000 | [diff] [blame] | 1525 | #endif |
Howard Hinnant | 27e0e77 | 2011-09-14 18:33:51 +0000 | [diff] [blame] | 1526 | return *__i; |
| 1527 | } |
Eric Fiselier | 873b8d3 | 2019-03-18 21:50:12 +0000 | [diff] [blame] | 1528 | _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG pointer operator->() const _NOEXCEPT |
Howard Hinnant | 76053d7 | 2013-06-27 19:35:32 +0000 | [diff] [blame] | 1529 | { |
Louis Dionne | ba40078 | 2020-10-02 15:02:52 -0400 | [diff] [blame] | 1530 | #if _LIBCPP_DEBUG_LEVEL == 2 |
Howard Hinnant | 76053d7 | 2013-06-27 19:35:32 +0000 | [diff] [blame] | 1531 | _LIBCPP_ASSERT(__get_const_db()->__dereferenceable(this), |
| 1532 | "Attempted to dereference a non-dereferenceable iterator"); |
| 1533 | #endif |
Louis Dionne | 1c8315b | 2021-05-04 18:51:58 -0400 | [diff] [blame] | 1534 | return _VSTD::__to_address(__i); |
Howard Hinnant | 76053d7 | 2013-06-27 19:35:32 +0000 | [diff] [blame] | 1535 | } |
Eric Fiselier | 873b8d3 | 2019-03-18 21:50:12 +0000 | [diff] [blame] | 1536 | _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG __wrap_iter& operator++() _NOEXCEPT |
Howard Hinnant | 27e0e77 | 2011-09-14 18:33:51 +0000 | [diff] [blame] | 1537 | { |
Louis Dionne | ba40078 | 2020-10-02 15:02:52 -0400 | [diff] [blame] | 1538 | #if _LIBCPP_DEBUG_LEVEL == 2 |
Howard Hinnant | 27e0e77 | 2011-09-14 18:33:51 +0000 | [diff] [blame] | 1539 | _LIBCPP_ASSERT(__get_const_db()->__dereferenceable(this), |
Kristina Bessonova | aeeaa7e | 2021-05-09 19:29:56 +0200 | [diff] [blame] | 1540 | "Attempted to increment a non-incrementable iterator"); |
Howard Hinnant | a47c6d5 | 2011-09-16 17:29:17 +0000 | [diff] [blame] | 1541 | #endif |
Howard Hinnant | 27e0e77 | 2011-09-14 18:33:51 +0000 | [diff] [blame] | 1542 | ++__i; |
| 1543 | return *this; |
| 1544 | } |
Eric Fiselier | 873b8d3 | 2019-03-18 21:50:12 +0000 | [diff] [blame] | 1545 | _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG __wrap_iter operator++(int) _NOEXCEPT |
Howard Hinnant | 27e0e77 | 2011-09-14 18:33:51 +0000 | [diff] [blame] | 1546 | {__wrap_iter __tmp(*this); ++(*this); return __tmp;} |
Marshall Clow | 6d553a5 | 2018-07-14 03:06:11 +0000 | [diff] [blame] | 1547 | |
Eric Fiselier | 873b8d3 | 2019-03-18 21:50:12 +0000 | [diff] [blame] | 1548 | _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG __wrap_iter& operator--() _NOEXCEPT |
Howard Hinnant | 27e0e77 | 2011-09-14 18:33:51 +0000 | [diff] [blame] | 1549 | { |
Louis Dionne | ba40078 | 2020-10-02 15:02:52 -0400 | [diff] [blame] | 1550 | #if _LIBCPP_DEBUG_LEVEL == 2 |
Howard Hinnant | 27e0e77 | 2011-09-14 18:33:51 +0000 | [diff] [blame] | 1551 | _LIBCPP_ASSERT(__get_const_db()->__decrementable(this), |
Kristina Bessonova | aeeaa7e | 2021-05-09 19:29:56 +0200 | [diff] [blame] | 1552 | "Attempted to decrement a non-decrementable iterator"); |
Howard Hinnant | a47c6d5 | 2011-09-16 17:29:17 +0000 | [diff] [blame] | 1553 | #endif |
Howard Hinnant | 27e0e77 | 2011-09-14 18:33:51 +0000 | [diff] [blame] | 1554 | --__i; |
| 1555 | return *this; |
| 1556 | } |
Eric Fiselier | 873b8d3 | 2019-03-18 21:50:12 +0000 | [diff] [blame] | 1557 | _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG __wrap_iter operator--(int) _NOEXCEPT |
Howard Hinnant | 27e0e77 | 2011-09-14 18:33:51 +0000 | [diff] [blame] | 1558 | {__wrap_iter __tmp(*this); --(*this); return __tmp;} |
Eric Fiselier | 873b8d3 | 2019-03-18 21:50:12 +0000 | [diff] [blame] | 1559 | _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG __wrap_iter operator+ (difference_type __n) const _NOEXCEPT |
Howard Hinnant | 27e0e77 | 2011-09-14 18:33:51 +0000 | [diff] [blame] | 1560 | {__wrap_iter __w(*this); __w += __n; return __w;} |
Eric Fiselier | 873b8d3 | 2019-03-18 21:50:12 +0000 | [diff] [blame] | 1561 | _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG __wrap_iter& operator+=(difference_type __n) _NOEXCEPT |
Howard Hinnant | 27e0e77 | 2011-09-14 18:33:51 +0000 | [diff] [blame] | 1562 | { |
Louis Dionne | ba40078 | 2020-10-02 15:02:52 -0400 | [diff] [blame] | 1563 | #if _LIBCPP_DEBUG_LEVEL == 2 |
Howard Hinnant | 27e0e77 | 2011-09-14 18:33:51 +0000 | [diff] [blame] | 1564 | _LIBCPP_ASSERT(__get_const_db()->__addable(this, __n), |
Kristina Bessonova | aeeaa7e | 2021-05-09 19:29:56 +0200 | [diff] [blame] | 1565 | "Attempted to add/subtract an iterator outside its valid range"); |
Howard Hinnant | a47c6d5 | 2011-09-16 17:29:17 +0000 | [diff] [blame] | 1566 | #endif |
Howard Hinnant | 27e0e77 | 2011-09-14 18:33:51 +0000 | [diff] [blame] | 1567 | __i += __n; |
| 1568 | return *this; |
| 1569 | } |
Eric Fiselier | 873b8d3 | 2019-03-18 21:50:12 +0000 | [diff] [blame] | 1570 | _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG __wrap_iter operator- (difference_type __n) const _NOEXCEPT |
Howard Hinnant | 27e0e77 | 2011-09-14 18:33:51 +0000 | [diff] [blame] | 1571 | {return *this + (-__n);} |
Eric Fiselier | 873b8d3 | 2019-03-18 21:50:12 +0000 | [diff] [blame] | 1572 | _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG __wrap_iter& operator-=(difference_type __n) _NOEXCEPT |
Howard Hinnant | 27e0e77 | 2011-09-14 18:33:51 +0000 | [diff] [blame] | 1573 | {*this += -__n; return *this;} |
Eric Fiselier | 873b8d3 | 2019-03-18 21:50:12 +0000 | [diff] [blame] | 1574 | _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG reference operator[](difference_type __n) const _NOEXCEPT |
Howard Hinnant | 27e0e77 | 2011-09-14 18:33:51 +0000 | [diff] [blame] | 1575 | { |
Louis Dionne | ba40078 | 2020-10-02 15:02:52 -0400 | [diff] [blame] | 1576 | #if _LIBCPP_DEBUG_LEVEL == 2 |
Howard Hinnant | 27e0e77 | 2011-09-14 18:33:51 +0000 | [diff] [blame] | 1577 | _LIBCPP_ASSERT(__get_const_db()->__subscriptable(this, __n), |
Kristina Bessonova | aeeaa7e | 2021-05-09 19:29:56 +0200 | [diff] [blame] | 1578 | "Attempted to subscript an iterator outside its valid range"); |
Howard Hinnant | a47c6d5 | 2011-09-16 17:29:17 +0000 | [diff] [blame] | 1579 | #endif |
Howard Hinnant | 27e0e77 | 2011-09-14 18:33:51 +0000 | [diff] [blame] | 1580 | return __i[__n]; |
| 1581 | } |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1582 | |
Eric Fiselier | 873b8d3 | 2019-03-18 21:50:12 +0000 | [diff] [blame] | 1583 | _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG iterator_type base() const _NOEXCEPT {return __i;} |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1584 | |
| 1585 | private: |
Louis Dionne | ba40078 | 2020-10-02 15:02:52 -0400 | [diff] [blame] | 1586 | #if _LIBCPP_DEBUG_LEVEL == 2 |
Marshall Clow | ae4f831 | 2018-07-13 16:35:26 +0000 | [diff] [blame] | 1587 | _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG __wrap_iter(const void* __p, iterator_type __x) : __i(__x) |
Howard Hinnant | 27e0e77 | 2011-09-14 18:33:51 +0000 | [diff] [blame] | 1588 | { |
| 1589 | __get_db()->__insert_ic(this, __p); |
| 1590 | } |
Howard Hinnant | 8ea9824 | 2013-08-23 17:37:05 +0000 | [diff] [blame] | 1591 | #else |
Eric Fiselier | 873b8d3 | 2019-03-18 21:50:12 +0000 | [diff] [blame] | 1592 | _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG __wrap_iter(iterator_type __x) _NOEXCEPT : __i(__x) {} |
Howard Hinnant | 27e0e77 | 2011-09-14 18:33:51 +0000 | [diff] [blame] | 1593 | #endif |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1594 | |
| 1595 | template <class _Up> friend class __wrap_iter; |
| 1596 | template <class _CharT, class _Traits, class _Alloc> friend class basic_string; |
Eric Fiselier | b5eb1bf | 2017-01-04 23:56:00 +0000 | [diff] [blame] | 1597 | template <class _Tp, class _Alloc> friend class _LIBCPP_TEMPLATE_VIS vector; |
Marshall Clow | cd6d880 | 2019-02-27 00:32:16 +0000 | [diff] [blame] | 1598 | template <class _Tp, size_t> friend class _LIBCPP_TEMPLATE_VIS span; |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1599 | |
| 1600 | template <class _Iter1, class _Iter2> |
Marshall Clow | ae4f831 | 2018-07-13 16:35:26 +0000 | [diff] [blame] | 1601 | _LIBCPP_CONSTEXPR_IF_NODEBUG friend |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1602 | bool |
Eric Fiselier | 873b8d3 | 2019-03-18 21:50:12 +0000 | [diff] [blame] | 1603 | operator==(const __wrap_iter<_Iter1>&, const __wrap_iter<_Iter2>&) _NOEXCEPT; |
Howard Hinnant | 3b6579a | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 1604 | |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1605 | template <class _Iter1, class _Iter2> |
Marshall Clow | ae4f831 | 2018-07-13 16:35:26 +0000 | [diff] [blame] | 1606 | _LIBCPP_CONSTEXPR_IF_NODEBUG friend |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1607 | bool |
Eric Fiselier | 873b8d3 | 2019-03-18 21:50:12 +0000 | [diff] [blame] | 1608 | operator<(const __wrap_iter<_Iter1>&, const __wrap_iter<_Iter2>&) _NOEXCEPT; |
Howard Hinnant | 3b6579a | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 1609 | |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1610 | template <class _Iter1, class _Iter2> |
Marshall Clow | ae4f831 | 2018-07-13 16:35:26 +0000 | [diff] [blame] | 1611 | _LIBCPP_CONSTEXPR_IF_NODEBUG friend |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1612 | bool |
Eric Fiselier | 873b8d3 | 2019-03-18 21:50:12 +0000 | [diff] [blame] | 1613 | operator!=(const __wrap_iter<_Iter1>&, const __wrap_iter<_Iter2>&) _NOEXCEPT; |
Howard Hinnant | 3b6579a | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 1614 | |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1615 | template <class _Iter1, class _Iter2> |
Marshall Clow | ae4f831 | 2018-07-13 16:35:26 +0000 | [diff] [blame] | 1616 | _LIBCPP_CONSTEXPR_IF_NODEBUG friend |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1617 | bool |
Eric Fiselier | 873b8d3 | 2019-03-18 21:50:12 +0000 | [diff] [blame] | 1618 | operator>(const __wrap_iter<_Iter1>&, const __wrap_iter<_Iter2>&) _NOEXCEPT; |
Howard Hinnant | 3b6579a | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 1619 | |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1620 | template <class _Iter1, class _Iter2> |
Marshall Clow | ae4f831 | 2018-07-13 16:35:26 +0000 | [diff] [blame] | 1621 | _LIBCPP_CONSTEXPR_IF_NODEBUG friend |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1622 | bool |
Eric Fiselier | 873b8d3 | 2019-03-18 21:50:12 +0000 | [diff] [blame] | 1623 | operator>=(const __wrap_iter<_Iter1>&, const __wrap_iter<_Iter2>&) _NOEXCEPT; |
Howard Hinnant | 3b6579a | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 1624 | |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1625 | template <class _Iter1, class _Iter2> |
Marshall Clow | ae4f831 | 2018-07-13 16:35:26 +0000 | [diff] [blame] | 1626 | _LIBCPP_CONSTEXPR_IF_NODEBUG friend |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1627 | bool |
Eric Fiselier | 873b8d3 | 2019-03-18 21:50:12 +0000 | [diff] [blame] | 1628 | operator<=(const __wrap_iter<_Iter1>&, const __wrap_iter<_Iter2>&) _NOEXCEPT; |
Howard Hinnant | 3b6579a | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 1629 | |
Marshall Clow | 476d3f4 | 2016-07-18 13:19:00 +0000 | [diff] [blame] | 1630 | #ifndef _LIBCPP_CXX03_LANG |
Marshall Clow | f8fec4e | 2016-07-08 16:54:47 +0000 | [diff] [blame] | 1631 | template <class _Iter1, class _Iter2> |
Marshall Clow | ae4f831 | 2018-07-13 16:35:26 +0000 | [diff] [blame] | 1632 | _LIBCPP_CONSTEXPR_IF_NODEBUG friend |
Marshall Clow | f8fec4e | 2016-07-08 16:54:47 +0000 | [diff] [blame] | 1633 | auto |
Eric Fiselier | 873b8d3 | 2019-03-18 21:50:12 +0000 | [diff] [blame] | 1634 | operator-(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter2>& __y) _NOEXCEPT |
Marshall Clow | f8fec4e | 2016-07-08 16:54:47 +0000 | [diff] [blame] | 1635 | -> decltype(__x.base() - __y.base()); |
| 1636 | #else |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1637 | template <class _Iter1, class _Iter2> |
Marshall Clow | ae4f831 | 2018-07-13 16:35:26 +0000 | [diff] [blame] | 1638 | _LIBCPP_CONSTEXPR_IF_NODEBUG friend |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1639 | typename __wrap_iter<_Iter1>::difference_type |
Eric Fiselier | 873b8d3 | 2019-03-18 21:50:12 +0000 | [diff] [blame] | 1640 | operator-(const __wrap_iter<_Iter1>&, const __wrap_iter<_Iter2>&) _NOEXCEPT; |
Marshall Clow | f8fec4e | 2016-07-08 16:54:47 +0000 | [diff] [blame] | 1641 | #endif |
Howard Hinnant | 3b6579a | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 1642 | |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1643 | template <class _Iter1> |
Marshall Clow | ae4f831 | 2018-07-13 16:35:26 +0000 | [diff] [blame] | 1644 | _LIBCPP_CONSTEXPR_IF_NODEBUG friend |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1645 | __wrap_iter<_Iter1> |
Eric Fiselier | 873b8d3 | 2019-03-18 21:50:12 +0000 | [diff] [blame] | 1646 | operator+(typename __wrap_iter<_Iter1>::difference_type, __wrap_iter<_Iter1>) _NOEXCEPT; |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1647 | }; |
| 1648 | |
Arthur O'Dwyer | 1ac9f09 | 2021-01-15 12:59:56 -0500 | [diff] [blame] | 1649 | #if _LIBCPP_STD_VER <= 17 |
| 1650 | template <class _It> |
Arthur O'Dwyer | 6eb8a5d | 2021-05-19 11:54:31 -0400 | [diff] [blame] | 1651 | struct __is_cpp17_contiguous_iterator<__wrap_iter<_It> > : true_type {}; |
Arthur O'Dwyer | 1ac9f09 | 2021-01-15 12:59:56 -0500 | [diff] [blame] | 1652 | #endif |
| 1653 | |
| 1654 | template <class _Iter> |
| 1655 | _LIBCPP_CONSTEXPR |
Arthur O'Dwyer | 6eb8a5d | 2021-05-19 11:54:31 -0400 | [diff] [blame] | 1656 | decltype(_VSTD::__to_address(declval<_Iter>())) |
Arthur O'Dwyer | 1ac9f09 | 2021-01-15 12:59:56 -0500 | [diff] [blame] | 1657 | __to_address(__wrap_iter<_Iter> __w) _NOEXCEPT { |
| 1658 | return _VSTD::__to_address(__w.base()); |
| 1659 | } |
| 1660 | |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1661 | template <class _Iter1, class _Iter2> |
Marshall Clow | ae4f831 | 2018-07-13 16:35:26 +0000 | [diff] [blame] | 1662 | inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1663 | bool |
Eric Fiselier | 873b8d3 | 2019-03-18 21:50:12 +0000 | [diff] [blame] | 1664 | operator==(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter2>& __y) _NOEXCEPT |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1665 | { |
| 1666 | return __x.base() == __y.base(); |
| 1667 | } |
| 1668 | |
| 1669 | template <class _Iter1, class _Iter2> |
Marshall Clow | ae4f831 | 2018-07-13 16:35:26 +0000 | [diff] [blame] | 1670 | inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1671 | bool |
Eric Fiselier | 873b8d3 | 2019-03-18 21:50:12 +0000 | [diff] [blame] | 1672 | operator<(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter2>& __y) _NOEXCEPT |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1673 | { |
Louis Dionne | ba40078 | 2020-10-02 15:02:52 -0400 | [diff] [blame] | 1674 | #if _LIBCPP_DEBUG_LEVEL == 2 |
Howard Hinnant | e6ff0b6 | 2013-08-02 00:26:35 +0000 | [diff] [blame] | 1675 | _LIBCPP_ASSERT(__get_const_db()->__less_than_comparable(&__x, &__y), |
Howard Hinnant | 27e0e77 | 2011-09-14 18:33:51 +0000 | [diff] [blame] | 1676 | "Attempted to compare incomparable iterators"); |
Howard Hinnant | a47c6d5 | 2011-09-16 17:29:17 +0000 | [diff] [blame] | 1677 | #endif |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1678 | return __x.base() < __y.base(); |
| 1679 | } |
| 1680 | |
| 1681 | template <class _Iter1, class _Iter2> |
Marshall Clow | ae4f831 | 2018-07-13 16:35:26 +0000 | [diff] [blame] | 1682 | inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1683 | bool |
Eric Fiselier | 873b8d3 | 2019-03-18 21:50:12 +0000 | [diff] [blame] | 1684 | operator!=(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter2>& __y) _NOEXCEPT |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1685 | { |
Howard Hinnant | 27e0e77 | 2011-09-14 18:33:51 +0000 | [diff] [blame] | 1686 | return !(__x == __y); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1687 | } |
| 1688 | |
| 1689 | template <class _Iter1, class _Iter2> |
Marshall Clow | ae4f831 | 2018-07-13 16:35:26 +0000 | [diff] [blame] | 1690 | inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1691 | bool |
Eric Fiselier | 873b8d3 | 2019-03-18 21:50:12 +0000 | [diff] [blame] | 1692 | operator>(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter2>& __y) _NOEXCEPT |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1693 | { |
Howard Hinnant | 27e0e77 | 2011-09-14 18:33:51 +0000 | [diff] [blame] | 1694 | return __y < __x; |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1695 | } |
| 1696 | |
| 1697 | template <class _Iter1, class _Iter2> |
Marshall Clow | ae4f831 | 2018-07-13 16:35:26 +0000 | [diff] [blame] | 1698 | inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1699 | bool |
Eric Fiselier | 873b8d3 | 2019-03-18 21:50:12 +0000 | [diff] [blame] | 1700 | operator>=(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter2>& __y) _NOEXCEPT |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1701 | { |
Howard Hinnant | 27e0e77 | 2011-09-14 18:33:51 +0000 | [diff] [blame] | 1702 | return !(__x < __y); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1703 | } |
| 1704 | |
| 1705 | template <class _Iter1, class _Iter2> |
Marshall Clow | ae4f831 | 2018-07-13 16:35:26 +0000 | [diff] [blame] | 1706 | inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1707 | bool |
Eric Fiselier | 873b8d3 | 2019-03-18 21:50:12 +0000 | [diff] [blame] | 1708 | operator<=(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter2>& __y) _NOEXCEPT |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1709 | { |
Howard Hinnant | 27e0e77 | 2011-09-14 18:33:51 +0000 | [diff] [blame] | 1710 | return !(__y < __x); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1711 | } |
| 1712 | |
Howard Hinnant | f78e32c | 2012-10-02 19:45:42 +0000 | [diff] [blame] | 1713 | template <class _Iter1> |
Marshall Clow | ae4f831 | 2018-07-13 16:35:26 +0000 | [diff] [blame] | 1714 | inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG |
Howard Hinnant | f78e32c | 2012-10-02 19:45:42 +0000 | [diff] [blame] | 1715 | bool |
Eric Fiselier | 873b8d3 | 2019-03-18 21:50:12 +0000 | [diff] [blame] | 1716 | operator!=(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter1>& __y) _NOEXCEPT |
Howard Hinnant | f78e32c | 2012-10-02 19:45:42 +0000 | [diff] [blame] | 1717 | { |
| 1718 | return !(__x == __y); |
| 1719 | } |
| 1720 | |
| 1721 | template <class _Iter1> |
Marshall Clow | ae4f831 | 2018-07-13 16:35:26 +0000 | [diff] [blame] | 1722 | inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG |
Howard Hinnant | f78e32c | 2012-10-02 19:45:42 +0000 | [diff] [blame] | 1723 | bool |
Eric Fiselier | 873b8d3 | 2019-03-18 21:50:12 +0000 | [diff] [blame] | 1724 | operator>(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter1>& __y) _NOEXCEPT |
Howard Hinnant | f78e32c | 2012-10-02 19:45:42 +0000 | [diff] [blame] | 1725 | { |
| 1726 | return __y < __x; |
| 1727 | } |
| 1728 | |
| 1729 | template <class _Iter1> |
Marshall Clow | ae4f831 | 2018-07-13 16:35:26 +0000 | [diff] [blame] | 1730 | inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG |
Howard Hinnant | f78e32c | 2012-10-02 19:45:42 +0000 | [diff] [blame] | 1731 | bool |
Eric Fiselier | 873b8d3 | 2019-03-18 21:50:12 +0000 | [diff] [blame] | 1732 | operator>=(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter1>& __y) _NOEXCEPT |
Howard Hinnant | f78e32c | 2012-10-02 19:45:42 +0000 | [diff] [blame] | 1733 | { |
| 1734 | return !(__x < __y); |
| 1735 | } |
| 1736 | |
| 1737 | template <class _Iter1> |
Marshall Clow | ae4f831 | 2018-07-13 16:35:26 +0000 | [diff] [blame] | 1738 | inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG |
Howard Hinnant | f78e32c | 2012-10-02 19:45:42 +0000 | [diff] [blame] | 1739 | bool |
Eric Fiselier | 873b8d3 | 2019-03-18 21:50:12 +0000 | [diff] [blame] | 1740 | operator<=(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter1>& __y) _NOEXCEPT |
Howard Hinnant | f78e32c | 2012-10-02 19:45:42 +0000 | [diff] [blame] | 1741 | { |
| 1742 | return !(__y < __x); |
| 1743 | } |
| 1744 | |
Marshall Clow | 476d3f4 | 2016-07-18 13:19:00 +0000 | [diff] [blame] | 1745 | #ifndef _LIBCPP_CXX03_LANG |
Marshall Clow | f8fec4e | 2016-07-08 16:54:47 +0000 | [diff] [blame] | 1746 | template <class _Iter1, class _Iter2> |
Marshall Clow | ae4f831 | 2018-07-13 16:35:26 +0000 | [diff] [blame] | 1747 | inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG |
Marshall Clow | f8fec4e | 2016-07-08 16:54:47 +0000 | [diff] [blame] | 1748 | auto |
Eric Fiselier | 873b8d3 | 2019-03-18 21:50:12 +0000 | [diff] [blame] | 1749 | operator-(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter2>& __y) _NOEXCEPT |
Marshall Clow | f8fec4e | 2016-07-08 16:54:47 +0000 | [diff] [blame] | 1750 | -> decltype(__x.base() - __y.base()) |
| 1751 | { |
Louis Dionne | ba40078 | 2020-10-02 15:02:52 -0400 | [diff] [blame] | 1752 | #if _LIBCPP_DEBUG_LEVEL == 2 |
Marshall Clow | f8fec4e | 2016-07-08 16:54:47 +0000 | [diff] [blame] | 1753 | _LIBCPP_ASSERT(__get_const_db()->__less_than_comparable(&__x, &__y), |
| 1754 | "Attempted to subtract incompatible iterators"); |
| 1755 | #endif |
| 1756 | return __x.base() - __y.base(); |
| 1757 | } |
| 1758 | #else |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1759 | template <class _Iter1, class _Iter2> |
Marshall Clow | ae4f831 | 2018-07-13 16:35:26 +0000 | [diff] [blame] | 1760 | inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1761 | typename __wrap_iter<_Iter1>::difference_type |
Eric Fiselier | 873b8d3 | 2019-03-18 21:50:12 +0000 | [diff] [blame] | 1762 | operator-(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter2>& __y) _NOEXCEPT |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1763 | { |
Louis Dionne | ba40078 | 2020-10-02 15:02:52 -0400 | [diff] [blame] | 1764 | #if _LIBCPP_DEBUG_LEVEL == 2 |
Howard Hinnant | e6ff0b6 | 2013-08-02 00:26:35 +0000 | [diff] [blame] | 1765 | _LIBCPP_ASSERT(__get_const_db()->__less_than_comparable(&__x, &__y), |
Howard Hinnant | 27e0e77 | 2011-09-14 18:33:51 +0000 | [diff] [blame] | 1766 | "Attempted to subtract incompatible iterators"); |
Howard Hinnant | a47c6d5 | 2011-09-16 17:29:17 +0000 | [diff] [blame] | 1767 | #endif |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1768 | return __x.base() - __y.base(); |
| 1769 | } |
Marshall Clow | f8fec4e | 2016-07-08 16:54:47 +0000 | [diff] [blame] | 1770 | #endif |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1771 | |
| 1772 | template <class _Iter> |
Marshall Clow | ae4f831 | 2018-07-13 16:35:26 +0000 | [diff] [blame] | 1773 | inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1774 | __wrap_iter<_Iter> |
| 1775 | operator+(typename __wrap_iter<_Iter>::difference_type __n, |
Eric Fiselier | 873b8d3 | 2019-03-18 21:50:12 +0000 | [diff] [blame] | 1776 | __wrap_iter<_Iter> __x) _NOEXCEPT |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1777 | { |
Howard Hinnant | 27e0e77 | 2011-09-14 18:33:51 +0000 | [diff] [blame] | 1778 | __x += __n; |
| 1779 | return __x; |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1780 | } |
| 1781 | |
Marshall Clow | 8411ebf | 2013-12-02 03:24:33 +0000 | [diff] [blame] | 1782 | template <class _Tp, size_t _Np> |
Marshall Clow | 0bd662d | 2019-02-27 03:25:43 +0000 | [diff] [blame] | 1783 | _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 |
Marshall Clow | 8411ebf | 2013-12-02 03:24:33 +0000 | [diff] [blame] | 1784 | _Tp* |
| 1785 | begin(_Tp (&__array)[_Np]) |
| 1786 | { |
| 1787 | return __array; |
| 1788 | } |
| 1789 | |
| 1790 | template <class _Tp, size_t _Np> |
Marshall Clow | 0bd662d | 2019-02-27 03:25:43 +0000 | [diff] [blame] | 1791 | _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 |
Marshall Clow | 8411ebf | 2013-12-02 03:24:33 +0000 | [diff] [blame] | 1792 | _Tp* |
| 1793 | end(_Tp (&__array)[_Np]) |
| 1794 | { |
| 1795 | return __array + _Np; |
| 1796 | } |
| 1797 | |
Eric Fiselier | c6f17cc | 2016-09-25 03:34:28 +0000 | [diff] [blame] | 1798 | #if !defined(_LIBCPP_CXX03_LANG) |
Marshall Clow | 037fcb7 | 2013-12-11 19:32:32 +0000 | [diff] [blame] | 1799 | |
Howard Hinnant | c834c51 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 1800 | template <class _Cp> |
Marshall Clow | 0bd662d | 2019-02-27 03:25:43 +0000 | [diff] [blame] | 1801 | _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1802 | auto |
Howard Hinnant | c834c51 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 1803 | begin(_Cp& __c) -> decltype(__c.begin()) |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1804 | { |
| 1805 | return __c.begin(); |
| 1806 | } |
| 1807 | |
Howard Hinnant | c834c51 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 1808 | template <class _Cp> |
Marshall Clow | 0bd662d | 2019-02-27 03:25:43 +0000 | [diff] [blame] | 1809 | _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1810 | auto |
Howard Hinnant | c834c51 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 1811 | begin(const _Cp& __c) -> decltype(__c.begin()) |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1812 | { |
| 1813 | return __c.begin(); |
| 1814 | } |
| 1815 | |
Howard Hinnant | c834c51 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 1816 | template <class _Cp> |
Marshall Clow | 0bd662d | 2019-02-27 03:25:43 +0000 | [diff] [blame] | 1817 | _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1818 | auto |
Howard Hinnant | c834c51 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 1819 | end(_Cp& __c) -> decltype(__c.end()) |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1820 | { |
| 1821 | return __c.end(); |
| 1822 | } |
| 1823 | |
Howard Hinnant | c834c51 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 1824 | template <class _Cp> |
Marshall Clow | 0bd662d | 2019-02-27 03:25:43 +0000 | [diff] [blame] | 1825 | _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1826 | auto |
Howard Hinnant | c834c51 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 1827 | end(const _Cp& __c) -> decltype(__c.end()) |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1828 | { |
| 1829 | return __c.end(); |
| 1830 | } |
| 1831 | |
Marshall Clow | b278e9c | 2013-08-30 01:17:07 +0000 | [diff] [blame] | 1832 | #if _LIBCPP_STD_VER > 11 |
| 1833 | |
Marshall Clow | 8411ebf | 2013-12-02 03:24:33 +0000 | [diff] [blame] | 1834 | template <class _Tp, size_t _Np> |
Marshall Clow | 0bd662d | 2019-02-27 03:25:43 +0000 | [diff] [blame] | 1835 | _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 |
Marshall Clow | 8411ebf | 2013-12-02 03:24:33 +0000 | [diff] [blame] | 1836 | reverse_iterator<_Tp*> rbegin(_Tp (&__array)[_Np]) |
| 1837 | { |
| 1838 | return reverse_iterator<_Tp*>(__array + _Np); |
| 1839 | } |
| 1840 | |
| 1841 | template <class _Tp, size_t _Np> |
Marshall Clow | 0bd662d | 2019-02-27 03:25:43 +0000 | [diff] [blame] | 1842 | _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 |
Marshall Clow | 8411ebf | 2013-12-02 03:24:33 +0000 | [diff] [blame] | 1843 | reverse_iterator<_Tp*> rend(_Tp (&__array)[_Np]) |
| 1844 | { |
| 1845 | return reverse_iterator<_Tp*>(__array); |
| 1846 | } |
| 1847 | |
| 1848 | template <class _Ep> |
Marshall Clow | 0bd662d | 2019-02-27 03:25:43 +0000 | [diff] [blame] | 1849 | _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 |
Marshall Clow | 8411ebf | 2013-12-02 03:24:33 +0000 | [diff] [blame] | 1850 | reverse_iterator<const _Ep*> rbegin(initializer_list<_Ep> __il) |
| 1851 | { |
| 1852 | return reverse_iterator<const _Ep*>(__il.end()); |
| 1853 | } |
| 1854 | |
| 1855 | template <class _Ep> |
Marshall Clow | 0bd662d | 2019-02-27 03:25:43 +0000 | [diff] [blame] | 1856 | _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 |
Marshall Clow | 8411ebf | 2013-12-02 03:24:33 +0000 | [diff] [blame] | 1857 | reverse_iterator<const _Ep*> rend(initializer_list<_Ep> __il) |
| 1858 | { |
| 1859 | return reverse_iterator<const _Ep*>(__il.begin()); |
| 1860 | } |
| 1861 | |
Marshall Clow | b278e9c | 2013-08-30 01:17:07 +0000 | [diff] [blame] | 1862 | template <class _Cp> |
Marshall Clow | 0bd662d | 2019-02-27 03:25:43 +0000 | [diff] [blame] | 1863 | _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 |
Marshall Clow | 3862f53 | 2016-08-10 20:04:46 +0000 | [diff] [blame] | 1864 | auto cbegin(const _Cp& __c) -> decltype(_VSTD::begin(__c)) |
Marshall Clow | b278e9c | 2013-08-30 01:17:07 +0000 | [diff] [blame] | 1865 | { |
Marshall Clow | 3862f53 | 2016-08-10 20:04:46 +0000 | [diff] [blame] | 1866 | return _VSTD::begin(__c); |
Marshall Clow | b278e9c | 2013-08-30 01:17:07 +0000 | [diff] [blame] | 1867 | } |
| 1868 | |
| 1869 | template <class _Cp> |
Marshall Clow | 0bd662d | 2019-02-27 03:25:43 +0000 | [diff] [blame] | 1870 | _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 |
Marshall Clow | 3862f53 | 2016-08-10 20:04:46 +0000 | [diff] [blame] | 1871 | auto cend(const _Cp& __c) -> decltype(_VSTD::end(__c)) |
Marshall Clow | b278e9c | 2013-08-30 01:17:07 +0000 | [diff] [blame] | 1872 | { |
Marshall Clow | 3862f53 | 2016-08-10 20:04:46 +0000 | [diff] [blame] | 1873 | return _VSTD::end(__c); |
Marshall Clow | b278e9c | 2013-08-30 01:17:07 +0000 | [diff] [blame] | 1874 | } |
| 1875 | |
| 1876 | template <class _Cp> |
Marshall Clow | 0bd662d | 2019-02-27 03:25:43 +0000 | [diff] [blame] | 1877 | _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 |
Marshall Clow | b278e9c | 2013-08-30 01:17:07 +0000 | [diff] [blame] | 1878 | auto rbegin(_Cp& __c) -> decltype(__c.rbegin()) |
| 1879 | { |
| 1880 | return __c.rbegin(); |
| 1881 | } |
| 1882 | |
| 1883 | template <class _Cp> |
Marshall Clow | 0bd662d | 2019-02-27 03:25:43 +0000 | [diff] [blame] | 1884 | _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 |
Marshall Clow | b278e9c | 2013-08-30 01:17:07 +0000 | [diff] [blame] | 1885 | auto rbegin(const _Cp& __c) -> decltype(__c.rbegin()) |
| 1886 | { |
| 1887 | return __c.rbegin(); |
| 1888 | } |
| 1889 | |
| 1890 | template <class _Cp> |
Marshall Clow | 0bd662d | 2019-02-27 03:25:43 +0000 | [diff] [blame] | 1891 | _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 |
Marshall Clow | b278e9c | 2013-08-30 01:17:07 +0000 | [diff] [blame] | 1892 | auto rend(_Cp& __c) -> decltype(__c.rend()) |
| 1893 | { |
| 1894 | return __c.rend(); |
| 1895 | } |
| 1896 | |
| 1897 | template <class _Cp> |
Marshall Clow | 0bd662d | 2019-02-27 03:25:43 +0000 | [diff] [blame] | 1898 | _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 |
Marshall Clow | b278e9c | 2013-08-30 01:17:07 +0000 | [diff] [blame] | 1899 | auto rend(const _Cp& __c) -> decltype(__c.rend()) |
| 1900 | { |
| 1901 | return __c.rend(); |
| 1902 | } |
| 1903 | |
| 1904 | template <class _Cp> |
Marshall Clow | 0bd662d | 2019-02-27 03:25:43 +0000 | [diff] [blame] | 1905 | _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 |
Marshall Clow | 3862f53 | 2016-08-10 20:04:46 +0000 | [diff] [blame] | 1906 | auto crbegin(const _Cp& __c) -> decltype(_VSTD::rbegin(__c)) |
Marshall Clow | b278e9c | 2013-08-30 01:17:07 +0000 | [diff] [blame] | 1907 | { |
Marshall Clow | 3862f53 | 2016-08-10 20:04:46 +0000 | [diff] [blame] | 1908 | return _VSTD::rbegin(__c); |
Marshall Clow | b278e9c | 2013-08-30 01:17:07 +0000 | [diff] [blame] | 1909 | } |
| 1910 | |
| 1911 | template <class _Cp> |
Marshall Clow | 0bd662d | 2019-02-27 03:25:43 +0000 | [diff] [blame] | 1912 | _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 |
Marshall Clow | 3862f53 | 2016-08-10 20:04:46 +0000 | [diff] [blame] | 1913 | auto crend(const _Cp& __c) -> decltype(_VSTD::rend(__c)) |
Marshall Clow | b278e9c | 2013-08-30 01:17:07 +0000 | [diff] [blame] | 1914 | { |
Marshall Clow | 3862f53 | 2016-08-10 20:04:46 +0000 | [diff] [blame] | 1915 | return _VSTD::rend(__c); |
Marshall Clow | b278e9c | 2013-08-30 01:17:07 +0000 | [diff] [blame] | 1916 | } |
| 1917 | |
| 1918 | #endif |
| 1919 | |
| 1920 | |
Eric Fiselier | c6f17cc | 2016-09-25 03:34:28 +0000 | [diff] [blame] | 1921 | #else // defined(_LIBCPP_CXX03_LANG) |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1922 | |
Howard Hinnant | c834c51 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 1923 | template <class _Cp> |
Marshall Clow | 0bd662d | 2019-02-27 03:25:43 +0000 | [diff] [blame] | 1924 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | c834c51 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 1925 | typename _Cp::iterator |
| 1926 | begin(_Cp& __c) |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1927 | { |
| 1928 | return __c.begin(); |
| 1929 | } |
| 1930 | |
Howard Hinnant | c834c51 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 1931 | template <class _Cp> |
Marshall Clow | 0bd662d | 2019-02-27 03:25:43 +0000 | [diff] [blame] | 1932 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | c834c51 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 1933 | typename _Cp::const_iterator |
| 1934 | begin(const _Cp& __c) |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1935 | { |
| 1936 | return __c.begin(); |
| 1937 | } |
| 1938 | |
Howard Hinnant | c834c51 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 1939 | template <class _Cp> |
Marshall Clow | 0bd662d | 2019-02-27 03:25:43 +0000 | [diff] [blame] | 1940 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | c834c51 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 1941 | typename _Cp::iterator |
| 1942 | end(_Cp& __c) |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1943 | { |
| 1944 | return __c.end(); |
| 1945 | } |
| 1946 | |
Howard Hinnant | c834c51 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 1947 | template <class _Cp> |
Marshall Clow | 0bd662d | 2019-02-27 03:25:43 +0000 | [diff] [blame] | 1948 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | c834c51 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 1949 | typename _Cp::const_iterator |
| 1950 | end(const _Cp& __c) |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1951 | { |
| 1952 | return __c.end(); |
| 1953 | } |
| 1954 | |
Louis Dionne | 2b1ceaa | 2021-04-20 12:03:32 -0400 | [diff] [blame] | 1955 | #endif // !defined(_LIBCPP_CXX03_LANG) |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1956 | |
Marshall Clow | ef35727 | 2014-11-19 19:43:23 +0000 | [diff] [blame] | 1957 | #if _LIBCPP_STD_VER > 14 |
Marshall Clow | 344c41d | 2017-11-16 17:55:41 +0000 | [diff] [blame] | 1958 | |
| 1959 | // #if _LIBCPP_STD_VER > 11 |
| 1960 | // template <> |
| 1961 | // struct _LIBCPP_TEMPLATE_VIS plus<void> |
| 1962 | // { |
| 1963 | // template <class _T1, class _T2> |
| 1964 | // _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY |
| 1965 | // auto operator()(_T1&& __t, _T2&& __u) const |
| 1966 | // _NOEXCEPT_(noexcept(_VSTD::forward<_T1>(__t) + _VSTD::forward<_T2>(__u))) |
| 1967 | // -> decltype (_VSTD::forward<_T1>(__t) + _VSTD::forward<_T2>(__u)) |
| 1968 | // { return _VSTD::forward<_T1>(__t) + _VSTD::forward<_T2>(__u); } |
| 1969 | // typedef void is_transparent; |
| 1970 | // }; |
| 1971 | // #endif |
| 1972 | |
Marshall Clow | c4b4a34 | 2015-02-11 16:14:01 +0000 | [diff] [blame] | 1973 | template <class _Cont> |
Marshall Clow | 0bd662d | 2019-02-27 03:25:43 +0000 | [diff] [blame] | 1974 | _LIBCPP_INLINE_VISIBILITY |
Marshall Clow | 344c41d | 2017-11-16 17:55:41 +0000 | [diff] [blame] | 1975 | constexpr auto size(const _Cont& __c) |
| 1976 | _NOEXCEPT_(noexcept(__c.size())) |
| 1977 | -> decltype (__c.size()) |
| 1978 | { return __c.size(); } |
Marshall Clow | ef35727 | 2014-11-19 19:43:23 +0000 | [diff] [blame] | 1979 | |
Marshall Clow | c4b4a34 | 2015-02-11 16:14:01 +0000 | [diff] [blame] | 1980 | template <class _Tp, size_t _Sz> |
Marshall Clow | 0bd662d | 2019-02-27 03:25:43 +0000 | [diff] [blame] | 1981 | _LIBCPP_INLINE_VISIBILITY |
Eric Fiselier | 6003c77 | 2016-12-23 23:37:52 +0000 | [diff] [blame] | 1982 | constexpr size_t size(const _Tp (&)[_Sz]) noexcept { return _Sz; } |
Marshall Clow | ef35727 | 2014-11-19 19:43:23 +0000 | [diff] [blame] | 1983 | |
Marshall Clow | 3c5363e | 2019-02-27 02:58:56 +0000 | [diff] [blame] | 1984 | #if _LIBCPP_STD_VER > 17 |
| 1985 | template <class _Cont> |
Marshall Clow | 0bd662d | 2019-02-27 03:25:43 +0000 | [diff] [blame] | 1986 | _LIBCPP_INLINE_VISIBILITY |
Marshall Clow | 3c5363e | 2019-02-27 02:58:56 +0000 | [diff] [blame] | 1987 | constexpr auto ssize(const _Cont& __c) |
| 1988 | _NOEXCEPT_(noexcept(static_cast<common_type_t<ptrdiff_t, make_signed_t<decltype(__c.size())>>>(__c.size()))) |
| 1989 | -> common_type_t<ptrdiff_t, make_signed_t<decltype(__c.size())>> |
| 1990 | { return static_cast<common_type_t<ptrdiff_t, make_signed_t<decltype(__c.size())>>>(__c.size()); } |
| 1991 | |
| 1992 | template <class _Tp, ptrdiff_t _Sz> |
Marshall Clow | 0bd662d | 2019-02-27 03:25:43 +0000 | [diff] [blame] | 1993 | _LIBCPP_INLINE_VISIBILITY |
Marshall Clow | 3c5363e | 2019-02-27 02:58:56 +0000 | [diff] [blame] | 1994 | constexpr ptrdiff_t ssize(const _Tp (&)[_Sz]) noexcept { return _Sz; } |
| 1995 | #endif |
| 1996 | |
Marshall Clow | c4b4a34 | 2015-02-11 16:14:01 +0000 | [diff] [blame] | 1997 | template <class _Cont> |
Marshall Clow | 0bd662d | 2019-02-27 03:25:43 +0000 | [diff] [blame] | 1998 | _LIBCPP_NODISCARD_AFTER_CXX17 _LIBCPP_INLINE_VISIBILITY |
Marshall Clow | 344c41d | 2017-11-16 17:55:41 +0000 | [diff] [blame] | 1999 | constexpr auto empty(const _Cont& __c) |
| 2000 | _NOEXCEPT_(noexcept(__c.empty())) |
| 2001 | -> decltype (__c.empty()) |
| 2002 | { return __c.empty(); } |
Marshall Clow | ef35727 | 2014-11-19 19:43:23 +0000 | [diff] [blame] | 2003 | |
Marshall Clow | c4b4a34 | 2015-02-11 16:14:01 +0000 | [diff] [blame] | 2004 | template <class _Tp, size_t _Sz> |
Marshall Clow | 0bd662d | 2019-02-27 03:25:43 +0000 | [diff] [blame] | 2005 | _LIBCPP_NODISCARD_AFTER_CXX17 _LIBCPP_INLINE_VISIBILITY |
Eric Fiselier | 6003c77 | 2016-12-23 23:37:52 +0000 | [diff] [blame] | 2006 | constexpr bool empty(const _Tp (&)[_Sz]) noexcept { return false; } |
Marshall Clow | ef35727 | 2014-11-19 19:43:23 +0000 | [diff] [blame] | 2007 | |
| 2008 | template <class _Ep> |
Marshall Clow | 0bd662d | 2019-02-27 03:25:43 +0000 | [diff] [blame] | 2009 | _LIBCPP_NODISCARD_AFTER_CXX17 _LIBCPP_INLINE_VISIBILITY |
Marshall Clow | ef35727 | 2014-11-19 19:43:23 +0000 | [diff] [blame] | 2010 | constexpr bool empty(initializer_list<_Ep> __il) noexcept { return __il.size() == 0; } |
| 2011 | |
Marshall Clow | c4b4a34 | 2015-02-11 16:14:01 +0000 | [diff] [blame] | 2012 | template <class _Cont> constexpr |
Marshall Clow | 0bd662d | 2019-02-27 03:25:43 +0000 | [diff] [blame] | 2013 | _LIBCPP_INLINE_VISIBILITY |
Marshall Clow | 344c41d | 2017-11-16 17:55:41 +0000 | [diff] [blame] | 2014 | auto data(_Cont& __c) |
| 2015 | _NOEXCEPT_(noexcept(__c.data())) |
| 2016 | -> decltype (__c.data()) |
| 2017 | { return __c.data(); } |
Marshall Clow | ef35727 | 2014-11-19 19:43:23 +0000 | [diff] [blame] | 2018 | |
Marshall Clow | c4b4a34 | 2015-02-11 16:14:01 +0000 | [diff] [blame] | 2019 | template <class _Cont> constexpr |
Marshall Clow | 0bd662d | 2019-02-27 03:25:43 +0000 | [diff] [blame] | 2020 | _LIBCPP_INLINE_VISIBILITY |
Marshall Clow | 344c41d | 2017-11-16 17:55:41 +0000 | [diff] [blame] | 2021 | auto data(const _Cont& __c) |
| 2022 | _NOEXCEPT_(noexcept(__c.data())) |
Louis Dionne | 173f29e | 2019-05-29 16:01:36 +0000 | [diff] [blame] | 2023 | -> decltype (__c.data()) |
Marshall Clow | 344c41d | 2017-11-16 17:55:41 +0000 | [diff] [blame] | 2024 | { return __c.data(); } |
Marshall Clow | ef35727 | 2014-11-19 19:43:23 +0000 | [diff] [blame] | 2025 | |
Marshall Clow | c4b4a34 | 2015-02-11 16:14:01 +0000 | [diff] [blame] | 2026 | template <class _Tp, size_t _Sz> |
Marshall Clow | 0bd662d | 2019-02-27 03:25:43 +0000 | [diff] [blame] | 2027 | _LIBCPP_INLINE_VISIBILITY |
Marshall Clow | c4b4a34 | 2015-02-11 16:14:01 +0000 | [diff] [blame] | 2028 | constexpr _Tp* data(_Tp (&__array)[_Sz]) noexcept { return __array; } |
Marshall Clow | ef35727 | 2014-11-19 19:43:23 +0000 | [diff] [blame] | 2029 | |
| 2030 | template <class _Ep> |
Marshall Clow | 0bd662d | 2019-02-27 03:25:43 +0000 | [diff] [blame] | 2031 | _LIBCPP_INLINE_VISIBILITY |
Marshall Clow | ef35727 | 2014-11-19 19:43:23 +0000 | [diff] [blame] | 2032 | constexpr const _Ep* data(initializer_list<_Ep> __il) noexcept { return __il.begin(); } |
| 2033 | #endif |
| 2034 | |
Arthur O'Dwyer | b6738bd | 2021-03-21 16:53:09 -0400 | [diff] [blame] | 2035 | template <class _Container, class _Predicate> |
| 2036 | typename _Container::size_type |
| 2037 | __libcpp_erase_if_container(_Container& __c, _Predicate& __pred) { |
| 2038 | typename _Container::size_type __old_size = __c.size(); |
| 2039 | |
| 2040 | const typename _Container::iterator __last = __c.end(); |
| 2041 | for (typename _Container::iterator __iter = __c.begin(); __iter != __last;) { |
| 2042 | if (__pred(*__iter)) |
| 2043 | __iter = __c.erase(__iter); |
| 2044 | else |
| 2045 | ++__iter; |
| 2046 | } |
| 2047 | |
| 2048 | return __old_size - __c.size(); |
| 2049 | } |
Marshall Clow | ef35727 | 2014-11-19 19:43:23 +0000 | [diff] [blame] | 2050 | |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2051 | _LIBCPP_END_NAMESPACE_STD |
| 2052 | |
Louis Dionne | 2b1ceaa | 2021-04-20 12:03:32 -0400 | [diff] [blame] | 2053 | #endif // _LIBCPP_ITERATOR |