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