13e519524SHoward Hinnant// -*- C++ -*- 23e519524SHoward Hinnant//===-------------------------- iterator ----------------------------------===// 33e519524SHoward Hinnant// 457b08b09SChandler Carruth// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 557b08b09SChandler Carruth// See https://llvm.org/LICENSE.txt for license information. 657b08b09SChandler Carruth// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 73e519524SHoward Hinnant// 83e519524SHoward Hinnant//===----------------------------------------------------------------------===// 93e519524SHoward Hinnant 103e519524SHoward Hinnant#ifndef _LIBCPP_ITERATOR 113e519524SHoward Hinnant#define _LIBCPP_ITERATOR 123e519524SHoward Hinnant 133e519524SHoward Hinnant/* 143e519524SHoward Hinnant iterator synopsis 153e519524SHoward Hinnant 163e519524SHoward Hinnantnamespace std 173e519524SHoward Hinnant{ 183e519524SHoward Hinnant 193e519524SHoward Hinnanttemplate<class Iterator> 203e519524SHoward Hinnantstruct iterator_traits 213e519524SHoward Hinnant{ 223e519524SHoward Hinnant typedef typename Iterator::difference_type difference_type; 233e519524SHoward Hinnant typedef typename Iterator::value_type value_type; 243e519524SHoward Hinnant typedef typename Iterator::pointer pointer; 253e519524SHoward Hinnant typedef typename Iterator::reference reference; 263e519524SHoward Hinnant typedef typename Iterator::iterator_category iterator_category; 273e519524SHoward Hinnant}; 283e519524SHoward Hinnant 293e519524SHoward Hinnanttemplate<class T> 303e519524SHoward Hinnantstruct iterator_traits<T*> 313e519524SHoward Hinnant{ 323e519524SHoward Hinnant typedef ptrdiff_t difference_type; 333e519524SHoward Hinnant typedef T value_type; 343e519524SHoward Hinnant typedef T* pointer; 353e519524SHoward Hinnant typedef T& reference; 363e519524SHoward Hinnant typedef random_access_iterator_tag iterator_category; 373e519524SHoward Hinnant}; 383e519524SHoward Hinnant 393e519524SHoward Hinnanttemplate<class Category, class T, class Distance = ptrdiff_t, 403e519524SHoward Hinnant class Pointer = T*, class Reference = T&> 413e519524SHoward Hinnantstruct iterator 423e519524SHoward Hinnant{ 433e519524SHoward Hinnant typedef T value_type; 443e519524SHoward Hinnant typedef Distance difference_type; 453e519524SHoward Hinnant typedef Pointer pointer; 463e519524SHoward Hinnant typedef Reference reference; 473e519524SHoward Hinnant typedef Category iterator_category; 483e519524SHoward Hinnant}; 493e519524SHoward Hinnant 503e519524SHoward Hinnantstruct input_iterator_tag {}; 513e519524SHoward Hinnantstruct output_iterator_tag {}; 523e519524SHoward Hinnantstruct forward_iterator_tag : public input_iterator_tag {}; 533e519524SHoward Hinnantstruct bidirectional_iterator_tag : public forward_iterator_tag {}; 543e519524SHoward Hinnantstruct random_access_iterator_tag : public bidirectional_iterator_tag {}; 553e519524SHoward Hinnant 56f51ee632SMarshall Clow// 27.4.3, iterator operations 5712b01ab7SLouis Dionnetemplate <class InputIterator, class Distance> // constexpr in C++17 5812b01ab7SLouis Dionne constexpr void advance(InputIterator& i, Distance n); 593e519524SHoward Hinnant 60f51ee632SMarshall Clowtemplate <class InputIterator> // constexpr in C++17 61f51ee632SMarshall Clow constexpr typename iterator_traits<InputIterator>::difference_type 623e519524SHoward Hinnant distance(InputIterator first, InputIterator last); 633e519524SHoward Hinnant 64f51ee632SMarshall Clowtemplate <class InputIterator> // constexpr in C++17 65f51ee632SMarshall Clow constexpr InputIterator next(InputIterator x, 66f51ee632SMarshall Clowtypename iterator_traits<InputIterator>::difference_type n = 1); 67f51ee632SMarshall Clow 68f51ee632SMarshall Clowtemplate <class BidirectionalIterator> // constexpr in C++17 69f51ee632SMarshall Clow constexpr BidirectionalIterator prev(BidirectionalIterator x, 70f51ee632SMarshall Clow typename iterator_traits<BidirectionalIterator>::difference_type n = 1); 71f51ee632SMarshall Clow 723e519524SHoward Hinnanttemplate <class Iterator> 733e519524SHoward Hinnantclass reverse_iterator 743e519524SHoward Hinnant : public iterator<typename iterator_traits<Iterator>::iterator_category, 753e519524SHoward Hinnant typename iterator_traits<Iterator>::value_type, 763e519524SHoward Hinnant typename iterator_traits<Iterator>::difference_type, 773e519524SHoward Hinnant typename iterator_traits<Iterator>::pointer, 783e519524SHoward Hinnant typename iterator_traits<Iterator>::reference> 793e519524SHoward Hinnant{ 803e519524SHoward Hinnantprotected: 813e519524SHoward Hinnant Iterator current; 823e519524SHoward Hinnantpublic: 833e519524SHoward Hinnant typedef Iterator iterator_type; 843e519524SHoward Hinnant typedef typename iterator_traits<Iterator>::difference_type difference_type; 853e519524SHoward Hinnant typedef typename iterator_traits<Iterator>::reference reference; 863e519524SHoward Hinnant typedef typename iterator_traits<Iterator>::pointer pointer; 873e519524SHoward Hinnant 881b8f260eSMarshall Clow constexpr reverse_iterator(); 891b8f260eSMarshall Clow constexpr explicit reverse_iterator(Iterator x); 901b8f260eSMarshall Clow template <class U> constexpr reverse_iterator(const reverse_iterator<U>& u); 911b8f260eSMarshall Clow template <class U> constexpr reverse_iterator& operator=(const reverse_iterator<U>& u); 921b8f260eSMarshall Clow constexpr Iterator base() const; 931b8f260eSMarshall Clow constexpr reference operator*() const; 941b8f260eSMarshall Clow constexpr pointer operator->() const; 951b8f260eSMarshall Clow constexpr reverse_iterator& operator++(); 961b8f260eSMarshall Clow constexpr reverse_iterator operator++(int); 971b8f260eSMarshall Clow constexpr reverse_iterator& operator--(); 981b8f260eSMarshall Clow constexpr reverse_iterator operator--(int); 991b8f260eSMarshall Clow constexpr reverse_iterator operator+ (difference_type n) const; 1001b8f260eSMarshall Clow constexpr reverse_iterator& operator+=(difference_type n); 1011b8f260eSMarshall Clow constexpr reverse_iterator operator- (difference_type n) const; 1021b8f260eSMarshall Clow constexpr reverse_iterator& operator-=(difference_type n); 1031b8f260eSMarshall Clow constexpr reference operator[](difference_type n) const; 1043e519524SHoward Hinnant}; 1053e519524SHoward Hinnant 1063e519524SHoward Hinnanttemplate <class Iterator1, class Iterator2> 1071b8f260eSMarshall Clowconstexpr bool // constexpr in C++17 1083e519524SHoward Hinnantoperator==(const reverse_iterator<Iterator1>& x, const reverse_iterator<Iterator2>& y); 1093e519524SHoward Hinnant 1103e519524SHoward Hinnanttemplate <class Iterator1, class Iterator2> 1111b8f260eSMarshall Clowconstexpr bool // constexpr in C++17 1123e519524SHoward Hinnantoperator<(const reverse_iterator<Iterator1>& x, const reverse_iterator<Iterator2>& y); 1133e519524SHoward Hinnant 1143e519524SHoward Hinnanttemplate <class Iterator1, class Iterator2> 1151b8f260eSMarshall Clowconstexpr bool // constexpr in C++17 1163e519524SHoward Hinnantoperator!=(const reverse_iterator<Iterator1>& x, const reverse_iterator<Iterator2>& y); 1173e519524SHoward Hinnant 1183e519524SHoward Hinnanttemplate <class Iterator1, class Iterator2> 1191b8f260eSMarshall Clowconstexpr bool // constexpr in C++17 1203e519524SHoward Hinnantoperator>(const reverse_iterator<Iterator1>& x, const reverse_iterator<Iterator2>& y); 1213e519524SHoward Hinnant 1223e519524SHoward Hinnanttemplate <class Iterator1, class Iterator2> 1231b8f260eSMarshall Clowconstexpr bool // constexpr in C++17 1243e519524SHoward Hinnantoperator>=(const reverse_iterator<Iterator1>& x, const reverse_iterator<Iterator2>& y); 1253e519524SHoward Hinnant 1263e519524SHoward Hinnanttemplate <class Iterator1, class Iterator2> 1271b8f260eSMarshall Clowconstexpr bool // constexpr in C++17 1283e519524SHoward Hinnantoperator<=(const reverse_iterator<Iterator1>& x, const reverse_iterator<Iterator2>& y); 1293e519524SHoward Hinnant 1303e519524SHoward Hinnanttemplate <class Iterator1, class Iterator2> 1311b8f260eSMarshall Clowconstexpr auto 132947ce6b5SMarshall Clowoperator-(const reverse_iterator<Iterator1>& x, const reverse_iterator<Iterator2>& y) 1331b8f260eSMarshall Clow-> decltype(__y.base() - __x.base()); // constexpr in C++17 1343e519524SHoward Hinnant 1353e519524SHoward Hinnanttemplate <class Iterator> 1361b8f260eSMarshall Clowconstexpr reverse_iterator<Iterator> 1371b8f260eSMarshall Clowoperator+(typename reverse_iterator<Iterator>::difference_type n, 1381b8f260eSMarshall Clow const reverse_iterator<Iterator>& x); // constexpr in C++17 1393e519524SHoward Hinnant 1401b8f260eSMarshall Clowtemplate <class Iterator> 1411b8f260eSMarshall Clowconstexpr reverse_iterator<Iterator> make_reverse_iterator(Iterator i); // C++14, constexpr in C++17 1426a640a18SMarshall Clow 1433e519524SHoward Hinnanttemplate <class Container> 1443e519524SHoward Hinnantclass back_insert_iterator 1453e519524SHoward Hinnant{ 1463e519524SHoward Hinnantprotected: 1473e519524SHoward Hinnant Container* container; 1483e519524SHoward Hinnantpublic: 1493e519524SHoward Hinnant typedef Container container_type; 1503e519524SHoward Hinnant typedef void value_type; 1513e519524SHoward Hinnant typedef void difference_type; 1528892b4eeSEric Fiselier typedef void reference; 1533e519524SHoward Hinnant typedef void pointer; 1543e519524SHoward Hinnant 155*06e2b737SArthur O'Dwyer explicit back_insert_iterator(Container& x); // constexpr in C++20 156*06e2b737SArthur O'Dwyer back_insert_iterator& operator=(const typename Container::value_type& value); // constexpr in C++20 157*06e2b737SArthur O'Dwyer back_insert_iterator& operator*(); // constexpr in C++20 158*06e2b737SArthur O'Dwyer back_insert_iterator& operator++(); // constexpr in C++20 159*06e2b737SArthur O'Dwyer back_insert_iterator operator++(int); // constexpr in C++20 1603e519524SHoward Hinnant}; 1613e519524SHoward Hinnant 162*06e2b737SArthur O'Dwyertemplate <class Container> back_insert_iterator<Container> back_inserter(Container& x); // constexpr in C++20 1633e519524SHoward Hinnant 1643e519524SHoward Hinnanttemplate <class Container> 1653e519524SHoward Hinnantclass front_insert_iterator 1663e519524SHoward Hinnant{ 1673e519524SHoward Hinnantprotected: 1683e519524SHoward Hinnant Container* container; 1693e519524SHoward Hinnantpublic: 1703e519524SHoward Hinnant typedef Container container_type; 1713e519524SHoward Hinnant typedef void value_type; 1723e519524SHoward Hinnant typedef void difference_type; 1738892b4eeSEric Fiselier typedef void reference; 1743e519524SHoward Hinnant typedef void pointer; 1753e519524SHoward Hinnant 176*06e2b737SArthur O'Dwyer explicit front_insert_iterator(Container& x); // constexpr in C++20 177*06e2b737SArthur O'Dwyer front_insert_iterator& operator=(const typename Container::value_type& value); // constexpr in C++20 178*06e2b737SArthur O'Dwyer front_insert_iterator& operator*(); // constexpr in C++20 179*06e2b737SArthur O'Dwyer front_insert_iterator& operator++(); // constexpr in C++20 180*06e2b737SArthur O'Dwyer front_insert_iterator operator++(int); // constexpr in C++20 1813e519524SHoward Hinnant}; 1823e519524SHoward Hinnant 183*06e2b737SArthur O'Dwyertemplate <class Container> front_insert_iterator<Container> front_inserter(Container& x); // constexpr in C++20 1843e519524SHoward Hinnant 1853e519524SHoward Hinnanttemplate <class Container> 1863e519524SHoward Hinnantclass insert_iterator 1873e519524SHoward Hinnant{ 1883e519524SHoward Hinnantprotected: 1893e519524SHoward Hinnant Container* container; 1903e519524SHoward Hinnant typename Container::iterator iter; 1913e519524SHoward Hinnantpublic: 1923e519524SHoward Hinnant typedef Container container_type; 1933e519524SHoward Hinnant typedef void value_type; 1943e519524SHoward Hinnant typedef void difference_type; 1958892b4eeSEric Fiselier typedef void reference; 1963e519524SHoward Hinnant typedef void pointer; 1973e519524SHoward Hinnant 198*06e2b737SArthur O'Dwyer insert_iterator(Container& x, typename Container::iterator i); // constexpr in C++20 199*06e2b737SArthur O'Dwyer insert_iterator& operator=(const typename Container::value_type& value); // constexpr in C++20 200*06e2b737SArthur O'Dwyer insert_iterator& operator*(); // constexpr in C++20 201*06e2b737SArthur O'Dwyer insert_iterator& operator++(); // constexpr in C++20 202*06e2b737SArthur O'Dwyer insert_iterator& operator++(int); // constexpr in C++20 2033e519524SHoward Hinnant}; 2043e519524SHoward Hinnant 2053e519524SHoward Hinnanttemplate <class Container, class Iterator> 206*06e2b737SArthur O'Dwyerinsert_iterator<Container> inserter(Container& x, Iterator i); // constexpr in C++20 2073e519524SHoward Hinnant 208947ce6b5SMarshall Clowtemplate <class Iterator> 209947ce6b5SMarshall Clowclass move_iterator { 210947ce6b5SMarshall Clowpublic: 211947ce6b5SMarshall Clow typedef Iterator iterator_type; 212947ce6b5SMarshall Clow typedef typename iterator_traits<Iterator>::difference_type difference_type; 213947ce6b5SMarshall Clow typedef Iterator pointer; 214947ce6b5SMarshall Clow typedef typename iterator_traits<Iterator>::value_type value_type; 215947ce6b5SMarshall Clow typedef typename iterator_traits<Iterator>::iterator_category iterator_category; 216947ce6b5SMarshall Clow typedef value_type&& reference; 217947ce6b5SMarshall Clow 218720ef472SMarshall Clow constexpr move_iterator(); // all the constexprs are in C++17 219720ef472SMarshall Clow constexpr explicit move_iterator(Iterator i); 220720ef472SMarshall Clow template <class U> 221720ef472SMarshall Clow constexpr move_iterator(const move_iterator<U>& u); 222720ef472SMarshall Clow template <class U> 223720ef472SMarshall Clow constexpr move_iterator& operator=(const move_iterator<U>& u); 224720ef472SMarshall Clow constexpr iterator_type base() const; 225720ef472SMarshall Clow constexpr reference operator*() const; 226720ef472SMarshall Clow constexpr pointer operator->() const; 227720ef472SMarshall Clow constexpr move_iterator& operator++(); 228720ef472SMarshall Clow constexpr move_iterator operator++(int); 229720ef472SMarshall Clow constexpr move_iterator& operator--(); 230720ef472SMarshall Clow constexpr move_iterator operator--(int); 231720ef472SMarshall Clow constexpr move_iterator operator+(difference_type n) const; 232720ef472SMarshall Clow constexpr move_iterator& operator+=(difference_type n); 233720ef472SMarshall Clow constexpr move_iterator operator-(difference_type n) const; 234720ef472SMarshall Clow constexpr move_iterator& operator-=(difference_type n); 235720ef472SMarshall Clow constexpr unspecified operator[](difference_type n) const; 236947ce6b5SMarshall Clowprivate: 237947ce6b5SMarshall Clow Iterator current; // exposition only 238947ce6b5SMarshall Clow}; 239947ce6b5SMarshall Clow 240947ce6b5SMarshall Clowtemplate <class Iterator1, class Iterator2> 241720ef472SMarshall Clowconstexpr bool // constexpr in C++17 242947ce6b5SMarshall Clowoperator==(const move_iterator<Iterator1>& x, const move_iterator<Iterator2>& y); 243947ce6b5SMarshall Clow 244947ce6b5SMarshall Clowtemplate <class Iterator1, class Iterator2> 245720ef472SMarshall Clowconstexpr bool // constexpr in C++17 246947ce6b5SMarshall Clowoperator!=(const move_iterator<Iterator1>& x, const move_iterator<Iterator2>& y); 247947ce6b5SMarshall Clow 248947ce6b5SMarshall Clowtemplate <class Iterator1, class Iterator2> 249720ef472SMarshall Clowconstexpr bool // constexpr in C++17 250947ce6b5SMarshall Clowoperator<(const move_iterator<Iterator1>& x, const move_iterator<Iterator2>& y); 251947ce6b5SMarshall Clow 252947ce6b5SMarshall Clowtemplate <class Iterator1, class Iterator2> 253720ef472SMarshall Clowconstexpr bool // constexpr in C++17 254947ce6b5SMarshall Clowoperator<=(const move_iterator<Iterator1>& x, const move_iterator<Iterator2>& y); 255947ce6b5SMarshall Clow 256947ce6b5SMarshall Clowtemplate <class Iterator1, class Iterator2> 257720ef472SMarshall Clowconstexpr bool // constexpr in C++17 258947ce6b5SMarshall Clowoperator>(const move_iterator<Iterator1>& x, const move_iterator<Iterator2>& y); 259947ce6b5SMarshall Clow 260947ce6b5SMarshall Clowtemplate <class Iterator1, class Iterator2> 261720ef472SMarshall Clowconstexpr bool // constexpr in C++17 262947ce6b5SMarshall Clowoperator>=(const move_iterator<Iterator1>& x, const move_iterator<Iterator2>& y); 263947ce6b5SMarshall Clow 264947ce6b5SMarshall Clowtemplate <class Iterator1, class Iterator2> 265720ef472SMarshall Clowconstexpr auto // constexpr in C++17 266947ce6b5SMarshall Clowoperator-(const move_iterator<Iterator1>& x, 267947ce6b5SMarshall Clow const move_iterator<Iterator2>& y) -> decltype(x.base() - y.base()); 268947ce6b5SMarshall Clow 269947ce6b5SMarshall Clowtemplate <class Iterator> 270720ef472SMarshall Clowconstexpr move_iterator<Iterator> operator+( // constexpr in C++17 271720ef472SMarshall Clow typename move_iterator<Iterator>::difference_type n, 272947ce6b5SMarshall Clow const move_iterator<Iterator>& x); 273947ce6b5SMarshall Clow 274720ef472SMarshall Clowtemplate <class Iterator> // constexpr in C++17 275720ef472SMarshall Clowconstexpr move_iterator<Iterator> make_move_iterator(const Iterator& i); 276947ce6b5SMarshall Clow 277947ce6b5SMarshall Clow 2783e519524SHoward Hinnanttemplate <class T, class charT = char, class traits = char_traits<charT>, class Distance = ptrdiff_t> 2793e519524SHoward Hinnantclass istream_iterator 2803e519524SHoward Hinnant : public iterator<input_iterator_tag, T, Distance, const T*, const T&> 2813e519524SHoward Hinnant{ 2823e519524SHoward Hinnantpublic: 2833e519524SHoward Hinnant typedef charT char_type; 2843e519524SHoward Hinnant typedef traits traits_type; 2853e519524SHoward Hinnant typedef basic_istream<charT,traits> istream_type; 2863e519524SHoward Hinnant 28760d5e0e0SMarshall Clow constexpr istream_iterator(); 2883e519524SHoward Hinnant istream_iterator(istream_type& s); 2893e519524SHoward Hinnant istream_iterator(const istream_iterator& x); 2903e519524SHoward Hinnant ~istream_iterator(); 2913e519524SHoward Hinnant 2923e519524SHoward Hinnant const T& operator*() const; 2933e519524SHoward Hinnant const T* operator->() const; 2943e519524SHoward Hinnant istream_iterator& operator++(); 2953e519524SHoward Hinnant istream_iterator operator++(int); 2963e519524SHoward Hinnant}; 2973e519524SHoward Hinnant 2983e519524SHoward Hinnanttemplate <class T, class charT, class traits, class Distance> 2993e519524SHoward Hinnantbool operator==(const istream_iterator<T,charT,traits,Distance>& x, 3003e519524SHoward Hinnant const istream_iterator<T,charT,traits,Distance>& y); 3013e519524SHoward Hinnanttemplate <class T, class charT, class traits, class Distance> 3023e519524SHoward Hinnantbool operator!=(const istream_iterator<T,charT,traits,Distance>& x, 3033e519524SHoward Hinnant const istream_iterator<T,charT,traits,Distance>& y); 3043e519524SHoward Hinnant 3053e519524SHoward Hinnanttemplate <class T, class charT = char, class traits = char_traits<charT> > 3063e519524SHoward Hinnantclass ostream_iterator 3073e519524SHoward Hinnant : public iterator<output_iterator_tag, void, void, void ,void> 3083e519524SHoward Hinnant{ 3093e519524SHoward Hinnantpublic: 3103e519524SHoward Hinnant typedef charT char_type; 3113e519524SHoward Hinnant typedef traits traits_type; 3123e519524SHoward Hinnant typedef basic_ostream<charT,traits> ostream_type; 3133e519524SHoward Hinnant 3143e519524SHoward Hinnant ostream_iterator(ostream_type& s); 3153e519524SHoward Hinnant ostream_iterator(ostream_type& s, const charT* delimiter); 3163e519524SHoward Hinnant ostream_iterator(const ostream_iterator& x); 3173e519524SHoward Hinnant ~ostream_iterator(); 3183e519524SHoward Hinnant ostream_iterator& operator=(const T& value); 3193e519524SHoward Hinnant 3203e519524SHoward Hinnant ostream_iterator& operator*(); 3213e519524SHoward Hinnant ostream_iterator& operator++(); 3223e519524SHoward Hinnant ostream_iterator& operator++(int); 3233e519524SHoward Hinnant}; 3243e519524SHoward Hinnant 3253e519524SHoward Hinnanttemplate<class charT, class traits = char_traits<charT> > 3263e519524SHoward Hinnantclass istreambuf_iterator 3273e519524SHoward Hinnant : public iterator<input_iterator_tag, charT, 3283e519524SHoward Hinnant typename traits::off_type, unspecified, 3293e519524SHoward Hinnant charT> 3303e519524SHoward Hinnant{ 3313e519524SHoward Hinnantpublic: 3323e519524SHoward Hinnant typedef charT char_type; 3333e519524SHoward Hinnant typedef traits traits_type; 3343e519524SHoward Hinnant typedef typename traits::int_type int_type; 3353e519524SHoward Hinnant typedef basic_streambuf<charT,traits> streambuf_type; 3363e519524SHoward Hinnant typedef basic_istream<charT,traits> istream_type; 3373e519524SHoward Hinnant 3388e882dcbSHoward Hinnant istreambuf_iterator() noexcept; 3398e882dcbSHoward Hinnant istreambuf_iterator(istream_type& s) noexcept; 3408e882dcbSHoward Hinnant istreambuf_iterator(streambuf_type* s) noexcept; 3418e882dcbSHoward Hinnant istreambuf_iterator(a-private-type) noexcept; 3423e519524SHoward Hinnant 3433e519524SHoward Hinnant charT operator*() const; 3443e519524SHoward Hinnant pointer operator->() const; 3453e519524SHoward Hinnant istreambuf_iterator& operator++(); 3463e519524SHoward Hinnant a-private-type operator++(int); 3473e519524SHoward Hinnant 3483e519524SHoward Hinnant bool equal(const istreambuf_iterator& b) const; 3493e519524SHoward Hinnant}; 3503e519524SHoward Hinnant 3513e519524SHoward Hinnanttemplate <class charT, class traits> 3523e519524SHoward Hinnantbool operator==(const istreambuf_iterator<charT,traits>& a, 3533e519524SHoward Hinnant const istreambuf_iterator<charT,traits>& b); 3543e519524SHoward Hinnanttemplate <class charT, class traits> 3553e519524SHoward Hinnantbool operator!=(const istreambuf_iterator<charT,traits>& a, 3563e519524SHoward Hinnant const istreambuf_iterator<charT,traits>& b); 3573e519524SHoward Hinnant 3583e519524SHoward Hinnanttemplate <class charT, class traits = char_traits<charT> > 3593e519524SHoward Hinnantclass ostreambuf_iterator 3603e519524SHoward Hinnant : public iterator<output_iterator_tag, void, void, void, void> 3613e519524SHoward Hinnant{ 3623e519524SHoward Hinnantpublic: 3633e519524SHoward Hinnant typedef charT char_type; 3643e519524SHoward Hinnant typedef traits traits_type; 3653e519524SHoward Hinnant typedef basic_streambuf<charT,traits> streambuf_type; 3663e519524SHoward Hinnant typedef basic_ostream<charT,traits> ostream_type; 3673e519524SHoward Hinnant 3688e882dcbSHoward Hinnant ostreambuf_iterator(ostream_type& s) noexcept; 3698e882dcbSHoward Hinnant ostreambuf_iterator(streambuf_type* s) noexcept; 3703e519524SHoward Hinnant ostreambuf_iterator& operator=(charT c); 3713e519524SHoward Hinnant ostreambuf_iterator& operator*(); 3723e519524SHoward Hinnant ostreambuf_iterator& operator++(); 3733e519524SHoward Hinnant ostreambuf_iterator& operator++(int); 3748e882dcbSHoward Hinnant bool failed() const noexcept; 3753e519524SHoward Hinnant}; 3763e519524SHoward Hinnant 377020b623aSMarshall Clowtemplate <class C> constexpr auto begin(C& c) -> decltype(c.begin()); 378020b623aSMarshall Clowtemplate <class C> constexpr auto begin(const C& c) -> decltype(c.begin()); 379020b623aSMarshall Clowtemplate <class C> constexpr auto end(C& c) -> decltype(c.end()); 380020b623aSMarshall Clowtemplate <class C> constexpr auto end(const C& c) -> decltype(c.end()); 381020b623aSMarshall Clowtemplate <class T, size_t N> constexpr T* begin(T (&array)[N]); 382020b623aSMarshall Clowtemplate <class T, size_t N> constexpr T* end(T (&array)[N]); 3833e519524SHoward Hinnant 384020b623aSMarshall Clowtemplate <class C> auto constexpr cbegin(const C& c) -> decltype(std::begin(c)); // C++14 385020b623aSMarshall Clowtemplate <class C> auto constexpr cend(const C& c) -> decltype(std::end(c)); // C++14 386020b623aSMarshall Clowtemplate <class C> auto constexpr rbegin(C& c) -> decltype(c.rbegin()); // C++14 387020b623aSMarshall Clowtemplate <class C> auto constexpr rbegin(const C& c) -> decltype(c.rbegin()); // C++14 388020b623aSMarshall Clowtemplate <class C> auto constexpr rend(C& c) -> decltype(c.rend()); // C++14 389020b623aSMarshall Clowtemplate <class C> constexpr auto rend(const C& c) -> decltype(c.rend()); // C++14 390020b623aSMarshall Clowtemplate <class E> reverse_iterator<const E*> constexpr rbegin(initializer_list<E> il); // C++14 391020b623aSMarshall Clowtemplate <class E> reverse_iterator<const E*> constexpr rend(initializer_list<E> il); // C++14 392020b623aSMarshall Clowtemplate <class T, size_t N> reverse_iterator<T*> constexpr rbegin(T (&array)[N]); // C++14 393020b623aSMarshall Clowtemplate <class T, size_t N> reverse_iterator<T*> constexpr rend(T (&array)[N]); // C++14 394020b623aSMarshall Clowtemplate <class C> constexpr auto crbegin(const C& c) -> decltype(std::rbegin(c)); // C++14 395020b623aSMarshall Clowtemplate <class C> constexpr auto crend(const C& c) -> decltype(std::rend(c)); // C++14 3961e548c72SMarshall Clow 397ad755104SMarshall Clow// 24.8, container access: 398ad755104SMarshall Clowtemplate <class C> constexpr auto size(const C& c) -> decltype(c.size()); // C++17 399ad755104SMarshall Clowtemplate <class T, size_t N> constexpr size_t size(const T (&array)[N]) noexcept; // C++17 4007d3986eaSMarshall Clow 4017d3986eaSMarshall Clowtemplate <class C> constexpr auto ssize(const C& c) 4027d3986eaSMarshall Clow -> common_type_t<ptrdiff_t, make_signed_t<decltype(c.size())>>; // C++20 4037d3986eaSMarshall Clowtemplate <class T, ptrdiff_t> constexpr ptrdiff_t ssize(const T (&array)[N]) noexcept; // C++20 4047d3986eaSMarshall Clow 405ad755104SMarshall Clowtemplate <class C> constexpr auto empty(const C& c) -> decltype(c.empty()); // C++17 406ad755104SMarshall Clowtemplate <class T, size_t N> constexpr bool empty(const T (&array)[N]) noexcept; // C++17 407ad755104SMarshall Clowtemplate <class E> constexpr bool empty(initializer_list<E> il) noexcept; // C++17 408ad755104SMarshall Clowtemplate <class C> constexpr auto data(C& c) -> decltype(c.data()); // C++17 409ad755104SMarshall Clowtemplate <class C> constexpr auto data(const C& c) -> decltype(c.data()); // C++17 410ad755104SMarshall Clowtemplate <class T, size_t N> constexpr T* data(T (&array)[N]) noexcept; // C++17 411ad755104SMarshall Clowtemplate <class E> constexpr const E* data(initializer_list<E> il) noexcept; // C++17 412ad755104SMarshall Clow 4133e519524SHoward Hinnant} // std 4143e519524SHoward Hinnant 4153e519524SHoward Hinnant*/ 4163e519524SHoward Hinnant 4173e519524SHoward Hinnant#include <__config> 41839c193b1SEric Fiselier#include <iosfwd> // for forward declarations of vector and string. 419c204c130SMarshall Clow#include <__functional_base> 4203e519524SHoward Hinnant#include <type_traits> 4213e519524SHoward Hinnant#include <cstddef> 4221e548c72SMarshall Clow#include <initializer_list> 4237ad49aecSLouis Dionne#include <__memory/base.h> 424d41c6d51SArthur O'Dwyer#include <__memory/pointer_traits.h> 425f56972e2SMarshall Clow#include <version> 426b5c63a2eSHoward Hinnant 42742a3046eSHoward Hinnant#include <__debug> 4283e519524SHoward Hinnant 429073458b1SHoward Hinnant#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) 4303e519524SHoward Hinnant#pragma GCC system_header 431073458b1SHoward Hinnant#endif 4323e519524SHoward Hinnant 4333e519524SHoward Hinnant_LIBCPP_BEGIN_NAMESPACE_STD 4346624fcbaSEric Fiseliertemplate <class _Iter> 4356624fcbaSEric Fiselierstruct _LIBCPP_TEMPLATE_VIS iterator_traits; 4363e519524SHoward Hinnant 437e2f2d1edSEric Fiselierstruct _LIBCPP_TEMPLATE_VIS input_iterator_tag {}; 438e2f2d1edSEric Fiselierstruct _LIBCPP_TEMPLATE_VIS output_iterator_tag {}; 439e2f2d1edSEric Fiselierstruct _LIBCPP_TEMPLATE_VIS forward_iterator_tag : public input_iterator_tag {}; 440e2f2d1edSEric Fiselierstruct _LIBCPP_TEMPLATE_VIS bidirectional_iterator_tag : public forward_iterator_tag {}; 441e2f2d1edSEric Fiselierstruct _LIBCPP_TEMPLATE_VIS random_access_iterator_tag : public bidirectional_iterator_tag {}; 44245d048c2SEric Fiselier#if _LIBCPP_STD_VER > 17 44345d048c2SEric Fiselierstruct _LIBCPP_TEMPLATE_VIS contiguous_iterator_tag : public random_access_iterator_tag {}; 44445d048c2SEric Fiselier#endif 4453e519524SHoward Hinnant 4466624fcbaSEric Fiseliertemplate <class _Iter> 4476624fcbaSEric Fiselierstruct __iter_traits_cache { 4486624fcbaSEric Fiselier using type = _If< 4496624fcbaSEric Fiselier __is_primary_template<iterator_traits<_Iter> >::value, 4506624fcbaSEric Fiselier _Iter, 4516624fcbaSEric Fiselier iterator_traits<_Iter> 4526624fcbaSEric Fiselier >; 4536624fcbaSEric Fiselier}; 4546624fcbaSEric Fiseliertemplate <class _Iter> 4556624fcbaSEric Fiselierusing _ITER_TRAITS = typename __iter_traits_cache<_Iter>::type; 4566624fcbaSEric Fiselier 4576624fcbaSEric Fiselierstruct __iter_concept_concept_test { 4586624fcbaSEric Fiselier template <class _Iter> 4596624fcbaSEric Fiselier using _Apply = typename _ITER_TRAITS<_Iter>::iterator_concept; 4606624fcbaSEric Fiselier}; 4616624fcbaSEric Fiselierstruct __iter_concept_category_test { 4626624fcbaSEric Fiselier template <class _Iter> 4636624fcbaSEric Fiselier using _Apply = typename _ITER_TRAITS<_Iter>::iterator_category; 4646624fcbaSEric Fiselier}; 4656624fcbaSEric Fiselierstruct __iter_concept_random_fallback { 4666624fcbaSEric Fiselier template <class _Iter> 4676624fcbaSEric Fiselier using _Apply = _EnableIf< 4686624fcbaSEric Fiselier __is_primary_template<iterator_traits<_Iter> >::value, 4696624fcbaSEric Fiselier random_access_iterator_tag 4706624fcbaSEric Fiselier >; 4716624fcbaSEric Fiselier}; 4726624fcbaSEric Fiselier 4736624fcbaSEric Fiseliertemplate <class _Iter, class _Tester> struct __test_iter_concept 4746624fcbaSEric Fiselier : _IsValidExpansion<_Tester::template _Apply, _Iter>, 4756624fcbaSEric Fiselier _Tester 4766624fcbaSEric Fiselier{ 4776624fcbaSEric Fiselier}; 4786624fcbaSEric Fiselier 4796624fcbaSEric Fiseliertemplate <class _Iter> 4806624fcbaSEric Fiselierstruct __iter_concept_cache { 4816624fcbaSEric Fiselier using type = _Or< 4826624fcbaSEric Fiselier __test_iter_concept<_Iter, __iter_concept_concept_test>, 4836624fcbaSEric Fiselier __test_iter_concept<_Iter, __iter_concept_category_test>, 4846624fcbaSEric Fiselier __test_iter_concept<_Iter, __iter_concept_random_fallback> 4856624fcbaSEric Fiselier >; 4866624fcbaSEric Fiselier}; 4876624fcbaSEric Fiselier 4886624fcbaSEric Fiseliertemplate <class _Iter> 4896624fcbaSEric Fiselierusing _ITER_CONCEPT = typename __iter_concept_cache<_Iter>::type::template _Apply<_Iter>; 4906624fcbaSEric Fiselier 4916624fcbaSEric Fiselier 4923e519524SHoward Hinnanttemplate <class _Tp> 493d4fa0381SMarshall Clowstruct __has_iterator_typedefs 494d4fa0381SMarshall Clow{ 495d4fa0381SMarshall Clowprivate: 496d4fa0381SMarshall Clow struct __two {char __lx; char __lxx;}; 497d4fa0381SMarshall Clow template <class _Up> static __two __test(...); 498d586f92cSArthur O'Dwyer template <class _Up> static char __test(typename __void_t<typename _Up::iterator_category>::type* = 0, 499d586f92cSArthur O'Dwyer typename __void_t<typename _Up::difference_type>::type* = 0, 500d586f92cSArthur O'Dwyer typename __void_t<typename _Up::value_type>::type* = 0, 501d586f92cSArthur O'Dwyer typename __void_t<typename _Up::reference>::type* = 0, 502d586f92cSArthur O'Dwyer typename __void_t<typename _Up::pointer>::type* = 0); 503d4fa0381SMarshall Clowpublic: 504d4fa0381SMarshall Clow static const bool value = sizeof(__test<_Tp>(0,0,0,0,0)) == 1; 505d4fa0381SMarshall Clow}; 506d4fa0381SMarshall Clow 507d4fa0381SMarshall Clow 508d4fa0381SMarshall Clowtemplate <class _Tp> 5093e519524SHoward Hinnantstruct __has_iterator_category 5103e519524SHoward Hinnant{ 5113e519524SHoward Hinnantprivate: 51254d333a6SHoward Hinnant struct __two {char __lx; char __lxx;}; 5133e519524SHoward Hinnant template <class _Up> static __two __test(...); 514527a7fdfSBruce Mitchener template <class _Up> static char __test(typename _Up::iterator_category* = nullptr); 5153e519524SHoward Hinnantpublic: 516527a7fdfSBruce Mitchener static const bool value = sizeof(__test<_Tp>(nullptr)) == 1; 5173e519524SHoward Hinnant}; 5183e519524SHoward Hinnant 519d41c6d51SArthur O'Dwyertemplate <class _Tp> 520d41c6d51SArthur O'Dwyerstruct __has_iterator_concept 521d41c6d51SArthur O'Dwyer{ 522d41c6d51SArthur O'Dwyerprivate: 523d41c6d51SArthur O'Dwyer struct __two {char __lx; char __lxx;}; 524d41c6d51SArthur O'Dwyer template <class _Up> static __two __test(...); 525d41c6d51SArthur O'Dwyer template <class _Up> static char __test(typename _Up::iterator_concept* = nullptr); 526d41c6d51SArthur O'Dwyerpublic: 527d41c6d51SArthur O'Dwyer static const bool value = sizeof(__test<_Tp>(nullptr)) == 1; 528d41c6d51SArthur O'Dwyer}; 529d41c6d51SArthur O'Dwyer 5300724bf67SMarshall Clowtemplate <class _Iter, bool> struct __iterator_traits_impl {}; 5313e519524SHoward Hinnant 5323e519524SHoward Hinnanttemplate <class _Iter> 5330724bf67SMarshall Clowstruct __iterator_traits_impl<_Iter, true> 5343e519524SHoward Hinnant{ 5353e519524SHoward Hinnant typedef typename _Iter::difference_type difference_type; 5363e519524SHoward Hinnant typedef typename _Iter::value_type value_type; 5373e519524SHoward Hinnant typedef typename _Iter::pointer pointer; 5383e519524SHoward Hinnant typedef typename _Iter::reference reference; 5393e519524SHoward Hinnant typedef typename _Iter::iterator_category iterator_category; 5403e519524SHoward Hinnant}; 5413e519524SHoward Hinnant 5423e519524SHoward Hinnanttemplate <class _Iter, bool> struct __iterator_traits {}; 5433e519524SHoward Hinnant 5443e519524SHoward Hinnanttemplate <class _Iter> 5453e519524SHoward Hinnantstruct __iterator_traits<_Iter, true> 5460724bf67SMarshall Clow : __iterator_traits_impl 5473e519524SHoward Hinnant < 5483e519524SHoward Hinnant _Iter, 5493e519524SHoward Hinnant is_convertible<typename _Iter::iterator_category, input_iterator_tag>::value || 5503e519524SHoward Hinnant is_convertible<typename _Iter::iterator_category, output_iterator_tag>::value 5513e519524SHoward Hinnant > 5523e519524SHoward Hinnant{}; 5533e519524SHoward Hinnant 5543e519524SHoward Hinnant// iterator_traits<Iterator> will only have the nested types if Iterator::iterator_category 5553e519524SHoward Hinnant// exists. Else iterator_traits<Iterator> will be an empty class. This is a 5563e519524SHoward Hinnant// conforming extension which allows some programs to compile and behave as 5573e519524SHoward Hinnant// the client expects instead of failing at compile time. 5583e519524SHoward Hinnant 5593e519524SHoward Hinnanttemplate <class _Iter> 560e2f2d1edSEric Fiselierstruct _LIBCPP_TEMPLATE_VIS iterator_traits 5616624fcbaSEric Fiselier : __iterator_traits<_Iter, __has_iterator_typedefs<_Iter>::value> { 5626624fcbaSEric Fiselier 5636624fcbaSEric Fiselier using __primary_template = iterator_traits; 5646624fcbaSEric Fiselier}; 5653e519524SHoward Hinnant 5663e519524SHoward Hinnanttemplate<class _Tp> 567e2f2d1edSEric Fiselierstruct _LIBCPP_TEMPLATE_VIS iterator_traits<_Tp*> 5683e519524SHoward Hinnant{ 5693e519524SHoward Hinnant typedef ptrdiff_t difference_type; 570ffcfd923SMarshall Clow typedef typename remove_cv<_Tp>::type value_type; 5713e519524SHoward Hinnant typedef _Tp* pointer; 5723e519524SHoward Hinnant typedef _Tp& reference; 5733e519524SHoward Hinnant typedef random_access_iterator_tag iterator_category; 57445d048c2SEric Fiselier#if _LIBCPP_STD_VER > 17 57545d048c2SEric Fiselier typedef contiguous_iterator_tag iterator_concept; 57645d048c2SEric Fiselier#endif 5773e519524SHoward Hinnant}; 5783e519524SHoward Hinnant 5793e519524SHoward Hinnanttemplate <class _Tp, class _Up, bool = __has_iterator_category<iterator_traits<_Tp> >::value> 5803e519524SHoward Hinnantstruct __has_iterator_category_convertible_to 581d41c6d51SArthur O'Dwyer : _BoolConstant<is_convertible<typename iterator_traits<_Tp>::iterator_category, _Up>::value> 5823e519524SHoward Hinnant{}; 5833e519524SHoward Hinnant 5843e519524SHoward Hinnanttemplate <class _Tp, class _Up> 585d41c6d51SArthur O'Dwyerstruct __has_iterator_category_convertible_to<_Tp, _Up, false> : false_type {}; 586d41c6d51SArthur O'Dwyer 587d41c6d51SArthur O'Dwyertemplate <class _Tp, class _Up, bool = __has_iterator_concept<_Tp>::value> 588d41c6d51SArthur O'Dwyerstruct __has_iterator_concept_convertible_to 589d41c6d51SArthur O'Dwyer : _BoolConstant<is_convertible<typename _Tp::iterator_concept, _Up>::value> 590d41c6d51SArthur O'Dwyer{}; 591d41c6d51SArthur O'Dwyer 592d41c6d51SArthur O'Dwyertemplate <class _Tp, class _Up> 593d41c6d51SArthur O'Dwyerstruct __has_iterator_concept_convertible_to<_Tp, _Up, false> : false_type {}; 5943e519524SHoward Hinnant 5953e519524SHoward Hinnanttemplate <class _Tp> 596f82dba01SEric Fiselierstruct __is_cpp17_input_iterator : public __has_iterator_category_convertible_to<_Tp, input_iterator_tag> {}; 5973e519524SHoward Hinnant 5983e519524SHoward Hinnanttemplate <class _Tp> 599f82dba01SEric Fiselierstruct __is_cpp17_forward_iterator : public __has_iterator_category_convertible_to<_Tp, forward_iterator_tag> {}; 6003e519524SHoward Hinnant 6013e519524SHoward Hinnanttemplate <class _Tp> 602f82dba01SEric Fiselierstruct __is_cpp17_bidirectional_iterator : public __has_iterator_category_convertible_to<_Tp, bidirectional_iterator_tag> {}; 6033e519524SHoward Hinnant 6043e519524SHoward Hinnanttemplate <class _Tp> 605f82dba01SEric Fiselierstruct __is_cpp17_random_access_iterator : public __has_iterator_category_convertible_to<_Tp, random_access_iterator_tag> {}; 6063e519524SHoward Hinnant 607d41c6d51SArthur O'Dwyer// __is_cpp17_contiguous_iterator determines if an iterator is contiguous, 608d41c6d51SArthur O'Dwyer// either because it advertises itself as such (in C++20) or because it 609d41c6d51SArthur O'Dwyer// is a pointer type or a known trivial wrapper around a pointer type, 610d41c6d51SArthur O'Dwyer// such as __wrap_iter<T*>. 611d41c6d51SArthur O'Dwyer// 61245d048c2SEric Fiselier#if _LIBCPP_STD_VER > 17 61345d048c2SEric Fiseliertemplate <class _Tp> 614d41c6d51SArthur O'Dwyerstruct __is_cpp17_contiguous_iterator : _Or< 615d41c6d51SArthur O'Dwyer __has_iterator_category_convertible_to<_Tp, contiguous_iterator_tag>, 616d41c6d51SArthur O'Dwyer __has_iterator_concept_convertible_to<_Tp, contiguous_iterator_tag> 617d41c6d51SArthur O'Dwyer> {}; 618f82dba01SEric Fiselier#else 619f82dba01SEric Fiseliertemplate <class _Tp> 620d41c6d51SArthur O'Dwyerstruct __is_cpp17_contiguous_iterator : false_type {}; 62145d048c2SEric Fiselier#endif 62245d048c2SEric Fiselier 623d41c6d51SArthur O'Dwyer// Any native pointer which is an iterator is also a contiguous iterator. 624d41c6d51SArthur O'Dwyertemplate <class _Up> 625d41c6d51SArthur O'Dwyerstruct __is_cpp17_contiguous_iterator<_Up*> : true_type {}; 626d41c6d51SArthur O'Dwyer 627f82dba01SEric Fiselier 62876b4afc0SMarshall Clowtemplate <class _Tp> 629f82dba01SEric Fiselierstruct __is_exactly_cpp17_input_iterator 63076b4afc0SMarshall Clow : public integral_constant<bool, 63176b4afc0SMarshall Clow __has_iterator_category_convertible_to<_Tp, input_iterator_tag>::value && 63276b4afc0SMarshall Clow !__has_iterator_category_convertible_to<_Tp, forward_iterator_tag>::value> {}; 63376b4afc0SMarshall Clow 634f2f7d72fSLouis Dionne#ifndef _LIBCPP_HAS_NO_DEDUCTION_GUIDES 635f2f7d72fSLouis Dionnetemplate<class _InputIterator> 636f2f7d72fSLouis Dionneusing __iter_value_type = typename iterator_traits<_InputIterator>::value_type; 637f2f7d72fSLouis Dionne 638f2f7d72fSLouis Dionnetemplate<class _InputIterator> 639f2f7d72fSLouis Dionneusing __iter_key_type = remove_const_t<typename iterator_traits<_InputIterator>::value_type::first_type>; 640f2f7d72fSLouis Dionne 641f2f7d72fSLouis Dionnetemplate<class _InputIterator> 642f2f7d72fSLouis Dionneusing __iter_mapped_type = typename iterator_traits<_InputIterator>::value_type::second_type; 643f2f7d72fSLouis Dionne 644f2f7d72fSLouis Dionnetemplate<class _InputIterator> 645f2f7d72fSLouis Dionneusing __iter_to_alloc_type = pair< 646f2f7d72fSLouis Dionne add_const_t<typename iterator_traits<_InputIterator>::value_type::first_type>, 647f2f7d72fSLouis Dionne typename iterator_traits<_InputIterator>::value_type::second_type>; 648f2f7d72fSLouis Dionne#endif 649f2f7d72fSLouis Dionne 6503e519524SHoward Hinnanttemplate<class _Category, class _Tp, class _Distance = ptrdiff_t, 6513e519524SHoward Hinnant class _Pointer = _Tp*, class _Reference = _Tp&> 652e2f2d1edSEric Fiselierstruct _LIBCPP_TEMPLATE_VIS iterator 6533e519524SHoward Hinnant{ 6543e519524SHoward Hinnant typedef _Tp value_type; 6553e519524SHoward Hinnant typedef _Distance difference_type; 6563e519524SHoward Hinnant typedef _Pointer pointer; 6573e519524SHoward Hinnant typedef _Reference reference; 6583e519524SHoward Hinnant typedef _Category iterator_category; 6593e519524SHoward Hinnant}; 6603e519524SHoward Hinnant 6613e519524SHoward Hinnanttemplate <class _InputIter> 662f51ee632SMarshall Clowinline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 6633e519524SHoward Hinnantvoid __advance(_InputIter& __i, 6643e519524SHoward Hinnant typename iterator_traits<_InputIter>::difference_type __n, input_iterator_tag) 6653e519524SHoward Hinnant{ 6663e519524SHoward Hinnant for (; __n > 0; --__n) 6673e519524SHoward Hinnant ++__i; 6683e519524SHoward Hinnant} 6693e519524SHoward Hinnant 6703e519524SHoward Hinnanttemplate <class _BiDirIter> 671f51ee632SMarshall Clowinline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 6723e519524SHoward Hinnantvoid __advance(_BiDirIter& __i, 6733e519524SHoward Hinnant typename iterator_traits<_BiDirIter>::difference_type __n, bidirectional_iterator_tag) 6743e519524SHoward Hinnant{ 6753e519524SHoward Hinnant if (__n >= 0) 6763e519524SHoward Hinnant for (; __n > 0; --__n) 6773e519524SHoward Hinnant ++__i; 6783e519524SHoward Hinnant else 6793e519524SHoward Hinnant for (; __n < 0; ++__n) 6803e519524SHoward Hinnant --__i; 6813e519524SHoward Hinnant} 6823e519524SHoward Hinnant 6833e519524SHoward Hinnanttemplate <class _RandIter> 684f51ee632SMarshall Clowinline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 6853e519524SHoward Hinnantvoid __advance(_RandIter& __i, 6863e519524SHoward Hinnant typename iterator_traits<_RandIter>::difference_type __n, random_access_iterator_tag) 6873e519524SHoward Hinnant{ 6883e519524SHoward Hinnant __i += __n; 6893e519524SHoward Hinnant} 6903e519524SHoward Hinnant 69112b01ab7SLouis Dionnetemplate <class _InputIter, class _Distance> 692f51ee632SMarshall Clowinline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 69312b01ab7SLouis Dionnevoid advance(_InputIter& __i, _Distance __orig_n) 6943e519524SHoward Hinnant{ 69512b01ab7SLouis Dionne _LIBCPP_ASSERT(__orig_n >= 0 || __is_cpp17_bidirectional_iterator<_InputIter>::value, 69612b01ab7SLouis Dionne "Attempt to advance(it, n) with negative n on a non-bidirectional iterator"); 697c0428b3cSArthur O'Dwyer typedef decltype(_VSTD::__convert_to_integral(__orig_n)) _IntegralSize; 69812b01ab7SLouis Dionne _IntegralSize __n = __orig_n; 699c0428b3cSArthur O'Dwyer _VSTD::__advance(__i, __n, typename iterator_traits<_InputIter>::iterator_category()); 7003e519524SHoward Hinnant} 7013e519524SHoward Hinnant 7023e519524SHoward Hinnanttemplate <class _InputIter> 703f51ee632SMarshall Clowinline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 7043e519524SHoward Hinnanttypename iterator_traits<_InputIter>::difference_type 7053e519524SHoward Hinnant__distance(_InputIter __first, _InputIter __last, input_iterator_tag) 7063e519524SHoward Hinnant{ 7073e519524SHoward Hinnant typename iterator_traits<_InputIter>::difference_type __r(0); 7083e519524SHoward Hinnant for (; __first != __last; ++__first) 7093e519524SHoward Hinnant ++__r; 7103e519524SHoward Hinnant return __r; 7113e519524SHoward Hinnant} 7123e519524SHoward Hinnant 7133e519524SHoward Hinnanttemplate <class _RandIter> 714f51ee632SMarshall Clowinline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 7153e519524SHoward Hinnanttypename iterator_traits<_RandIter>::difference_type 7163e519524SHoward Hinnant__distance(_RandIter __first, _RandIter __last, random_access_iterator_tag) 7173e519524SHoward Hinnant{ 7183e519524SHoward Hinnant return __last - __first; 7193e519524SHoward Hinnant} 7203e519524SHoward Hinnant 7213e519524SHoward Hinnanttemplate <class _InputIter> 722f51ee632SMarshall Clowinline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 7233e519524SHoward Hinnanttypename iterator_traits<_InputIter>::difference_type 7243e519524SHoward Hinnantdistance(_InputIter __first, _InputIter __last) 7253e519524SHoward Hinnant{ 726c0428b3cSArthur O'Dwyer return _VSTD::__distance(__first, __last, typename iterator_traits<_InputIter>::iterator_category()); 7273e519524SHoward Hinnant} 7283e519524SHoward Hinnant 729e5f1288fSMarshall Clowtemplate <class _InputIter> 730f51ee632SMarshall Clowinline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 7313e2ef408SRachel Craiktypename enable_if 7323e2ef408SRachel Craik< 733f82dba01SEric Fiselier __is_cpp17_input_iterator<_InputIter>::value, 734e5f1288fSMarshall Clow _InputIter 7353e2ef408SRachel Craik>::type 736e5f1288fSMarshall Clownext(_InputIter __x, 7373e2ef408SRachel Craik typename iterator_traits<_InputIter>::difference_type __n = 1) 7383e519524SHoward Hinnant{ 739f82dba01SEric Fiselier _LIBCPP_ASSERT(__n >= 0 || __is_cpp17_bidirectional_iterator<_InputIter>::value, 74012b01ab7SLouis Dionne "Attempt to next(it, n) with negative n on a non-bidirectional iterator"); 741e1cd11d8SMarshall Clow 742ce48a113SHoward Hinnant _VSTD::advance(__x, __n); 7433e519524SHoward Hinnant return __x; 7443e519524SHoward Hinnant} 7453e519524SHoward Hinnant 746e1cd11d8SMarshall Clowtemplate <class _InputIter> 747f51ee632SMarshall Clowinline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 7483e2ef408SRachel Craiktypename enable_if 7493e2ef408SRachel Craik< 750f82dba01SEric Fiselier __is_cpp17_input_iterator<_InputIter>::value, 751e1cd11d8SMarshall Clow _InputIter 7523e2ef408SRachel Craik>::type 753e1cd11d8SMarshall Clowprev(_InputIter __x, 754e1cd11d8SMarshall Clow typename iterator_traits<_InputIter>::difference_type __n = 1) 7553e519524SHoward Hinnant{ 756f82dba01SEric Fiselier _LIBCPP_ASSERT(__n <= 0 || __is_cpp17_bidirectional_iterator<_InputIter>::value, 75712b01ab7SLouis Dionne "Attempt to prev(it, n) with a positive n on a non-bidirectional iterator"); 758ce48a113SHoward Hinnant _VSTD::advance(__x, -__n); 7593e519524SHoward Hinnant return __x; 7603e519524SHoward Hinnant} 7613e519524SHoward Hinnant 762e02ed1c2SEric Fiselier 763e02ed1c2SEric Fiseliertemplate <class _Tp, class = void> 764e02ed1c2SEric Fiselierstruct __is_stashing_iterator : false_type {}; 765e02ed1c2SEric Fiselier 766e02ed1c2SEric Fiseliertemplate <class _Tp> 767e02ed1c2SEric Fiselierstruct __is_stashing_iterator<_Tp, typename __void_t<typename _Tp::__stashing_iterator_tag>::type> 768e02ed1c2SEric Fiselier : true_type {}; 769e02ed1c2SEric Fiselier 7703e519524SHoward Hinnanttemplate <class _Iter> 771e2f2d1edSEric Fiselierclass _LIBCPP_TEMPLATE_VIS reverse_iterator 7723e519524SHoward Hinnant : public iterator<typename iterator_traits<_Iter>::iterator_category, 7733e519524SHoward Hinnant typename iterator_traits<_Iter>::value_type, 7743e519524SHoward Hinnant typename iterator_traits<_Iter>::difference_type, 7753e519524SHoward Hinnant typename iterator_traits<_Iter>::pointer, 7763e519524SHoward Hinnant typename iterator_traits<_Iter>::reference> 7773e519524SHoward Hinnant{ 7783b83496dSMarshall Clowprivate: 7791b8f260eSMarshall Clow /*mutable*/ _Iter __t; // no longer used as of LWG #2360, not removed due to ABI break 780e02ed1c2SEric Fiselier 781e02ed1c2SEric Fiselier static_assert(!__is_stashing_iterator<_Iter>::value, 782e02ed1c2SEric Fiselier "The specified iterator type cannot be used with reverse_iterator; " 783e02ed1c2SEric Fiselier "Using stashing iterators with reverse_iterator causes undefined behavior"); 784e02ed1c2SEric Fiselier 785b2d74f29SMarshall Clowprotected: 786b2d74f29SMarshall Clow _Iter current; 7873e519524SHoward Hinnantpublic: 7883e519524SHoward Hinnant typedef _Iter iterator_type; 7893e519524SHoward Hinnant typedef typename iterator_traits<_Iter>::difference_type difference_type; 7903e519524SHoward Hinnant typedef typename iterator_traits<_Iter>::reference reference; 7913e519524SHoward Hinnant typedef typename iterator_traits<_Iter>::pointer pointer; 792d41c6d51SArthur O'Dwyer typedef _If<__is_cpp17_random_access_iterator<_Iter>::value, 793d41c6d51SArthur O'Dwyer random_access_iterator_tag, 794d41c6d51SArthur O'Dwyer typename iterator_traits<_Iter>::iterator_category> iterator_category; 795d41c6d51SArthur O'Dwyer#if _LIBCPP_STD_VER > 17 796d41c6d51SArthur O'Dwyer typedef _If<__is_cpp17_random_access_iterator<_Iter>::value, 797d41c6d51SArthur O'Dwyer random_access_iterator_tag, 798d41c6d51SArthur O'Dwyer bidirectional_iterator_tag> iterator_concept; 799d41c6d51SArthur O'Dwyer#endif 8003e519524SHoward Hinnant 8011b8f260eSMarshall Clow _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 8021b8f260eSMarshall Clow reverse_iterator() : __t(), current() {} 8031b8f260eSMarshall Clow _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 8041b8f260eSMarshall Clow explicit reverse_iterator(_Iter __x) : __t(__x), current(__x) {} 8051b8f260eSMarshall Clow template <class _Up> 8061b8f260eSMarshall Clow _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 8071b8f260eSMarshall Clow reverse_iterator(const reverse_iterator<_Up>& __u) : __t(__u.base()), current(__u.base()) {} 8081b8f260eSMarshall Clow template <class _Up> 8091b8f260eSMarshall Clow _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 8101b8f260eSMarshall Clow reverse_iterator& operator=(const reverse_iterator<_Up>& __u) 8111b8f260eSMarshall Clow { __t = current = __u.base(); return *this; } 8121b8f260eSMarshall Clow _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 8131b8f260eSMarshall Clow _Iter base() const {return current;} 8141b8f260eSMarshall Clow _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 8151b8f260eSMarshall Clow reference operator*() const {_Iter __tmp = current; return *--__tmp;} 8161b8f260eSMarshall Clow _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 8171b8f260eSMarshall Clow pointer operator->() const {return _VSTD::addressof(operator*());} 8181b8f260eSMarshall Clow _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 8191b8f260eSMarshall Clow reverse_iterator& operator++() {--current; return *this;} 8201b8f260eSMarshall Clow _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 8211b8f260eSMarshall Clow reverse_iterator operator++(int) {reverse_iterator __tmp(*this); --current; return __tmp;} 8221b8f260eSMarshall Clow _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 8231b8f260eSMarshall Clow reverse_iterator& operator--() {++current; return *this;} 8241b8f260eSMarshall Clow _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 8251b8f260eSMarshall Clow reverse_iterator operator--(int) {reverse_iterator __tmp(*this); ++current; return __tmp;} 8261b8f260eSMarshall Clow _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 8271b8f260eSMarshall Clow reverse_iterator operator+ (difference_type __n) const {return reverse_iterator(current - __n);} 8281b8f260eSMarshall Clow _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 8291b8f260eSMarshall Clow reverse_iterator& operator+=(difference_type __n) {current -= __n; return *this;} 8301b8f260eSMarshall Clow _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 8311b8f260eSMarshall Clow reverse_iterator operator- (difference_type __n) const {return reverse_iterator(current + __n);} 8321b8f260eSMarshall Clow _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 8331b8f260eSMarshall Clow reverse_iterator& operator-=(difference_type __n) {current += __n; return *this;} 8341b8f260eSMarshall Clow _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 8351b8f260eSMarshall Clow reference operator[](difference_type __n) const {return *(*this + __n);} 8363e519524SHoward Hinnant}; 8373e519524SHoward Hinnant 8383e519524SHoward Hinnanttemplate <class _Iter1, class _Iter2> 8391b8f260eSMarshall Clowinline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 8403e519524SHoward Hinnantbool 8413e519524SHoward Hinnantoperator==(const reverse_iterator<_Iter1>& __x, const reverse_iterator<_Iter2>& __y) 8423e519524SHoward Hinnant{ 8433e519524SHoward Hinnant return __x.base() == __y.base(); 8443e519524SHoward Hinnant} 8453e519524SHoward Hinnant 8463e519524SHoward Hinnanttemplate <class _Iter1, class _Iter2> 8471b8f260eSMarshall Clowinline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 8483e519524SHoward Hinnantbool 8493e519524SHoward Hinnantoperator<(const reverse_iterator<_Iter1>& __x, const reverse_iterator<_Iter2>& __y) 8503e519524SHoward Hinnant{ 8513e519524SHoward Hinnant return __x.base() > __y.base(); 8523e519524SHoward Hinnant} 8533e519524SHoward Hinnant 8543e519524SHoward Hinnanttemplate <class _Iter1, class _Iter2> 8551b8f260eSMarshall Clowinline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 8563e519524SHoward Hinnantbool 8573e519524SHoward Hinnantoperator!=(const reverse_iterator<_Iter1>& __x, const reverse_iterator<_Iter2>& __y) 8583e519524SHoward Hinnant{ 8593e519524SHoward Hinnant return __x.base() != __y.base(); 8603e519524SHoward Hinnant} 8613e519524SHoward Hinnant 8623e519524SHoward Hinnanttemplate <class _Iter1, class _Iter2> 8631b8f260eSMarshall Clowinline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 8643e519524SHoward Hinnantbool 8653e519524SHoward Hinnantoperator>(const reverse_iterator<_Iter1>& __x, const reverse_iterator<_Iter2>& __y) 8663e519524SHoward Hinnant{ 8673e519524SHoward Hinnant return __x.base() < __y.base(); 8683e519524SHoward Hinnant} 8693e519524SHoward Hinnant 8703e519524SHoward Hinnanttemplate <class _Iter1, class _Iter2> 8711b8f260eSMarshall Clowinline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 8723e519524SHoward Hinnantbool 8733e519524SHoward Hinnantoperator>=(const reverse_iterator<_Iter1>& __x, const reverse_iterator<_Iter2>& __y) 8743e519524SHoward Hinnant{ 8753e519524SHoward Hinnant return __x.base() <= __y.base(); 8763e519524SHoward Hinnant} 8773e519524SHoward Hinnant 8783e519524SHoward Hinnanttemplate <class _Iter1, class _Iter2> 8791b8f260eSMarshall Clowinline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 8803e519524SHoward Hinnantbool 8813e519524SHoward Hinnantoperator<=(const reverse_iterator<_Iter1>& __x, const reverse_iterator<_Iter2>& __y) 8823e519524SHoward Hinnant{ 8833e519524SHoward Hinnant return __x.base() >= __y.base(); 8843e519524SHoward Hinnant} 8853e519524SHoward Hinnant 8862ee83725SMarshall Clow#ifndef _LIBCPP_CXX03_LANG 887947ce6b5SMarshall Clowtemplate <class _Iter1, class _Iter2> 8881b8f260eSMarshall Clowinline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 889947ce6b5SMarshall Clowauto 890947ce6b5SMarshall Clowoperator-(const reverse_iterator<_Iter1>& __x, const reverse_iterator<_Iter2>& __y) 891947ce6b5SMarshall Clow-> decltype(__y.base() - __x.base()) 892947ce6b5SMarshall Clow{ 893947ce6b5SMarshall Clow return __y.base() - __x.base(); 894947ce6b5SMarshall Clow} 895947ce6b5SMarshall Clow#else 8963e519524SHoward Hinnanttemplate <class _Iter1, class _Iter2> 8973e519524SHoward Hinnantinline _LIBCPP_INLINE_VISIBILITY 8983e519524SHoward Hinnanttypename reverse_iterator<_Iter1>::difference_type 8993e519524SHoward Hinnantoperator-(const reverse_iterator<_Iter1>& __x, const reverse_iterator<_Iter2>& __y) 9003e519524SHoward Hinnant{ 9013e519524SHoward Hinnant return __y.base() - __x.base(); 9023e519524SHoward Hinnant} 903947ce6b5SMarshall Clow#endif 9043e519524SHoward Hinnant 9053e519524SHoward Hinnanttemplate <class _Iter> 9061b8f260eSMarshall Clowinline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 9073e519524SHoward Hinnantreverse_iterator<_Iter> 9083e519524SHoward Hinnantoperator+(typename reverse_iterator<_Iter>::difference_type __n, const reverse_iterator<_Iter>& __x) 9093e519524SHoward Hinnant{ 9103e519524SHoward Hinnant return reverse_iterator<_Iter>(__x.base() - __n); 9113e519524SHoward Hinnant} 9123e519524SHoward Hinnant 9136a640a18SMarshall Clow#if _LIBCPP_STD_VER > 11 9146a640a18SMarshall Clowtemplate <class _Iter> 9151b8f260eSMarshall Clowinline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 9166a640a18SMarshall Clowreverse_iterator<_Iter> make_reverse_iterator(_Iter __i) 9176a640a18SMarshall Clow{ 9186a640a18SMarshall Clow return reverse_iterator<_Iter>(__i); 9196a640a18SMarshall Clow} 9206a640a18SMarshall Clow#endif 9216a640a18SMarshall Clow 9223e519524SHoward Hinnanttemplate <class _Container> 923e2f2d1edSEric Fiselierclass _LIBCPP_TEMPLATE_VIS back_insert_iterator 9243e519524SHoward Hinnant : public iterator<output_iterator_tag, 9253e519524SHoward Hinnant void, 9263e519524SHoward Hinnant void, 9273e519524SHoward Hinnant void, 9288892b4eeSEric Fiselier void> 9293e519524SHoward Hinnant{ 9303e519524SHoward Hinnantprotected: 9313e519524SHoward Hinnant _Container* container; 9323e519524SHoward Hinnantpublic: 9333e519524SHoward Hinnant typedef _Container container_type; 9343e519524SHoward Hinnant 935*06e2b737SArthur O'Dwyer _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 explicit back_insert_iterator(_Container& __x) : container(_VSTD::addressof(__x)) {} 936*06e2b737SArthur O'Dwyer _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 back_insert_iterator& operator=(const typename _Container::value_type& __value_) 937e4383379SHoward Hinnant {container->push_back(__value_); return *this;} 938046492b9SEric Fiselier#ifndef _LIBCPP_CXX03_LANG 939*06e2b737SArthur O'Dwyer _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 back_insert_iterator& operator=(typename _Container::value_type&& __value_) 940e4383379SHoward Hinnant {container->push_back(_VSTD::move(__value_)); return *this;} 941046492b9SEric Fiselier#endif // _LIBCPP_CXX03_LANG 942*06e2b737SArthur O'Dwyer _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 back_insert_iterator& operator*() {return *this;} 943*06e2b737SArthur O'Dwyer _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 back_insert_iterator& operator++() {return *this;} 944*06e2b737SArthur O'Dwyer _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 back_insert_iterator operator++(int) {return *this;} 9453e519524SHoward Hinnant}; 9463e519524SHoward Hinnant 9473e519524SHoward Hinnanttemplate <class _Container> 948*06e2b737SArthur O'Dwyerinline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 9493e519524SHoward Hinnantback_insert_iterator<_Container> 9503e519524SHoward Hinnantback_inserter(_Container& __x) 9513e519524SHoward Hinnant{ 9523e519524SHoward Hinnant return back_insert_iterator<_Container>(__x); 9533e519524SHoward Hinnant} 9543e519524SHoward Hinnant 9553e519524SHoward Hinnanttemplate <class _Container> 956e2f2d1edSEric Fiselierclass _LIBCPP_TEMPLATE_VIS front_insert_iterator 9573e519524SHoward Hinnant : public iterator<output_iterator_tag, 9583e519524SHoward Hinnant void, 9593e519524SHoward Hinnant void, 9603e519524SHoward Hinnant void, 9618892b4eeSEric Fiselier void> 9623e519524SHoward Hinnant{ 9633e519524SHoward Hinnantprotected: 9643e519524SHoward Hinnant _Container* container; 9653e519524SHoward Hinnantpublic: 9663e519524SHoward Hinnant typedef _Container container_type; 9673e519524SHoward Hinnant 968*06e2b737SArthur O'Dwyer _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 explicit front_insert_iterator(_Container& __x) : container(_VSTD::addressof(__x)) {} 969*06e2b737SArthur O'Dwyer _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 front_insert_iterator& operator=(const typename _Container::value_type& __value_) 970e4383379SHoward Hinnant {container->push_front(__value_); return *this;} 971046492b9SEric Fiselier#ifndef _LIBCPP_CXX03_LANG 972*06e2b737SArthur O'Dwyer _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 front_insert_iterator& operator=(typename _Container::value_type&& __value_) 973e4383379SHoward Hinnant {container->push_front(_VSTD::move(__value_)); return *this;} 974046492b9SEric Fiselier#endif // _LIBCPP_CXX03_LANG 975*06e2b737SArthur O'Dwyer _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 front_insert_iterator& operator*() {return *this;} 976*06e2b737SArthur O'Dwyer _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 front_insert_iterator& operator++() {return *this;} 977*06e2b737SArthur O'Dwyer _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 front_insert_iterator operator++(int) {return *this;} 9783e519524SHoward Hinnant}; 9793e519524SHoward Hinnant 9803e519524SHoward Hinnanttemplate <class _Container> 981*06e2b737SArthur O'Dwyerinline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 9823e519524SHoward Hinnantfront_insert_iterator<_Container> 9833e519524SHoward Hinnantfront_inserter(_Container& __x) 9843e519524SHoward Hinnant{ 9853e519524SHoward Hinnant return front_insert_iterator<_Container>(__x); 9863e519524SHoward Hinnant} 9873e519524SHoward Hinnant 9883e519524SHoward Hinnanttemplate <class _Container> 989e2f2d1edSEric Fiselierclass _LIBCPP_TEMPLATE_VIS insert_iterator 9903e519524SHoward Hinnant : public iterator<output_iterator_tag, 9913e519524SHoward Hinnant void, 9923e519524SHoward Hinnant void, 9933e519524SHoward Hinnant void, 9948892b4eeSEric Fiselier void> 9953e519524SHoward Hinnant{ 9963e519524SHoward Hinnantprotected: 9973e519524SHoward Hinnant _Container* container; 9983e519524SHoward Hinnant typename _Container::iterator iter; 9993e519524SHoward Hinnantpublic: 10003e519524SHoward Hinnant typedef _Container container_type; 10013e519524SHoward Hinnant 1002*06e2b737SArthur O'Dwyer _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 insert_iterator(_Container& __x, typename _Container::iterator __i) 1003f519be34SMarshall Clow : container(_VSTD::addressof(__x)), iter(__i) {} 1004*06e2b737SArthur O'Dwyer _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 insert_iterator& operator=(const typename _Container::value_type& __value_) 1005e4383379SHoward Hinnant {iter = container->insert(iter, __value_); ++iter; return *this;} 1006046492b9SEric Fiselier#ifndef _LIBCPP_CXX03_LANG 1007*06e2b737SArthur O'Dwyer _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 insert_iterator& operator=(typename _Container::value_type&& __value_) 1008e4383379SHoward Hinnant {iter = container->insert(iter, _VSTD::move(__value_)); ++iter; return *this;} 1009046492b9SEric Fiselier#endif // _LIBCPP_CXX03_LANG 1010*06e2b737SArthur O'Dwyer _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 insert_iterator& operator*() {return *this;} 1011*06e2b737SArthur O'Dwyer _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 insert_iterator& operator++() {return *this;} 1012*06e2b737SArthur O'Dwyer _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 insert_iterator& operator++(int) {return *this;} 10133e519524SHoward Hinnant}; 10143e519524SHoward Hinnant 10153e519524SHoward Hinnanttemplate <class _Container> 1016*06e2b737SArthur O'Dwyerinline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 10173e519524SHoward Hinnantinsert_iterator<_Container> 10183e519524SHoward Hinnantinserter(_Container& __x, typename _Container::iterator __i) 10193e519524SHoward Hinnant{ 10203e519524SHoward Hinnant return insert_iterator<_Container>(__x, __i); 10213e519524SHoward Hinnant} 10223e519524SHoward Hinnant 10233e519524SHoward Hinnanttemplate <class _Tp, class _CharT = char, 10243e519524SHoward Hinnant class _Traits = char_traits<_CharT>, class _Distance = ptrdiff_t> 1025e2f2d1edSEric Fiselierclass _LIBCPP_TEMPLATE_VIS istream_iterator 10263e519524SHoward Hinnant : public iterator<input_iterator_tag, _Tp, _Distance, const _Tp*, const _Tp&> 10273e519524SHoward Hinnant{ 10283e519524SHoward Hinnantpublic: 10293e519524SHoward Hinnant typedef _CharT char_type; 10303e519524SHoward Hinnant typedef _Traits traits_type; 10313e519524SHoward Hinnant typedef basic_istream<_CharT,_Traits> istream_type; 10323e519524SHoward Hinnantprivate: 10333e519524SHoward Hinnant istream_type* __in_stream_; 10343e519524SHoward Hinnant _Tp __value_; 10353e519524SHoward Hinnantpublic: 1036527a7fdfSBruce Mitchener _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR istream_iterator() : __in_stream_(nullptr), __value_() {} 1037bc6a7df0SMarshall Clow _LIBCPP_INLINE_VISIBILITY istream_iterator(istream_type& __s) : __in_stream_(_VSTD::addressof(__s)) 10383e519524SHoward Hinnant { 10393e519524SHoward Hinnant if (!(*__in_stream_ >> __value_)) 1040527a7fdfSBruce Mitchener __in_stream_ = nullptr; 10413e519524SHoward Hinnant } 10423e519524SHoward Hinnant 10433e519524SHoward Hinnant _LIBCPP_INLINE_VISIBILITY const _Tp& operator*() const {return __value_;} 1044bc6a7df0SMarshall Clow _LIBCPP_INLINE_VISIBILITY const _Tp* operator->() const {return _VSTD::addressof((operator*()));} 10453e519524SHoward Hinnant _LIBCPP_INLINE_VISIBILITY istream_iterator& operator++() 10463e519524SHoward Hinnant { 10473e519524SHoward Hinnant if (!(*__in_stream_ >> __value_)) 1048527a7fdfSBruce Mitchener __in_stream_ = nullptr; 10493e519524SHoward Hinnant return *this; 10503e519524SHoward Hinnant } 10513e519524SHoward Hinnant _LIBCPP_INLINE_VISIBILITY istream_iterator operator++(int) 10523e519524SHoward Hinnant {istream_iterator __t(*this); ++(*this); return __t;} 10533e519524SHoward Hinnant 10546f56d3eeSRoger Ferrer Ibanez template <class _Up, class _CharU, class _TraitsU, class _DistanceU> 10553e519524SHoward Hinnant friend _LIBCPP_INLINE_VISIBILITY 10566f56d3eeSRoger Ferrer Ibanez bool 10576f56d3eeSRoger Ferrer Ibanez operator==(const istream_iterator<_Up, _CharU, _TraitsU, _DistanceU>& __x, 10586f56d3eeSRoger Ferrer Ibanez const istream_iterator<_Up, _CharU, _TraitsU, _DistanceU>& __y); 10593e519524SHoward Hinnant 10606f56d3eeSRoger Ferrer Ibanez template <class _Up, class _CharU, class _TraitsU, class _DistanceU> 10613e519524SHoward Hinnant friend _LIBCPP_INLINE_VISIBILITY 10626f56d3eeSRoger Ferrer Ibanez bool 10636f56d3eeSRoger Ferrer Ibanez operator==(const istream_iterator<_Up, _CharU, _TraitsU, _DistanceU>& __x, 10646f56d3eeSRoger Ferrer Ibanez const istream_iterator<_Up, _CharU, _TraitsU, _DistanceU>& __y); 10653e519524SHoward Hinnant}; 10663e519524SHoward Hinnant 10676f56d3eeSRoger Ferrer Ibaneztemplate <class _Tp, class _CharT, class _Traits, class _Distance> 10686f56d3eeSRoger Ferrer Ibanezinline _LIBCPP_INLINE_VISIBILITY 10696f56d3eeSRoger Ferrer Ibanezbool 10706f56d3eeSRoger Ferrer Ibanezoperator==(const istream_iterator<_Tp, _CharT, _Traits, _Distance>& __x, 10716f56d3eeSRoger Ferrer Ibanez const istream_iterator<_Tp, _CharT, _Traits, _Distance>& __y) 10726f56d3eeSRoger Ferrer Ibanez{ 10736f56d3eeSRoger Ferrer Ibanez return __x.__in_stream_ == __y.__in_stream_; 10746f56d3eeSRoger Ferrer Ibanez} 10756f56d3eeSRoger Ferrer Ibanez 10766f56d3eeSRoger Ferrer Ibaneztemplate <class _Tp, class _CharT, class _Traits, class _Distance> 10776f56d3eeSRoger Ferrer Ibanezinline _LIBCPP_INLINE_VISIBILITY 10786f56d3eeSRoger Ferrer Ibanezbool 10796f56d3eeSRoger Ferrer Ibanezoperator!=(const istream_iterator<_Tp, _CharT, _Traits, _Distance>& __x, 10806f56d3eeSRoger Ferrer Ibanez const istream_iterator<_Tp, _CharT, _Traits, _Distance>& __y) 10816f56d3eeSRoger Ferrer Ibanez{ 10826f56d3eeSRoger Ferrer Ibanez return !(__x == __y); 10836f56d3eeSRoger Ferrer Ibanez} 10846f56d3eeSRoger Ferrer Ibanez 10853e519524SHoward Hinnanttemplate <class _Tp, class _CharT = char, class _Traits = char_traits<_CharT> > 1086e2f2d1edSEric Fiselierclass _LIBCPP_TEMPLATE_VIS ostream_iterator 10873e519524SHoward Hinnant : public iterator<output_iterator_tag, void, void, void, void> 10883e519524SHoward Hinnant{ 10893e519524SHoward Hinnantpublic: 109071a16e40SLouis Dionne typedef output_iterator_tag iterator_category; 109171a16e40SLouis Dionne typedef void value_type; 109271a16e40SLouis Dionne#if _LIBCPP_STD_VER > 17 109371a16e40SLouis Dionne typedef std::ptrdiff_t difference_type; 109471a16e40SLouis Dionne#else 109571a16e40SLouis Dionne typedef void difference_type; 109671a16e40SLouis Dionne#endif 109771a16e40SLouis Dionne typedef void pointer; 109871a16e40SLouis Dionne typedef void reference; 10993e519524SHoward Hinnant typedef _CharT char_type; 11003e519524SHoward Hinnant typedef _Traits traits_type; 11013e519524SHoward Hinnant typedef basic_ostream<_CharT, _Traits> ostream_type; 110271a16e40SLouis Dionne 11033e519524SHoward Hinnantprivate: 11043e519524SHoward Hinnant ostream_type* __out_stream_; 11053e519524SHoward Hinnant const char_type* __delim_; 11063e519524SHoward Hinnantpublic: 1107853042cfSMarshall Clow _LIBCPP_INLINE_VISIBILITY ostream_iterator(ostream_type& __s) _NOEXCEPT 1108527a7fdfSBruce Mitchener : __out_stream_(_VSTD::addressof(__s)), __delim_(nullptr) {} 1109853042cfSMarshall Clow _LIBCPP_INLINE_VISIBILITY ostream_iterator(ostream_type& __s, const _CharT* __delimiter) _NOEXCEPT 1110bc6a7df0SMarshall Clow : __out_stream_(_VSTD::addressof(__s)), __delim_(__delimiter) {} 1111e4383379SHoward Hinnant _LIBCPP_INLINE_VISIBILITY ostream_iterator& operator=(const _Tp& __value_) 11123e519524SHoward Hinnant { 1113e4383379SHoward Hinnant *__out_stream_ << __value_; 11143e519524SHoward Hinnant if (__delim_) 11153e519524SHoward Hinnant *__out_stream_ << __delim_; 11163e519524SHoward Hinnant return *this; 11173e519524SHoward Hinnant } 11183e519524SHoward Hinnant 11193e519524SHoward Hinnant _LIBCPP_INLINE_VISIBILITY ostream_iterator& operator*() {return *this;} 11203e519524SHoward Hinnant _LIBCPP_INLINE_VISIBILITY ostream_iterator& operator++() {return *this;} 11213e519524SHoward Hinnant _LIBCPP_INLINE_VISIBILITY ostream_iterator& operator++(int) {return *this;} 11223e519524SHoward Hinnant}; 11233e519524SHoward Hinnant 11243e519524SHoward Hinnanttemplate<class _CharT, class _Traits> 1125e2f2d1edSEric Fiselierclass _LIBCPP_TEMPLATE_VIS istreambuf_iterator 11263e519524SHoward Hinnant : public iterator<input_iterator_tag, _CharT, 11273e519524SHoward Hinnant typename _Traits::off_type, _CharT*, 11283e519524SHoward Hinnant _CharT> 11293e519524SHoward Hinnant{ 11303e519524SHoward Hinnantpublic: 11313e519524SHoward Hinnant typedef _CharT char_type; 11323e519524SHoward Hinnant typedef _Traits traits_type; 11333e519524SHoward Hinnant typedef typename _Traits::int_type int_type; 11343e519524SHoward Hinnant typedef basic_streambuf<_CharT,_Traits> streambuf_type; 11353e519524SHoward Hinnant typedef basic_istream<_CharT,_Traits> istream_type; 11363e519524SHoward Hinnantprivate: 1137dfdf5085SHoward Hinnant mutable streambuf_type* __sbuf_; 11383e519524SHoward Hinnant 11393e519524SHoward Hinnant class __proxy 11403e519524SHoward Hinnant { 11413e519524SHoward Hinnant char_type __keep_; 11423e519524SHoward Hinnant streambuf_type* __sbuf_; 11433e519524SHoward Hinnant _LIBCPP_INLINE_VISIBILITY __proxy(char_type __c, streambuf_type* __s) 11443e519524SHoward Hinnant : __keep_(__c), __sbuf_(__s) {} 11453e519524SHoward Hinnant friend class istreambuf_iterator; 11463e519524SHoward Hinnant public: 11473e519524SHoward Hinnant _LIBCPP_INLINE_VISIBILITY char_type operator*() const {return __keep_;} 11483e519524SHoward Hinnant }; 11493e519524SHoward Hinnant 1150848a5374SHoward Hinnant _LIBCPP_INLINE_VISIBILITY 1151dfdf5085SHoward Hinnant bool __test_for_eof() const 11523e519524SHoward Hinnant { 11533e519524SHoward Hinnant if (__sbuf_ && traits_type::eq_int_type(__sbuf_->sgetc(), traits_type::eof())) 1154527a7fdfSBruce Mitchener __sbuf_ = nullptr; 1155527a7fdfSBruce Mitchener return __sbuf_ == nullptr; 11563e519524SHoward Hinnant } 11573e519524SHoward Hinnantpublic: 1158527a7fdfSBruce Mitchener _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR istreambuf_iterator() _NOEXCEPT : __sbuf_(nullptr) {} 11598e882dcbSHoward Hinnant _LIBCPP_INLINE_VISIBILITY istreambuf_iterator(istream_type& __s) _NOEXCEPT 1160a96d7458SHoward Hinnant : __sbuf_(__s.rdbuf()) {} 11618e882dcbSHoward Hinnant _LIBCPP_INLINE_VISIBILITY istreambuf_iterator(streambuf_type* __s) _NOEXCEPT 1162a96d7458SHoward Hinnant : __sbuf_(__s) {} 11638e882dcbSHoward Hinnant _LIBCPP_INLINE_VISIBILITY istreambuf_iterator(const __proxy& __p) _NOEXCEPT 11643e519524SHoward Hinnant : __sbuf_(__p.__sbuf_) {} 11653e519524SHoward Hinnant 1166c206366fSHoward Hinnant _LIBCPP_INLINE_VISIBILITY char_type operator*() const 1167c206366fSHoward Hinnant {return static_cast<char_type>(__sbuf_->sgetc());} 11683e519524SHoward Hinnant _LIBCPP_INLINE_VISIBILITY istreambuf_iterator& operator++() 11693e519524SHoward Hinnant { 1170dfdf5085SHoward Hinnant __sbuf_->sbumpc(); 11713e519524SHoward Hinnant return *this; 11723e519524SHoward Hinnant } 11733e519524SHoward Hinnant _LIBCPP_INLINE_VISIBILITY __proxy operator++(int) 11743e519524SHoward Hinnant { 1175dfdf5085SHoward Hinnant return __proxy(__sbuf_->sbumpc(), __sbuf_); 11763e519524SHoward Hinnant } 11773e519524SHoward Hinnant 11783e519524SHoward Hinnant _LIBCPP_INLINE_VISIBILITY bool equal(const istreambuf_iterator& __b) const 1179dfdf5085SHoward Hinnant {return __test_for_eof() == __b.__test_for_eof();} 11803e519524SHoward Hinnant}; 11813e519524SHoward Hinnant 11823e519524SHoward Hinnanttemplate <class _CharT, class _Traits> 11833e519524SHoward Hinnantinline _LIBCPP_INLINE_VISIBILITY 11843e519524SHoward Hinnantbool operator==(const istreambuf_iterator<_CharT,_Traits>& __a, 11853e519524SHoward Hinnant const istreambuf_iterator<_CharT,_Traits>& __b) 11863e519524SHoward Hinnant {return __a.equal(__b);} 11873e519524SHoward Hinnant 11883e519524SHoward Hinnanttemplate <class _CharT, class _Traits> 11893e519524SHoward Hinnantinline _LIBCPP_INLINE_VISIBILITY 11903e519524SHoward Hinnantbool operator!=(const istreambuf_iterator<_CharT,_Traits>& __a, 11913e519524SHoward Hinnant const istreambuf_iterator<_CharT,_Traits>& __b) 11923e519524SHoward Hinnant {return !__a.equal(__b);} 11933e519524SHoward Hinnant 11943e519524SHoward Hinnanttemplate <class _CharT, class _Traits> 1195e2f2d1edSEric Fiselierclass _LIBCPP_TEMPLATE_VIS ostreambuf_iterator 11963e519524SHoward Hinnant : public iterator<output_iterator_tag, void, void, void, void> 11973e519524SHoward Hinnant{ 11983e519524SHoward Hinnantpublic: 119971a16e40SLouis Dionne typedef output_iterator_tag iterator_category; 120071a16e40SLouis Dionne typedef void value_type; 120171a16e40SLouis Dionne#if _LIBCPP_STD_VER > 17 120271a16e40SLouis Dionne typedef std::ptrdiff_t difference_type; 120371a16e40SLouis Dionne#else 120471a16e40SLouis Dionne typedef void difference_type; 120571a16e40SLouis Dionne#endif 120671a16e40SLouis Dionne typedef void pointer; 120771a16e40SLouis Dionne typedef void reference; 12083e519524SHoward Hinnant typedef _CharT char_type; 12093e519524SHoward Hinnant typedef _Traits traits_type; 12103e519524SHoward Hinnant typedef basic_streambuf<_CharT, _Traits> streambuf_type; 12113e519524SHoward Hinnant typedef basic_ostream<_CharT, _Traits> ostream_type; 121271a16e40SLouis Dionne 12133e519524SHoward Hinnantprivate: 12143e519524SHoward Hinnant streambuf_type* __sbuf_; 12153e519524SHoward Hinnantpublic: 12168e882dcbSHoward Hinnant _LIBCPP_INLINE_VISIBILITY ostreambuf_iterator(ostream_type& __s) _NOEXCEPT 12173e519524SHoward Hinnant : __sbuf_(__s.rdbuf()) {} 12188e882dcbSHoward Hinnant _LIBCPP_INLINE_VISIBILITY ostreambuf_iterator(streambuf_type* __s) _NOEXCEPT 12193e519524SHoward Hinnant : __sbuf_(__s) {} 12203e519524SHoward Hinnant _LIBCPP_INLINE_VISIBILITY ostreambuf_iterator& operator=(_CharT __c) 12213e519524SHoward Hinnant { 12223e519524SHoward Hinnant if (__sbuf_ && traits_type::eq_int_type(__sbuf_->sputc(__c), traits_type::eof())) 1223527a7fdfSBruce Mitchener __sbuf_ = nullptr; 12243e519524SHoward Hinnant return *this; 12253e519524SHoward Hinnant } 12263e519524SHoward Hinnant _LIBCPP_INLINE_VISIBILITY ostreambuf_iterator& operator*() {return *this;} 12273e519524SHoward Hinnant _LIBCPP_INLINE_VISIBILITY ostreambuf_iterator& operator++() {return *this;} 12283e519524SHoward Hinnant _LIBCPP_INLINE_VISIBILITY ostreambuf_iterator& operator++(int) {return *this;} 1229527a7fdfSBruce Mitchener _LIBCPP_INLINE_VISIBILITY bool failed() const _NOEXCEPT {return __sbuf_ == nullptr;} 123092b5940fSHoward Hinnant 123192b5940fSHoward Hinnant template <class _Ch, class _Tr> 123292b5940fSHoward Hinnant friend 123392b5940fSHoward Hinnant _LIBCPP_HIDDEN 123492b5940fSHoward Hinnant ostreambuf_iterator<_Ch, _Tr> 123592b5940fSHoward Hinnant __pad_and_output(ostreambuf_iterator<_Ch, _Tr> __s, 123692b5940fSHoward Hinnant const _Ch* __ob, const _Ch* __op, const _Ch* __oe, 123792b5940fSHoward Hinnant ios_base& __iob, _Ch __fl); 12383e519524SHoward Hinnant}; 12393e519524SHoward Hinnant 12403e519524SHoward Hinnanttemplate <class _Iter> 1241e2f2d1edSEric Fiselierclass _LIBCPP_TEMPLATE_VIS move_iterator 12423e519524SHoward Hinnant{ 12433e519524SHoward Hinnantprivate: 12443e519524SHoward Hinnant _Iter __i; 12453e519524SHoward Hinnantpublic: 12463e519524SHoward Hinnant typedef _Iter iterator_type; 12473e519524SHoward Hinnant typedef typename iterator_traits<iterator_type>::value_type value_type; 12483e519524SHoward Hinnant typedef typename iterator_traits<iterator_type>::difference_type difference_type; 124905333fc8SMarshall Clow typedef iterator_type pointer; 1250d41c6d51SArthur O'Dwyer typedef _If<__is_cpp17_random_access_iterator<_Iter>::value, 1251d41c6d51SArthur O'Dwyer random_access_iterator_tag, 1252d41c6d51SArthur O'Dwyer typename iterator_traits<_Iter>::iterator_category> iterator_category; 1253d41c6d51SArthur O'Dwyer#if _LIBCPP_STD_VER > 17 1254d41c6d51SArthur O'Dwyer typedef input_iterator_tag iterator_concept; 1255d41c6d51SArthur O'Dwyer#endif 1256d41c6d51SArthur O'Dwyer 1257046492b9SEric Fiselier#ifndef _LIBCPP_CXX03_LANG 1258906c5085SEric Fiselier typedef typename iterator_traits<iterator_type>::reference __reference; 1259906c5085SEric Fiselier typedef typename conditional< 1260906c5085SEric Fiselier is_reference<__reference>::value, 1261906c5085SEric Fiselier typename remove_reference<__reference>::type&&, 1262906c5085SEric Fiselier __reference 1263906c5085SEric Fiselier >::type reference; 12643e519524SHoward Hinnant#else 12653e519524SHoward Hinnant typedef typename iterator_traits<iterator_type>::reference reference; 12663e519524SHoward Hinnant#endif 12673e519524SHoward Hinnant 1268720ef472SMarshall Clow _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 1269720ef472SMarshall Clow move_iterator() : __i() {} 1270720ef472SMarshall Clow _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 1271720ef472SMarshall Clow explicit move_iterator(_Iter __x) : __i(__x) {} 1272720ef472SMarshall Clow template <class _Up> 1273720ef472SMarshall Clow _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 1274720ef472SMarshall Clow move_iterator(const move_iterator<_Up>& __u) : __i(__u.base()) {} 1275720ef472SMarshall Clow _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 _Iter base() const {return __i;} 1276720ef472SMarshall Clow _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 1277720ef472SMarshall Clow reference operator*() const { return static_cast<reference>(*__i); } 1278720ef472SMarshall Clow _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 1279720ef472SMarshall Clow pointer operator->() const { return __i;} 1280720ef472SMarshall Clow _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 1281720ef472SMarshall Clow move_iterator& operator++() {++__i; return *this;} 1282720ef472SMarshall Clow _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 1283720ef472SMarshall Clow move_iterator operator++(int) {move_iterator __tmp(*this); ++__i; return __tmp;} 1284720ef472SMarshall Clow _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 1285720ef472SMarshall Clow move_iterator& operator--() {--__i; return *this;} 1286720ef472SMarshall Clow _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 1287720ef472SMarshall Clow move_iterator operator--(int) {move_iterator __tmp(*this); --__i; return __tmp;} 1288720ef472SMarshall Clow _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 1289720ef472SMarshall Clow move_iterator operator+ (difference_type __n) const {return move_iterator(__i + __n);} 1290720ef472SMarshall Clow _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 1291720ef472SMarshall Clow move_iterator& operator+=(difference_type __n) {__i += __n; return *this;} 1292720ef472SMarshall Clow _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 1293720ef472SMarshall Clow move_iterator operator- (difference_type __n) const {return move_iterator(__i - __n);} 1294720ef472SMarshall Clow _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 1295720ef472SMarshall Clow move_iterator& operator-=(difference_type __n) {__i -= __n; return *this;} 1296720ef472SMarshall Clow _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 1297720ef472SMarshall Clow reference operator[](difference_type __n) const { return static_cast<reference>(__i[__n]); } 12983e519524SHoward Hinnant}; 12993e519524SHoward Hinnant 13003e519524SHoward Hinnanttemplate <class _Iter1, class _Iter2> 1301720ef472SMarshall Clowinline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 13023e519524SHoward Hinnantbool 13033e519524SHoward Hinnantoperator==(const move_iterator<_Iter1>& __x, const move_iterator<_Iter2>& __y) 13043e519524SHoward Hinnant{ 13053e519524SHoward Hinnant return __x.base() == __y.base(); 13063e519524SHoward Hinnant} 13073e519524SHoward Hinnant 13083e519524SHoward Hinnanttemplate <class _Iter1, class _Iter2> 1309720ef472SMarshall Clowinline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 13103e519524SHoward Hinnantbool 13113e519524SHoward Hinnantoperator<(const move_iterator<_Iter1>& __x, const move_iterator<_Iter2>& __y) 13123e519524SHoward Hinnant{ 13133e519524SHoward Hinnant return __x.base() < __y.base(); 13143e519524SHoward Hinnant} 13153e519524SHoward Hinnant 13163e519524SHoward Hinnanttemplate <class _Iter1, class _Iter2> 1317720ef472SMarshall Clowinline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 13183e519524SHoward Hinnantbool 13193e519524SHoward Hinnantoperator!=(const move_iterator<_Iter1>& __x, const move_iterator<_Iter2>& __y) 13203e519524SHoward Hinnant{ 13213e519524SHoward Hinnant return __x.base() != __y.base(); 13223e519524SHoward Hinnant} 13233e519524SHoward Hinnant 13243e519524SHoward Hinnanttemplate <class _Iter1, class _Iter2> 1325720ef472SMarshall Clowinline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 13263e519524SHoward Hinnantbool 13273e519524SHoward Hinnantoperator>(const move_iterator<_Iter1>& __x, const move_iterator<_Iter2>& __y) 13283e519524SHoward Hinnant{ 13293e519524SHoward Hinnant return __x.base() > __y.base(); 13303e519524SHoward Hinnant} 13313e519524SHoward Hinnant 13323e519524SHoward Hinnanttemplate <class _Iter1, class _Iter2> 1333720ef472SMarshall Clowinline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 13343e519524SHoward Hinnantbool 13353e519524SHoward Hinnantoperator>=(const move_iterator<_Iter1>& __x, const move_iterator<_Iter2>& __y) 13363e519524SHoward Hinnant{ 13373e519524SHoward Hinnant return __x.base() >= __y.base(); 13383e519524SHoward Hinnant} 13393e519524SHoward Hinnant 13403e519524SHoward Hinnanttemplate <class _Iter1, class _Iter2> 1341720ef472SMarshall Clowinline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 13423e519524SHoward Hinnantbool 13433e519524SHoward Hinnantoperator<=(const move_iterator<_Iter1>& __x, const move_iterator<_Iter2>& __y) 13443e519524SHoward Hinnant{ 13453e519524SHoward Hinnant return __x.base() <= __y.base(); 13463e519524SHoward Hinnant} 13473e519524SHoward Hinnant 13482ee83725SMarshall Clow#ifndef _LIBCPP_CXX03_LANG 1349947ce6b5SMarshall Clowtemplate <class _Iter1, class _Iter2> 1350720ef472SMarshall Clowinline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 1351947ce6b5SMarshall Clowauto 1352947ce6b5SMarshall Clowoperator-(const move_iterator<_Iter1>& __x, const move_iterator<_Iter2>& __y) 1353947ce6b5SMarshall Clow-> decltype(__x.base() - __y.base()) 1354947ce6b5SMarshall Clow{ 1355947ce6b5SMarshall Clow return __x.base() - __y.base(); 1356947ce6b5SMarshall Clow} 1357947ce6b5SMarshall Clow#else 13583e519524SHoward Hinnanttemplate <class _Iter1, class _Iter2> 13593e519524SHoward Hinnantinline _LIBCPP_INLINE_VISIBILITY 13603e519524SHoward Hinnanttypename move_iterator<_Iter1>::difference_type 13613e519524SHoward Hinnantoperator-(const move_iterator<_Iter1>& __x, const move_iterator<_Iter2>& __y) 13623e519524SHoward Hinnant{ 13633e519524SHoward Hinnant return __x.base() - __y.base(); 13643e519524SHoward Hinnant} 1365947ce6b5SMarshall Clow#endif 13663e519524SHoward Hinnant 13673e519524SHoward Hinnanttemplate <class _Iter> 1368720ef472SMarshall Clowinline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 13693e519524SHoward Hinnantmove_iterator<_Iter> 13703e519524SHoward Hinnantoperator+(typename move_iterator<_Iter>::difference_type __n, const move_iterator<_Iter>& __x) 13713e519524SHoward Hinnant{ 13723e519524SHoward Hinnant return move_iterator<_Iter>(__x.base() + __n); 13733e519524SHoward Hinnant} 13743e519524SHoward Hinnant 13753e519524SHoward Hinnanttemplate <class _Iter> 1376720ef472SMarshall Clowinline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 13773e519524SHoward Hinnantmove_iterator<_Iter> 137854c83368SMarshall Clowmake_move_iterator(_Iter __i) 13793e519524SHoward Hinnant{ 13803e519524SHoward Hinnant return move_iterator<_Iter>(__i); 13813e519524SHoward Hinnant} 13823e519524SHoward Hinnant 13833e519524SHoward Hinnant// __wrap_iter 13843e519524SHoward Hinnant 13853e519524SHoward Hinnanttemplate <class _Iter> class __wrap_iter; 13863e519524SHoward Hinnant 13873e519524SHoward Hinnanttemplate <class _Iter1, class _Iter2> 13889cad5025SMarshall Clow_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG 13893e519524SHoward Hinnantbool 139061b302f9SEric Fiselieroperator==(const __wrap_iter<_Iter1>&, const __wrap_iter<_Iter2>&) _NOEXCEPT; 13913e519524SHoward Hinnant 13923e519524SHoward Hinnanttemplate <class _Iter1, class _Iter2> 13939cad5025SMarshall Clow_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG 13943e519524SHoward Hinnantbool 139561b302f9SEric Fiselieroperator<(const __wrap_iter<_Iter1>&, const __wrap_iter<_Iter2>&) _NOEXCEPT; 13963e519524SHoward Hinnant 13973e519524SHoward Hinnanttemplate <class _Iter1, class _Iter2> 13989cad5025SMarshall Clow_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG 13993e519524SHoward Hinnantbool 140061b302f9SEric Fiselieroperator!=(const __wrap_iter<_Iter1>&, const __wrap_iter<_Iter2>&) _NOEXCEPT; 14013e519524SHoward Hinnant 14023e519524SHoward Hinnanttemplate <class _Iter1, class _Iter2> 14039cad5025SMarshall Clow_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG 14043e519524SHoward Hinnantbool 140561b302f9SEric Fiselieroperator>(const __wrap_iter<_Iter1>&, const __wrap_iter<_Iter2>&) _NOEXCEPT; 14063e519524SHoward Hinnant 14073e519524SHoward Hinnanttemplate <class _Iter1, class _Iter2> 14089cad5025SMarshall Clow_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG 14093e519524SHoward Hinnantbool 141061b302f9SEric Fiselieroperator>=(const __wrap_iter<_Iter1>&, const __wrap_iter<_Iter2>&) _NOEXCEPT; 14113e519524SHoward Hinnant 14123e519524SHoward Hinnanttemplate <class _Iter1, class _Iter2> 14139cad5025SMarshall Clow_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG 14143e519524SHoward Hinnantbool 141561b302f9SEric Fiselieroperator<=(const __wrap_iter<_Iter1>&, const __wrap_iter<_Iter2>&) _NOEXCEPT; 14163e519524SHoward Hinnant 14172ee83725SMarshall Clow#ifndef _LIBCPP_CXX03_LANG 1418947ce6b5SMarshall Clowtemplate <class _Iter1, class _Iter2> 14199cad5025SMarshall Clow_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG 1420947ce6b5SMarshall Clowauto 142161b302f9SEric Fiselieroperator-(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter2>& __y) _NOEXCEPT 1422947ce6b5SMarshall Clow-> decltype(__x.base() - __y.base()); 1423947ce6b5SMarshall Clow#else 14243e519524SHoward Hinnanttemplate <class _Iter1, class _Iter2> 1425aeb85680SHoward Hinnant_LIBCPP_INLINE_VISIBILITY 14263e519524SHoward Hinnanttypename __wrap_iter<_Iter1>::difference_type 142761b302f9SEric Fiselieroperator-(const __wrap_iter<_Iter1>&, const __wrap_iter<_Iter2>&) _NOEXCEPT; 1428947ce6b5SMarshall Clow#endif 14293e519524SHoward Hinnant 14303e519524SHoward Hinnanttemplate <class _Iter> 14319cad5025SMarshall Clow_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG 14323e519524SHoward Hinnant__wrap_iter<_Iter> 143361b302f9SEric Fiselieroperator+(typename __wrap_iter<_Iter>::difference_type, __wrap_iter<_Iter>) _NOEXCEPT; 14343e519524SHoward Hinnant 143513c90a57SLouis Dionnetemplate <class _Ip, class _Op> _Op _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 copy(_Ip, _Ip, _Op); 143613c90a57SLouis Dionnetemplate <class _B1, class _B2> _B2 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 copy_backward(_B1, _B1, _B2); 14373ed89b51Szoecarvertemplate <class _Ip, class _Op> _Op _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 move(_Ip, _Ip, _Op); 14383ed89b51Szoecarvertemplate <class _B1, class _B2> _B2 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 move_backward(_B1, _B1, _B2); 14393e519524SHoward Hinnant 14403e519524SHoward Hinnanttemplate <class _Iter> 14413e519524SHoward Hinnantclass __wrap_iter 14423e519524SHoward Hinnant{ 14433e519524SHoward Hinnantpublic: 14443e519524SHoward Hinnant typedef _Iter iterator_type; 14453e519524SHoward Hinnant typedef typename iterator_traits<iterator_type>::value_type value_type; 14463e519524SHoward Hinnant typedef typename iterator_traits<iterator_type>::difference_type difference_type; 14473e519524SHoward Hinnant typedef typename iterator_traits<iterator_type>::pointer pointer; 14483e519524SHoward Hinnant typedef typename iterator_traits<iterator_type>::reference reference; 1449d41c6d51SArthur O'Dwyer typedef typename iterator_traits<iterator_type>::iterator_category iterator_category; 1450d41c6d51SArthur O'Dwyer#if _LIBCPP_STD_VER > 17 1451d41c6d51SArthur O'Dwyer typedef _If<__is_cpp17_contiguous_iterator<_Iter>::value, 1452d41c6d51SArthur O'Dwyer contiguous_iterator_tag, iterator_category> iterator_concept; 1453d41c6d51SArthur O'Dwyer#endif 1454d41c6d51SArthur O'Dwyer 14553e519524SHoward Hinnantprivate: 14563e519524SHoward Hinnant iterator_type __i; 14573e519524SHoward Hinnantpublic: 145861b302f9SEric Fiselier _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG __wrap_iter() _NOEXCEPT 145907186a7dSMarshall Clow#if _LIBCPP_STD_VER > 11 146007186a7dSMarshall Clow : __i{} 146107186a7dSMarshall Clow#endif 1462c36bfc49SHoward Hinnant { 146331e82037SLouis Dionne#if _LIBCPP_DEBUG_LEVEL == 2 1464c36bfc49SHoward Hinnant __get_db()->__insert_i(this); 1465c36bfc49SHoward Hinnant#endif 1466c36bfc49SHoward Hinnant } 14679cad5025SMarshall Clow template <class _Up> _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG 14689cad5025SMarshall Clow __wrap_iter(const __wrap_iter<_Up>& __u, 1469527a7fdfSBruce Mitchener typename enable_if<is_convertible<_Up, iterator_type>::value>::type* = nullptr) _NOEXCEPT 1470f554add5SHoward Hinnant : __i(__u.base()) 1471f554add5SHoward Hinnant { 147231e82037SLouis Dionne#if _LIBCPP_DEBUG_LEVEL == 2 1473f554add5SHoward Hinnant __get_db()->__iterator_copy(this, &__u); 1474f554add5SHoward Hinnant#endif 1475f554add5SHoward Hinnant } 147631e82037SLouis Dionne#if _LIBCPP_DEBUG_LEVEL == 2 14779cad5025SMarshall Clow _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG 1478f554add5SHoward Hinnant __wrap_iter(const __wrap_iter& __x) 1479f554add5SHoward Hinnant : __i(__x.base()) 1480f554add5SHoward Hinnant { 1481f554add5SHoward Hinnant __get_db()->__iterator_copy(this, &__x); 1482f554add5SHoward Hinnant } 14839cad5025SMarshall Clow _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG 1484f554add5SHoward Hinnant __wrap_iter& operator=(const __wrap_iter& __x) 1485f554add5SHoward Hinnant { 1486f554add5SHoward Hinnant if (this != &__x) 1487f554add5SHoward Hinnant { 1488f554add5SHoward Hinnant __get_db()->__iterator_copy(this, &__x); 1489f554add5SHoward Hinnant __i = __x.__i; 1490f554add5SHoward Hinnant } 1491f554add5SHoward Hinnant return *this; 1492f554add5SHoward Hinnant } 14939cad5025SMarshall Clow _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG 1494f554add5SHoward Hinnant ~__wrap_iter() 1495f554add5SHoward Hinnant { 1496f554add5SHoward Hinnant __get_db()->__erase_i(this); 1497f554add5SHoward Hinnant } 1498f554add5SHoward Hinnant#endif 149961b302f9SEric Fiselier _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG reference operator*() const _NOEXCEPT 1500f554add5SHoward Hinnant { 150131e82037SLouis Dionne#if _LIBCPP_DEBUG_LEVEL == 2 1502f554add5SHoward Hinnant _LIBCPP_ASSERT(__get_const_db()->__dereferenceable(this), 1503f554add5SHoward Hinnant "Attempted to dereference a non-dereferenceable iterator"); 1504cec9af9eSHoward Hinnant#endif 1505f554add5SHoward Hinnant return *__i; 1506f554add5SHoward Hinnant } 150761b302f9SEric Fiselier _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG pointer operator->() const _NOEXCEPT 15083ec1f00bSHoward Hinnant { 150931e82037SLouis Dionne#if _LIBCPP_DEBUG_LEVEL == 2 15103ec1f00bSHoward Hinnant _LIBCPP_ASSERT(__get_const_db()->__dereferenceable(this), 15113ec1f00bSHoward Hinnant "Attempted to dereference a non-dereferenceable iterator"); 15123ec1f00bSHoward Hinnant#endif 151305333fc8SMarshall Clow return (pointer)_VSTD::addressof(*__i); 15143ec1f00bSHoward Hinnant } 151561b302f9SEric Fiselier _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG __wrap_iter& operator++() _NOEXCEPT 1516f554add5SHoward Hinnant { 151731e82037SLouis Dionne#if _LIBCPP_DEBUG_LEVEL == 2 1518f554add5SHoward Hinnant _LIBCPP_ASSERT(__get_const_db()->__dereferenceable(this), 1519f554add5SHoward Hinnant "Attempted to increment non-incrementable iterator"); 1520cec9af9eSHoward Hinnant#endif 1521f554add5SHoward Hinnant ++__i; 1522f554add5SHoward Hinnant return *this; 1523f554add5SHoward Hinnant } 152461b302f9SEric Fiselier _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG __wrap_iter operator++(int) _NOEXCEPT 1525f554add5SHoward Hinnant {__wrap_iter __tmp(*this); ++(*this); return __tmp;} 15264ce0a916SMarshall Clow 152761b302f9SEric Fiselier _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG __wrap_iter& operator--() _NOEXCEPT 1528f554add5SHoward Hinnant { 152931e82037SLouis Dionne#if _LIBCPP_DEBUG_LEVEL == 2 1530f554add5SHoward Hinnant _LIBCPP_ASSERT(__get_const_db()->__decrementable(this), 1531f554add5SHoward Hinnant "Attempted to decrement non-decrementable iterator"); 1532cec9af9eSHoward Hinnant#endif 1533f554add5SHoward Hinnant --__i; 1534f554add5SHoward Hinnant return *this; 1535f554add5SHoward Hinnant } 153661b302f9SEric Fiselier _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG __wrap_iter operator--(int) _NOEXCEPT 1537f554add5SHoward Hinnant {__wrap_iter __tmp(*this); --(*this); return __tmp;} 153861b302f9SEric Fiselier _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG __wrap_iter operator+ (difference_type __n) const _NOEXCEPT 1539f554add5SHoward Hinnant {__wrap_iter __w(*this); __w += __n; return __w;} 154061b302f9SEric Fiselier _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG __wrap_iter& operator+=(difference_type __n) _NOEXCEPT 1541f554add5SHoward Hinnant { 154231e82037SLouis Dionne#if _LIBCPP_DEBUG_LEVEL == 2 1543f554add5SHoward Hinnant _LIBCPP_ASSERT(__get_const_db()->__addable(this, __n), 1544f554add5SHoward Hinnant "Attempted to add/subtract iterator outside of valid range"); 1545cec9af9eSHoward Hinnant#endif 1546f554add5SHoward Hinnant __i += __n; 1547f554add5SHoward Hinnant return *this; 1548f554add5SHoward Hinnant } 154961b302f9SEric Fiselier _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG __wrap_iter operator- (difference_type __n) const _NOEXCEPT 1550f554add5SHoward Hinnant {return *this + (-__n);} 155161b302f9SEric Fiselier _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG __wrap_iter& operator-=(difference_type __n) _NOEXCEPT 1552f554add5SHoward Hinnant {*this += -__n; return *this;} 155361b302f9SEric Fiselier _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG reference operator[](difference_type __n) const _NOEXCEPT 1554f554add5SHoward Hinnant { 155531e82037SLouis Dionne#if _LIBCPP_DEBUG_LEVEL == 2 1556f554add5SHoward Hinnant _LIBCPP_ASSERT(__get_const_db()->__subscriptable(this, __n), 1557f554add5SHoward Hinnant "Attempted to subscript iterator outside of valid range"); 1558cec9af9eSHoward Hinnant#endif 1559f554add5SHoward Hinnant return __i[__n]; 1560f554add5SHoward Hinnant } 15613e519524SHoward Hinnant 156261b302f9SEric Fiselier _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG iterator_type base() const _NOEXCEPT {return __i;} 15633e519524SHoward Hinnant 15643e519524SHoward Hinnantprivate: 156531e82037SLouis Dionne#if _LIBCPP_DEBUG_LEVEL == 2 15669cad5025SMarshall Clow _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG __wrap_iter(const void* __p, iterator_type __x) : __i(__x) 1567f554add5SHoward Hinnant { 1568f554add5SHoward Hinnant __get_db()->__insert_ic(this, __p); 1569f554add5SHoward Hinnant } 1570fc88dbd2SHoward Hinnant#else 157161b302f9SEric Fiselier _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG __wrap_iter(iterator_type __x) _NOEXCEPT : __i(__x) {} 1572f554add5SHoward Hinnant#endif 15733e519524SHoward Hinnant 15743e519524SHoward Hinnant template <class _Up> friend class __wrap_iter; 15753e519524SHoward Hinnant template <class _CharT, class _Traits, class _Alloc> friend class basic_string; 1576e2f2d1edSEric Fiselier template <class _Tp, class _Alloc> friend class _LIBCPP_TEMPLATE_VIS vector; 15777ad06a93SMarshall Clow template <class _Tp, size_t> friend class _LIBCPP_TEMPLATE_VIS span; 15783e519524SHoward Hinnant 15793e519524SHoward Hinnant template <class _Iter1, class _Iter2> 15809cad5025SMarshall Clow _LIBCPP_CONSTEXPR_IF_NODEBUG friend 15813e519524SHoward Hinnant bool 158261b302f9SEric Fiselier operator==(const __wrap_iter<_Iter1>&, const __wrap_iter<_Iter2>&) _NOEXCEPT; 15833e519524SHoward Hinnant 15843e519524SHoward Hinnant template <class _Iter1, class _Iter2> 15859cad5025SMarshall Clow _LIBCPP_CONSTEXPR_IF_NODEBUG friend 15863e519524SHoward Hinnant bool 158761b302f9SEric Fiselier operator<(const __wrap_iter<_Iter1>&, const __wrap_iter<_Iter2>&) _NOEXCEPT; 15883e519524SHoward Hinnant 15893e519524SHoward Hinnant template <class _Iter1, class _Iter2> 15909cad5025SMarshall Clow _LIBCPP_CONSTEXPR_IF_NODEBUG friend 15913e519524SHoward Hinnant bool 159261b302f9SEric Fiselier operator!=(const __wrap_iter<_Iter1>&, const __wrap_iter<_Iter2>&) _NOEXCEPT; 15933e519524SHoward Hinnant 15943e519524SHoward Hinnant template <class _Iter1, class _Iter2> 15959cad5025SMarshall Clow _LIBCPP_CONSTEXPR_IF_NODEBUG friend 15963e519524SHoward Hinnant bool 159761b302f9SEric Fiselier operator>(const __wrap_iter<_Iter1>&, const __wrap_iter<_Iter2>&) _NOEXCEPT; 15983e519524SHoward Hinnant 15993e519524SHoward Hinnant template <class _Iter1, class _Iter2> 16009cad5025SMarshall Clow _LIBCPP_CONSTEXPR_IF_NODEBUG friend 16013e519524SHoward Hinnant bool 160261b302f9SEric Fiselier operator>=(const __wrap_iter<_Iter1>&, const __wrap_iter<_Iter2>&) _NOEXCEPT; 16033e519524SHoward Hinnant 16043e519524SHoward Hinnant template <class _Iter1, class _Iter2> 16059cad5025SMarshall Clow _LIBCPP_CONSTEXPR_IF_NODEBUG friend 16063e519524SHoward Hinnant bool 160761b302f9SEric Fiselier operator<=(const __wrap_iter<_Iter1>&, const __wrap_iter<_Iter2>&) _NOEXCEPT; 16083e519524SHoward Hinnant 16092ee83725SMarshall Clow#ifndef _LIBCPP_CXX03_LANG 1610947ce6b5SMarshall Clow template <class _Iter1, class _Iter2> 16119cad5025SMarshall Clow _LIBCPP_CONSTEXPR_IF_NODEBUG friend 1612947ce6b5SMarshall Clow auto 161361b302f9SEric Fiselier operator-(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter2>& __y) _NOEXCEPT 1614947ce6b5SMarshall Clow -> decltype(__x.base() - __y.base()); 1615947ce6b5SMarshall Clow#else 16163e519524SHoward Hinnant template <class _Iter1, class _Iter2> 16179cad5025SMarshall Clow _LIBCPP_CONSTEXPR_IF_NODEBUG friend 16183e519524SHoward Hinnant typename __wrap_iter<_Iter1>::difference_type 161961b302f9SEric Fiselier operator-(const __wrap_iter<_Iter1>&, const __wrap_iter<_Iter2>&) _NOEXCEPT; 1620947ce6b5SMarshall Clow#endif 16213e519524SHoward Hinnant 16223e519524SHoward Hinnant template <class _Iter1> 16239cad5025SMarshall Clow _LIBCPP_CONSTEXPR_IF_NODEBUG friend 16243e519524SHoward Hinnant __wrap_iter<_Iter1> 162561b302f9SEric Fiselier operator+(typename __wrap_iter<_Iter1>::difference_type, __wrap_iter<_Iter1>) _NOEXCEPT; 16263e519524SHoward Hinnant 162713c90a57SLouis Dionne template <class _Ip, class _Op> friend _LIBCPP_CONSTEXPR_AFTER_CXX17 _Op copy(_Ip, _Ip, _Op); 162813c90a57SLouis Dionne template <class _B1, class _B2> friend _LIBCPP_CONSTEXPR_AFTER_CXX17 _B2 copy_backward(_B1, _B1, _B2); 16293ed89b51Szoecarver template <class _Ip, class _Op> friend _LIBCPP_CONSTEXPR_AFTER_CXX17 _Op move(_Ip, _Ip, _Op); 16303ed89b51Szoecarver template <class _B1, class _B2> friend _LIBCPP_CONSTEXPR_AFTER_CXX17 _B2 move_backward(_B1, _B1, _B2); 16313e519524SHoward Hinnant}; 16323e519524SHoward Hinnant 1633d41c6d51SArthur O'Dwyer#if _LIBCPP_STD_VER <= 17 1634d41c6d51SArthur O'Dwyertemplate <class _It> 1635d41c6d51SArthur O'Dwyerstruct __is_cpp17_contiguous_iterator<__wrap_iter<_It> > : __is_cpp17_contiguous_iterator<_It> {}; 1636d41c6d51SArthur O'Dwyer#endif 1637d41c6d51SArthur O'Dwyer 1638d41c6d51SArthur O'Dwyertemplate <class _Iter> 1639d41c6d51SArthur O'Dwyer_LIBCPP_CONSTEXPR 1640d41c6d51SArthur O'Dwyer_EnableIf<__is_cpp17_contiguous_iterator<_Iter>::value, decltype(_VSTD::__to_address(declval<_Iter>()))> 1641d41c6d51SArthur O'Dwyer__to_address(__wrap_iter<_Iter> __w) _NOEXCEPT { 1642d41c6d51SArthur O'Dwyer return _VSTD::__to_address(__w.base()); 1643d41c6d51SArthur O'Dwyer} 1644d41c6d51SArthur O'Dwyer 16453e519524SHoward Hinnanttemplate <class _Iter1, class _Iter2> 16469cad5025SMarshall Clowinline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG 16473e519524SHoward Hinnantbool 164861b302f9SEric Fiselieroperator==(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter2>& __y) _NOEXCEPT 16493e519524SHoward Hinnant{ 16503e519524SHoward Hinnant return __x.base() == __y.base(); 16513e519524SHoward Hinnant} 16523e519524SHoward Hinnant 16533e519524SHoward Hinnanttemplate <class _Iter1, class _Iter2> 16549cad5025SMarshall Clowinline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG 16553e519524SHoward Hinnantbool 165661b302f9SEric Fiselieroperator<(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter2>& __y) _NOEXCEPT 16573e519524SHoward Hinnant{ 165831e82037SLouis Dionne#if _LIBCPP_DEBUG_LEVEL == 2 165942a3046eSHoward Hinnant _LIBCPP_ASSERT(__get_const_db()->__less_than_comparable(&__x, &__y), 1660f554add5SHoward Hinnant "Attempted to compare incomparable iterators"); 1661cec9af9eSHoward Hinnant#endif 16623e519524SHoward Hinnant return __x.base() < __y.base(); 16633e519524SHoward Hinnant} 16643e519524SHoward Hinnant 16653e519524SHoward Hinnanttemplate <class _Iter1, class _Iter2> 16669cad5025SMarshall Clowinline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG 16673e519524SHoward Hinnantbool 166861b302f9SEric Fiselieroperator!=(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter2>& __y) _NOEXCEPT 16693e519524SHoward Hinnant{ 1670f554add5SHoward Hinnant return !(__x == __y); 16713e519524SHoward Hinnant} 16723e519524SHoward Hinnant 16733e519524SHoward Hinnanttemplate <class _Iter1, class _Iter2> 16749cad5025SMarshall Clowinline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG 16753e519524SHoward Hinnantbool 167661b302f9SEric Fiselieroperator>(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter2>& __y) _NOEXCEPT 16773e519524SHoward Hinnant{ 1678f554add5SHoward Hinnant return __y < __x; 16793e519524SHoward Hinnant} 16803e519524SHoward Hinnant 16813e519524SHoward Hinnanttemplate <class _Iter1, class _Iter2> 16829cad5025SMarshall Clowinline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG 16833e519524SHoward Hinnantbool 168461b302f9SEric Fiselieroperator>=(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter2>& __y) _NOEXCEPT 16853e519524SHoward Hinnant{ 1686f554add5SHoward Hinnant return !(__x < __y); 16873e519524SHoward Hinnant} 16883e519524SHoward Hinnant 16893e519524SHoward Hinnanttemplate <class _Iter1, class _Iter2> 16909cad5025SMarshall Clowinline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG 16913e519524SHoward Hinnantbool 169261b302f9SEric Fiselieroperator<=(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter2>& __y) _NOEXCEPT 16933e519524SHoward Hinnant{ 1694f554add5SHoward Hinnant return !(__y < __x); 16953e519524SHoward Hinnant} 16963e519524SHoward Hinnant 16976e551ae1SHoward Hinnanttemplate <class _Iter1> 16989cad5025SMarshall Clowinline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG 16996e551ae1SHoward Hinnantbool 170061b302f9SEric Fiselieroperator!=(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter1>& __y) _NOEXCEPT 17016e551ae1SHoward Hinnant{ 17026e551ae1SHoward Hinnant return !(__x == __y); 17036e551ae1SHoward Hinnant} 17046e551ae1SHoward Hinnant 17056e551ae1SHoward Hinnanttemplate <class _Iter1> 17069cad5025SMarshall Clowinline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG 17076e551ae1SHoward Hinnantbool 170861b302f9SEric Fiselieroperator>(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter1>& __y) _NOEXCEPT 17096e551ae1SHoward Hinnant{ 17106e551ae1SHoward Hinnant return __y < __x; 17116e551ae1SHoward Hinnant} 17126e551ae1SHoward Hinnant 17136e551ae1SHoward Hinnanttemplate <class _Iter1> 17149cad5025SMarshall Clowinline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG 17156e551ae1SHoward Hinnantbool 171661b302f9SEric Fiselieroperator>=(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter1>& __y) _NOEXCEPT 17176e551ae1SHoward Hinnant{ 17186e551ae1SHoward Hinnant return !(__x < __y); 17196e551ae1SHoward Hinnant} 17206e551ae1SHoward Hinnant 17216e551ae1SHoward Hinnanttemplate <class _Iter1> 17229cad5025SMarshall Clowinline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG 17236e551ae1SHoward Hinnantbool 172461b302f9SEric Fiselieroperator<=(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter1>& __y) _NOEXCEPT 17256e551ae1SHoward Hinnant{ 17266e551ae1SHoward Hinnant return !(__y < __x); 17276e551ae1SHoward Hinnant} 17286e551ae1SHoward Hinnant 17292ee83725SMarshall Clow#ifndef _LIBCPP_CXX03_LANG 1730947ce6b5SMarshall Clowtemplate <class _Iter1, class _Iter2> 17319cad5025SMarshall Clowinline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG 1732947ce6b5SMarshall Clowauto 173361b302f9SEric Fiselieroperator-(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter2>& __y) _NOEXCEPT 1734947ce6b5SMarshall Clow-> decltype(__x.base() - __y.base()) 1735947ce6b5SMarshall Clow{ 173631e82037SLouis Dionne#if _LIBCPP_DEBUG_LEVEL == 2 1737947ce6b5SMarshall Clow _LIBCPP_ASSERT(__get_const_db()->__less_than_comparable(&__x, &__y), 1738947ce6b5SMarshall Clow "Attempted to subtract incompatible iterators"); 1739947ce6b5SMarshall Clow#endif 1740947ce6b5SMarshall Clow return __x.base() - __y.base(); 1741947ce6b5SMarshall Clow} 1742947ce6b5SMarshall Clow#else 17433e519524SHoward Hinnanttemplate <class _Iter1, class _Iter2> 17449cad5025SMarshall Clowinline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG 17453e519524SHoward Hinnanttypename __wrap_iter<_Iter1>::difference_type 174661b302f9SEric Fiselieroperator-(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter2>& __y) _NOEXCEPT 17473e519524SHoward Hinnant{ 174831e82037SLouis Dionne#if _LIBCPP_DEBUG_LEVEL == 2 174942a3046eSHoward Hinnant _LIBCPP_ASSERT(__get_const_db()->__less_than_comparable(&__x, &__y), 1750f554add5SHoward Hinnant "Attempted to subtract incompatible iterators"); 1751cec9af9eSHoward Hinnant#endif 17523e519524SHoward Hinnant return __x.base() - __y.base(); 17533e519524SHoward Hinnant} 1754947ce6b5SMarshall Clow#endif 17553e519524SHoward Hinnant 17563e519524SHoward Hinnanttemplate <class _Iter> 17579cad5025SMarshall Clowinline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG 17583e519524SHoward Hinnant__wrap_iter<_Iter> 17593e519524SHoward Hinnantoperator+(typename __wrap_iter<_Iter>::difference_type __n, 176061b302f9SEric Fiselier __wrap_iter<_Iter> __x) _NOEXCEPT 17613e519524SHoward Hinnant{ 1762f554add5SHoward Hinnant __x += __n; 1763f554add5SHoward Hinnant return __x; 17643e519524SHoward Hinnant} 17653e519524SHoward Hinnant 176676b4afc0SMarshall Clowtemplate <class _Iter> 176776b4afc0SMarshall Clowstruct __libcpp_is_trivial_iterator 176876b4afc0SMarshall Clow : public _LIBCPP_BOOL_CONSTANT(is_pointer<_Iter>::value) {}; 176976b4afc0SMarshall Clow 177076b4afc0SMarshall Clowtemplate <class _Iter> 177176b4afc0SMarshall Clowstruct __libcpp_is_trivial_iterator<move_iterator<_Iter> > 177276b4afc0SMarshall Clow : public _LIBCPP_BOOL_CONSTANT(__libcpp_is_trivial_iterator<_Iter>::value) {}; 177376b4afc0SMarshall Clow 177476b4afc0SMarshall Clowtemplate <class _Iter> 177576b4afc0SMarshall Clowstruct __libcpp_is_trivial_iterator<reverse_iterator<_Iter> > 177676b4afc0SMarshall Clow : public _LIBCPP_BOOL_CONSTANT(__libcpp_is_trivial_iterator<_Iter>::value) {}; 177776b4afc0SMarshall Clow 177876b4afc0SMarshall Clowtemplate <class _Iter> 177976b4afc0SMarshall Clowstruct __libcpp_is_trivial_iterator<__wrap_iter<_Iter> > 178076b4afc0SMarshall Clow : public _LIBCPP_BOOL_CONSTANT(__libcpp_is_trivial_iterator<_Iter>::value) {}; 178176b4afc0SMarshall Clow 178276b4afc0SMarshall Clow 17833772a46aSMarshall Clowtemplate <class _Tp, size_t _Np> 17842ffa1705SMarshall Clow_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 17853772a46aSMarshall Clow_Tp* 17863772a46aSMarshall Clowbegin(_Tp (&__array)[_Np]) 17873772a46aSMarshall Clow{ 17883772a46aSMarshall Clow return __array; 17893772a46aSMarshall Clow} 17903772a46aSMarshall Clow 17913772a46aSMarshall Clowtemplate <class _Tp, size_t _Np> 17922ffa1705SMarshall Clow_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 17933772a46aSMarshall Clow_Tp* 17943772a46aSMarshall Clowend(_Tp (&__array)[_Np]) 17953772a46aSMarshall Clow{ 17963772a46aSMarshall Clow return __array + _Np; 17973772a46aSMarshall Clow} 17983772a46aSMarshall Clow 179954613ab4SEric Fiselier#if !defined(_LIBCPP_CXX03_LANG) 1800c66a611bSMarshall Clow 1801c003db1fSHoward Hinnanttemplate <class _Cp> 18022ffa1705SMarshall Clow_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 18033e519524SHoward Hinnantauto 1804c003db1fSHoward Hinnantbegin(_Cp& __c) -> decltype(__c.begin()) 18053e519524SHoward Hinnant{ 18063e519524SHoward Hinnant return __c.begin(); 18073e519524SHoward Hinnant} 18083e519524SHoward Hinnant 1809c003db1fSHoward Hinnanttemplate <class _Cp> 18102ffa1705SMarshall Clow_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 18113e519524SHoward Hinnantauto 1812c003db1fSHoward Hinnantbegin(const _Cp& __c) -> decltype(__c.begin()) 18133e519524SHoward Hinnant{ 18143e519524SHoward Hinnant return __c.begin(); 18153e519524SHoward Hinnant} 18163e519524SHoward Hinnant 1817c003db1fSHoward Hinnanttemplate <class _Cp> 18182ffa1705SMarshall Clow_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 18193e519524SHoward Hinnantauto 1820c003db1fSHoward Hinnantend(_Cp& __c) -> decltype(__c.end()) 18213e519524SHoward Hinnant{ 18223e519524SHoward Hinnant return __c.end(); 18233e519524SHoward Hinnant} 18243e519524SHoward Hinnant 1825c003db1fSHoward Hinnanttemplate <class _Cp> 18262ffa1705SMarshall Clow_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 18273e519524SHoward Hinnantauto 1828c003db1fSHoward Hinnantend(const _Cp& __c) -> decltype(__c.end()) 18293e519524SHoward Hinnant{ 18303e519524SHoward Hinnant return __c.end(); 18313e519524SHoward Hinnant} 18323e519524SHoward Hinnant 18331e548c72SMarshall Clow#if _LIBCPP_STD_VER > 11 18341e548c72SMarshall Clow 18353772a46aSMarshall Clowtemplate <class _Tp, size_t _Np> 18362ffa1705SMarshall Clow_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 18373772a46aSMarshall Clowreverse_iterator<_Tp*> rbegin(_Tp (&__array)[_Np]) 18383772a46aSMarshall Clow{ 18393772a46aSMarshall Clow return reverse_iterator<_Tp*>(__array + _Np); 18403772a46aSMarshall Clow} 18413772a46aSMarshall Clow 18423772a46aSMarshall Clowtemplate <class _Tp, size_t _Np> 18432ffa1705SMarshall Clow_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 18443772a46aSMarshall Clowreverse_iterator<_Tp*> rend(_Tp (&__array)[_Np]) 18453772a46aSMarshall Clow{ 18463772a46aSMarshall Clow return reverse_iterator<_Tp*>(__array); 18473772a46aSMarshall Clow} 18483772a46aSMarshall Clow 18493772a46aSMarshall Clowtemplate <class _Ep> 18502ffa1705SMarshall Clow_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 18513772a46aSMarshall Clowreverse_iterator<const _Ep*> rbegin(initializer_list<_Ep> __il) 18523772a46aSMarshall Clow{ 18533772a46aSMarshall Clow return reverse_iterator<const _Ep*>(__il.end()); 18543772a46aSMarshall Clow} 18553772a46aSMarshall Clow 18563772a46aSMarshall Clowtemplate <class _Ep> 18572ffa1705SMarshall Clow_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 18583772a46aSMarshall Clowreverse_iterator<const _Ep*> rend(initializer_list<_Ep> __il) 18593772a46aSMarshall Clow{ 18603772a46aSMarshall Clow return reverse_iterator<const _Ep*>(__il.begin()); 18613772a46aSMarshall Clow} 18623772a46aSMarshall Clow 18631e548c72SMarshall Clowtemplate <class _Cp> 18642ffa1705SMarshall Clow_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 18657725546aSMarshall Clowauto cbegin(const _Cp& __c) -> decltype(_VSTD::begin(__c)) 18661e548c72SMarshall Clow{ 18677725546aSMarshall Clow return _VSTD::begin(__c); 18681e548c72SMarshall Clow} 18691e548c72SMarshall Clow 18701e548c72SMarshall Clowtemplate <class _Cp> 18712ffa1705SMarshall Clow_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 18727725546aSMarshall Clowauto cend(const _Cp& __c) -> decltype(_VSTD::end(__c)) 18731e548c72SMarshall Clow{ 18747725546aSMarshall Clow return _VSTD::end(__c); 18751e548c72SMarshall Clow} 18761e548c72SMarshall Clow 18771e548c72SMarshall Clowtemplate <class _Cp> 18782ffa1705SMarshall Clow_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 18791e548c72SMarshall Clowauto rbegin(_Cp& __c) -> decltype(__c.rbegin()) 18801e548c72SMarshall Clow{ 18811e548c72SMarshall Clow return __c.rbegin(); 18821e548c72SMarshall Clow} 18831e548c72SMarshall Clow 18841e548c72SMarshall Clowtemplate <class _Cp> 18852ffa1705SMarshall Clow_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 18861e548c72SMarshall Clowauto rbegin(const _Cp& __c) -> decltype(__c.rbegin()) 18871e548c72SMarshall Clow{ 18881e548c72SMarshall Clow return __c.rbegin(); 18891e548c72SMarshall Clow} 18901e548c72SMarshall Clow 18911e548c72SMarshall Clowtemplate <class _Cp> 18922ffa1705SMarshall Clow_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 18931e548c72SMarshall Clowauto rend(_Cp& __c) -> decltype(__c.rend()) 18941e548c72SMarshall Clow{ 18951e548c72SMarshall Clow return __c.rend(); 18961e548c72SMarshall Clow} 18971e548c72SMarshall Clow 18981e548c72SMarshall Clowtemplate <class _Cp> 18992ffa1705SMarshall Clow_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 19001e548c72SMarshall Clowauto rend(const _Cp& __c) -> decltype(__c.rend()) 19011e548c72SMarshall Clow{ 19021e548c72SMarshall Clow return __c.rend(); 19031e548c72SMarshall Clow} 19041e548c72SMarshall Clow 19051e548c72SMarshall Clowtemplate <class _Cp> 19062ffa1705SMarshall Clow_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 19077725546aSMarshall Clowauto crbegin(const _Cp& __c) -> decltype(_VSTD::rbegin(__c)) 19081e548c72SMarshall Clow{ 19097725546aSMarshall Clow return _VSTD::rbegin(__c); 19101e548c72SMarshall Clow} 19111e548c72SMarshall Clow 19121e548c72SMarshall Clowtemplate <class _Cp> 19132ffa1705SMarshall Clow_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 19147725546aSMarshall Clowauto crend(const _Cp& __c) -> decltype(_VSTD::rend(__c)) 19151e548c72SMarshall Clow{ 19167725546aSMarshall Clow return _VSTD::rend(__c); 19171e548c72SMarshall Clow} 19181e548c72SMarshall Clow 19191e548c72SMarshall Clow#endif 19201e548c72SMarshall Clow 19211e548c72SMarshall Clow 192254613ab4SEric Fiselier#else // defined(_LIBCPP_CXX03_LANG) 19233e519524SHoward Hinnant 1924c003db1fSHoward Hinnanttemplate <class _Cp> 19252ffa1705SMarshall Clow_LIBCPP_INLINE_VISIBILITY 1926c003db1fSHoward Hinnanttypename _Cp::iterator 1927c003db1fSHoward Hinnantbegin(_Cp& __c) 19283e519524SHoward Hinnant{ 19293e519524SHoward Hinnant return __c.begin(); 19303e519524SHoward Hinnant} 19313e519524SHoward Hinnant 1932c003db1fSHoward Hinnanttemplate <class _Cp> 19332ffa1705SMarshall Clow_LIBCPP_INLINE_VISIBILITY 1934c003db1fSHoward Hinnanttypename _Cp::const_iterator 1935c003db1fSHoward Hinnantbegin(const _Cp& __c) 19363e519524SHoward Hinnant{ 19373e519524SHoward Hinnant return __c.begin(); 19383e519524SHoward Hinnant} 19393e519524SHoward Hinnant 1940c003db1fSHoward Hinnanttemplate <class _Cp> 19412ffa1705SMarshall Clow_LIBCPP_INLINE_VISIBILITY 1942c003db1fSHoward Hinnanttypename _Cp::iterator 1943c003db1fSHoward Hinnantend(_Cp& __c) 19443e519524SHoward Hinnant{ 19453e519524SHoward Hinnant return __c.end(); 19463e519524SHoward Hinnant} 19473e519524SHoward Hinnant 1948c003db1fSHoward Hinnanttemplate <class _Cp> 19492ffa1705SMarshall Clow_LIBCPP_INLINE_VISIBILITY 1950c003db1fSHoward Hinnanttypename _Cp::const_iterator 1951c003db1fSHoward Hinnantend(const _Cp& __c) 19523e519524SHoward Hinnant{ 19533e519524SHoward Hinnant return __c.end(); 19543e519524SHoward Hinnant} 19553e519524SHoward Hinnant 195654613ab4SEric Fiselier#endif // !defined(_LIBCPP_CXX03_LANG) 19573e519524SHoward Hinnant 1958ad755104SMarshall Clow#if _LIBCPP_STD_VER > 14 1959d1dcda19SMarshall Clow 1960d1dcda19SMarshall Clow// #if _LIBCPP_STD_VER > 11 1961d1dcda19SMarshall Clow// template <> 1962d1dcda19SMarshall Clow// struct _LIBCPP_TEMPLATE_VIS plus<void> 1963d1dcda19SMarshall Clow// { 1964d1dcda19SMarshall Clow// template <class _T1, class _T2> 1965d1dcda19SMarshall Clow// _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY 1966d1dcda19SMarshall Clow// auto operator()(_T1&& __t, _T2&& __u) const 1967d1dcda19SMarshall Clow// _NOEXCEPT_(noexcept(_VSTD::forward<_T1>(__t) + _VSTD::forward<_T2>(__u))) 1968d1dcda19SMarshall Clow// -> decltype (_VSTD::forward<_T1>(__t) + _VSTD::forward<_T2>(__u)) 1969d1dcda19SMarshall Clow// { return _VSTD::forward<_T1>(__t) + _VSTD::forward<_T2>(__u); } 1970d1dcda19SMarshall Clow// typedef void is_transparent; 1971d1dcda19SMarshall Clow// }; 1972d1dcda19SMarshall Clow// #endif 1973d1dcda19SMarshall Clow 197488d21343SMarshall Clowtemplate <class _Cont> 19752ffa1705SMarshall Clow_LIBCPP_INLINE_VISIBILITY 1976d1dcda19SMarshall Clowconstexpr auto size(const _Cont& __c) 1977d1dcda19SMarshall Clow_NOEXCEPT_(noexcept(__c.size())) 1978d1dcda19SMarshall Clow-> decltype (__c.size()) 1979d1dcda19SMarshall Clow{ return __c.size(); } 1980ad755104SMarshall Clow 198188d21343SMarshall Clowtemplate <class _Tp, size_t _Sz> 19822ffa1705SMarshall Clow_LIBCPP_INLINE_VISIBILITY 1983fd838227SEric Fiselierconstexpr size_t size(const _Tp (&)[_Sz]) noexcept { return _Sz; } 1984ad755104SMarshall Clow 19857d3986eaSMarshall Clow#if _LIBCPP_STD_VER > 17 19867d3986eaSMarshall Clowtemplate <class _Cont> 19872ffa1705SMarshall Clow_LIBCPP_INLINE_VISIBILITY 19887d3986eaSMarshall Clowconstexpr auto ssize(const _Cont& __c) 19897d3986eaSMarshall Clow_NOEXCEPT_(noexcept(static_cast<common_type_t<ptrdiff_t, make_signed_t<decltype(__c.size())>>>(__c.size()))) 19907d3986eaSMarshall Clow-> common_type_t<ptrdiff_t, make_signed_t<decltype(__c.size())>> 19917d3986eaSMarshall Clow{ return static_cast<common_type_t<ptrdiff_t, make_signed_t<decltype(__c.size())>>>(__c.size()); } 19927d3986eaSMarshall Clow 19937d3986eaSMarshall Clowtemplate <class _Tp, ptrdiff_t _Sz> 19942ffa1705SMarshall Clow_LIBCPP_INLINE_VISIBILITY 19957d3986eaSMarshall Clowconstexpr ptrdiff_t ssize(const _Tp (&)[_Sz]) noexcept { return _Sz; } 19967d3986eaSMarshall Clow#endif 19977d3986eaSMarshall Clow 199888d21343SMarshall Clowtemplate <class _Cont> 19992ffa1705SMarshall Clow_LIBCPP_NODISCARD_AFTER_CXX17 _LIBCPP_INLINE_VISIBILITY 2000d1dcda19SMarshall Clowconstexpr auto empty(const _Cont& __c) 2001d1dcda19SMarshall Clow_NOEXCEPT_(noexcept(__c.empty())) 2002d1dcda19SMarshall Clow-> decltype (__c.empty()) 2003d1dcda19SMarshall Clow{ return __c.empty(); } 2004ad755104SMarshall Clow 200588d21343SMarshall Clowtemplate <class _Tp, size_t _Sz> 20062ffa1705SMarshall Clow_LIBCPP_NODISCARD_AFTER_CXX17 _LIBCPP_INLINE_VISIBILITY 2007fd838227SEric Fiselierconstexpr bool empty(const _Tp (&)[_Sz]) noexcept { return false; } 2008ad755104SMarshall Clow 2009ad755104SMarshall Clowtemplate <class _Ep> 20102ffa1705SMarshall Clow_LIBCPP_NODISCARD_AFTER_CXX17 _LIBCPP_INLINE_VISIBILITY 2011ad755104SMarshall Clowconstexpr bool empty(initializer_list<_Ep> __il) noexcept { return __il.size() == 0; } 2012ad755104SMarshall Clow 201388d21343SMarshall Clowtemplate <class _Cont> constexpr 20142ffa1705SMarshall Clow_LIBCPP_INLINE_VISIBILITY 2015d1dcda19SMarshall Clowauto data(_Cont& __c) 2016d1dcda19SMarshall Clow_NOEXCEPT_(noexcept(__c.data())) 2017d1dcda19SMarshall Clow-> decltype (__c.data()) 2018d1dcda19SMarshall Clow{ return __c.data(); } 2019ad755104SMarshall Clow 202088d21343SMarshall Clowtemplate <class _Cont> constexpr 20212ffa1705SMarshall Clow_LIBCPP_INLINE_VISIBILITY 2022d1dcda19SMarshall Clowauto data(const _Cont& __c) 2023d1dcda19SMarshall Clow_NOEXCEPT_(noexcept(__c.data())) 2024d1dcda19SMarshall Clow-> decltype (__c.data()) 2025d1dcda19SMarshall Clow{ return __c.data(); } 2026ad755104SMarshall Clow 202788d21343SMarshall Clowtemplate <class _Tp, size_t _Sz> 20282ffa1705SMarshall Clow_LIBCPP_INLINE_VISIBILITY 202988d21343SMarshall Clowconstexpr _Tp* data(_Tp (&__array)[_Sz]) noexcept { return __array; } 2030ad755104SMarshall Clow 2031ad755104SMarshall Clowtemplate <class _Ep> 20322ffa1705SMarshall Clow_LIBCPP_INLINE_VISIBILITY 2033ad755104SMarshall Clowconstexpr const _Ep* data(initializer_list<_Ep> __il) noexcept { return __il.begin(); } 2034ad755104SMarshall Clow#endif 2035ad755104SMarshall Clow 20362ac6babcSArthur O'Dwyertemplate <class _Container, class _Predicate> 20372ac6babcSArthur O'Dwyertypename _Container::size_type 20382ac6babcSArthur O'Dwyer__libcpp_erase_if_container(_Container& __c, _Predicate& __pred) { 20392ac6babcSArthur O'Dwyer typename _Container::size_type __old_size = __c.size(); 20402ac6babcSArthur O'Dwyer 20412ac6babcSArthur O'Dwyer const typename _Container::iterator __last = __c.end(); 20422ac6babcSArthur O'Dwyer for (typename _Container::iterator __iter = __c.begin(); __iter != __last;) { 20432ac6babcSArthur O'Dwyer if (__pred(*__iter)) 20442ac6babcSArthur O'Dwyer __iter = __c.erase(__iter); 20452ac6babcSArthur O'Dwyer else 20462ac6babcSArthur O'Dwyer ++__iter; 20472ac6babcSArthur O'Dwyer } 20482ac6babcSArthur O'Dwyer 20492ac6babcSArthur O'Dwyer return __old_size - __c.size(); 20502ac6babcSArthur O'Dwyer} 2051ad755104SMarshall Clow 20523e519524SHoward Hinnant_LIBCPP_END_NAMESPACE_STD 20533e519524SHoward Hinnant 20543e519524SHoward Hinnant#endif // _LIBCPP_ITERATOR 2055