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