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