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 16fe31f11cSChristopher Di Bella#include <concepts> 17fe31f11cSChristopher Di Bella 183e519524SHoward Hinnantnamespace std 193e519524SHoward Hinnant{ 20fe31f11cSChristopher Di Bellatemplate<class> struct incrementable_traits; // since C++20 213e519524SHoward Hinnant 223e519524SHoward Hinnanttemplate<class Iterator> 233e519524SHoward Hinnantstruct iterator_traits 243e519524SHoward Hinnant{ 253e519524SHoward Hinnant typedef typename Iterator::difference_type difference_type; 263e519524SHoward Hinnant typedef typename Iterator::value_type value_type; 273e519524SHoward Hinnant typedef typename Iterator::pointer pointer; 283e519524SHoward Hinnant typedef typename Iterator::reference reference; 293e519524SHoward Hinnant typedef typename Iterator::iterator_category iterator_category; 303e519524SHoward Hinnant}; 313e519524SHoward Hinnant 323e519524SHoward Hinnanttemplate<class T> 333e519524SHoward Hinnantstruct iterator_traits<T*> 343e519524SHoward Hinnant{ 353e519524SHoward Hinnant typedef ptrdiff_t difference_type; 363e519524SHoward Hinnant typedef T value_type; 373e519524SHoward Hinnant typedef T* pointer; 383e519524SHoward Hinnant typedef T& reference; 393e519524SHoward Hinnant typedef random_access_iterator_tag iterator_category; 403e519524SHoward Hinnant}; 413e519524SHoward Hinnant 423e519524SHoward Hinnanttemplate<class Category, class T, class Distance = ptrdiff_t, 433e519524SHoward Hinnant class Pointer = T*, class Reference = T&> 443e519524SHoward Hinnantstruct iterator 453e519524SHoward Hinnant{ 463e519524SHoward Hinnant typedef T value_type; 473e519524SHoward Hinnant typedef Distance difference_type; 483e519524SHoward Hinnant typedef Pointer pointer; 493e519524SHoward Hinnant typedef Reference reference; 503e519524SHoward Hinnant typedef Category iterator_category; 513e519524SHoward Hinnant}; 523e519524SHoward Hinnant 533e519524SHoward Hinnantstruct input_iterator_tag {}; 543e519524SHoward Hinnantstruct output_iterator_tag {}; 553e519524SHoward Hinnantstruct forward_iterator_tag : public input_iterator_tag {}; 563e519524SHoward Hinnantstruct bidirectional_iterator_tag : public forward_iterator_tag {}; 573e519524SHoward Hinnantstruct random_access_iterator_tag : public bidirectional_iterator_tag {}; 583e519524SHoward Hinnant 59f51ee632SMarshall Clow// 27.4.3, iterator operations 6012b01ab7SLouis Dionnetemplate <class InputIterator, class Distance> // constexpr in C++17 6112b01ab7SLouis Dionne constexpr void advance(InputIterator& i, Distance n); 623e519524SHoward Hinnant 63f51ee632SMarshall Clowtemplate <class InputIterator> // constexpr in C++17 64f51ee632SMarshall Clow constexpr typename iterator_traits<InputIterator>::difference_type 653e519524SHoward Hinnant distance(InputIterator first, InputIterator last); 663e519524SHoward Hinnant 67f51ee632SMarshall Clowtemplate <class InputIterator> // constexpr in C++17 68f51ee632SMarshall Clow constexpr InputIterator next(InputIterator x, 69f51ee632SMarshall Clowtypename iterator_traits<InputIterator>::difference_type n = 1); 70f51ee632SMarshall Clow 71f51ee632SMarshall Clowtemplate <class BidirectionalIterator> // constexpr in C++17 72f51ee632SMarshall Clow constexpr BidirectionalIterator prev(BidirectionalIterator x, 73f51ee632SMarshall Clow typename iterator_traits<BidirectionalIterator>::difference_type n = 1); 74f51ee632SMarshall Clow 753e519524SHoward Hinnanttemplate <class Iterator> 763e519524SHoward Hinnantclass reverse_iterator 773e519524SHoward Hinnant : public iterator<typename iterator_traits<Iterator>::iterator_category, 783e519524SHoward Hinnant typename iterator_traits<Iterator>::value_type, 793e519524SHoward Hinnant typename iterator_traits<Iterator>::difference_type, 803e519524SHoward Hinnant typename iterator_traits<Iterator>::pointer, 813e519524SHoward Hinnant typename iterator_traits<Iterator>::reference> 823e519524SHoward Hinnant{ 833e519524SHoward Hinnantprotected: 843e519524SHoward Hinnant Iterator current; 853e519524SHoward Hinnantpublic: 863e519524SHoward Hinnant typedef Iterator iterator_type; 873e519524SHoward Hinnant typedef typename iterator_traits<Iterator>::difference_type difference_type; 883e519524SHoward Hinnant typedef typename iterator_traits<Iterator>::reference reference; 893e519524SHoward Hinnant typedef typename iterator_traits<Iterator>::pointer pointer; 903e519524SHoward Hinnant 911b8f260eSMarshall Clow constexpr reverse_iterator(); 921b8f260eSMarshall Clow constexpr explicit reverse_iterator(Iterator x); 931b8f260eSMarshall Clow template <class U> constexpr reverse_iterator(const reverse_iterator<U>& u); 941b8f260eSMarshall Clow template <class U> constexpr reverse_iterator& operator=(const reverse_iterator<U>& u); 951b8f260eSMarshall Clow constexpr Iterator base() const; 961b8f260eSMarshall Clow constexpr reference operator*() const; 971b8f260eSMarshall Clow constexpr pointer operator->() const; 981b8f260eSMarshall Clow constexpr reverse_iterator& operator++(); 991b8f260eSMarshall Clow constexpr reverse_iterator operator++(int); 1001b8f260eSMarshall Clow constexpr reverse_iterator& operator--(); 1011b8f260eSMarshall Clow constexpr reverse_iterator operator--(int); 1021b8f260eSMarshall Clow constexpr reverse_iterator operator+ (difference_type n) const; 1031b8f260eSMarshall Clow constexpr reverse_iterator& operator+=(difference_type n); 1041b8f260eSMarshall Clow constexpr reverse_iterator operator- (difference_type n) const; 1051b8f260eSMarshall Clow constexpr reverse_iterator& operator-=(difference_type n); 1061b8f260eSMarshall Clow constexpr reference operator[](difference_type n) const; 1073e519524SHoward Hinnant}; 1083e519524SHoward Hinnant 1093e519524SHoward Hinnanttemplate <class Iterator1, class Iterator2> 1101b8f260eSMarshall Clowconstexpr bool // constexpr in C++17 1113e519524SHoward Hinnantoperator==(const reverse_iterator<Iterator1>& x, const reverse_iterator<Iterator2>& y); 1123e519524SHoward Hinnant 1133e519524SHoward Hinnanttemplate <class Iterator1, class Iterator2> 1141b8f260eSMarshall Clowconstexpr bool // constexpr in C++17 1153e519524SHoward Hinnantoperator<(const reverse_iterator<Iterator1>& x, const reverse_iterator<Iterator2>& y); 1163e519524SHoward Hinnant 1173e519524SHoward Hinnanttemplate <class Iterator1, class Iterator2> 1181b8f260eSMarshall Clowconstexpr bool // constexpr in C++17 1193e519524SHoward Hinnantoperator!=(const reverse_iterator<Iterator1>& x, const reverse_iterator<Iterator2>& y); 1203e519524SHoward Hinnant 1213e519524SHoward Hinnanttemplate <class Iterator1, class Iterator2> 1221b8f260eSMarshall Clowconstexpr bool // constexpr in C++17 1233e519524SHoward Hinnantoperator>(const reverse_iterator<Iterator1>& x, const reverse_iterator<Iterator2>& y); 1243e519524SHoward Hinnant 1253e519524SHoward Hinnanttemplate <class Iterator1, class Iterator2> 1261b8f260eSMarshall Clowconstexpr bool // constexpr in C++17 1273e519524SHoward Hinnantoperator>=(const reverse_iterator<Iterator1>& x, const reverse_iterator<Iterator2>& y); 1283e519524SHoward Hinnant 1293e519524SHoward Hinnanttemplate <class Iterator1, class Iterator2> 1301b8f260eSMarshall Clowconstexpr bool // constexpr in C++17 1313e519524SHoward Hinnantoperator<=(const reverse_iterator<Iterator1>& x, const reverse_iterator<Iterator2>& y); 1323e519524SHoward Hinnant 1333e519524SHoward Hinnanttemplate <class Iterator1, class Iterator2> 1341b8f260eSMarshall Clowconstexpr auto 135947ce6b5SMarshall Clowoperator-(const reverse_iterator<Iterator1>& x, const reverse_iterator<Iterator2>& y) 1361b8f260eSMarshall Clow-> decltype(__y.base() - __x.base()); // constexpr in C++17 1373e519524SHoward Hinnant 1383e519524SHoward Hinnanttemplate <class Iterator> 1391b8f260eSMarshall Clowconstexpr reverse_iterator<Iterator> 1401b8f260eSMarshall Clowoperator+(typename reverse_iterator<Iterator>::difference_type n, 1411b8f260eSMarshall Clow const reverse_iterator<Iterator>& x); // constexpr in C++17 1423e519524SHoward Hinnant 1431b8f260eSMarshall Clowtemplate <class Iterator> 1441b8f260eSMarshall Clowconstexpr reverse_iterator<Iterator> make_reverse_iterator(Iterator i); // C++14, constexpr in C++17 1456a640a18SMarshall Clow 1463e519524SHoward Hinnanttemplate <class Container> 1473e519524SHoward Hinnantclass back_insert_iterator 1483e519524SHoward Hinnant{ 1493e519524SHoward Hinnantprotected: 1503e519524SHoward Hinnant Container* container; 1513e519524SHoward Hinnantpublic: 1523e519524SHoward Hinnant typedef Container container_type; 1533e519524SHoward Hinnant typedef void value_type; 1543e519524SHoward Hinnant typedef void difference_type; 1558892b4eeSEric Fiselier typedef void reference; 1563e519524SHoward Hinnant typedef void pointer; 1573e519524SHoward Hinnant 15806e2b737SArthur O'Dwyer explicit back_insert_iterator(Container& x); // constexpr in C++20 15906e2b737SArthur O'Dwyer back_insert_iterator& operator=(const typename Container::value_type& value); // constexpr in C++20 16006e2b737SArthur O'Dwyer back_insert_iterator& operator*(); // constexpr in C++20 16106e2b737SArthur O'Dwyer back_insert_iterator& operator++(); // constexpr in C++20 16206e2b737SArthur O'Dwyer back_insert_iterator operator++(int); // constexpr in C++20 1633e519524SHoward Hinnant}; 1643e519524SHoward Hinnant 16506e2b737SArthur O'Dwyertemplate <class Container> back_insert_iterator<Container> back_inserter(Container& x); // constexpr in C++20 1663e519524SHoward Hinnant 1673e519524SHoward Hinnanttemplate <class Container> 1683e519524SHoward Hinnantclass front_insert_iterator 1693e519524SHoward Hinnant{ 1703e519524SHoward Hinnantprotected: 1713e519524SHoward Hinnant Container* container; 1723e519524SHoward Hinnantpublic: 1733e519524SHoward Hinnant typedef Container container_type; 1743e519524SHoward Hinnant typedef void value_type; 1753e519524SHoward Hinnant typedef void difference_type; 1768892b4eeSEric Fiselier typedef void reference; 1773e519524SHoward Hinnant typedef void pointer; 1783e519524SHoward Hinnant 17906e2b737SArthur O'Dwyer explicit front_insert_iterator(Container& x); // constexpr in C++20 18006e2b737SArthur O'Dwyer front_insert_iterator& operator=(const typename Container::value_type& value); // constexpr in C++20 18106e2b737SArthur O'Dwyer front_insert_iterator& operator*(); // constexpr in C++20 18206e2b737SArthur O'Dwyer front_insert_iterator& operator++(); // constexpr in C++20 18306e2b737SArthur O'Dwyer front_insert_iterator operator++(int); // constexpr in C++20 1843e519524SHoward Hinnant}; 1853e519524SHoward Hinnant 18606e2b737SArthur O'Dwyertemplate <class Container> front_insert_iterator<Container> front_inserter(Container& x); // constexpr in C++20 1873e519524SHoward Hinnant 1883e519524SHoward Hinnanttemplate <class Container> 1893e519524SHoward Hinnantclass insert_iterator 1903e519524SHoward Hinnant{ 1913e519524SHoward Hinnantprotected: 1923e519524SHoward Hinnant Container* container; 1933e519524SHoward Hinnant typename Container::iterator iter; 1943e519524SHoward Hinnantpublic: 1953e519524SHoward Hinnant typedef Container container_type; 1963e519524SHoward Hinnant typedef void value_type; 1973e519524SHoward Hinnant typedef void difference_type; 1988892b4eeSEric Fiselier typedef void reference; 1993e519524SHoward Hinnant typedef void pointer; 2003e519524SHoward Hinnant 20106e2b737SArthur O'Dwyer insert_iterator(Container& x, typename Container::iterator i); // constexpr in C++20 20206e2b737SArthur O'Dwyer insert_iterator& operator=(const typename Container::value_type& value); // constexpr in C++20 20306e2b737SArthur O'Dwyer insert_iterator& operator*(); // constexpr in C++20 20406e2b737SArthur O'Dwyer insert_iterator& operator++(); // constexpr in C++20 20506e2b737SArthur O'Dwyer insert_iterator& operator++(int); // constexpr in C++20 2063e519524SHoward Hinnant}; 2073e519524SHoward Hinnant 2083e519524SHoward Hinnanttemplate <class Container, class Iterator> 20906e2b737SArthur O'Dwyerinsert_iterator<Container> inserter(Container& x, Iterator i); // constexpr in C++20 2103e519524SHoward Hinnant 211947ce6b5SMarshall Clowtemplate <class Iterator> 212947ce6b5SMarshall Clowclass move_iterator { 213947ce6b5SMarshall Clowpublic: 214947ce6b5SMarshall Clow typedef Iterator iterator_type; 215947ce6b5SMarshall Clow typedef typename iterator_traits<Iterator>::difference_type difference_type; 216947ce6b5SMarshall Clow typedef Iterator pointer; 217947ce6b5SMarshall Clow typedef typename iterator_traits<Iterator>::value_type value_type; 218947ce6b5SMarshall Clow typedef typename iterator_traits<Iterator>::iterator_category iterator_category; 219947ce6b5SMarshall Clow typedef value_type&& reference; 220947ce6b5SMarshall Clow 221720ef472SMarshall Clow constexpr move_iterator(); // all the constexprs are in C++17 222720ef472SMarshall Clow constexpr explicit move_iterator(Iterator i); 223720ef472SMarshall Clow template <class U> 224720ef472SMarshall Clow constexpr move_iterator(const move_iterator<U>& u); 225720ef472SMarshall Clow template <class U> 226720ef472SMarshall Clow constexpr move_iterator& operator=(const move_iterator<U>& u); 227720ef472SMarshall Clow constexpr iterator_type base() const; 228720ef472SMarshall Clow constexpr reference operator*() const; 229720ef472SMarshall Clow constexpr pointer operator->() const; 230720ef472SMarshall Clow constexpr move_iterator& operator++(); 231720ef472SMarshall Clow constexpr move_iterator operator++(int); 232720ef472SMarshall Clow constexpr move_iterator& operator--(); 233720ef472SMarshall Clow constexpr move_iterator operator--(int); 234720ef472SMarshall Clow constexpr move_iterator operator+(difference_type n) const; 235720ef472SMarshall Clow constexpr move_iterator& operator+=(difference_type n); 236720ef472SMarshall Clow constexpr move_iterator operator-(difference_type n) const; 237720ef472SMarshall Clow constexpr move_iterator& operator-=(difference_type n); 238720ef472SMarshall Clow constexpr unspecified operator[](difference_type n) const; 239947ce6b5SMarshall Clowprivate: 240947ce6b5SMarshall Clow Iterator current; // exposition only 241947ce6b5SMarshall Clow}; 242947ce6b5SMarshall Clow 243947ce6b5SMarshall Clowtemplate <class Iterator1, class Iterator2> 244720ef472SMarshall Clowconstexpr bool // constexpr in C++17 245947ce6b5SMarshall Clowoperator==(const move_iterator<Iterator1>& x, const move_iterator<Iterator2>& y); 246947ce6b5SMarshall Clow 247947ce6b5SMarshall Clowtemplate <class Iterator1, class Iterator2> 248720ef472SMarshall Clowconstexpr bool // constexpr in C++17 249947ce6b5SMarshall Clowoperator!=(const move_iterator<Iterator1>& x, const move_iterator<Iterator2>& y); 250947ce6b5SMarshall Clow 251947ce6b5SMarshall Clowtemplate <class Iterator1, class Iterator2> 252720ef472SMarshall Clowconstexpr bool // constexpr in C++17 253947ce6b5SMarshall Clowoperator<(const move_iterator<Iterator1>& x, const move_iterator<Iterator2>& y); 254947ce6b5SMarshall Clow 255947ce6b5SMarshall Clowtemplate <class Iterator1, class Iterator2> 256720ef472SMarshall Clowconstexpr bool // constexpr in C++17 257947ce6b5SMarshall Clowoperator<=(const move_iterator<Iterator1>& x, const move_iterator<Iterator2>& y); 258947ce6b5SMarshall Clow 259947ce6b5SMarshall Clowtemplate <class Iterator1, class Iterator2> 260720ef472SMarshall Clowconstexpr bool // constexpr in C++17 261947ce6b5SMarshall Clowoperator>(const move_iterator<Iterator1>& x, const move_iterator<Iterator2>& y); 262947ce6b5SMarshall Clow 263947ce6b5SMarshall Clowtemplate <class Iterator1, class Iterator2> 264720ef472SMarshall Clowconstexpr bool // constexpr in C++17 265947ce6b5SMarshall Clowoperator>=(const move_iterator<Iterator1>& x, const move_iterator<Iterator2>& y); 266947ce6b5SMarshall Clow 267947ce6b5SMarshall Clowtemplate <class Iterator1, class Iterator2> 268720ef472SMarshall Clowconstexpr auto // constexpr in C++17 269947ce6b5SMarshall Clowoperator-(const move_iterator<Iterator1>& x, 270947ce6b5SMarshall Clow const move_iterator<Iterator2>& y) -> decltype(x.base() - y.base()); 271947ce6b5SMarshall Clow 272947ce6b5SMarshall Clowtemplate <class Iterator> 273720ef472SMarshall Clowconstexpr move_iterator<Iterator> operator+( // constexpr in C++17 274720ef472SMarshall Clow typename move_iterator<Iterator>::difference_type n, 275947ce6b5SMarshall Clow const move_iterator<Iterator>& x); 276947ce6b5SMarshall Clow 277720ef472SMarshall Clowtemplate <class Iterator> // constexpr in C++17 278720ef472SMarshall Clowconstexpr move_iterator<Iterator> make_move_iterator(const Iterator& i); 279947ce6b5SMarshall Clow 280947ce6b5SMarshall Clow 2813e519524SHoward Hinnanttemplate <class T, class charT = char, class traits = char_traits<charT>, class Distance = ptrdiff_t> 2823e519524SHoward Hinnantclass istream_iterator 2833e519524SHoward Hinnant : public iterator<input_iterator_tag, T, Distance, const T*, const T&> 2843e519524SHoward Hinnant{ 2853e519524SHoward Hinnantpublic: 2863e519524SHoward Hinnant typedef charT char_type; 2873e519524SHoward Hinnant typedef traits traits_type; 2883e519524SHoward Hinnant typedef basic_istream<charT,traits> istream_type; 2893e519524SHoward Hinnant 29060d5e0e0SMarshall Clow constexpr istream_iterator(); 2913e519524SHoward Hinnant istream_iterator(istream_type& s); 2923e519524SHoward Hinnant istream_iterator(const istream_iterator& x); 2933e519524SHoward Hinnant ~istream_iterator(); 2943e519524SHoward Hinnant 2953e519524SHoward Hinnant const T& operator*() const; 2963e519524SHoward Hinnant const T* operator->() const; 2973e519524SHoward Hinnant istream_iterator& operator++(); 2983e519524SHoward Hinnant istream_iterator operator++(int); 2993e519524SHoward Hinnant}; 3003e519524SHoward Hinnant 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 Hinnanttemplate <class T, class charT, class traits, class Distance> 3053e519524SHoward Hinnantbool operator!=(const istream_iterator<T,charT,traits,Distance>& x, 3063e519524SHoward Hinnant const istream_iterator<T,charT,traits,Distance>& y); 3073e519524SHoward Hinnant 3083e519524SHoward Hinnanttemplate <class T, class charT = char, class traits = char_traits<charT> > 3093e519524SHoward Hinnantclass ostream_iterator 3103e519524SHoward Hinnant : public iterator<output_iterator_tag, void, void, void ,void> 3113e519524SHoward Hinnant{ 3123e519524SHoward Hinnantpublic: 3133e519524SHoward Hinnant typedef charT char_type; 3143e519524SHoward Hinnant typedef traits traits_type; 3153e519524SHoward Hinnant typedef basic_ostream<charT,traits> ostream_type; 3163e519524SHoward Hinnant 3173e519524SHoward Hinnant ostream_iterator(ostream_type& s); 3183e519524SHoward Hinnant ostream_iterator(ostream_type& s, const charT* delimiter); 3193e519524SHoward Hinnant ostream_iterator(const ostream_iterator& x); 3203e519524SHoward Hinnant ~ostream_iterator(); 3213e519524SHoward Hinnant ostream_iterator& operator=(const T& value); 3223e519524SHoward Hinnant 3233e519524SHoward Hinnant ostream_iterator& operator*(); 3243e519524SHoward Hinnant ostream_iterator& operator++(); 3253e519524SHoward Hinnant ostream_iterator& operator++(int); 3263e519524SHoward Hinnant}; 3273e519524SHoward Hinnant 3283e519524SHoward Hinnanttemplate<class charT, class traits = char_traits<charT> > 3293e519524SHoward Hinnantclass istreambuf_iterator 3303e519524SHoward Hinnant : public iterator<input_iterator_tag, charT, 3313e519524SHoward Hinnant typename traits::off_type, unspecified, 3323e519524SHoward Hinnant charT> 3333e519524SHoward Hinnant{ 3343e519524SHoward Hinnantpublic: 3353e519524SHoward Hinnant typedef charT char_type; 3363e519524SHoward Hinnant typedef traits traits_type; 3373e519524SHoward Hinnant typedef typename traits::int_type int_type; 3383e519524SHoward Hinnant typedef basic_streambuf<charT,traits> streambuf_type; 3393e519524SHoward Hinnant typedef basic_istream<charT,traits> istream_type; 3403e519524SHoward Hinnant 3418e882dcbSHoward Hinnant istreambuf_iterator() noexcept; 3428e882dcbSHoward Hinnant istreambuf_iterator(istream_type& s) noexcept; 3438e882dcbSHoward Hinnant istreambuf_iterator(streambuf_type* s) noexcept; 3448e882dcbSHoward Hinnant istreambuf_iterator(a-private-type) noexcept; 3453e519524SHoward Hinnant 3463e519524SHoward Hinnant charT operator*() const; 3473e519524SHoward Hinnant pointer operator->() const; 3483e519524SHoward Hinnant istreambuf_iterator& operator++(); 3493e519524SHoward Hinnant a-private-type operator++(int); 3503e519524SHoward Hinnant 3513e519524SHoward Hinnant bool equal(const istreambuf_iterator& b) const; 3523e519524SHoward Hinnant}; 3533e519524SHoward Hinnant 3543e519524SHoward Hinnanttemplate <class charT, class traits> 3553e519524SHoward Hinnantbool operator==(const istreambuf_iterator<charT,traits>& a, 3563e519524SHoward Hinnant const istreambuf_iterator<charT,traits>& b); 3573e519524SHoward Hinnanttemplate <class charT, class traits> 3583e519524SHoward Hinnantbool operator!=(const istreambuf_iterator<charT,traits>& a, 3593e519524SHoward Hinnant const istreambuf_iterator<charT,traits>& b); 3603e519524SHoward Hinnant 3613e519524SHoward Hinnanttemplate <class charT, class traits = char_traits<charT> > 3623e519524SHoward Hinnantclass ostreambuf_iterator 3633e519524SHoward Hinnant : public iterator<output_iterator_tag, void, void, void, void> 3643e519524SHoward Hinnant{ 3653e519524SHoward Hinnantpublic: 3663e519524SHoward Hinnant typedef charT char_type; 3673e519524SHoward Hinnant typedef traits traits_type; 3683e519524SHoward Hinnant typedef basic_streambuf<charT,traits> streambuf_type; 3693e519524SHoward Hinnant typedef basic_ostream<charT,traits> ostream_type; 3703e519524SHoward Hinnant 3718e882dcbSHoward Hinnant ostreambuf_iterator(ostream_type& s) noexcept; 3728e882dcbSHoward Hinnant ostreambuf_iterator(streambuf_type* s) noexcept; 3733e519524SHoward Hinnant ostreambuf_iterator& operator=(charT c); 3743e519524SHoward Hinnant ostreambuf_iterator& operator*(); 3753e519524SHoward Hinnant ostreambuf_iterator& operator++(); 3763e519524SHoward Hinnant ostreambuf_iterator& operator++(int); 3778e882dcbSHoward Hinnant bool failed() const noexcept; 3783e519524SHoward Hinnant}; 3793e519524SHoward Hinnant 380020b623aSMarshall Clowtemplate <class C> constexpr auto begin(C& c) -> decltype(c.begin()); 381020b623aSMarshall Clowtemplate <class C> constexpr auto begin(const C& c) -> decltype(c.begin()); 382020b623aSMarshall Clowtemplate <class C> constexpr auto end(C& c) -> decltype(c.end()); 383020b623aSMarshall Clowtemplate <class C> constexpr auto end(const C& c) -> decltype(c.end()); 384020b623aSMarshall Clowtemplate <class T, size_t N> constexpr T* begin(T (&array)[N]); 385020b623aSMarshall Clowtemplate <class T, size_t N> constexpr T* end(T (&array)[N]); 3863e519524SHoward Hinnant 387020b623aSMarshall Clowtemplate <class C> auto constexpr cbegin(const C& c) -> decltype(std::begin(c)); // C++14 388020b623aSMarshall Clowtemplate <class C> auto constexpr cend(const C& c) -> decltype(std::end(c)); // C++14 389020b623aSMarshall Clowtemplate <class C> auto constexpr rbegin(C& c) -> decltype(c.rbegin()); // C++14 390020b623aSMarshall Clowtemplate <class C> auto constexpr rbegin(const C& c) -> decltype(c.rbegin()); // C++14 391020b623aSMarshall Clowtemplate <class C> auto constexpr rend(C& c) -> decltype(c.rend()); // C++14 392020b623aSMarshall Clowtemplate <class C> constexpr auto rend(const C& c) -> decltype(c.rend()); // C++14 393020b623aSMarshall Clowtemplate <class E> reverse_iterator<const E*> constexpr rbegin(initializer_list<E> il); // C++14 394020b623aSMarshall Clowtemplate <class E> reverse_iterator<const E*> constexpr rend(initializer_list<E> il); // C++14 395020b623aSMarshall Clowtemplate <class T, size_t N> reverse_iterator<T*> constexpr rbegin(T (&array)[N]); // C++14 396020b623aSMarshall Clowtemplate <class T, size_t N> reverse_iterator<T*> constexpr rend(T (&array)[N]); // C++14 397020b623aSMarshall Clowtemplate <class C> constexpr auto crbegin(const C& c) -> decltype(std::rbegin(c)); // C++14 398020b623aSMarshall Clowtemplate <class C> constexpr auto crend(const C& c) -> decltype(std::rend(c)); // C++14 3991e548c72SMarshall Clow 400ad755104SMarshall Clow// 24.8, container access: 401ad755104SMarshall Clowtemplate <class C> constexpr auto size(const C& c) -> decltype(c.size()); // C++17 402ad755104SMarshall Clowtemplate <class T, size_t N> constexpr size_t size(const T (&array)[N]) noexcept; // C++17 4037d3986eaSMarshall Clow 4047d3986eaSMarshall Clowtemplate <class C> constexpr auto ssize(const C& c) 4057d3986eaSMarshall Clow -> common_type_t<ptrdiff_t, make_signed_t<decltype(c.size())>>; // C++20 4067d3986eaSMarshall Clowtemplate <class T, ptrdiff_t> constexpr ptrdiff_t ssize(const T (&array)[N]) noexcept; // C++20 4077d3986eaSMarshall Clow 408ad755104SMarshall Clowtemplate <class C> constexpr auto empty(const C& c) -> decltype(c.empty()); // C++17 409ad755104SMarshall Clowtemplate <class T, size_t N> constexpr bool empty(const T (&array)[N]) noexcept; // C++17 410ad755104SMarshall Clowtemplate <class E> constexpr bool empty(initializer_list<E> il) noexcept; // C++17 411ad755104SMarshall Clowtemplate <class C> constexpr auto data(C& c) -> decltype(c.data()); // C++17 412ad755104SMarshall Clowtemplate <class C> constexpr auto data(const C& c) -> decltype(c.data()); // C++17 413ad755104SMarshall Clowtemplate <class T, size_t N> constexpr T* data(T (&array)[N]) noexcept; // C++17 414ad755104SMarshall Clowtemplate <class E> constexpr const E* data(initializer_list<E> il) noexcept; // C++17 415ad755104SMarshall Clow 4163e519524SHoward Hinnant} // std 4173e519524SHoward Hinnant 4183e519524SHoward Hinnant*/ 4193e519524SHoward Hinnant 4203e519524SHoward Hinnant#include <__config> 42139c193b1SEric Fiselier#include <iosfwd> // for forward declarations of vector and string. 422c204c130SMarshall Clow#include <__functional_base> 4233e519524SHoward Hinnant#include <type_traits> 4242d0f1fa4SArthur O'Dwyer#include <compare> 4252d0f1fa4SArthur O'Dwyer#include <concepts> 4263e519524SHoward Hinnant#include <cstddef> 4271e548c72SMarshall Clow#include <initializer_list> 428*f992cfbaSLouis Dionne#include <__memory/addressof.h> 429d41c6d51SArthur O'Dwyer#include <__memory/pointer_traits.h> 430f56972e2SMarshall Clow#include <version> 431fe31f11cSChristopher Di Bella#include <concepts> 432b5c63a2eSHoward Hinnant 43342a3046eSHoward Hinnant#include <__debug> 4343e519524SHoward Hinnant 435073458b1SHoward Hinnant#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) 4363e519524SHoward Hinnant#pragma GCC system_header 437073458b1SHoward Hinnant#endif 4383e519524SHoward Hinnant 4393e519524SHoward Hinnant_LIBCPP_BEGIN_NAMESPACE_STD 440fe31f11cSChristopher Di Bella 441fe31f11cSChristopher Di Bella#if !defined(_LIBCPP_HAS_NO_RANGES) 442fe31f11cSChristopher Di Bella// [incrementable.traits] 443fe31f11cSChristopher Di Bellatemplate<class> struct incrementable_traits {}; 444fe31f11cSChristopher Di Bella 445fe31f11cSChristopher Di Bellatemplate<class _Tp> 446fe31f11cSChristopher Di Bellarequires is_object_v<_Tp> 447fe31f11cSChristopher Di Bellastruct incrementable_traits<_Tp*> { 448fe31f11cSChristopher Di Bella using difference_type = ptrdiff_t; 449fe31f11cSChristopher Di Bella}; 450fe31f11cSChristopher Di Bella 451fe31f11cSChristopher Di Bellatemplate<class _Ip> 452fe31f11cSChristopher Di Bellastruct incrementable_traits<const _Ip> : incrementable_traits<_Ip> {}; 453fe31f11cSChristopher Di Bella 454fe31f11cSChristopher Di Bellatemplate<class _Tp> 455fe31f11cSChristopher Di Bellaconcept __has_member_difference_type = requires { typename _Tp::difference_type; }; 456fe31f11cSChristopher Di Bella 457fe31f11cSChristopher Di Bellatemplate<__has_member_difference_type _Tp> 458fe31f11cSChristopher Di Bellastruct incrementable_traits<_Tp> { 459fe31f11cSChristopher Di Bella using difference_type = typename _Tp::difference_type; 460fe31f11cSChristopher Di Bella}; 461fe31f11cSChristopher Di Bella 462fe31f11cSChristopher Di Bellatemplate<class _Tp> 463fe31f11cSChristopher Di Bellaconcept __has_integral_minus = 464fe31f11cSChristopher Di Bella requires(const _Tp& __x, const _Tp& __y) { 465fe31f11cSChristopher Di Bella { __x - __y } -> integral; 466fe31f11cSChristopher Di Bella }; 467fe31f11cSChristopher Di Bella 468fe31f11cSChristopher Di Bellatemplate<__has_integral_minus _Tp> 4690fcea419SChristopher Di Bellarequires (!__has_member_difference_type<_Tp>) 470fe31f11cSChristopher Di Bellastruct incrementable_traits<_Tp> { 471fe31f11cSChristopher Di Bella using difference_type = make_signed_t<decltype(declval<_Tp>() - declval<_Tp>())>; 472fe31f11cSChristopher Di Bella}; 473fe31f11cSChristopher Di Bella 474fe31f11cSChristopher Di Bella// TODO(cjdb): add iter_difference_t once iterator_traits is cleaned up. 475fe31f11cSChristopher Di Bella#endif // !defined(_LIBCPP_HAS_NO_RANGES) 476fe31f11cSChristopher Di Bella 4776624fcbaSEric Fiseliertemplate <class _Iter> 4786624fcbaSEric Fiselierstruct _LIBCPP_TEMPLATE_VIS iterator_traits; 4793e519524SHoward Hinnant 480e2f2d1edSEric Fiselierstruct _LIBCPP_TEMPLATE_VIS input_iterator_tag {}; 481e2f2d1edSEric Fiselierstruct _LIBCPP_TEMPLATE_VIS output_iterator_tag {}; 482e2f2d1edSEric Fiselierstruct _LIBCPP_TEMPLATE_VIS forward_iterator_tag : public input_iterator_tag {}; 483e2f2d1edSEric Fiselierstruct _LIBCPP_TEMPLATE_VIS bidirectional_iterator_tag : public forward_iterator_tag {}; 484e2f2d1edSEric Fiselierstruct _LIBCPP_TEMPLATE_VIS random_access_iterator_tag : public bidirectional_iterator_tag {}; 48545d048c2SEric Fiselier#if _LIBCPP_STD_VER > 17 48645d048c2SEric Fiselierstruct _LIBCPP_TEMPLATE_VIS contiguous_iterator_tag : public random_access_iterator_tag {}; 48745d048c2SEric Fiselier#endif 4883e519524SHoward Hinnant 4896624fcbaSEric Fiseliertemplate <class _Iter> 4906624fcbaSEric Fiselierstruct __iter_traits_cache { 4916624fcbaSEric Fiselier using type = _If< 4926624fcbaSEric Fiselier __is_primary_template<iterator_traits<_Iter> >::value, 4936624fcbaSEric Fiselier _Iter, 4946624fcbaSEric Fiselier iterator_traits<_Iter> 4956624fcbaSEric Fiselier >; 4966624fcbaSEric Fiselier}; 4976624fcbaSEric Fiseliertemplate <class _Iter> 4986624fcbaSEric Fiselierusing _ITER_TRAITS = typename __iter_traits_cache<_Iter>::type; 4996624fcbaSEric Fiselier 5006624fcbaSEric Fiselierstruct __iter_concept_concept_test { 5016624fcbaSEric Fiselier template <class _Iter> 5026624fcbaSEric Fiselier using _Apply = typename _ITER_TRAITS<_Iter>::iterator_concept; 5036624fcbaSEric Fiselier}; 5046624fcbaSEric Fiselierstruct __iter_concept_category_test { 5056624fcbaSEric Fiselier template <class _Iter> 5066624fcbaSEric Fiselier using _Apply = typename _ITER_TRAITS<_Iter>::iterator_category; 5076624fcbaSEric Fiselier}; 5086624fcbaSEric Fiselierstruct __iter_concept_random_fallback { 5096624fcbaSEric Fiselier template <class _Iter> 5106624fcbaSEric Fiselier using _Apply = _EnableIf< 5116624fcbaSEric Fiselier __is_primary_template<iterator_traits<_Iter> >::value, 5126624fcbaSEric Fiselier random_access_iterator_tag 5136624fcbaSEric Fiselier >; 5146624fcbaSEric Fiselier}; 5156624fcbaSEric Fiselier 5166624fcbaSEric Fiseliertemplate <class _Iter, class _Tester> struct __test_iter_concept 5176624fcbaSEric Fiselier : _IsValidExpansion<_Tester::template _Apply, _Iter>, 5186624fcbaSEric Fiselier _Tester 5196624fcbaSEric Fiselier{ 5206624fcbaSEric Fiselier}; 5216624fcbaSEric Fiselier 5226624fcbaSEric Fiseliertemplate <class _Iter> 5236624fcbaSEric Fiselierstruct __iter_concept_cache { 5246624fcbaSEric Fiselier using type = _Or< 5256624fcbaSEric Fiselier __test_iter_concept<_Iter, __iter_concept_concept_test>, 5266624fcbaSEric Fiselier __test_iter_concept<_Iter, __iter_concept_category_test>, 5276624fcbaSEric Fiselier __test_iter_concept<_Iter, __iter_concept_random_fallback> 5286624fcbaSEric Fiselier >; 5296624fcbaSEric Fiselier}; 5306624fcbaSEric Fiselier 5316624fcbaSEric Fiseliertemplate <class _Iter> 5326624fcbaSEric Fiselierusing _ITER_CONCEPT = typename __iter_concept_cache<_Iter>::type::template _Apply<_Iter>; 5336624fcbaSEric Fiselier 5346624fcbaSEric Fiselier 5353e519524SHoward Hinnanttemplate <class _Tp> 536d4fa0381SMarshall Clowstruct __has_iterator_typedefs 537d4fa0381SMarshall Clow{ 538d4fa0381SMarshall Clowprivate: 539d4fa0381SMarshall Clow struct __two {char __lx; char __lxx;}; 540d4fa0381SMarshall Clow template <class _Up> static __two __test(...); 541d586f92cSArthur O'Dwyer template <class _Up> static char __test(typename __void_t<typename _Up::iterator_category>::type* = 0, 542d586f92cSArthur O'Dwyer typename __void_t<typename _Up::difference_type>::type* = 0, 543d586f92cSArthur O'Dwyer typename __void_t<typename _Up::value_type>::type* = 0, 544d586f92cSArthur O'Dwyer typename __void_t<typename _Up::reference>::type* = 0, 545d586f92cSArthur O'Dwyer typename __void_t<typename _Up::pointer>::type* = 0); 546d4fa0381SMarshall Clowpublic: 547d4fa0381SMarshall Clow static const bool value = sizeof(__test<_Tp>(0,0,0,0,0)) == 1; 548d4fa0381SMarshall Clow}; 549d4fa0381SMarshall Clow 550d4fa0381SMarshall Clow 551d4fa0381SMarshall Clowtemplate <class _Tp> 5523e519524SHoward Hinnantstruct __has_iterator_category 5533e519524SHoward Hinnant{ 5543e519524SHoward Hinnantprivate: 55554d333a6SHoward Hinnant struct __two {char __lx; char __lxx;}; 5563e519524SHoward Hinnant template <class _Up> static __two __test(...); 557527a7fdfSBruce Mitchener template <class _Up> static char __test(typename _Up::iterator_category* = nullptr); 5583e519524SHoward Hinnantpublic: 559527a7fdfSBruce Mitchener static const bool value = sizeof(__test<_Tp>(nullptr)) == 1; 5603e519524SHoward Hinnant}; 5613e519524SHoward Hinnant 562d41c6d51SArthur O'Dwyertemplate <class _Tp> 563d41c6d51SArthur O'Dwyerstruct __has_iterator_concept 564d41c6d51SArthur O'Dwyer{ 565d41c6d51SArthur O'Dwyerprivate: 566d41c6d51SArthur O'Dwyer struct __two {char __lx; char __lxx;}; 567d41c6d51SArthur O'Dwyer template <class _Up> static __two __test(...); 568d41c6d51SArthur O'Dwyer template <class _Up> static char __test(typename _Up::iterator_concept* = nullptr); 569d41c6d51SArthur O'Dwyerpublic: 570d41c6d51SArthur O'Dwyer static const bool value = sizeof(__test<_Tp>(nullptr)) == 1; 571d41c6d51SArthur O'Dwyer}; 572d41c6d51SArthur O'Dwyer 5730724bf67SMarshall Clowtemplate <class _Iter, bool> struct __iterator_traits_impl {}; 5743e519524SHoward Hinnant 5753e519524SHoward Hinnanttemplate <class _Iter> 5760724bf67SMarshall Clowstruct __iterator_traits_impl<_Iter, true> 5773e519524SHoward Hinnant{ 5783e519524SHoward Hinnant typedef typename _Iter::difference_type difference_type; 5793e519524SHoward Hinnant typedef typename _Iter::value_type value_type; 5803e519524SHoward Hinnant typedef typename _Iter::pointer pointer; 5813e519524SHoward Hinnant typedef typename _Iter::reference reference; 5823e519524SHoward Hinnant typedef typename _Iter::iterator_category iterator_category; 5833e519524SHoward Hinnant}; 5843e519524SHoward Hinnant 5853e519524SHoward Hinnanttemplate <class _Iter, bool> struct __iterator_traits {}; 5863e519524SHoward Hinnant 5873e519524SHoward Hinnanttemplate <class _Iter> 5883e519524SHoward Hinnantstruct __iterator_traits<_Iter, true> 5890724bf67SMarshall Clow : __iterator_traits_impl 5903e519524SHoward Hinnant < 5913e519524SHoward Hinnant _Iter, 5923e519524SHoward Hinnant is_convertible<typename _Iter::iterator_category, input_iterator_tag>::value || 5933e519524SHoward Hinnant is_convertible<typename _Iter::iterator_category, output_iterator_tag>::value 5943e519524SHoward Hinnant > 5953e519524SHoward Hinnant{}; 5963e519524SHoward Hinnant 5973e519524SHoward Hinnant// iterator_traits<Iterator> will only have the nested types if Iterator::iterator_category 5983e519524SHoward Hinnant// exists. Else iterator_traits<Iterator> will be an empty class. This is a 5993e519524SHoward Hinnant// conforming extension which allows some programs to compile and behave as 6003e519524SHoward Hinnant// the client expects instead of failing at compile time. 6013e519524SHoward Hinnant 6023e519524SHoward Hinnanttemplate <class _Iter> 603e2f2d1edSEric Fiselierstruct _LIBCPP_TEMPLATE_VIS iterator_traits 6046624fcbaSEric Fiselier : __iterator_traits<_Iter, __has_iterator_typedefs<_Iter>::value> { 6056624fcbaSEric Fiselier 6066624fcbaSEric Fiselier using __primary_template = iterator_traits; 6076624fcbaSEric Fiselier}; 6083e519524SHoward Hinnant 6093e519524SHoward Hinnanttemplate<class _Tp> 610e2f2d1edSEric Fiselierstruct _LIBCPP_TEMPLATE_VIS iterator_traits<_Tp*> 6113e519524SHoward Hinnant{ 6123e519524SHoward Hinnant typedef ptrdiff_t difference_type; 613ffcfd923SMarshall Clow typedef typename remove_cv<_Tp>::type value_type; 6143e519524SHoward Hinnant typedef _Tp* pointer; 6153e519524SHoward Hinnant typedef _Tp& reference; 6163e519524SHoward Hinnant typedef random_access_iterator_tag iterator_category; 61745d048c2SEric Fiselier#if _LIBCPP_STD_VER > 17 61845d048c2SEric Fiselier typedef contiguous_iterator_tag iterator_concept; 61945d048c2SEric Fiselier#endif 6203e519524SHoward Hinnant}; 6213e519524SHoward Hinnant 6223e519524SHoward Hinnanttemplate <class _Tp, class _Up, bool = __has_iterator_category<iterator_traits<_Tp> >::value> 6233e519524SHoward Hinnantstruct __has_iterator_category_convertible_to 624d41c6d51SArthur O'Dwyer : _BoolConstant<is_convertible<typename iterator_traits<_Tp>::iterator_category, _Up>::value> 6253e519524SHoward Hinnant{}; 6263e519524SHoward Hinnant 6273e519524SHoward Hinnanttemplate <class _Tp, class _Up> 628d41c6d51SArthur O'Dwyerstruct __has_iterator_category_convertible_to<_Tp, _Up, false> : false_type {}; 629d41c6d51SArthur O'Dwyer 630d41c6d51SArthur O'Dwyertemplate <class _Tp, class _Up, bool = __has_iterator_concept<_Tp>::value> 631d41c6d51SArthur O'Dwyerstruct __has_iterator_concept_convertible_to 632d41c6d51SArthur O'Dwyer : _BoolConstant<is_convertible<typename _Tp::iterator_concept, _Up>::value> 633d41c6d51SArthur O'Dwyer{}; 634d41c6d51SArthur O'Dwyer 635d41c6d51SArthur O'Dwyertemplate <class _Tp, class _Up> 636d41c6d51SArthur O'Dwyerstruct __has_iterator_concept_convertible_to<_Tp, _Up, false> : false_type {}; 6373e519524SHoward Hinnant 6383e519524SHoward Hinnanttemplate <class _Tp> 639f82dba01SEric Fiselierstruct __is_cpp17_input_iterator : public __has_iterator_category_convertible_to<_Tp, input_iterator_tag> {}; 6403e519524SHoward Hinnant 6413e519524SHoward Hinnanttemplate <class _Tp> 642f82dba01SEric Fiselierstruct __is_cpp17_forward_iterator : public __has_iterator_category_convertible_to<_Tp, forward_iterator_tag> {}; 6433e519524SHoward Hinnant 6443e519524SHoward Hinnanttemplate <class _Tp> 645f82dba01SEric Fiselierstruct __is_cpp17_bidirectional_iterator : public __has_iterator_category_convertible_to<_Tp, bidirectional_iterator_tag> {}; 6463e519524SHoward Hinnant 6473e519524SHoward Hinnanttemplate <class _Tp> 648f82dba01SEric Fiselierstruct __is_cpp17_random_access_iterator : public __has_iterator_category_convertible_to<_Tp, random_access_iterator_tag> {}; 6493e519524SHoward Hinnant 650d41c6d51SArthur O'Dwyer// __is_cpp17_contiguous_iterator determines if an iterator is contiguous, 651d41c6d51SArthur O'Dwyer// either because it advertises itself as such (in C++20) or because it 652d41c6d51SArthur O'Dwyer// is a pointer type or a known trivial wrapper around a pointer type, 653d41c6d51SArthur O'Dwyer// such as __wrap_iter<T*>. 654d41c6d51SArthur O'Dwyer// 65545d048c2SEric Fiselier#if _LIBCPP_STD_VER > 17 65645d048c2SEric Fiseliertemplate <class _Tp> 657d41c6d51SArthur O'Dwyerstruct __is_cpp17_contiguous_iterator : _Or< 658d41c6d51SArthur O'Dwyer __has_iterator_category_convertible_to<_Tp, contiguous_iterator_tag>, 659d41c6d51SArthur O'Dwyer __has_iterator_concept_convertible_to<_Tp, contiguous_iterator_tag> 660d41c6d51SArthur O'Dwyer> {}; 661f82dba01SEric Fiselier#else 662f82dba01SEric Fiseliertemplate <class _Tp> 663d41c6d51SArthur O'Dwyerstruct __is_cpp17_contiguous_iterator : false_type {}; 66445d048c2SEric Fiselier#endif 66545d048c2SEric Fiselier 666d41c6d51SArthur O'Dwyer// Any native pointer which is an iterator is also a contiguous iterator. 667d41c6d51SArthur O'Dwyertemplate <class _Up> 668d41c6d51SArthur O'Dwyerstruct __is_cpp17_contiguous_iterator<_Up*> : true_type {}; 669d41c6d51SArthur O'Dwyer 670f82dba01SEric Fiselier 67176b4afc0SMarshall Clowtemplate <class _Tp> 672f82dba01SEric Fiselierstruct __is_exactly_cpp17_input_iterator 67376b4afc0SMarshall Clow : public integral_constant<bool, 67476b4afc0SMarshall Clow __has_iterator_category_convertible_to<_Tp, input_iterator_tag>::value && 67576b4afc0SMarshall Clow !__has_iterator_category_convertible_to<_Tp, forward_iterator_tag>::value> {}; 67676b4afc0SMarshall Clow 677f2f7d72fSLouis Dionne#ifndef _LIBCPP_HAS_NO_DEDUCTION_GUIDES 678f2f7d72fSLouis Dionnetemplate<class _InputIterator> 679f2f7d72fSLouis Dionneusing __iter_value_type = typename iterator_traits<_InputIterator>::value_type; 680f2f7d72fSLouis Dionne 681f2f7d72fSLouis Dionnetemplate<class _InputIterator> 682f2f7d72fSLouis Dionneusing __iter_key_type = remove_const_t<typename iterator_traits<_InputIterator>::value_type::first_type>; 683f2f7d72fSLouis Dionne 684f2f7d72fSLouis Dionnetemplate<class _InputIterator> 685f2f7d72fSLouis Dionneusing __iter_mapped_type = typename iterator_traits<_InputIterator>::value_type::second_type; 686f2f7d72fSLouis Dionne 687f2f7d72fSLouis Dionnetemplate<class _InputIterator> 688f2f7d72fSLouis Dionneusing __iter_to_alloc_type = pair< 689f2f7d72fSLouis Dionne add_const_t<typename iterator_traits<_InputIterator>::value_type::first_type>, 690f2f7d72fSLouis Dionne typename iterator_traits<_InputIterator>::value_type::second_type>; 691f2f7d72fSLouis Dionne#endif 692f2f7d72fSLouis Dionne 6933e519524SHoward Hinnanttemplate<class _Category, class _Tp, class _Distance = ptrdiff_t, 6943e519524SHoward Hinnant class _Pointer = _Tp*, class _Reference = _Tp&> 695e2f2d1edSEric Fiselierstruct _LIBCPP_TEMPLATE_VIS iterator 6963e519524SHoward Hinnant{ 6973e519524SHoward Hinnant typedef _Tp value_type; 6983e519524SHoward Hinnant typedef _Distance difference_type; 6993e519524SHoward Hinnant typedef _Pointer pointer; 7003e519524SHoward Hinnant typedef _Reference reference; 7013e519524SHoward Hinnant typedef _Category iterator_category; 7023e519524SHoward Hinnant}; 7033e519524SHoward Hinnant 7043e519524SHoward Hinnanttemplate <class _InputIter> 705f51ee632SMarshall Clowinline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 7063e519524SHoward Hinnantvoid __advance(_InputIter& __i, 7073e519524SHoward Hinnant typename iterator_traits<_InputIter>::difference_type __n, input_iterator_tag) 7083e519524SHoward Hinnant{ 7093e519524SHoward Hinnant for (; __n > 0; --__n) 7103e519524SHoward Hinnant ++__i; 7113e519524SHoward Hinnant} 7123e519524SHoward Hinnant 7133e519524SHoward Hinnanttemplate <class _BiDirIter> 714f51ee632SMarshall Clowinline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 7153e519524SHoward Hinnantvoid __advance(_BiDirIter& __i, 7163e519524SHoward Hinnant typename iterator_traits<_BiDirIter>::difference_type __n, bidirectional_iterator_tag) 7173e519524SHoward Hinnant{ 7183e519524SHoward Hinnant if (__n >= 0) 7193e519524SHoward Hinnant for (; __n > 0; --__n) 7203e519524SHoward Hinnant ++__i; 7213e519524SHoward Hinnant else 7223e519524SHoward Hinnant for (; __n < 0; ++__n) 7233e519524SHoward Hinnant --__i; 7243e519524SHoward Hinnant} 7253e519524SHoward Hinnant 7263e519524SHoward Hinnanttemplate <class _RandIter> 727f51ee632SMarshall Clowinline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 7283e519524SHoward Hinnantvoid __advance(_RandIter& __i, 7293e519524SHoward Hinnant typename iterator_traits<_RandIter>::difference_type __n, random_access_iterator_tag) 7303e519524SHoward Hinnant{ 7313e519524SHoward Hinnant __i += __n; 7323e519524SHoward Hinnant} 7333e519524SHoward Hinnant 73412b01ab7SLouis Dionnetemplate <class _InputIter, class _Distance> 735f51ee632SMarshall Clowinline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 73612b01ab7SLouis Dionnevoid advance(_InputIter& __i, _Distance __orig_n) 7373e519524SHoward Hinnant{ 73812b01ab7SLouis Dionne _LIBCPP_ASSERT(__orig_n >= 0 || __is_cpp17_bidirectional_iterator<_InputIter>::value, 73912b01ab7SLouis Dionne "Attempt to advance(it, n) with negative n on a non-bidirectional iterator"); 740c0428b3cSArthur O'Dwyer typedef decltype(_VSTD::__convert_to_integral(__orig_n)) _IntegralSize; 74112b01ab7SLouis Dionne _IntegralSize __n = __orig_n; 742c0428b3cSArthur O'Dwyer _VSTD::__advance(__i, __n, typename iterator_traits<_InputIter>::iterator_category()); 7433e519524SHoward Hinnant} 7443e519524SHoward Hinnant 7453e519524SHoward Hinnanttemplate <class _InputIter> 746f51ee632SMarshall Clowinline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 7473e519524SHoward Hinnanttypename iterator_traits<_InputIter>::difference_type 7483e519524SHoward Hinnant__distance(_InputIter __first, _InputIter __last, input_iterator_tag) 7493e519524SHoward Hinnant{ 7503e519524SHoward Hinnant typename iterator_traits<_InputIter>::difference_type __r(0); 7513e519524SHoward Hinnant for (; __first != __last; ++__first) 7523e519524SHoward Hinnant ++__r; 7533e519524SHoward Hinnant return __r; 7543e519524SHoward Hinnant} 7553e519524SHoward Hinnant 7563e519524SHoward Hinnanttemplate <class _RandIter> 757f51ee632SMarshall Clowinline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 7583e519524SHoward Hinnanttypename iterator_traits<_RandIter>::difference_type 7593e519524SHoward Hinnant__distance(_RandIter __first, _RandIter __last, random_access_iterator_tag) 7603e519524SHoward Hinnant{ 7613e519524SHoward Hinnant return __last - __first; 7623e519524SHoward Hinnant} 7633e519524SHoward Hinnant 7643e519524SHoward Hinnanttemplate <class _InputIter> 765f51ee632SMarshall Clowinline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 7663e519524SHoward Hinnanttypename iterator_traits<_InputIter>::difference_type 7673e519524SHoward Hinnantdistance(_InputIter __first, _InputIter __last) 7683e519524SHoward Hinnant{ 769c0428b3cSArthur O'Dwyer return _VSTD::__distance(__first, __last, typename iterator_traits<_InputIter>::iterator_category()); 7703e519524SHoward Hinnant} 7713e519524SHoward Hinnant 772e5f1288fSMarshall Clowtemplate <class _InputIter> 773f51ee632SMarshall Clowinline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 7743e2ef408SRachel Craiktypename enable_if 7753e2ef408SRachel Craik< 776f82dba01SEric Fiselier __is_cpp17_input_iterator<_InputIter>::value, 777e5f1288fSMarshall Clow _InputIter 7783e2ef408SRachel Craik>::type 779e5f1288fSMarshall Clownext(_InputIter __x, 7803e2ef408SRachel Craik typename iterator_traits<_InputIter>::difference_type __n = 1) 7813e519524SHoward Hinnant{ 782f82dba01SEric Fiselier _LIBCPP_ASSERT(__n >= 0 || __is_cpp17_bidirectional_iterator<_InputIter>::value, 78312b01ab7SLouis Dionne "Attempt to next(it, n) with negative n on a non-bidirectional iterator"); 784e1cd11d8SMarshall Clow 785ce48a113SHoward Hinnant _VSTD::advance(__x, __n); 7863e519524SHoward Hinnant return __x; 7873e519524SHoward Hinnant} 7883e519524SHoward Hinnant 789e1cd11d8SMarshall Clowtemplate <class _InputIter> 790f51ee632SMarshall Clowinline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 7913e2ef408SRachel Craiktypename enable_if 7923e2ef408SRachel Craik< 793f82dba01SEric Fiselier __is_cpp17_input_iterator<_InputIter>::value, 794e1cd11d8SMarshall Clow _InputIter 7953e2ef408SRachel Craik>::type 796e1cd11d8SMarshall Clowprev(_InputIter __x, 797e1cd11d8SMarshall Clow typename iterator_traits<_InputIter>::difference_type __n = 1) 7983e519524SHoward Hinnant{ 799f82dba01SEric Fiselier _LIBCPP_ASSERT(__n <= 0 || __is_cpp17_bidirectional_iterator<_InputIter>::value, 80012b01ab7SLouis Dionne "Attempt to prev(it, n) with a positive n on a non-bidirectional iterator"); 801ce48a113SHoward Hinnant _VSTD::advance(__x, -__n); 8023e519524SHoward Hinnant return __x; 8033e519524SHoward Hinnant} 8043e519524SHoward Hinnant 805e02ed1c2SEric Fiselier 806e02ed1c2SEric Fiseliertemplate <class _Tp, class = void> 807e02ed1c2SEric Fiselierstruct __is_stashing_iterator : false_type {}; 808e02ed1c2SEric Fiselier 809e02ed1c2SEric Fiseliertemplate <class _Tp> 810e02ed1c2SEric Fiselierstruct __is_stashing_iterator<_Tp, typename __void_t<typename _Tp::__stashing_iterator_tag>::type> 811e02ed1c2SEric Fiselier : true_type {}; 812e02ed1c2SEric Fiselier 8133e519524SHoward Hinnanttemplate <class _Iter> 814e2f2d1edSEric Fiselierclass _LIBCPP_TEMPLATE_VIS reverse_iterator 8153e519524SHoward Hinnant : public iterator<typename iterator_traits<_Iter>::iterator_category, 8163e519524SHoward Hinnant typename iterator_traits<_Iter>::value_type, 8173e519524SHoward Hinnant typename iterator_traits<_Iter>::difference_type, 8183e519524SHoward Hinnant typename iterator_traits<_Iter>::pointer, 8193e519524SHoward Hinnant typename iterator_traits<_Iter>::reference> 8203e519524SHoward Hinnant{ 8213b83496dSMarshall Clowprivate: 8221b8f260eSMarshall Clow /*mutable*/ _Iter __t; // no longer used as of LWG #2360, not removed due to ABI break 823e02ed1c2SEric Fiselier 824e02ed1c2SEric Fiselier static_assert(!__is_stashing_iterator<_Iter>::value, 825e02ed1c2SEric Fiselier "The specified iterator type cannot be used with reverse_iterator; " 826e02ed1c2SEric Fiselier "Using stashing iterators with reverse_iterator causes undefined behavior"); 827e02ed1c2SEric Fiselier 828b2d74f29SMarshall Clowprotected: 829b2d74f29SMarshall Clow _Iter current; 8303e519524SHoward Hinnantpublic: 8313e519524SHoward Hinnant typedef _Iter iterator_type; 8323e519524SHoward Hinnant typedef typename iterator_traits<_Iter>::difference_type difference_type; 8333e519524SHoward Hinnant typedef typename iterator_traits<_Iter>::reference reference; 8343e519524SHoward Hinnant typedef typename iterator_traits<_Iter>::pointer pointer; 835d41c6d51SArthur O'Dwyer typedef _If<__is_cpp17_random_access_iterator<_Iter>::value, 836d41c6d51SArthur O'Dwyer random_access_iterator_tag, 837d41c6d51SArthur O'Dwyer typename iterator_traits<_Iter>::iterator_category> iterator_category; 838d41c6d51SArthur O'Dwyer#if _LIBCPP_STD_VER > 17 839d41c6d51SArthur O'Dwyer typedef _If<__is_cpp17_random_access_iterator<_Iter>::value, 840d41c6d51SArthur O'Dwyer random_access_iterator_tag, 841d41c6d51SArthur O'Dwyer bidirectional_iterator_tag> iterator_concept; 842d41c6d51SArthur O'Dwyer#endif 8433e519524SHoward Hinnant 8441b8f260eSMarshall Clow _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 8451b8f260eSMarshall Clow reverse_iterator() : __t(), current() {} 8461b8f260eSMarshall Clow _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 8471b8f260eSMarshall Clow explicit reverse_iterator(_Iter __x) : __t(__x), current(__x) {} 8481b8f260eSMarshall Clow template <class _Up> 8491b8f260eSMarshall Clow _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 8501b8f260eSMarshall Clow reverse_iterator(const reverse_iterator<_Up>& __u) : __t(__u.base()), current(__u.base()) {} 8511b8f260eSMarshall Clow template <class _Up> 8521b8f260eSMarshall Clow _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 8531b8f260eSMarshall Clow reverse_iterator& operator=(const reverse_iterator<_Up>& __u) 8541b8f260eSMarshall Clow { __t = current = __u.base(); return *this; } 8551b8f260eSMarshall Clow _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 8561b8f260eSMarshall Clow _Iter base() const {return current;} 8571b8f260eSMarshall Clow _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 8581b8f260eSMarshall Clow reference operator*() const {_Iter __tmp = current; return *--__tmp;} 8591b8f260eSMarshall Clow _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 8601b8f260eSMarshall Clow pointer operator->() const {return _VSTD::addressof(operator*());} 8611b8f260eSMarshall Clow _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 8621b8f260eSMarshall Clow reverse_iterator& operator++() {--current; return *this;} 8631b8f260eSMarshall Clow _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 8641b8f260eSMarshall Clow reverse_iterator operator++(int) {reverse_iterator __tmp(*this); --current; return __tmp;} 8651b8f260eSMarshall Clow _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 8661b8f260eSMarshall Clow reverse_iterator& operator--() {++current; return *this;} 8671b8f260eSMarshall Clow _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 8681b8f260eSMarshall Clow reverse_iterator operator--(int) {reverse_iterator __tmp(*this); ++current; return __tmp;} 8691b8f260eSMarshall Clow _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 8701b8f260eSMarshall Clow reverse_iterator operator+ (difference_type __n) const {return reverse_iterator(current - __n);} 8711b8f260eSMarshall Clow _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 8721b8f260eSMarshall Clow reverse_iterator& operator+=(difference_type __n) {current -= __n; return *this;} 8731b8f260eSMarshall Clow _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 8741b8f260eSMarshall Clow reverse_iterator operator- (difference_type __n) const {return reverse_iterator(current + __n);} 8751b8f260eSMarshall Clow _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 8761b8f260eSMarshall Clow reverse_iterator& operator-=(difference_type __n) {current += __n; return *this;} 8771b8f260eSMarshall Clow _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 8781b8f260eSMarshall Clow reference operator[](difference_type __n) const {return *(*this + __n);} 8793e519524SHoward Hinnant}; 8803e519524SHoward Hinnant 8813e519524SHoward Hinnanttemplate <class _Iter1, class _Iter2> 8821b8f260eSMarshall Clowinline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 8833e519524SHoward Hinnantbool 8843e519524SHoward Hinnantoperator==(const reverse_iterator<_Iter1>& __x, const reverse_iterator<_Iter2>& __y) 8853e519524SHoward Hinnant{ 8863e519524SHoward Hinnant return __x.base() == __y.base(); 8873e519524SHoward Hinnant} 8883e519524SHoward Hinnant 8893e519524SHoward Hinnanttemplate <class _Iter1, class _Iter2> 8901b8f260eSMarshall Clowinline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 8913e519524SHoward Hinnantbool 8923e519524SHoward Hinnantoperator<(const reverse_iterator<_Iter1>& __x, const reverse_iterator<_Iter2>& __y) 8933e519524SHoward Hinnant{ 8943e519524SHoward Hinnant return __x.base() > __y.base(); 8953e519524SHoward Hinnant} 8963e519524SHoward Hinnant 8973e519524SHoward Hinnanttemplate <class _Iter1, class _Iter2> 8981b8f260eSMarshall Clowinline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 8993e519524SHoward Hinnantbool 9003e519524SHoward Hinnantoperator!=(const reverse_iterator<_Iter1>& __x, const reverse_iterator<_Iter2>& __y) 9013e519524SHoward Hinnant{ 9023e519524SHoward Hinnant return __x.base() != __y.base(); 9033e519524SHoward Hinnant} 9043e519524SHoward Hinnant 9053e519524SHoward Hinnanttemplate <class _Iter1, class _Iter2> 9061b8f260eSMarshall Clowinline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 9073e519524SHoward Hinnantbool 9083e519524SHoward Hinnantoperator>(const reverse_iterator<_Iter1>& __x, const reverse_iterator<_Iter2>& __y) 9093e519524SHoward Hinnant{ 9103e519524SHoward Hinnant return __x.base() < __y.base(); 9113e519524SHoward Hinnant} 9123e519524SHoward Hinnant 9133e519524SHoward Hinnanttemplate <class _Iter1, class _Iter2> 9141b8f260eSMarshall Clowinline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 9153e519524SHoward Hinnantbool 9163e519524SHoward Hinnantoperator>=(const reverse_iterator<_Iter1>& __x, const reverse_iterator<_Iter2>& __y) 9173e519524SHoward Hinnant{ 9183e519524SHoward Hinnant return __x.base() <= __y.base(); 9193e519524SHoward Hinnant} 9203e519524SHoward Hinnant 9213e519524SHoward Hinnanttemplate <class _Iter1, class _Iter2> 9221b8f260eSMarshall Clowinline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 9233e519524SHoward Hinnantbool 9243e519524SHoward Hinnantoperator<=(const reverse_iterator<_Iter1>& __x, const reverse_iterator<_Iter2>& __y) 9253e519524SHoward Hinnant{ 9263e519524SHoward Hinnant return __x.base() >= __y.base(); 9273e519524SHoward Hinnant} 9283e519524SHoward Hinnant 9292ee83725SMarshall Clow#ifndef _LIBCPP_CXX03_LANG 930947ce6b5SMarshall Clowtemplate <class _Iter1, class _Iter2> 9311b8f260eSMarshall Clowinline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 932947ce6b5SMarshall Clowauto 933947ce6b5SMarshall Clowoperator-(const reverse_iterator<_Iter1>& __x, const reverse_iterator<_Iter2>& __y) 934947ce6b5SMarshall Clow-> decltype(__y.base() - __x.base()) 935947ce6b5SMarshall Clow{ 936947ce6b5SMarshall Clow return __y.base() - __x.base(); 937947ce6b5SMarshall Clow} 938947ce6b5SMarshall Clow#else 9393e519524SHoward Hinnanttemplate <class _Iter1, class _Iter2> 9403e519524SHoward Hinnantinline _LIBCPP_INLINE_VISIBILITY 9413e519524SHoward Hinnanttypename reverse_iterator<_Iter1>::difference_type 9423e519524SHoward Hinnantoperator-(const reverse_iterator<_Iter1>& __x, const reverse_iterator<_Iter2>& __y) 9433e519524SHoward Hinnant{ 9443e519524SHoward Hinnant return __y.base() - __x.base(); 9453e519524SHoward Hinnant} 946947ce6b5SMarshall Clow#endif 9473e519524SHoward Hinnant 9483e519524SHoward Hinnanttemplate <class _Iter> 9491b8f260eSMarshall Clowinline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 9503e519524SHoward Hinnantreverse_iterator<_Iter> 9513e519524SHoward Hinnantoperator+(typename reverse_iterator<_Iter>::difference_type __n, const reverse_iterator<_Iter>& __x) 9523e519524SHoward Hinnant{ 9533e519524SHoward Hinnant return reverse_iterator<_Iter>(__x.base() - __n); 9543e519524SHoward Hinnant} 9553e519524SHoward Hinnant 9566a640a18SMarshall Clow#if _LIBCPP_STD_VER > 11 9576a640a18SMarshall Clowtemplate <class _Iter> 9581b8f260eSMarshall Clowinline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 9596a640a18SMarshall Clowreverse_iterator<_Iter> make_reverse_iterator(_Iter __i) 9606a640a18SMarshall Clow{ 9616a640a18SMarshall Clow return reverse_iterator<_Iter>(__i); 9626a640a18SMarshall Clow} 9636a640a18SMarshall Clow#endif 9646a640a18SMarshall Clow 9653e519524SHoward Hinnanttemplate <class _Container> 966e2f2d1edSEric Fiselierclass _LIBCPP_TEMPLATE_VIS back_insert_iterator 9673e519524SHoward Hinnant : public iterator<output_iterator_tag, 9683e519524SHoward Hinnant void, 9693e519524SHoward Hinnant void, 9703e519524SHoward Hinnant void, 9718892b4eeSEric Fiselier void> 9723e519524SHoward Hinnant{ 9733e519524SHoward Hinnantprotected: 9743e519524SHoward Hinnant _Container* container; 9753e519524SHoward Hinnantpublic: 9763e519524SHoward Hinnant typedef _Container container_type; 9773e519524SHoward Hinnant 97806e2b737SArthur O'Dwyer _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 explicit back_insert_iterator(_Container& __x) : container(_VSTD::addressof(__x)) {} 97906e2b737SArthur O'Dwyer _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 back_insert_iterator& operator=(const typename _Container::value_type& __value_) 980e4383379SHoward Hinnant {container->push_back(__value_); return *this;} 981046492b9SEric Fiselier#ifndef _LIBCPP_CXX03_LANG 98206e2b737SArthur O'Dwyer _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 back_insert_iterator& operator=(typename _Container::value_type&& __value_) 983e4383379SHoward Hinnant {container->push_back(_VSTD::move(__value_)); return *this;} 984046492b9SEric Fiselier#endif // _LIBCPP_CXX03_LANG 98506e2b737SArthur O'Dwyer _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 back_insert_iterator& operator*() {return *this;} 98606e2b737SArthur O'Dwyer _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 back_insert_iterator& operator++() {return *this;} 98706e2b737SArthur O'Dwyer _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 back_insert_iterator operator++(int) {return *this;} 9883e519524SHoward Hinnant}; 9893e519524SHoward Hinnant 9903e519524SHoward Hinnanttemplate <class _Container> 99106e2b737SArthur O'Dwyerinline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 9923e519524SHoward Hinnantback_insert_iterator<_Container> 9933e519524SHoward Hinnantback_inserter(_Container& __x) 9943e519524SHoward Hinnant{ 9953e519524SHoward Hinnant return back_insert_iterator<_Container>(__x); 9963e519524SHoward Hinnant} 9973e519524SHoward Hinnant 9983e519524SHoward Hinnanttemplate <class _Container> 999e2f2d1edSEric Fiselierclass _LIBCPP_TEMPLATE_VIS front_insert_iterator 10003e519524SHoward Hinnant : public iterator<output_iterator_tag, 10013e519524SHoward Hinnant void, 10023e519524SHoward Hinnant void, 10033e519524SHoward Hinnant void, 10048892b4eeSEric Fiselier void> 10053e519524SHoward Hinnant{ 10063e519524SHoward Hinnantprotected: 10073e519524SHoward Hinnant _Container* container; 10083e519524SHoward Hinnantpublic: 10093e519524SHoward Hinnant typedef _Container container_type; 10103e519524SHoward Hinnant 101106e2b737SArthur O'Dwyer _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 explicit front_insert_iterator(_Container& __x) : container(_VSTD::addressof(__x)) {} 101206e2b737SArthur O'Dwyer _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 front_insert_iterator& operator=(const typename _Container::value_type& __value_) 1013e4383379SHoward Hinnant {container->push_front(__value_); return *this;} 1014046492b9SEric Fiselier#ifndef _LIBCPP_CXX03_LANG 101506e2b737SArthur O'Dwyer _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 front_insert_iterator& operator=(typename _Container::value_type&& __value_) 1016e4383379SHoward Hinnant {container->push_front(_VSTD::move(__value_)); return *this;} 1017046492b9SEric Fiselier#endif // _LIBCPP_CXX03_LANG 101806e2b737SArthur O'Dwyer _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 front_insert_iterator& operator*() {return *this;} 101906e2b737SArthur O'Dwyer _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 front_insert_iterator& operator++() {return *this;} 102006e2b737SArthur O'Dwyer _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 front_insert_iterator operator++(int) {return *this;} 10213e519524SHoward Hinnant}; 10223e519524SHoward Hinnant 10233e519524SHoward Hinnanttemplate <class _Container> 102406e2b737SArthur O'Dwyerinline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 10253e519524SHoward Hinnantfront_insert_iterator<_Container> 10263e519524SHoward Hinnantfront_inserter(_Container& __x) 10273e519524SHoward Hinnant{ 10283e519524SHoward Hinnant return front_insert_iterator<_Container>(__x); 10293e519524SHoward Hinnant} 10303e519524SHoward Hinnant 10313e519524SHoward Hinnanttemplate <class _Container> 1032e2f2d1edSEric Fiselierclass _LIBCPP_TEMPLATE_VIS insert_iterator 10333e519524SHoward Hinnant : public iterator<output_iterator_tag, 10343e519524SHoward Hinnant void, 10353e519524SHoward Hinnant void, 10363e519524SHoward Hinnant void, 10378892b4eeSEric Fiselier void> 10383e519524SHoward Hinnant{ 10393e519524SHoward Hinnantprotected: 10403e519524SHoward Hinnant _Container* container; 10413e519524SHoward Hinnant typename _Container::iterator iter; 10423e519524SHoward Hinnantpublic: 10433e519524SHoward Hinnant typedef _Container container_type; 10443e519524SHoward Hinnant 104506e2b737SArthur O'Dwyer _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 insert_iterator(_Container& __x, typename _Container::iterator __i) 1046f519be34SMarshall Clow : container(_VSTD::addressof(__x)), iter(__i) {} 104706e2b737SArthur O'Dwyer _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 insert_iterator& operator=(const typename _Container::value_type& __value_) 1048e4383379SHoward Hinnant {iter = container->insert(iter, __value_); ++iter; return *this;} 1049046492b9SEric Fiselier#ifndef _LIBCPP_CXX03_LANG 105006e2b737SArthur O'Dwyer _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 insert_iterator& operator=(typename _Container::value_type&& __value_) 1051e4383379SHoward Hinnant {iter = container->insert(iter, _VSTD::move(__value_)); ++iter; return *this;} 1052046492b9SEric Fiselier#endif // _LIBCPP_CXX03_LANG 105306e2b737SArthur O'Dwyer _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 insert_iterator& operator*() {return *this;} 105406e2b737SArthur O'Dwyer _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 insert_iterator& operator++() {return *this;} 105506e2b737SArthur O'Dwyer _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 insert_iterator& operator++(int) {return *this;} 10563e519524SHoward Hinnant}; 10573e519524SHoward Hinnant 10583e519524SHoward Hinnanttemplate <class _Container> 105906e2b737SArthur O'Dwyerinline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 10603e519524SHoward Hinnantinsert_iterator<_Container> 10613e519524SHoward Hinnantinserter(_Container& __x, typename _Container::iterator __i) 10623e519524SHoward Hinnant{ 10633e519524SHoward Hinnant return insert_iterator<_Container>(__x, __i); 10643e519524SHoward Hinnant} 10653e519524SHoward Hinnant 10663e519524SHoward Hinnanttemplate <class _Tp, class _CharT = char, 10673e519524SHoward Hinnant class _Traits = char_traits<_CharT>, class _Distance = ptrdiff_t> 1068e2f2d1edSEric Fiselierclass _LIBCPP_TEMPLATE_VIS istream_iterator 10693e519524SHoward Hinnant : public iterator<input_iterator_tag, _Tp, _Distance, const _Tp*, const _Tp&> 10703e519524SHoward Hinnant{ 10713e519524SHoward Hinnantpublic: 10723e519524SHoward Hinnant typedef _CharT char_type; 10733e519524SHoward Hinnant typedef _Traits traits_type; 10743e519524SHoward Hinnant typedef basic_istream<_CharT,_Traits> istream_type; 10753e519524SHoward Hinnantprivate: 10763e519524SHoward Hinnant istream_type* __in_stream_; 10773e519524SHoward Hinnant _Tp __value_; 10783e519524SHoward Hinnantpublic: 1079527a7fdfSBruce Mitchener _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR istream_iterator() : __in_stream_(nullptr), __value_() {} 1080bc6a7df0SMarshall Clow _LIBCPP_INLINE_VISIBILITY istream_iterator(istream_type& __s) : __in_stream_(_VSTD::addressof(__s)) 10813e519524SHoward Hinnant { 10823e519524SHoward Hinnant if (!(*__in_stream_ >> __value_)) 1083527a7fdfSBruce Mitchener __in_stream_ = nullptr; 10843e519524SHoward Hinnant } 10853e519524SHoward Hinnant 10863e519524SHoward Hinnant _LIBCPP_INLINE_VISIBILITY const _Tp& operator*() const {return __value_;} 1087bc6a7df0SMarshall Clow _LIBCPP_INLINE_VISIBILITY const _Tp* operator->() const {return _VSTD::addressof((operator*()));} 10883e519524SHoward Hinnant _LIBCPP_INLINE_VISIBILITY istream_iterator& operator++() 10893e519524SHoward Hinnant { 10903e519524SHoward Hinnant if (!(*__in_stream_ >> __value_)) 1091527a7fdfSBruce Mitchener __in_stream_ = nullptr; 10923e519524SHoward Hinnant return *this; 10933e519524SHoward Hinnant } 10943e519524SHoward Hinnant _LIBCPP_INLINE_VISIBILITY istream_iterator operator++(int) 10953e519524SHoward Hinnant {istream_iterator __t(*this); ++(*this); return __t;} 10963e519524SHoward Hinnant 10976f56d3eeSRoger Ferrer Ibanez template <class _Up, class _CharU, class _TraitsU, class _DistanceU> 10983e519524SHoward Hinnant friend _LIBCPP_INLINE_VISIBILITY 10996f56d3eeSRoger Ferrer Ibanez bool 11006f56d3eeSRoger Ferrer Ibanez operator==(const istream_iterator<_Up, _CharU, _TraitsU, _DistanceU>& __x, 11016f56d3eeSRoger Ferrer Ibanez const istream_iterator<_Up, _CharU, _TraitsU, _DistanceU>& __y); 11023e519524SHoward Hinnant 11036f56d3eeSRoger Ferrer Ibanez template <class _Up, class _CharU, class _TraitsU, class _DistanceU> 11043e519524SHoward Hinnant friend _LIBCPP_INLINE_VISIBILITY 11056f56d3eeSRoger Ferrer Ibanez bool 11066f56d3eeSRoger Ferrer Ibanez operator==(const istream_iterator<_Up, _CharU, _TraitsU, _DistanceU>& __x, 11076f56d3eeSRoger Ferrer Ibanez const istream_iterator<_Up, _CharU, _TraitsU, _DistanceU>& __y); 11083e519524SHoward Hinnant}; 11093e519524SHoward Hinnant 11106f56d3eeSRoger Ferrer Ibaneztemplate <class _Tp, class _CharT, class _Traits, class _Distance> 11116f56d3eeSRoger Ferrer Ibanezinline _LIBCPP_INLINE_VISIBILITY 11126f56d3eeSRoger Ferrer Ibanezbool 11136f56d3eeSRoger Ferrer Ibanezoperator==(const istream_iterator<_Tp, _CharT, _Traits, _Distance>& __x, 11146f56d3eeSRoger Ferrer Ibanez const istream_iterator<_Tp, _CharT, _Traits, _Distance>& __y) 11156f56d3eeSRoger Ferrer Ibanez{ 11166f56d3eeSRoger Ferrer Ibanez return __x.__in_stream_ == __y.__in_stream_; 11176f56d3eeSRoger Ferrer Ibanez} 11186f56d3eeSRoger Ferrer Ibanez 11196f56d3eeSRoger Ferrer Ibaneztemplate <class _Tp, class _CharT, class _Traits, class _Distance> 11206f56d3eeSRoger Ferrer Ibanezinline _LIBCPP_INLINE_VISIBILITY 11216f56d3eeSRoger Ferrer Ibanezbool 11226f56d3eeSRoger Ferrer Ibanezoperator!=(const istream_iterator<_Tp, _CharT, _Traits, _Distance>& __x, 11236f56d3eeSRoger Ferrer Ibanez const istream_iterator<_Tp, _CharT, _Traits, _Distance>& __y) 11246f56d3eeSRoger Ferrer Ibanez{ 11256f56d3eeSRoger Ferrer Ibanez return !(__x == __y); 11266f56d3eeSRoger Ferrer Ibanez} 11276f56d3eeSRoger Ferrer Ibanez 11283e519524SHoward Hinnanttemplate <class _Tp, class _CharT = char, class _Traits = char_traits<_CharT> > 1129e2f2d1edSEric Fiselierclass _LIBCPP_TEMPLATE_VIS ostream_iterator 11303e519524SHoward Hinnant : public iterator<output_iterator_tag, void, void, void, void> 11313e519524SHoward Hinnant{ 11323e519524SHoward Hinnantpublic: 113371a16e40SLouis Dionne typedef output_iterator_tag iterator_category; 113471a16e40SLouis Dionne typedef void value_type; 113571a16e40SLouis Dionne#if _LIBCPP_STD_VER > 17 113671a16e40SLouis Dionne typedef std::ptrdiff_t difference_type; 113771a16e40SLouis Dionne#else 113871a16e40SLouis Dionne typedef void difference_type; 113971a16e40SLouis Dionne#endif 114071a16e40SLouis Dionne typedef void pointer; 114171a16e40SLouis Dionne typedef void reference; 11423e519524SHoward Hinnant typedef _CharT char_type; 11433e519524SHoward Hinnant typedef _Traits traits_type; 11443e519524SHoward Hinnant typedef basic_ostream<_CharT, _Traits> ostream_type; 114571a16e40SLouis Dionne 11463e519524SHoward Hinnantprivate: 11473e519524SHoward Hinnant ostream_type* __out_stream_; 11483e519524SHoward Hinnant const char_type* __delim_; 11493e519524SHoward Hinnantpublic: 1150853042cfSMarshall Clow _LIBCPP_INLINE_VISIBILITY ostream_iterator(ostream_type& __s) _NOEXCEPT 1151527a7fdfSBruce Mitchener : __out_stream_(_VSTD::addressof(__s)), __delim_(nullptr) {} 1152853042cfSMarshall Clow _LIBCPP_INLINE_VISIBILITY ostream_iterator(ostream_type& __s, const _CharT* __delimiter) _NOEXCEPT 1153bc6a7df0SMarshall Clow : __out_stream_(_VSTD::addressof(__s)), __delim_(__delimiter) {} 1154e4383379SHoward Hinnant _LIBCPP_INLINE_VISIBILITY ostream_iterator& operator=(const _Tp& __value_) 11553e519524SHoward Hinnant { 1156e4383379SHoward Hinnant *__out_stream_ << __value_; 11573e519524SHoward Hinnant if (__delim_) 11583e519524SHoward Hinnant *__out_stream_ << __delim_; 11593e519524SHoward Hinnant return *this; 11603e519524SHoward Hinnant } 11613e519524SHoward Hinnant 11623e519524SHoward Hinnant _LIBCPP_INLINE_VISIBILITY ostream_iterator& operator*() {return *this;} 11633e519524SHoward Hinnant _LIBCPP_INLINE_VISIBILITY ostream_iterator& operator++() {return *this;} 11643e519524SHoward Hinnant _LIBCPP_INLINE_VISIBILITY ostream_iterator& operator++(int) {return *this;} 11653e519524SHoward Hinnant}; 11663e519524SHoward Hinnant 11673e519524SHoward Hinnanttemplate<class _CharT, class _Traits> 1168e2f2d1edSEric Fiselierclass _LIBCPP_TEMPLATE_VIS istreambuf_iterator 11693e519524SHoward Hinnant : public iterator<input_iterator_tag, _CharT, 11703e519524SHoward Hinnant typename _Traits::off_type, _CharT*, 11713e519524SHoward Hinnant _CharT> 11723e519524SHoward Hinnant{ 11733e519524SHoward Hinnantpublic: 11743e519524SHoward Hinnant typedef _CharT char_type; 11753e519524SHoward Hinnant typedef _Traits traits_type; 11763e519524SHoward Hinnant typedef typename _Traits::int_type int_type; 11773e519524SHoward Hinnant typedef basic_streambuf<_CharT,_Traits> streambuf_type; 11783e519524SHoward Hinnant typedef basic_istream<_CharT,_Traits> istream_type; 11793e519524SHoward Hinnantprivate: 1180dfdf5085SHoward Hinnant mutable streambuf_type* __sbuf_; 11813e519524SHoward Hinnant 11823e519524SHoward Hinnant class __proxy 11833e519524SHoward Hinnant { 11843e519524SHoward Hinnant char_type __keep_; 11853e519524SHoward Hinnant streambuf_type* __sbuf_; 11863e519524SHoward Hinnant _LIBCPP_INLINE_VISIBILITY __proxy(char_type __c, streambuf_type* __s) 11873e519524SHoward Hinnant : __keep_(__c), __sbuf_(__s) {} 11883e519524SHoward Hinnant friend class istreambuf_iterator; 11893e519524SHoward Hinnant public: 11903e519524SHoward Hinnant _LIBCPP_INLINE_VISIBILITY char_type operator*() const {return __keep_;} 11913e519524SHoward Hinnant }; 11923e519524SHoward Hinnant 1193848a5374SHoward Hinnant _LIBCPP_INLINE_VISIBILITY 1194dfdf5085SHoward Hinnant bool __test_for_eof() const 11953e519524SHoward Hinnant { 11963e519524SHoward Hinnant if (__sbuf_ && traits_type::eq_int_type(__sbuf_->sgetc(), traits_type::eof())) 1197527a7fdfSBruce Mitchener __sbuf_ = nullptr; 1198527a7fdfSBruce Mitchener return __sbuf_ == nullptr; 11993e519524SHoward Hinnant } 12003e519524SHoward Hinnantpublic: 1201527a7fdfSBruce Mitchener _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR istreambuf_iterator() _NOEXCEPT : __sbuf_(nullptr) {} 12028e882dcbSHoward Hinnant _LIBCPP_INLINE_VISIBILITY istreambuf_iterator(istream_type& __s) _NOEXCEPT 1203a96d7458SHoward Hinnant : __sbuf_(__s.rdbuf()) {} 12048e882dcbSHoward Hinnant _LIBCPP_INLINE_VISIBILITY istreambuf_iterator(streambuf_type* __s) _NOEXCEPT 1205a96d7458SHoward Hinnant : __sbuf_(__s) {} 12068e882dcbSHoward Hinnant _LIBCPP_INLINE_VISIBILITY istreambuf_iterator(const __proxy& __p) _NOEXCEPT 12073e519524SHoward Hinnant : __sbuf_(__p.__sbuf_) {} 12083e519524SHoward Hinnant 1209c206366fSHoward Hinnant _LIBCPP_INLINE_VISIBILITY char_type operator*() const 1210c206366fSHoward Hinnant {return static_cast<char_type>(__sbuf_->sgetc());} 12113e519524SHoward Hinnant _LIBCPP_INLINE_VISIBILITY istreambuf_iterator& operator++() 12123e519524SHoward Hinnant { 1213dfdf5085SHoward Hinnant __sbuf_->sbumpc(); 12143e519524SHoward Hinnant return *this; 12153e519524SHoward Hinnant } 12163e519524SHoward Hinnant _LIBCPP_INLINE_VISIBILITY __proxy operator++(int) 12173e519524SHoward Hinnant { 1218dfdf5085SHoward Hinnant return __proxy(__sbuf_->sbumpc(), __sbuf_); 12193e519524SHoward Hinnant } 12203e519524SHoward Hinnant 12213e519524SHoward Hinnant _LIBCPP_INLINE_VISIBILITY bool equal(const istreambuf_iterator& __b) const 1222dfdf5085SHoward Hinnant {return __test_for_eof() == __b.__test_for_eof();} 12233e519524SHoward Hinnant}; 12243e519524SHoward Hinnant 12253e519524SHoward Hinnanttemplate <class _CharT, class _Traits> 12263e519524SHoward Hinnantinline _LIBCPP_INLINE_VISIBILITY 12273e519524SHoward Hinnantbool operator==(const istreambuf_iterator<_CharT,_Traits>& __a, 12283e519524SHoward Hinnant const istreambuf_iterator<_CharT,_Traits>& __b) 12293e519524SHoward Hinnant {return __a.equal(__b);} 12303e519524SHoward Hinnant 12313e519524SHoward Hinnanttemplate <class _CharT, class _Traits> 12323e519524SHoward Hinnantinline _LIBCPP_INLINE_VISIBILITY 12333e519524SHoward Hinnantbool operator!=(const istreambuf_iterator<_CharT,_Traits>& __a, 12343e519524SHoward Hinnant const istreambuf_iterator<_CharT,_Traits>& __b) 12353e519524SHoward Hinnant {return !__a.equal(__b);} 12363e519524SHoward Hinnant 12373e519524SHoward Hinnanttemplate <class _CharT, class _Traits> 1238e2f2d1edSEric Fiselierclass _LIBCPP_TEMPLATE_VIS ostreambuf_iterator 12393e519524SHoward Hinnant : public iterator<output_iterator_tag, void, void, void, void> 12403e519524SHoward Hinnant{ 12413e519524SHoward Hinnantpublic: 124271a16e40SLouis Dionne typedef output_iterator_tag iterator_category; 124371a16e40SLouis Dionne typedef void value_type; 124471a16e40SLouis Dionne#if _LIBCPP_STD_VER > 17 124571a16e40SLouis Dionne typedef std::ptrdiff_t difference_type; 124671a16e40SLouis Dionne#else 124771a16e40SLouis Dionne typedef void difference_type; 124871a16e40SLouis Dionne#endif 124971a16e40SLouis Dionne typedef void pointer; 125071a16e40SLouis Dionne typedef void reference; 12513e519524SHoward Hinnant typedef _CharT char_type; 12523e519524SHoward Hinnant typedef _Traits traits_type; 12533e519524SHoward Hinnant typedef basic_streambuf<_CharT, _Traits> streambuf_type; 12543e519524SHoward Hinnant typedef basic_ostream<_CharT, _Traits> ostream_type; 125571a16e40SLouis Dionne 12563e519524SHoward Hinnantprivate: 12573e519524SHoward Hinnant streambuf_type* __sbuf_; 12583e519524SHoward Hinnantpublic: 12598e882dcbSHoward Hinnant _LIBCPP_INLINE_VISIBILITY ostreambuf_iterator(ostream_type& __s) _NOEXCEPT 12603e519524SHoward Hinnant : __sbuf_(__s.rdbuf()) {} 12618e882dcbSHoward Hinnant _LIBCPP_INLINE_VISIBILITY ostreambuf_iterator(streambuf_type* __s) _NOEXCEPT 12623e519524SHoward Hinnant : __sbuf_(__s) {} 12633e519524SHoward Hinnant _LIBCPP_INLINE_VISIBILITY ostreambuf_iterator& operator=(_CharT __c) 12643e519524SHoward Hinnant { 12653e519524SHoward Hinnant if (__sbuf_ && traits_type::eq_int_type(__sbuf_->sputc(__c), traits_type::eof())) 1266527a7fdfSBruce Mitchener __sbuf_ = nullptr; 12673e519524SHoward Hinnant return *this; 12683e519524SHoward Hinnant } 12693e519524SHoward Hinnant _LIBCPP_INLINE_VISIBILITY ostreambuf_iterator& operator*() {return *this;} 12703e519524SHoward Hinnant _LIBCPP_INLINE_VISIBILITY ostreambuf_iterator& operator++() {return *this;} 12713e519524SHoward Hinnant _LIBCPP_INLINE_VISIBILITY ostreambuf_iterator& operator++(int) {return *this;} 1272527a7fdfSBruce Mitchener _LIBCPP_INLINE_VISIBILITY bool failed() const _NOEXCEPT {return __sbuf_ == nullptr;} 127392b5940fSHoward Hinnant 127492b5940fSHoward Hinnant template <class _Ch, class _Tr> 127592b5940fSHoward Hinnant friend 127692b5940fSHoward Hinnant _LIBCPP_HIDDEN 127792b5940fSHoward Hinnant ostreambuf_iterator<_Ch, _Tr> 127892b5940fSHoward Hinnant __pad_and_output(ostreambuf_iterator<_Ch, _Tr> __s, 127992b5940fSHoward Hinnant const _Ch* __ob, const _Ch* __op, const _Ch* __oe, 128092b5940fSHoward Hinnant ios_base& __iob, _Ch __fl); 12813e519524SHoward Hinnant}; 12823e519524SHoward Hinnant 12833e519524SHoward Hinnanttemplate <class _Iter> 1284e2f2d1edSEric Fiselierclass _LIBCPP_TEMPLATE_VIS move_iterator 12853e519524SHoward Hinnant{ 12863e519524SHoward Hinnantprivate: 12873e519524SHoward Hinnant _Iter __i; 12883e519524SHoward Hinnantpublic: 12893e519524SHoward Hinnant typedef _Iter iterator_type; 12903e519524SHoward Hinnant typedef typename iterator_traits<iterator_type>::value_type value_type; 12913e519524SHoward Hinnant typedef typename iterator_traits<iterator_type>::difference_type difference_type; 129205333fc8SMarshall Clow typedef iterator_type pointer; 1293d41c6d51SArthur O'Dwyer typedef _If<__is_cpp17_random_access_iterator<_Iter>::value, 1294d41c6d51SArthur O'Dwyer random_access_iterator_tag, 1295d41c6d51SArthur O'Dwyer typename iterator_traits<_Iter>::iterator_category> iterator_category; 1296d41c6d51SArthur O'Dwyer#if _LIBCPP_STD_VER > 17 1297d41c6d51SArthur O'Dwyer typedef input_iterator_tag iterator_concept; 1298d41c6d51SArthur O'Dwyer#endif 1299d41c6d51SArthur O'Dwyer 1300046492b9SEric Fiselier#ifndef _LIBCPP_CXX03_LANG 1301906c5085SEric Fiselier typedef typename iterator_traits<iterator_type>::reference __reference; 1302906c5085SEric Fiselier typedef typename conditional< 1303906c5085SEric Fiselier is_reference<__reference>::value, 1304906c5085SEric Fiselier typename remove_reference<__reference>::type&&, 1305906c5085SEric Fiselier __reference 1306906c5085SEric Fiselier >::type reference; 13073e519524SHoward Hinnant#else 13083e519524SHoward Hinnant typedef typename iterator_traits<iterator_type>::reference reference; 13093e519524SHoward Hinnant#endif 13103e519524SHoward Hinnant 1311720ef472SMarshall Clow _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 1312720ef472SMarshall Clow move_iterator() : __i() {} 1313720ef472SMarshall Clow _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 1314720ef472SMarshall Clow explicit move_iterator(_Iter __x) : __i(__x) {} 1315720ef472SMarshall Clow template <class _Up> 1316720ef472SMarshall Clow _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 1317720ef472SMarshall Clow move_iterator(const move_iterator<_Up>& __u) : __i(__u.base()) {} 1318720ef472SMarshall Clow _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 _Iter base() const {return __i;} 1319720ef472SMarshall Clow _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 1320720ef472SMarshall Clow reference operator*() const { return static_cast<reference>(*__i); } 1321720ef472SMarshall Clow _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 1322720ef472SMarshall Clow pointer operator->() const { return __i;} 1323720ef472SMarshall Clow _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 1324720ef472SMarshall Clow move_iterator& operator++() {++__i; return *this;} 1325720ef472SMarshall Clow _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 1326720ef472SMarshall Clow move_iterator operator++(int) {move_iterator __tmp(*this); ++__i; return __tmp;} 1327720ef472SMarshall Clow _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 1328720ef472SMarshall Clow move_iterator& operator--() {--__i; return *this;} 1329720ef472SMarshall Clow _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 1330720ef472SMarshall Clow move_iterator operator--(int) {move_iterator __tmp(*this); --__i; return __tmp;} 1331720ef472SMarshall Clow _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 1332720ef472SMarshall Clow move_iterator operator+ (difference_type __n) const {return move_iterator(__i + __n);} 1333720ef472SMarshall Clow _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 1334720ef472SMarshall Clow move_iterator& operator+=(difference_type __n) {__i += __n; return *this;} 1335720ef472SMarshall Clow _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 1336720ef472SMarshall Clow move_iterator operator- (difference_type __n) const {return move_iterator(__i - __n);} 1337720ef472SMarshall Clow _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 1338720ef472SMarshall Clow move_iterator& operator-=(difference_type __n) {__i -= __n; return *this;} 1339720ef472SMarshall Clow _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 1340720ef472SMarshall Clow reference operator[](difference_type __n) const { return static_cast<reference>(__i[__n]); } 13413e519524SHoward Hinnant}; 13423e519524SHoward Hinnant 13433e519524SHoward Hinnanttemplate <class _Iter1, class _Iter2> 1344720ef472SMarshall Clowinline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 13453e519524SHoward Hinnantbool 13463e519524SHoward Hinnantoperator==(const move_iterator<_Iter1>& __x, const move_iterator<_Iter2>& __y) 13473e519524SHoward Hinnant{ 13483e519524SHoward Hinnant return __x.base() == __y.base(); 13493e519524SHoward Hinnant} 13503e519524SHoward Hinnant 13513e519524SHoward Hinnanttemplate <class _Iter1, class _Iter2> 1352720ef472SMarshall Clowinline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 13533e519524SHoward Hinnantbool 13543e519524SHoward Hinnantoperator<(const move_iterator<_Iter1>& __x, const move_iterator<_Iter2>& __y) 13553e519524SHoward Hinnant{ 13563e519524SHoward Hinnant return __x.base() < __y.base(); 13573e519524SHoward Hinnant} 13583e519524SHoward Hinnant 13593e519524SHoward Hinnanttemplate <class _Iter1, class _Iter2> 1360720ef472SMarshall Clowinline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 13613e519524SHoward Hinnantbool 13623e519524SHoward Hinnantoperator!=(const move_iterator<_Iter1>& __x, const move_iterator<_Iter2>& __y) 13633e519524SHoward Hinnant{ 13643e519524SHoward Hinnant return __x.base() != __y.base(); 13653e519524SHoward Hinnant} 13663e519524SHoward Hinnant 13673e519524SHoward Hinnanttemplate <class _Iter1, class _Iter2> 1368720ef472SMarshall Clowinline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 13693e519524SHoward Hinnantbool 13703e519524SHoward Hinnantoperator>(const move_iterator<_Iter1>& __x, const move_iterator<_Iter2>& __y) 13713e519524SHoward Hinnant{ 13723e519524SHoward Hinnant return __x.base() > __y.base(); 13733e519524SHoward Hinnant} 13743e519524SHoward Hinnant 13753e519524SHoward Hinnanttemplate <class _Iter1, class _Iter2> 1376720ef472SMarshall Clowinline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 13773e519524SHoward Hinnantbool 13783e519524SHoward Hinnantoperator>=(const move_iterator<_Iter1>& __x, const move_iterator<_Iter2>& __y) 13793e519524SHoward Hinnant{ 13803e519524SHoward Hinnant return __x.base() >= __y.base(); 13813e519524SHoward Hinnant} 13823e519524SHoward Hinnant 13833e519524SHoward Hinnanttemplate <class _Iter1, class _Iter2> 1384720ef472SMarshall Clowinline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 13853e519524SHoward Hinnantbool 13863e519524SHoward Hinnantoperator<=(const move_iterator<_Iter1>& __x, const move_iterator<_Iter2>& __y) 13873e519524SHoward Hinnant{ 13883e519524SHoward Hinnant return __x.base() <= __y.base(); 13893e519524SHoward Hinnant} 13903e519524SHoward Hinnant 13912ee83725SMarshall Clow#ifndef _LIBCPP_CXX03_LANG 1392947ce6b5SMarshall Clowtemplate <class _Iter1, class _Iter2> 1393720ef472SMarshall Clowinline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 1394947ce6b5SMarshall Clowauto 1395947ce6b5SMarshall Clowoperator-(const move_iterator<_Iter1>& __x, const move_iterator<_Iter2>& __y) 1396947ce6b5SMarshall Clow-> decltype(__x.base() - __y.base()) 1397947ce6b5SMarshall Clow{ 1398947ce6b5SMarshall Clow return __x.base() - __y.base(); 1399947ce6b5SMarshall Clow} 1400947ce6b5SMarshall Clow#else 14013e519524SHoward Hinnanttemplate <class _Iter1, class _Iter2> 14023e519524SHoward Hinnantinline _LIBCPP_INLINE_VISIBILITY 14033e519524SHoward Hinnanttypename move_iterator<_Iter1>::difference_type 14043e519524SHoward Hinnantoperator-(const move_iterator<_Iter1>& __x, const move_iterator<_Iter2>& __y) 14053e519524SHoward Hinnant{ 14063e519524SHoward Hinnant return __x.base() - __y.base(); 14073e519524SHoward Hinnant} 1408947ce6b5SMarshall Clow#endif 14093e519524SHoward Hinnant 14103e519524SHoward Hinnanttemplate <class _Iter> 1411720ef472SMarshall Clowinline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 14123e519524SHoward Hinnantmove_iterator<_Iter> 14133e519524SHoward Hinnantoperator+(typename move_iterator<_Iter>::difference_type __n, const move_iterator<_Iter>& __x) 14143e519524SHoward Hinnant{ 14153e519524SHoward Hinnant return move_iterator<_Iter>(__x.base() + __n); 14163e519524SHoward Hinnant} 14173e519524SHoward Hinnant 14183e519524SHoward Hinnanttemplate <class _Iter> 1419720ef472SMarshall Clowinline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 14203e519524SHoward Hinnantmove_iterator<_Iter> 142154c83368SMarshall Clowmake_move_iterator(_Iter __i) 14223e519524SHoward Hinnant{ 14233e519524SHoward Hinnant return move_iterator<_Iter>(__i); 14243e519524SHoward Hinnant} 14253e519524SHoward Hinnant 14263e519524SHoward Hinnant// __wrap_iter 14273e519524SHoward Hinnant 14283e519524SHoward Hinnanttemplate <class _Iter> class __wrap_iter; 14293e519524SHoward Hinnant 14303e519524SHoward Hinnanttemplate <class _Iter1, class _Iter2> 14319cad5025SMarshall Clow_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG 14323e519524SHoward Hinnantbool 143361b302f9SEric Fiselieroperator==(const __wrap_iter<_Iter1>&, const __wrap_iter<_Iter2>&) _NOEXCEPT; 14343e519524SHoward Hinnant 14353e519524SHoward Hinnanttemplate <class _Iter1, class _Iter2> 14369cad5025SMarshall Clow_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG 14373e519524SHoward Hinnantbool 143861b302f9SEric Fiselieroperator<(const __wrap_iter<_Iter1>&, const __wrap_iter<_Iter2>&) _NOEXCEPT; 14393e519524SHoward Hinnant 14403e519524SHoward Hinnanttemplate <class _Iter1, class _Iter2> 14419cad5025SMarshall Clow_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG 14423e519524SHoward Hinnantbool 144361b302f9SEric Fiselieroperator!=(const __wrap_iter<_Iter1>&, const __wrap_iter<_Iter2>&) _NOEXCEPT; 14443e519524SHoward Hinnant 14453e519524SHoward Hinnanttemplate <class _Iter1, class _Iter2> 14469cad5025SMarshall Clow_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG 14473e519524SHoward Hinnantbool 144861b302f9SEric Fiselieroperator>(const __wrap_iter<_Iter1>&, const __wrap_iter<_Iter2>&) _NOEXCEPT; 14493e519524SHoward Hinnant 14503e519524SHoward Hinnanttemplate <class _Iter1, class _Iter2> 14519cad5025SMarshall Clow_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG 14523e519524SHoward Hinnantbool 145361b302f9SEric Fiselieroperator>=(const __wrap_iter<_Iter1>&, const __wrap_iter<_Iter2>&) _NOEXCEPT; 14543e519524SHoward Hinnant 14553e519524SHoward Hinnanttemplate <class _Iter1, class _Iter2> 14569cad5025SMarshall Clow_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG 14573e519524SHoward Hinnantbool 145861b302f9SEric Fiselieroperator<=(const __wrap_iter<_Iter1>&, const __wrap_iter<_Iter2>&) _NOEXCEPT; 14593e519524SHoward Hinnant 14602ee83725SMarshall Clow#ifndef _LIBCPP_CXX03_LANG 1461947ce6b5SMarshall Clowtemplate <class _Iter1, class _Iter2> 14629cad5025SMarshall Clow_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG 1463947ce6b5SMarshall Clowauto 146461b302f9SEric Fiselieroperator-(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter2>& __y) _NOEXCEPT 1465947ce6b5SMarshall Clow-> decltype(__x.base() - __y.base()); 1466947ce6b5SMarshall Clow#else 14673e519524SHoward Hinnanttemplate <class _Iter1, class _Iter2> 1468aeb85680SHoward Hinnant_LIBCPP_INLINE_VISIBILITY 14693e519524SHoward Hinnanttypename __wrap_iter<_Iter1>::difference_type 147061b302f9SEric Fiselieroperator-(const __wrap_iter<_Iter1>&, const __wrap_iter<_Iter2>&) _NOEXCEPT; 1471947ce6b5SMarshall Clow#endif 14723e519524SHoward Hinnant 14733e519524SHoward Hinnanttemplate <class _Iter> 14749cad5025SMarshall Clow_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG 14753e519524SHoward Hinnant__wrap_iter<_Iter> 147661b302f9SEric Fiselieroperator+(typename __wrap_iter<_Iter>::difference_type, __wrap_iter<_Iter>) _NOEXCEPT; 14773e519524SHoward Hinnant 147813c90a57SLouis Dionnetemplate <class _Ip, class _Op> _Op _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 copy(_Ip, _Ip, _Op); 147913c90a57SLouis Dionnetemplate <class _B1, class _B2> _B2 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 copy_backward(_B1, _B1, _B2); 14803ed89b51Szoecarvertemplate <class _Ip, class _Op> _Op _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 move(_Ip, _Ip, _Op); 14813ed89b51Szoecarvertemplate <class _B1, class _B2> _B2 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 move_backward(_B1, _B1, _B2); 14823e519524SHoward Hinnant 14833e519524SHoward Hinnanttemplate <class _Iter> 14843e519524SHoward Hinnantclass __wrap_iter 14853e519524SHoward Hinnant{ 14863e519524SHoward Hinnantpublic: 14873e519524SHoward Hinnant typedef _Iter iterator_type; 14883e519524SHoward Hinnant typedef typename iterator_traits<iterator_type>::value_type value_type; 14893e519524SHoward Hinnant typedef typename iterator_traits<iterator_type>::difference_type difference_type; 14903e519524SHoward Hinnant typedef typename iterator_traits<iterator_type>::pointer pointer; 14913e519524SHoward Hinnant typedef typename iterator_traits<iterator_type>::reference reference; 1492d41c6d51SArthur O'Dwyer typedef typename iterator_traits<iterator_type>::iterator_category iterator_category; 1493d41c6d51SArthur O'Dwyer#if _LIBCPP_STD_VER > 17 1494d41c6d51SArthur O'Dwyer typedef _If<__is_cpp17_contiguous_iterator<_Iter>::value, 1495d41c6d51SArthur O'Dwyer contiguous_iterator_tag, iterator_category> iterator_concept; 1496d41c6d51SArthur O'Dwyer#endif 1497d41c6d51SArthur O'Dwyer 14983e519524SHoward Hinnantprivate: 14993e519524SHoward Hinnant iterator_type __i; 15003e519524SHoward Hinnantpublic: 150161b302f9SEric Fiselier _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG __wrap_iter() _NOEXCEPT 150207186a7dSMarshall Clow#if _LIBCPP_STD_VER > 11 150307186a7dSMarshall Clow : __i{} 150407186a7dSMarshall Clow#endif 1505c36bfc49SHoward Hinnant { 150631e82037SLouis Dionne#if _LIBCPP_DEBUG_LEVEL == 2 1507c36bfc49SHoward Hinnant __get_db()->__insert_i(this); 1508c36bfc49SHoward Hinnant#endif 1509c36bfc49SHoward Hinnant } 15109cad5025SMarshall Clow template <class _Up> _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG 15119cad5025SMarshall Clow __wrap_iter(const __wrap_iter<_Up>& __u, 1512527a7fdfSBruce Mitchener typename enable_if<is_convertible<_Up, iterator_type>::value>::type* = nullptr) _NOEXCEPT 1513f554add5SHoward Hinnant : __i(__u.base()) 1514f554add5SHoward Hinnant { 151531e82037SLouis Dionne#if _LIBCPP_DEBUG_LEVEL == 2 1516f554add5SHoward Hinnant __get_db()->__iterator_copy(this, &__u); 1517f554add5SHoward Hinnant#endif 1518f554add5SHoward Hinnant } 151931e82037SLouis Dionne#if _LIBCPP_DEBUG_LEVEL == 2 15209cad5025SMarshall Clow _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG 1521f554add5SHoward Hinnant __wrap_iter(const __wrap_iter& __x) 1522f554add5SHoward Hinnant : __i(__x.base()) 1523f554add5SHoward Hinnant { 1524f554add5SHoward Hinnant __get_db()->__iterator_copy(this, &__x); 1525f554add5SHoward Hinnant } 15269cad5025SMarshall Clow _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG 1527f554add5SHoward Hinnant __wrap_iter& operator=(const __wrap_iter& __x) 1528f554add5SHoward Hinnant { 1529f554add5SHoward Hinnant if (this != &__x) 1530f554add5SHoward Hinnant { 1531f554add5SHoward Hinnant __get_db()->__iterator_copy(this, &__x); 1532f554add5SHoward Hinnant __i = __x.__i; 1533f554add5SHoward Hinnant } 1534f554add5SHoward Hinnant return *this; 1535f554add5SHoward Hinnant } 15369cad5025SMarshall Clow _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG 1537f554add5SHoward Hinnant ~__wrap_iter() 1538f554add5SHoward Hinnant { 1539f554add5SHoward Hinnant __get_db()->__erase_i(this); 1540f554add5SHoward Hinnant } 1541f554add5SHoward Hinnant#endif 154261b302f9SEric Fiselier _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG reference operator*() const _NOEXCEPT 1543f554add5SHoward Hinnant { 154431e82037SLouis Dionne#if _LIBCPP_DEBUG_LEVEL == 2 1545f554add5SHoward Hinnant _LIBCPP_ASSERT(__get_const_db()->__dereferenceable(this), 1546f554add5SHoward Hinnant "Attempted to dereference a non-dereferenceable iterator"); 1547cec9af9eSHoward Hinnant#endif 1548f554add5SHoward Hinnant return *__i; 1549f554add5SHoward Hinnant } 155061b302f9SEric Fiselier _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG pointer operator->() const _NOEXCEPT 15513ec1f00bSHoward Hinnant { 155231e82037SLouis Dionne#if _LIBCPP_DEBUG_LEVEL == 2 15533ec1f00bSHoward Hinnant _LIBCPP_ASSERT(__get_const_db()->__dereferenceable(this), 15543ec1f00bSHoward Hinnant "Attempted to dereference a non-dereferenceable iterator"); 15553ec1f00bSHoward Hinnant#endif 155605333fc8SMarshall Clow return (pointer)_VSTD::addressof(*__i); 15573ec1f00bSHoward Hinnant } 155861b302f9SEric Fiselier _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG __wrap_iter& operator++() _NOEXCEPT 1559f554add5SHoward Hinnant { 156031e82037SLouis Dionne#if _LIBCPP_DEBUG_LEVEL == 2 1561f554add5SHoward Hinnant _LIBCPP_ASSERT(__get_const_db()->__dereferenceable(this), 1562f554add5SHoward Hinnant "Attempted to increment non-incrementable iterator"); 1563cec9af9eSHoward Hinnant#endif 1564f554add5SHoward Hinnant ++__i; 1565f554add5SHoward Hinnant return *this; 1566f554add5SHoward Hinnant } 156761b302f9SEric Fiselier _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG __wrap_iter operator++(int) _NOEXCEPT 1568f554add5SHoward Hinnant {__wrap_iter __tmp(*this); ++(*this); return __tmp;} 15694ce0a916SMarshall Clow 157061b302f9SEric Fiselier _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG __wrap_iter& operator--() _NOEXCEPT 1571f554add5SHoward Hinnant { 157231e82037SLouis Dionne#if _LIBCPP_DEBUG_LEVEL == 2 1573f554add5SHoward Hinnant _LIBCPP_ASSERT(__get_const_db()->__decrementable(this), 1574f554add5SHoward Hinnant "Attempted to decrement non-decrementable iterator"); 1575cec9af9eSHoward Hinnant#endif 1576f554add5SHoward Hinnant --__i; 1577f554add5SHoward Hinnant return *this; 1578f554add5SHoward Hinnant } 157961b302f9SEric Fiselier _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG __wrap_iter operator--(int) _NOEXCEPT 1580f554add5SHoward Hinnant {__wrap_iter __tmp(*this); --(*this); return __tmp;} 158161b302f9SEric Fiselier _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG __wrap_iter operator+ (difference_type __n) const _NOEXCEPT 1582f554add5SHoward Hinnant {__wrap_iter __w(*this); __w += __n; return __w;} 158361b302f9SEric Fiselier _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG __wrap_iter& operator+=(difference_type __n) _NOEXCEPT 1584f554add5SHoward Hinnant { 158531e82037SLouis Dionne#if _LIBCPP_DEBUG_LEVEL == 2 1586f554add5SHoward Hinnant _LIBCPP_ASSERT(__get_const_db()->__addable(this, __n), 1587f554add5SHoward Hinnant "Attempted to add/subtract iterator outside of valid range"); 1588cec9af9eSHoward Hinnant#endif 1589f554add5SHoward Hinnant __i += __n; 1590f554add5SHoward Hinnant return *this; 1591f554add5SHoward Hinnant } 159261b302f9SEric Fiselier _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG __wrap_iter operator- (difference_type __n) const _NOEXCEPT 1593f554add5SHoward Hinnant {return *this + (-__n);} 159461b302f9SEric Fiselier _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG __wrap_iter& operator-=(difference_type __n) _NOEXCEPT 1595f554add5SHoward Hinnant {*this += -__n; return *this;} 159661b302f9SEric Fiselier _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG reference operator[](difference_type __n) const _NOEXCEPT 1597f554add5SHoward Hinnant { 159831e82037SLouis Dionne#if _LIBCPP_DEBUG_LEVEL == 2 1599f554add5SHoward Hinnant _LIBCPP_ASSERT(__get_const_db()->__subscriptable(this, __n), 1600f554add5SHoward Hinnant "Attempted to subscript iterator outside of valid range"); 1601cec9af9eSHoward Hinnant#endif 1602f554add5SHoward Hinnant return __i[__n]; 1603f554add5SHoward Hinnant } 16043e519524SHoward Hinnant 160561b302f9SEric Fiselier _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG iterator_type base() const _NOEXCEPT {return __i;} 16063e519524SHoward Hinnant 16073e519524SHoward Hinnantprivate: 160831e82037SLouis Dionne#if _LIBCPP_DEBUG_LEVEL == 2 16099cad5025SMarshall Clow _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG __wrap_iter(const void* __p, iterator_type __x) : __i(__x) 1610f554add5SHoward Hinnant { 1611f554add5SHoward Hinnant __get_db()->__insert_ic(this, __p); 1612f554add5SHoward Hinnant } 1613fc88dbd2SHoward Hinnant#else 161461b302f9SEric Fiselier _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG __wrap_iter(iterator_type __x) _NOEXCEPT : __i(__x) {} 1615f554add5SHoward Hinnant#endif 16163e519524SHoward Hinnant 16173e519524SHoward Hinnant template <class _Up> friend class __wrap_iter; 16183e519524SHoward Hinnant template <class _CharT, class _Traits, class _Alloc> friend class basic_string; 1619e2f2d1edSEric Fiselier template <class _Tp, class _Alloc> friend class _LIBCPP_TEMPLATE_VIS vector; 16207ad06a93SMarshall Clow template <class _Tp, size_t> friend class _LIBCPP_TEMPLATE_VIS span; 16213e519524SHoward Hinnant 16223e519524SHoward Hinnant template <class _Iter1, class _Iter2> 16239cad5025SMarshall Clow _LIBCPP_CONSTEXPR_IF_NODEBUG friend 16243e519524SHoward Hinnant bool 162561b302f9SEric Fiselier operator==(const __wrap_iter<_Iter1>&, const __wrap_iter<_Iter2>&) _NOEXCEPT; 16263e519524SHoward Hinnant 16273e519524SHoward Hinnant template <class _Iter1, class _Iter2> 16289cad5025SMarshall Clow _LIBCPP_CONSTEXPR_IF_NODEBUG friend 16293e519524SHoward Hinnant bool 163061b302f9SEric Fiselier operator<(const __wrap_iter<_Iter1>&, const __wrap_iter<_Iter2>&) _NOEXCEPT; 16313e519524SHoward Hinnant 16323e519524SHoward Hinnant template <class _Iter1, class _Iter2> 16339cad5025SMarshall Clow _LIBCPP_CONSTEXPR_IF_NODEBUG friend 16343e519524SHoward Hinnant bool 163561b302f9SEric Fiselier operator!=(const __wrap_iter<_Iter1>&, const __wrap_iter<_Iter2>&) _NOEXCEPT; 16363e519524SHoward Hinnant 16373e519524SHoward Hinnant template <class _Iter1, class _Iter2> 16389cad5025SMarshall Clow _LIBCPP_CONSTEXPR_IF_NODEBUG friend 16393e519524SHoward Hinnant bool 164061b302f9SEric Fiselier operator>(const __wrap_iter<_Iter1>&, const __wrap_iter<_Iter2>&) _NOEXCEPT; 16413e519524SHoward Hinnant 16423e519524SHoward Hinnant template <class _Iter1, class _Iter2> 16439cad5025SMarshall Clow _LIBCPP_CONSTEXPR_IF_NODEBUG friend 16443e519524SHoward Hinnant bool 164561b302f9SEric Fiselier operator>=(const __wrap_iter<_Iter1>&, const __wrap_iter<_Iter2>&) _NOEXCEPT; 16463e519524SHoward Hinnant 16473e519524SHoward Hinnant template <class _Iter1, class _Iter2> 16489cad5025SMarshall Clow _LIBCPP_CONSTEXPR_IF_NODEBUG friend 16493e519524SHoward Hinnant bool 165061b302f9SEric Fiselier operator<=(const __wrap_iter<_Iter1>&, const __wrap_iter<_Iter2>&) _NOEXCEPT; 16513e519524SHoward Hinnant 16522ee83725SMarshall Clow#ifndef _LIBCPP_CXX03_LANG 1653947ce6b5SMarshall Clow template <class _Iter1, class _Iter2> 16549cad5025SMarshall Clow _LIBCPP_CONSTEXPR_IF_NODEBUG friend 1655947ce6b5SMarshall Clow auto 165661b302f9SEric Fiselier operator-(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter2>& __y) _NOEXCEPT 1657947ce6b5SMarshall Clow -> decltype(__x.base() - __y.base()); 1658947ce6b5SMarshall Clow#else 16593e519524SHoward Hinnant template <class _Iter1, class _Iter2> 16609cad5025SMarshall Clow _LIBCPP_CONSTEXPR_IF_NODEBUG friend 16613e519524SHoward Hinnant typename __wrap_iter<_Iter1>::difference_type 166261b302f9SEric Fiselier operator-(const __wrap_iter<_Iter1>&, const __wrap_iter<_Iter2>&) _NOEXCEPT; 1663947ce6b5SMarshall Clow#endif 16643e519524SHoward Hinnant 16653e519524SHoward Hinnant template <class _Iter1> 16669cad5025SMarshall Clow _LIBCPP_CONSTEXPR_IF_NODEBUG friend 16673e519524SHoward Hinnant __wrap_iter<_Iter1> 166861b302f9SEric Fiselier operator+(typename __wrap_iter<_Iter1>::difference_type, __wrap_iter<_Iter1>) _NOEXCEPT; 16693e519524SHoward Hinnant 167013c90a57SLouis Dionne template <class _Ip, class _Op> friend _LIBCPP_CONSTEXPR_AFTER_CXX17 _Op copy(_Ip, _Ip, _Op); 167113c90a57SLouis Dionne template <class _B1, class _B2> friend _LIBCPP_CONSTEXPR_AFTER_CXX17 _B2 copy_backward(_B1, _B1, _B2); 16723ed89b51Szoecarver template <class _Ip, class _Op> friend _LIBCPP_CONSTEXPR_AFTER_CXX17 _Op move(_Ip, _Ip, _Op); 16733ed89b51Szoecarver template <class _B1, class _B2> friend _LIBCPP_CONSTEXPR_AFTER_CXX17 _B2 move_backward(_B1, _B1, _B2); 16743e519524SHoward Hinnant}; 16753e519524SHoward Hinnant 1676d41c6d51SArthur O'Dwyer#if _LIBCPP_STD_VER <= 17 1677d41c6d51SArthur O'Dwyertemplate <class _It> 1678d41c6d51SArthur O'Dwyerstruct __is_cpp17_contiguous_iterator<__wrap_iter<_It> > : __is_cpp17_contiguous_iterator<_It> {}; 1679d41c6d51SArthur O'Dwyer#endif 1680d41c6d51SArthur O'Dwyer 1681d41c6d51SArthur O'Dwyertemplate <class _Iter> 1682d41c6d51SArthur O'Dwyer_LIBCPP_CONSTEXPR 1683d41c6d51SArthur O'Dwyer_EnableIf<__is_cpp17_contiguous_iterator<_Iter>::value, decltype(_VSTD::__to_address(declval<_Iter>()))> 1684d41c6d51SArthur O'Dwyer__to_address(__wrap_iter<_Iter> __w) _NOEXCEPT { 1685d41c6d51SArthur O'Dwyer return _VSTD::__to_address(__w.base()); 1686d41c6d51SArthur O'Dwyer} 1687d41c6d51SArthur O'Dwyer 16883e519524SHoward Hinnanttemplate <class _Iter1, class _Iter2> 16899cad5025SMarshall Clowinline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG 16903e519524SHoward Hinnantbool 169161b302f9SEric Fiselieroperator==(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter2>& __y) _NOEXCEPT 16923e519524SHoward Hinnant{ 16933e519524SHoward Hinnant return __x.base() == __y.base(); 16943e519524SHoward Hinnant} 16953e519524SHoward Hinnant 16963e519524SHoward Hinnanttemplate <class _Iter1, class _Iter2> 16979cad5025SMarshall Clowinline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG 16983e519524SHoward Hinnantbool 169961b302f9SEric Fiselieroperator<(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter2>& __y) _NOEXCEPT 17003e519524SHoward Hinnant{ 170131e82037SLouis Dionne#if _LIBCPP_DEBUG_LEVEL == 2 170242a3046eSHoward Hinnant _LIBCPP_ASSERT(__get_const_db()->__less_than_comparable(&__x, &__y), 1703f554add5SHoward Hinnant "Attempted to compare incomparable iterators"); 1704cec9af9eSHoward Hinnant#endif 17053e519524SHoward Hinnant return __x.base() < __y.base(); 17063e519524SHoward Hinnant} 17073e519524SHoward Hinnant 17083e519524SHoward Hinnanttemplate <class _Iter1, class _Iter2> 17099cad5025SMarshall Clowinline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG 17103e519524SHoward Hinnantbool 171161b302f9SEric Fiselieroperator!=(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter2>& __y) _NOEXCEPT 17123e519524SHoward Hinnant{ 1713f554add5SHoward Hinnant return !(__x == __y); 17143e519524SHoward Hinnant} 17153e519524SHoward Hinnant 17163e519524SHoward Hinnanttemplate <class _Iter1, class _Iter2> 17179cad5025SMarshall Clowinline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG 17183e519524SHoward Hinnantbool 171961b302f9SEric Fiselieroperator>(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter2>& __y) _NOEXCEPT 17203e519524SHoward Hinnant{ 1721f554add5SHoward Hinnant return __y < __x; 17223e519524SHoward Hinnant} 17233e519524SHoward Hinnant 17243e519524SHoward Hinnanttemplate <class _Iter1, class _Iter2> 17259cad5025SMarshall Clowinline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG 17263e519524SHoward Hinnantbool 172761b302f9SEric Fiselieroperator>=(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter2>& __y) _NOEXCEPT 17283e519524SHoward Hinnant{ 1729f554add5SHoward Hinnant return !(__x < __y); 17303e519524SHoward Hinnant} 17313e519524SHoward Hinnant 17323e519524SHoward Hinnanttemplate <class _Iter1, class _Iter2> 17339cad5025SMarshall Clowinline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG 17343e519524SHoward Hinnantbool 173561b302f9SEric Fiselieroperator<=(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter2>& __y) _NOEXCEPT 17363e519524SHoward Hinnant{ 1737f554add5SHoward Hinnant return !(__y < __x); 17383e519524SHoward Hinnant} 17393e519524SHoward Hinnant 17406e551ae1SHoward Hinnanttemplate <class _Iter1> 17419cad5025SMarshall Clowinline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG 17426e551ae1SHoward Hinnantbool 174361b302f9SEric Fiselieroperator!=(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter1>& __y) _NOEXCEPT 17446e551ae1SHoward Hinnant{ 17456e551ae1SHoward Hinnant return !(__x == __y); 17466e551ae1SHoward Hinnant} 17476e551ae1SHoward Hinnant 17486e551ae1SHoward Hinnanttemplate <class _Iter1> 17499cad5025SMarshall Clowinline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG 17506e551ae1SHoward Hinnantbool 175161b302f9SEric Fiselieroperator>(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter1>& __y) _NOEXCEPT 17526e551ae1SHoward Hinnant{ 17536e551ae1SHoward Hinnant return __y < __x; 17546e551ae1SHoward Hinnant} 17556e551ae1SHoward Hinnant 17566e551ae1SHoward Hinnanttemplate <class _Iter1> 17579cad5025SMarshall Clowinline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG 17586e551ae1SHoward Hinnantbool 175961b302f9SEric Fiselieroperator>=(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter1>& __y) _NOEXCEPT 17606e551ae1SHoward Hinnant{ 17616e551ae1SHoward Hinnant return !(__x < __y); 17626e551ae1SHoward Hinnant} 17636e551ae1SHoward Hinnant 17646e551ae1SHoward Hinnanttemplate <class _Iter1> 17659cad5025SMarshall Clowinline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG 17666e551ae1SHoward Hinnantbool 176761b302f9SEric Fiselieroperator<=(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter1>& __y) _NOEXCEPT 17686e551ae1SHoward Hinnant{ 17696e551ae1SHoward Hinnant return !(__y < __x); 17706e551ae1SHoward Hinnant} 17716e551ae1SHoward Hinnant 17722ee83725SMarshall Clow#ifndef _LIBCPP_CXX03_LANG 1773947ce6b5SMarshall Clowtemplate <class _Iter1, class _Iter2> 17749cad5025SMarshall Clowinline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG 1775947ce6b5SMarshall Clowauto 177661b302f9SEric Fiselieroperator-(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter2>& __y) _NOEXCEPT 1777947ce6b5SMarshall Clow-> decltype(__x.base() - __y.base()) 1778947ce6b5SMarshall Clow{ 177931e82037SLouis Dionne#if _LIBCPP_DEBUG_LEVEL == 2 1780947ce6b5SMarshall Clow _LIBCPP_ASSERT(__get_const_db()->__less_than_comparable(&__x, &__y), 1781947ce6b5SMarshall Clow "Attempted to subtract incompatible iterators"); 1782947ce6b5SMarshall Clow#endif 1783947ce6b5SMarshall Clow return __x.base() - __y.base(); 1784947ce6b5SMarshall Clow} 1785947ce6b5SMarshall Clow#else 17863e519524SHoward Hinnanttemplate <class _Iter1, class _Iter2> 17879cad5025SMarshall Clowinline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG 17883e519524SHoward Hinnanttypename __wrap_iter<_Iter1>::difference_type 178961b302f9SEric Fiselieroperator-(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter2>& __y) _NOEXCEPT 17903e519524SHoward Hinnant{ 179131e82037SLouis Dionne#if _LIBCPP_DEBUG_LEVEL == 2 179242a3046eSHoward Hinnant _LIBCPP_ASSERT(__get_const_db()->__less_than_comparable(&__x, &__y), 1793f554add5SHoward Hinnant "Attempted to subtract incompatible iterators"); 1794cec9af9eSHoward Hinnant#endif 17953e519524SHoward Hinnant return __x.base() - __y.base(); 17963e519524SHoward Hinnant} 1797947ce6b5SMarshall Clow#endif 17983e519524SHoward Hinnant 17993e519524SHoward Hinnanttemplate <class _Iter> 18009cad5025SMarshall Clowinline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG 18013e519524SHoward Hinnant__wrap_iter<_Iter> 18023e519524SHoward Hinnantoperator+(typename __wrap_iter<_Iter>::difference_type __n, 180361b302f9SEric Fiselier __wrap_iter<_Iter> __x) _NOEXCEPT 18043e519524SHoward Hinnant{ 1805f554add5SHoward Hinnant __x += __n; 1806f554add5SHoward Hinnant return __x; 18073e519524SHoward Hinnant} 18083e519524SHoward Hinnant 180976b4afc0SMarshall Clowtemplate <class _Iter> 181076b4afc0SMarshall Clowstruct __libcpp_is_trivial_iterator 181176b4afc0SMarshall Clow : public _LIBCPP_BOOL_CONSTANT(is_pointer<_Iter>::value) {}; 181276b4afc0SMarshall Clow 181376b4afc0SMarshall Clowtemplate <class _Iter> 181476b4afc0SMarshall Clowstruct __libcpp_is_trivial_iterator<move_iterator<_Iter> > 181576b4afc0SMarshall Clow : public _LIBCPP_BOOL_CONSTANT(__libcpp_is_trivial_iterator<_Iter>::value) {}; 181676b4afc0SMarshall Clow 181776b4afc0SMarshall Clowtemplate <class _Iter> 181876b4afc0SMarshall Clowstruct __libcpp_is_trivial_iterator<reverse_iterator<_Iter> > 181976b4afc0SMarshall Clow : public _LIBCPP_BOOL_CONSTANT(__libcpp_is_trivial_iterator<_Iter>::value) {}; 182076b4afc0SMarshall Clow 182176b4afc0SMarshall Clowtemplate <class _Iter> 182276b4afc0SMarshall Clowstruct __libcpp_is_trivial_iterator<__wrap_iter<_Iter> > 182376b4afc0SMarshall Clow : public _LIBCPP_BOOL_CONSTANT(__libcpp_is_trivial_iterator<_Iter>::value) {}; 182476b4afc0SMarshall Clow 182576b4afc0SMarshall Clow 18263772a46aSMarshall Clowtemplate <class _Tp, size_t _Np> 18272ffa1705SMarshall Clow_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 18283772a46aSMarshall Clow_Tp* 18293772a46aSMarshall Clowbegin(_Tp (&__array)[_Np]) 18303772a46aSMarshall Clow{ 18313772a46aSMarshall Clow return __array; 18323772a46aSMarshall Clow} 18333772a46aSMarshall Clow 18343772a46aSMarshall Clowtemplate <class _Tp, size_t _Np> 18352ffa1705SMarshall Clow_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 18363772a46aSMarshall Clow_Tp* 18373772a46aSMarshall Clowend(_Tp (&__array)[_Np]) 18383772a46aSMarshall Clow{ 18393772a46aSMarshall Clow return __array + _Np; 18403772a46aSMarshall Clow} 18413772a46aSMarshall Clow 184254613ab4SEric Fiselier#if !defined(_LIBCPP_CXX03_LANG) 1843c66a611bSMarshall Clow 1844c003db1fSHoward Hinnanttemplate <class _Cp> 18452ffa1705SMarshall Clow_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 18463e519524SHoward Hinnantauto 1847c003db1fSHoward Hinnantbegin(_Cp& __c) -> decltype(__c.begin()) 18483e519524SHoward Hinnant{ 18493e519524SHoward Hinnant return __c.begin(); 18503e519524SHoward Hinnant} 18513e519524SHoward Hinnant 1852c003db1fSHoward Hinnanttemplate <class _Cp> 18532ffa1705SMarshall Clow_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 18543e519524SHoward Hinnantauto 1855c003db1fSHoward Hinnantbegin(const _Cp& __c) -> decltype(__c.begin()) 18563e519524SHoward Hinnant{ 18573e519524SHoward Hinnant return __c.begin(); 18583e519524SHoward Hinnant} 18593e519524SHoward Hinnant 1860c003db1fSHoward Hinnanttemplate <class _Cp> 18612ffa1705SMarshall Clow_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 18623e519524SHoward Hinnantauto 1863c003db1fSHoward Hinnantend(_Cp& __c) -> decltype(__c.end()) 18643e519524SHoward Hinnant{ 18653e519524SHoward Hinnant return __c.end(); 18663e519524SHoward Hinnant} 18673e519524SHoward Hinnant 1868c003db1fSHoward Hinnanttemplate <class _Cp> 18692ffa1705SMarshall Clow_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 18703e519524SHoward Hinnantauto 1871c003db1fSHoward Hinnantend(const _Cp& __c) -> decltype(__c.end()) 18723e519524SHoward Hinnant{ 18733e519524SHoward Hinnant return __c.end(); 18743e519524SHoward Hinnant} 18753e519524SHoward Hinnant 18761e548c72SMarshall Clow#if _LIBCPP_STD_VER > 11 18771e548c72SMarshall Clow 18783772a46aSMarshall Clowtemplate <class _Tp, size_t _Np> 18792ffa1705SMarshall Clow_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 18803772a46aSMarshall Clowreverse_iterator<_Tp*> rbegin(_Tp (&__array)[_Np]) 18813772a46aSMarshall Clow{ 18823772a46aSMarshall Clow return reverse_iterator<_Tp*>(__array + _Np); 18833772a46aSMarshall Clow} 18843772a46aSMarshall Clow 18853772a46aSMarshall Clowtemplate <class _Tp, size_t _Np> 18862ffa1705SMarshall Clow_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 18873772a46aSMarshall Clowreverse_iterator<_Tp*> rend(_Tp (&__array)[_Np]) 18883772a46aSMarshall Clow{ 18893772a46aSMarshall Clow return reverse_iterator<_Tp*>(__array); 18903772a46aSMarshall Clow} 18913772a46aSMarshall Clow 18923772a46aSMarshall Clowtemplate <class _Ep> 18932ffa1705SMarshall Clow_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 18943772a46aSMarshall Clowreverse_iterator<const _Ep*> rbegin(initializer_list<_Ep> __il) 18953772a46aSMarshall Clow{ 18963772a46aSMarshall Clow return reverse_iterator<const _Ep*>(__il.end()); 18973772a46aSMarshall Clow} 18983772a46aSMarshall Clow 18993772a46aSMarshall Clowtemplate <class _Ep> 19002ffa1705SMarshall Clow_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 19013772a46aSMarshall Clowreverse_iterator<const _Ep*> rend(initializer_list<_Ep> __il) 19023772a46aSMarshall Clow{ 19033772a46aSMarshall Clow return reverse_iterator<const _Ep*>(__il.begin()); 19043772a46aSMarshall Clow} 19053772a46aSMarshall Clow 19061e548c72SMarshall Clowtemplate <class _Cp> 19072ffa1705SMarshall Clow_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 19087725546aSMarshall Clowauto cbegin(const _Cp& __c) -> decltype(_VSTD::begin(__c)) 19091e548c72SMarshall Clow{ 19107725546aSMarshall Clow return _VSTD::begin(__c); 19111e548c72SMarshall Clow} 19121e548c72SMarshall Clow 19131e548c72SMarshall Clowtemplate <class _Cp> 19142ffa1705SMarshall Clow_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 19157725546aSMarshall Clowauto cend(const _Cp& __c) -> decltype(_VSTD::end(__c)) 19161e548c72SMarshall Clow{ 19177725546aSMarshall Clow return _VSTD::end(__c); 19181e548c72SMarshall Clow} 19191e548c72SMarshall Clow 19201e548c72SMarshall Clowtemplate <class _Cp> 19212ffa1705SMarshall Clow_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 19221e548c72SMarshall Clowauto rbegin(_Cp& __c) -> decltype(__c.rbegin()) 19231e548c72SMarshall Clow{ 19241e548c72SMarshall Clow return __c.rbegin(); 19251e548c72SMarshall Clow} 19261e548c72SMarshall Clow 19271e548c72SMarshall Clowtemplate <class _Cp> 19282ffa1705SMarshall Clow_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 19291e548c72SMarshall Clowauto rbegin(const _Cp& __c) -> decltype(__c.rbegin()) 19301e548c72SMarshall Clow{ 19311e548c72SMarshall Clow return __c.rbegin(); 19321e548c72SMarshall Clow} 19331e548c72SMarshall Clow 19341e548c72SMarshall Clowtemplate <class _Cp> 19352ffa1705SMarshall Clow_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 19361e548c72SMarshall Clowauto rend(_Cp& __c) -> decltype(__c.rend()) 19371e548c72SMarshall Clow{ 19381e548c72SMarshall Clow return __c.rend(); 19391e548c72SMarshall Clow} 19401e548c72SMarshall Clow 19411e548c72SMarshall Clowtemplate <class _Cp> 19422ffa1705SMarshall Clow_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 19431e548c72SMarshall Clowauto rend(const _Cp& __c) -> decltype(__c.rend()) 19441e548c72SMarshall Clow{ 19451e548c72SMarshall Clow return __c.rend(); 19461e548c72SMarshall Clow} 19471e548c72SMarshall Clow 19481e548c72SMarshall Clowtemplate <class _Cp> 19492ffa1705SMarshall Clow_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 19507725546aSMarshall Clowauto crbegin(const _Cp& __c) -> decltype(_VSTD::rbegin(__c)) 19511e548c72SMarshall Clow{ 19527725546aSMarshall Clow return _VSTD::rbegin(__c); 19531e548c72SMarshall Clow} 19541e548c72SMarshall Clow 19551e548c72SMarshall Clowtemplate <class _Cp> 19562ffa1705SMarshall Clow_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 19577725546aSMarshall Clowauto crend(const _Cp& __c) -> decltype(_VSTD::rend(__c)) 19581e548c72SMarshall Clow{ 19597725546aSMarshall Clow return _VSTD::rend(__c); 19601e548c72SMarshall Clow} 19611e548c72SMarshall Clow 19621e548c72SMarshall Clow#endif 19631e548c72SMarshall Clow 19641e548c72SMarshall Clow 196554613ab4SEric Fiselier#else // defined(_LIBCPP_CXX03_LANG) 19663e519524SHoward Hinnant 1967c003db1fSHoward Hinnanttemplate <class _Cp> 19682ffa1705SMarshall Clow_LIBCPP_INLINE_VISIBILITY 1969c003db1fSHoward Hinnanttypename _Cp::iterator 1970c003db1fSHoward Hinnantbegin(_Cp& __c) 19713e519524SHoward Hinnant{ 19723e519524SHoward Hinnant return __c.begin(); 19733e519524SHoward Hinnant} 19743e519524SHoward Hinnant 1975c003db1fSHoward Hinnanttemplate <class _Cp> 19762ffa1705SMarshall Clow_LIBCPP_INLINE_VISIBILITY 1977c003db1fSHoward Hinnanttypename _Cp::const_iterator 1978c003db1fSHoward Hinnantbegin(const _Cp& __c) 19793e519524SHoward Hinnant{ 19803e519524SHoward Hinnant return __c.begin(); 19813e519524SHoward Hinnant} 19823e519524SHoward Hinnant 1983c003db1fSHoward Hinnanttemplate <class _Cp> 19842ffa1705SMarshall Clow_LIBCPP_INLINE_VISIBILITY 1985c003db1fSHoward Hinnanttypename _Cp::iterator 1986c003db1fSHoward Hinnantend(_Cp& __c) 19873e519524SHoward Hinnant{ 19883e519524SHoward Hinnant return __c.end(); 19893e519524SHoward Hinnant} 19903e519524SHoward Hinnant 1991c003db1fSHoward Hinnanttemplate <class _Cp> 19922ffa1705SMarshall Clow_LIBCPP_INLINE_VISIBILITY 1993c003db1fSHoward Hinnanttypename _Cp::const_iterator 1994c003db1fSHoward Hinnantend(const _Cp& __c) 19953e519524SHoward Hinnant{ 19963e519524SHoward Hinnant return __c.end(); 19973e519524SHoward Hinnant} 19983e519524SHoward Hinnant 199954613ab4SEric Fiselier#endif // !defined(_LIBCPP_CXX03_LANG) 20003e519524SHoward Hinnant 2001ad755104SMarshall Clow#if _LIBCPP_STD_VER > 14 2002d1dcda19SMarshall Clow 2003d1dcda19SMarshall Clow// #if _LIBCPP_STD_VER > 11 2004d1dcda19SMarshall Clow// template <> 2005d1dcda19SMarshall Clow// struct _LIBCPP_TEMPLATE_VIS plus<void> 2006d1dcda19SMarshall Clow// { 2007d1dcda19SMarshall Clow// template <class _T1, class _T2> 2008d1dcda19SMarshall Clow// _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY 2009d1dcda19SMarshall Clow// auto operator()(_T1&& __t, _T2&& __u) const 2010d1dcda19SMarshall Clow// _NOEXCEPT_(noexcept(_VSTD::forward<_T1>(__t) + _VSTD::forward<_T2>(__u))) 2011d1dcda19SMarshall Clow// -> decltype (_VSTD::forward<_T1>(__t) + _VSTD::forward<_T2>(__u)) 2012d1dcda19SMarshall Clow// { return _VSTD::forward<_T1>(__t) + _VSTD::forward<_T2>(__u); } 2013d1dcda19SMarshall Clow// typedef void is_transparent; 2014d1dcda19SMarshall Clow// }; 2015d1dcda19SMarshall Clow// #endif 2016d1dcda19SMarshall Clow 201788d21343SMarshall Clowtemplate <class _Cont> 20182ffa1705SMarshall Clow_LIBCPP_INLINE_VISIBILITY 2019d1dcda19SMarshall Clowconstexpr auto size(const _Cont& __c) 2020d1dcda19SMarshall Clow_NOEXCEPT_(noexcept(__c.size())) 2021d1dcda19SMarshall Clow-> decltype (__c.size()) 2022d1dcda19SMarshall Clow{ return __c.size(); } 2023ad755104SMarshall Clow 202488d21343SMarshall Clowtemplate <class _Tp, size_t _Sz> 20252ffa1705SMarshall Clow_LIBCPP_INLINE_VISIBILITY 2026fd838227SEric Fiselierconstexpr size_t size(const _Tp (&)[_Sz]) noexcept { return _Sz; } 2027ad755104SMarshall Clow 20287d3986eaSMarshall Clow#if _LIBCPP_STD_VER > 17 20297d3986eaSMarshall Clowtemplate <class _Cont> 20302ffa1705SMarshall Clow_LIBCPP_INLINE_VISIBILITY 20317d3986eaSMarshall Clowconstexpr auto ssize(const _Cont& __c) 20327d3986eaSMarshall Clow_NOEXCEPT_(noexcept(static_cast<common_type_t<ptrdiff_t, make_signed_t<decltype(__c.size())>>>(__c.size()))) 20337d3986eaSMarshall Clow-> common_type_t<ptrdiff_t, make_signed_t<decltype(__c.size())>> 20347d3986eaSMarshall Clow{ return static_cast<common_type_t<ptrdiff_t, make_signed_t<decltype(__c.size())>>>(__c.size()); } 20357d3986eaSMarshall Clow 20367d3986eaSMarshall Clowtemplate <class _Tp, ptrdiff_t _Sz> 20372ffa1705SMarshall Clow_LIBCPP_INLINE_VISIBILITY 20387d3986eaSMarshall Clowconstexpr ptrdiff_t ssize(const _Tp (&)[_Sz]) noexcept { return _Sz; } 20397d3986eaSMarshall Clow#endif 20407d3986eaSMarshall Clow 204188d21343SMarshall Clowtemplate <class _Cont> 20422ffa1705SMarshall Clow_LIBCPP_NODISCARD_AFTER_CXX17 _LIBCPP_INLINE_VISIBILITY 2043d1dcda19SMarshall Clowconstexpr auto empty(const _Cont& __c) 2044d1dcda19SMarshall Clow_NOEXCEPT_(noexcept(__c.empty())) 2045d1dcda19SMarshall Clow-> decltype (__c.empty()) 2046d1dcda19SMarshall Clow{ return __c.empty(); } 2047ad755104SMarshall Clow 204888d21343SMarshall Clowtemplate <class _Tp, size_t _Sz> 20492ffa1705SMarshall Clow_LIBCPP_NODISCARD_AFTER_CXX17 _LIBCPP_INLINE_VISIBILITY 2050fd838227SEric Fiselierconstexpr bool empty(const _Tp (&)[_Sz]) noexcept { return false; } 2051ad755104SMarshall Clow 2052ad755104SMarshall Clowtemplate <class _Ep> 20532ffa1705SMarshall Clow_LIBCPP_NODISCARD_AFTER_CXX17 _LIBCPP_INLINE_VISIBILITY 2054ad755104SMarshall Clowconstexpr bool empty(initializer_list<_Ep> __il) noexcept { return __il.size() == 0; } 2055ad755104SMarshall Clow 205688d21343SMarshall Clowtemplate <class _Cont> constexpr 20572ffa1705SMarshall Clow_LIBCPP_INLINE_VISIBILITY 2058d1dcda19SMarshall Clowauto data(_Cont& __c) 2059d1dcda19SMarshall Clow_NOEXCEPT_(noexcept(__c.data())) 2060d1dcda19SMarshall Clow-> decltype (__c.data()) 2061d1dcda19SMarshall Clow{ return __c.data(); } 2062ad755104SMarshall Clow 206388d21343SMarshall Clowtemplate <class _Cont> constexpr 20642ffa1705SMarshall Clow_LIBCPP_INLINE_VISIBILITY 2065d1dcda19SMarshall Clowauto data(const _Cont& __c) 2066d1dcda19SMarshall Clow_NOEXCEPT_(noexcept(__c.data())) 2067d1dcda19SMarshall Clow-> decltype (__c.data()) 2068d1dcda19SMarshall Clow{ return __c.data(); } 2069ad755104SMarshall Clow 207088d21343SMarshall Clowtemplate <class _Tp, size_t _Sz> 20712ffa1705SMarshall Clow_LIBCPP_INLINE_VISIBILITY 207288d21343SMarshall Clowconstexpr _Tp* data(_Tp (&__array)[_Sz]) noexcept { return __array; } 2073ad755104SMarshall Clow 2074ad755104SMarshall Clowtemplate <class _Ep> 20752ffa1705SMarshall Clow_LIBCPP_INLINE_VISIBILITY 2076ad755104SMarshall Clowconstexpr const _Ep* data(initializer_list<_Ep> __il) noexcept { return __il.begin(); } 2077ad755104SMarshall Clow#endif 2078ad755104SMarshall Clow 20792ac6babcSArthur O'Dwyertemplate <class _Container, class _Predicate> 20802ac6babcSArthur O'Dwyertypename _Container::size_type 20812ac6babcSArthur O'Dwyer__libcpp_erase_if_container(_Container& __c, _Predicate& __pred) { 20822ac6babcSArthur O'Dwyer typename _Container::size_type __old_size = __c.size(); 20832ac6babcSArthur O'Dwyer 20842ac6babcSArthur O'Dwyer const typename _Container::iterator __last = __c.end(); 20852ac6babcSArthur O'Dwyer for (typename _Container::iterator __iter = __c.begin(); __iter != __last;) { 20862ac6babcSArthur O'Dwyer if (__pred(*__iter)) 20872ac6babcSArthur O'Dwyer __iter = __c.erase(__iter); 20882ac6babcSArthur O'Dwyer else 20892ac6babcSArthur O'Dwyer ++__iter; 20902ac6babcSArthur O'Dwyer } 20912ac6babcSArthur O'Dwyer 20922ac6babcSArthur O'Dwyer return __old_size - __c.size(); 20932ac6babcSArthur O'Dwyer} 2094ad755104SMarshall Clow 20953e519524SHoward Hinnant_LIBCPP_END_NAMESPACE_STD 20963e519524SHoward Hinnant 20973e519524SHoward Hinnant#endif // _LIBCPP_ITERATOR 2098