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