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