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