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