13e519524SHoward Hinnant// -*- C++ -*-
23e519524SHoward Hinnant//===-------------------------- iterator ----------------------------------===//
33e519524SHoward Hinnant//
45b08a8a4SHoward Hinnant//                     The LLVM Compiler Infrastructure
53e519524SHoward Hinnant//
6412dbebeSHoward Hinnant// This file is dual licensed under the MIT and the University of Illinois Open
7412dbebeSHoward Hinnant// Source Licenses. See LICENSE.TXT for details.
83e519524SHoward Hinnant//
93e519524SHoward Hinnant//===----------------------------------------------------------------------===//
103e519524SHoward Hinnant
113e519524SHoward Hinnant#ifndef _LIBCPP_ITERATOR
123e519524SHoward Hinnant#define _LIBCPP_ITERATOR
133e519524SHoward Hinnant
143e519524SHoward Hinnant/*
153e519524SHoward Hinnant    iterator synopsis
163e519524SHoward Hinnant
173e519524SHoward Hinnantnamespace std
183e519524SHoward Hinnant{
193e519524SHoward Hinnant
203e519524SHoward Hinnanttemplate<class Iterator>
213e519524SHoward Hinnantstruct iterator_traits
223e519524SHoward Hinnant{
233e519524SHoward Hinnant    typedef typename Iterator::difference_type difference_type;
243e519524SHoward Hinnant    typedef typename Iterator::value_type value_type;
253e519524SHoward Hinnant    typedef typename Iterator::pointer pointer;
263e519524SHoward Hinnant    typedef typename Iterator::reference reference;
273e519524SHoward Hinnant    typedef typename Iterator::iterator_category iterator_category;
283e519524SHoward Hinnant};
293e519524SHoward Hinnant
303e519524SHoward Hinnanttemplate<class T>
313e519524SHoward Hinnantstruct iterator_traits<T*>
323e519524SHoward Hinnant{
333e519524SHoward Hinnant    typedef ptrdiff_t difference_type;
343e519524SHoward Hinnant    typedef T value_type;
353e519524SHoward Hinnant    typedef T* pointer;
363e519524SHoward Hinnant    typedef T& reference;
373e519524SHoward Hinnant    typedef random_access_iterator_tag iterator_category;
383e519524SHoward Hinnant};
393e519524SHoward Hinnant
403e519524SHoward Hinnanttemplate<class Category, class T, class Distance = ptrdiff_t,
413e519524SHoward Hinnant         class Pointer = T*, class Reference = T&>
423e519524SHoward Hinnantstruct iterator
433e519524SHoward Hinnant{
443e519524SHoward Hinnant    typedef T         value_type;
453e519524SHoward Hinnant    typedef Distance  difference_type;
463e519524SHoward Hinnant    typedef Pointer   pointer;
473e519524SHoward Hinnant    typedef Reference reference;
483e519524SHoward Hinnant    typedef Category  iterator_category;
493e519524SHoward Hinnant};
503e519524SHoward Hinnant
513e519524SHoward Hinnantstruct input_iterator_tag  {};
523e519524SHoward Hinnantstruct output_iterator_tag {};
533e519524SHoward Hinnantstruct forward_iterator_tag       : public input_iterator_tag         {};
543e519524SHoward Hinnantstruct bidirectional_iterator_tag : public forward_iterator_tag       {};
553e519524SHoward Hinnantstruct random_access_iterator_tag : public bidirectional_iterator_tag {};
563e519524SHoward Hinnant
57f51ee632SMarshall Clow// 27.4.3, iterator operations
583e519524SHoward Hinnant// extension: second argument not conforming to C++03
59f51ee632SMarshall Clowtemplate <class InputIterator>  // constexpr in C++17
60f51ee632SMarshall Clow  constexpr void advance(InputIterator& i,
613e519524SHoward Hinnant             typename iterator_traits<InputIterator>::difference_type 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
1583e519524SHoward Hinnant    explicit back_insert_iterator(Container& x);
15903976c1bSHoward Hinnant    back_insert_iterator& operator=(const typename Container::value_type& value);
1603e519524SHoward Hinnant    back_insert_iterator& operator*();
1613e519524SHoward Hinnant    back_insert_iterator& operator++();
1623e519524SHoward Hinnant    back_insert_iterator  operator++(int);
1633e519524SHoward Hinnant};
1643e519524SHoward Hinnant
1653e519524SHoward Hinnanttemplate <class Container> back_insert_iterator<Container> back_inserter(Container& x);
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
1793e519524SHoward Hinnant    explicit front_insert_iterator(Container& x);
18003976c1bSHoward Hinnant    front_insert_iterator& operator=(const typename Container::value_type& value);
1813e519524SHoward Hinnant    front_insert_iterator& operator*();
1823e519524SHoward Hinnant    front_insert_iterator& operator++();
1833e519524SHoward Hinnant    front_insert_iterator  operator++(int);
1843e519524SHoward Hinnant};
1853e519524SHoward Hinnant
1863e519524SHoward Hinnanttemplate <class Container> front_insert_iterator<Container> front_inserter(Container& x);
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
2013e519524SHoward Hinnant    insert_iterator(Container& x, typename Container::iterator i);
20203976c1bSHoward Hinnant    insert_iterator& operator=(const typename Container::value_type& value);
2033e519524SHoward Hinnant    insert_iterator& operator*();
2043e519524SHoward Hinnant    insert_iterator& operator++();
2053e519524SHoward Hinnant    insert_iterator& operator++(int);
2063e519524SHoward Hinnant};
2073e519524SHoward Hinnant
2083e519524SHoward Hinnanttemplate <class Container, class Iterator>
2093e519524SHoward Hinnantinsert_iterator<Container> inserter(Container& x, Iterator i);
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
403ad755104SMarshall Clowtemplate <class C> constexpr auto empty(const C& c) -> decltype(c.empty());       // C++17
404ad755104SMarshall Clowtemplate <class T, size_t N> constexpr bool empty(const T (&array)[N]) noexcept;  // C++17
405ad755104SMarshall Clowtemplate <class E> constexpr bool empty(initializer_list<E> il) noexcept;         // C++17
406ad755104SMarshall Clowtemplate <class C> constexpr auto data(C& c) -> decltype(c.data());               // C++17
407ad755104SMarshall Clowtemplate <class C> constexpr auto data(const C& c) -> decltype(c.data());         // C++17
408ad755104SMarshall Clowtemplate <class T, size_t N> constexpr T* data(T (&array)[N]) noexcept;           // C++17
409ad755104SMarshall Clowtemplate <class E> constexpr const E* data(initializer_list<E> il) noexcept;      // C++17
410ad755104SMarshall Clow
4113e519524SHoward Hinnant}  // std
4123e519524SHoward Hinnant
4133e519524SHoward Hinnant*/
4143e519524SHoward Hinnant
4153e519524SHoward Hinnant#include <__config>
41639c193b1SEric Fiselier#include <iosfwd> // for forward declarations of vector and string.
417c204c130SMarshall Clow#include <__functional_base>
4183e519524SHoward Hinnant#include <type_traits>
4193e519524SHoward Hinnant#include <cstddef>
4201e548c72SMarshall Clow#include <initializer_list>
421b56e8587SMarshall Clow#ifdef __APPLE__
422b5c63a2eSHoward Hinnant#include <Availability.h>
423b5c63a2eSHoward Hinnant#endif
424b5c63a2eSHoward Hinnant
42542a3046eSHoward Hinnant#include <__debug>
4263e519524SHoward Hinnant
427073458b1SHoward Hinnant#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
4283e519524SHoward Hinnant#pragma GCC system_header
429073458b1SHoward Hinnant#endif
4303e519524SHoward Hinnant
4313e519524SHoward Hinnant_LIBCPP_BEGIN_NAMESPACE_STD
4323e519524SHoward Hinnant
433e2f2d1edSEric Fiselierstruct _LIBCPP_TEMPLATE_VIS input_iterator_tag {};
434e2f2d1edSEric Fiselierstruct _LIBCPP_TEMPLATE_VIS output_iterator_tag {};
435e2f2d1edSEric Fiselierstruct _LIBCPP_TEMPLATE_VIS forward_iterator_tag       : public input_iterator_tag {};
436e2f2d1edSEric Fiselierstruct _LIBCPP_TEMPLATE_VIS bidirectional_iterator_tag : public forward_iterator_tag {};
437e2f2d1edSEric Fiselierstruct _LIBCPP_TEMPLATE_VIS random_access_iterator_tag : public bidirectional_iterator_tag {};
4383e519524SHoward Hinnant
4393e519524SHoward Hinnanttemplate <class _Tp>
4403e519524SHoward Hinnantstruct __has_iterator_category
4413e519524SHoward Hinnant{
4423e519524SHoward Hinnantprivate:
44354d333a6SHoward Hinnant    struct __two {char __lx; char __lxx;};
4443e519524SHoward Hinnant    template <class _Up> static __two __test(...);
4453e519524SHoward Hinnant    template <class _Up> static char __test(typename _Up::iterator_category* = 0);
4463e519524SHoward Hinnantpublic:
4473e519524SHoward Hinnant    static const bool value = sizeof(__test<_Tp>(0)) == 1;
4483e519524SHoward Hinnant};
4493e519524SHoward Hinnant
4500724bf67SMarshall Clowtemplate <class _Iter, bool> struct __iterator_traits_impl {};
4513e519524SHoward Hinnant
4523e519524SHoward Hinnanttemplate <class _Iter>
4530724bf67SMarshall Clowstruct __iterator_traits_impl<_Iter, true>
4543e519524SHoward Hinnant{
4553e519524SHoward Hinnant    typedef typename _Iter::difference_type   difference_type;
4563e519524SHoward Hinnant    typedef typename _Iter::value_type        value_type;
4573e519524SHoward Hinnant    typedef typename _Iter::pointer           pointer;
4583e519524SHoward Hinnant    typedef typename _Iter::reference         reference;
4593e519524SHoward Hinnant    typedef typename _Iter::iterator_category iterator_category;
4603e519524SHoward Hinnant};
4613e519524SHoward Hinnant
4623e519524SHoward Hinnanttemplate <class _Iter, bool> struct __iterator_traits {};
4633e519524SHoward Hinnant
4643e519524SHoward Hinnanttemplate <class _Iter>
4653e519524SHoward Hinnantstruct __iterator_traits<_Iter, true>
4660724bf67SMarshall Clow    :  __iterator_traits_impl
4673e519524SHoward Hinnant      <
4683e519524SHoward Hinnant        _Iter,
4693e519524SHoward Hinnant        is_convertible<typename _Iter::iterator_category, input_iterator_tag>::value ||
4703e519524SHoward Hinnant        is_convertible<typename _Iter::iterator_category, output_iterator_tag>::value
4713e519524SHoward Hinnant      >
4723e519524SHoward Hinnant{};
4733e519524SHoward Hinnant
4743e519524SHoward Hinnant// iterator_traits<Iterator> will only have the nested types if Iterator::iterator_category
4753e519524SHoward Hinnant//    exists.  Else iterator_traits<Iterator> will be an empty class.  This is a
4763e519524SHoward Hinnant//    conforming extension which allows some programs to compile and behave as
4773e519524SHoward Hinnant//    the client expects instead of failing at compile time.
4783e519524SHoward Hinnant
4793e519524SHoward Hinnanttemplate <class _Iter>
480e2f2d1edSEric Fiselierstruct _LIBCPP_TEMPLATE_VIS iterator_traits
4813e519524SHoward Hinnant    : __iterator_traits<_Iter, __has_iterator_category<_Iter>::value> {};
4823e519524SHoward Hinnant
4833e519524SHoward Hinnanttemplate<class _Tp>
484e2f2d1edSEric Fiselierstruct _LIBCPP_TEMPLATE_VIS iterator_traits<_Tp*>
4853e519524SHoward Hinnant{
4863e519524SHoward Hinnant    typedef ptrdiff_t difference_type;
487ffcfd923SMarshall Clow    typedef typename remove_cv<_Tp>::type value_type;
4883e519524SHoward Hinnant    typedef _Tp* pointer;
4893e519524SHoward Hinnant    typedef _Tp& reference;
4903e519524SHoward Hinnant    typedef random_access_iterator_tag iterator_category;
4913e519524SHoward Hinnant};
4923e519524SHoward Hinnant
4933e519524SHoward Hinnanttemplate <class _Tp, class _Up, bool = __has_iterator_category<iterator_traits<_Tp> >::value>
4943e519524SHoward Hinnantstruct __has_iterator_category_convertible_to
4953e519524SHoward Hinnant    : public integral_constant<bool, is_convertible<typename iterator_traits<_Tp>::iterator_category, _Up>::value>
4963e519524SHoward Hinnant{};
4973e519524SHoward Hinnant
4983e519524SHoward Hinnanttemplate <class _Tp, class _Up>
4993e519524SHoward Hinnantstruct __has_iterator_category_convertible_to<_Tp, _Up, false> : public false_type {};
5003e519524SHoward Hinnant
5013e519524SHoward Hinnanttemplate <class _Tp>
5023e519524SHoward Hinnantstruct __is_input_iterator : public __has_iterator_category_convertible_to<_Tp, input_iterator_tag> {};
5033e519524SHoward Hinnant
5043e519524SHoward Hinnanttemplate <class _Tp>
5053e519524SHoward Hinnantstruct __is_forward_iterator : public __has_iterator_category_convertible_to<_Tp, forward_iterator_tag> {};
5063e519524SHoward Hinnant
5073e519524SHoward Hinnanttemplate <class _Tp>
5083e519524SHoward Hinnantstruct __is_bidirectional_iterator : public __has_iterator_category_convertible_to<_Tp, bidirectional_iterator_tag> {};
5093e519524SHoward Hinnant
5103e519524SHoward Hinnanttemplate <class _Tp>
5113e519524SHoward Hinnantstruct __is_random_access_iterator : public __has_iterator_category_convertible_to<_Tp, random_access_iterator_tag> {};
5123e519524SHoward Hinnant
51376b4afc0SMarshall Clowtemplate <class _Tp>
51476b4afc0SMarshall Clowstruct __is_exactly_input_iterator
51576b4afc0SMarshall Clow    : public integral_constant<bool,
51676b4afc0SMarshall Clow         __has_iterator_category_convertible_to<_Tp, input_iterator_tag>::value &&
51776b4afc0SMarshall Clow        !__has_iterator_category_convertible_to<_Tp, forward_iterator_tag>::value> {};
51876b4afc0SMarshall Clow
5193e519524SHoward Hinnanttemplate<class _Category, class _Tp, class _Distance = ptrdiff_t,
5203e519524SHoward Hinnant         class _Pointer = _Tp*, class _Reference = _Tp&>
521e2f2d1edSEric Fiselierstruct _LIBCPP_TEMPLATE_VIS iterator
5223e519524SHoward Hinnant{
5233e519524SHoward Hinnant    typedef _Tp        value_type;
5243e519524SHoward Hinnant    typedef _Distance  difference_type;
5253e519524SHoward Hinnant    typedef _Pointer   pointer;
5263e519524SHoward Hinnant    typedef _Reference reference;
5273e519524SHoward Hinnant    typedef _Category  iterator_category;
5283e519524SHoward Hinnant};
5293e519524SHoward Hinnant
5303e519524SHoward Hinnanttemplate <class _InputIter>
531f51ee632SMarshall Clowinline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
5323e519524SHoward Hinnantvoid __advance(_InputIter& __i,
5333e519524SHoward Hinnant             typename iterator_traits<_InputIter>::difference_type __n, input_iterator_tag)
5343e519524SHoward Hinnant{
5353e519524SHoward Hinnant    for (; __n > 0; --__n)
5363e519524SHoward Hinnant        ++__i;
5373e519524SHoward Hinnant}
5383e519524SHoward Hinnant
5393e519524SHoward Hinnanttemplate <class _BiDirIter>
540f51ee632SMarshall Clowinline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
5413e519524SHoward Hinnantvoid __advance(_BiDirIter& __i,
5423e519524SHoward Hinnant             typename iterator_traits<_BiDirIter>::difference_type __n, bidirectional_iterator_tag)
5433e519524SHoward Hinnant{
5443e519524SHoward Hinnant    if (__n >= 0)
5453e519524SHoward Hinnant        for (; __n > 0; --__n)
5463e519524SHoward Hinnant            ++__i;
5473e519524SHoward Hinnant    else
5483e519524SHoward Hinnant        for (; __n < 0; ++__n)
5493e519524SHoward Hinnant            --__i;
5503e519524SHoward Hinnant}
5513e519524SHoward Hinnant
5523e519524SHoward Hinnanttemplate <class _RandIter>
553f51ee632SMarshall Clowinline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
5543e519524SHoward Hinnantvoid __advance(_RandIter& __i,
5553e519524SHoward Hinnant             typename iterator_traits<_RandIter>::difference_type __n, random_access_iterator_tag)
5563e519524SHoward Hinnant{
5573e519524SHoward Hinnant   __i += __n;
5583e519524SHoward Hinnant}
5593e519524SHoward Hinnant
5603e519524SHoward Hinnanttemplate <class _InputIter>
561f51ee632SMarshall Clowinline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
5623e519524SHoward Hinnantvoid advance(_InputIter& __i,
5633e519524SHoward Hinnant             typename iterator_traits<_InputIter>::difference_type __n)
5643e519524SHoward Hinnant{
5653e519524SHoward Hinnant    __advance(__i, __n, typename iterator_traits<_InputIter>::iterator_category());
5663e519524SHoward Hinnant}
5673e519524SHoward Hinnant
5683e519524SHoward Hinnanttemplate <class _InputIter>
569f51ee632SMarshall Clowinline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
5703e519524SHoward Hinnanttypename iterator_traits<_InputIter>::difference_type
5713e519524SHoward Hinnant__distance(_InputIter __first, _InputIter __last, input_iterator_tag)
5723e519524SHoward Hinnant{
5733e519524SHoward Hinnant    typename iterator_traits<_InputIter>::difference_type __r(0);
5743e519524SHoward Hinnant    for (; __first != __last; ++__first)
5753e519524SHoward Hinnant        ++__r;
5763e519524SHoward Hinnant    return __r;
5773e519524SHoward Hinnant}
5783e519524SHoward Hinnant
5793e519524SHoward Hinnanttemplate <class _RandIter>
580f51ee632SMarshall Clowinline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
5813e519524SHoward Hinnanttypename iterator_traits<_RandIter>::difference_type
5823e519524SHoward Hinnant__distance(_RandIter __first, _RandIter __last, random_access_iterator_tag)
5833e519524SHoward Hinnant{
5843e519524SHoward Hinnant    return __last - __first;
5853e519524SHoward Hinnant}
5863e519524SHoward Hinnant
5873e519524SHoward Hinnanttemplate <class _InputIter>
588f51ee632SMarshall Clowinline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
5893e519524SHoward Hinnanttypename iterator_traits<_InputIter>::difference_type
5903e519524SHoward Hinnantdistance(_InputIter __first, _InputIter __last)
5913e519524SHoward Hinnant{
5923e519524SHoward Hinnant    return __distance(__first, __last, typename iterator_traits<_InputIter>::iterator_category());
5933e519524SHoward Hinnant}
5943e519524SHoward Hinnant
595e5f1288fSMarshall Clowtemplate <class _InputIter>
596f51ee632SMarshall Clowinline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
5973e2ef408SRachel Craiktypename enable_if
5983e2ef408SRachel Craik<
5993e2ef408SRachel Craik    __is_input_iterator<_InputIter>::value,
600e5f1288fSMarshall Clow    _InputIter
6013e2ef408SRachel Craik>::type
602e5f1288fSMarshall Clownext(_InputIter __x,
6033e2ef408SRachel Craik     typename iterator_traits<_InputIter>::difference_type __n = 1)
6043e519524SHoward Hinnant{
605ce48a113SHoward Hinnant    _VSTD::advance(__x, __n);
6063e519524SHoward Hinnant    return __x;
6073e519524SHoward Hinnant}
6083e519524SHoward Hinnant
6093e2ef408SRachel Craiktemplate <class _BidirectionalIter>
610f51ee632SMarshall Clowinline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
6113e2ef408SRachel Craiktypename enable_if
6123e2ef408SRachel Craik<
6133e2ef408SRachel Craik    __is_bidirectional_iterator<_BidirectionalIter>::value,
6143e2ef408SRachel Craik    _BidirectionalIter
6153e2ef408SRachel Craik>::type
6163e2ef408SRachel Craikprev(_BidirectionalIter __x,
6173e2ef408SRachel Craik     typename iterator_traits<_BidirectionalIter>::difference_type __n = 1)
6183e519524SHoward Hinnant{
619ce48a113SHoward Hinnant    _VSTD::advance(__x, -__n);
6203e519524SHoward Hinnant    return __x;
6213e519524SHoward Hinnant}
6223e519524SHoward Hinnant
623e02ed1c2SEric Fiselier
624e02ed1c2SEric Fiseliertemplate <class _Tp, class = void>
625e02ed1c2SEric Fiselierstruct __is_stashing_iterator : false_type {};
626e02ed1c2SEric Fiselier
627e02ed1c2SEric Fiseliertemplate <class _Tp>
628e02ed1c2SEric Fiselierstruct __is_stashing_iterator<_Tp, typename __void_t<typename _Tp::__stashing_iterator_tag>::type>
629e02ed1c2SEric Fiselier  : true_type {};
630e02ed1c2SEric Fiselier
6313e519524SHoward Hinnanttemplate <class _Iter>
632e2f2d1edSEric Fiselierclass _LIBCPP_TEMPLATE_VIS reverse_iterator
6333e519524SHoward Hinnant    : public iterator<typename iterator_traits<_Iter>::iterator_category,
6343e519524SHoward Hinnant                      typename iterator_traits<_Iter>::value_type,
6353e519524SHoward Hinnant                      typename iterator_traits<_Iter>::difference_type,
6363e519524SHoward Hinnant                      typename iterator_traits<_Iter>::pointer,
6373e519524SHoward Hinnant                      typename iterator_traits<_Iter>::reference>
6383e519524SHoward Hinnant{
6393b83496dSMarshall Clowprivate:
6401b8f260eSMarshall Clow    /*mutable*/ _Iter __t;  // no longer used as of LWG #2360, not removed due to ABI break
641e02ed1c2SEric Fiselier
642e02ed1c2SEric Fiselier    static_assert(!__is_stashing_iterator<_Iter>::value,
643e02ed1c2SEric Fiselier      "The specified iterator type cannot be used with reverse_iterator; "
644e02ed1c2SEric Fiselier      "Using stashing iterators with reverse_iterator causes undefined behavior");
645e02ed1c2SEric Fiselier
646b2d74f29SMarshall Clowprotected:
647b2d74f29SMarshall Clow    _Iter current;
6483e519524SHoward Hinnantpublic:
6493e519524SHoward Hinnant    typedef _Iter                                            iterator_type;
6503e519524SHoward Hinnant    typedef typename iterator_traits<_Iter>::difference_type difference_type;
6513e519524SHoward Hinnant    typedef typename iterator_traits<_Iter>::reference       reference;
6523e519524SHoward Hinnant    typedef typename iterator_traits<_Iter>::pointer         pointer;
6533e519524SHoward Hinnant
6541b8f260eSMarshall Clow    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
6551b8f260eSMarshall Clow    reverse_iterator() : __t(), current() {}
6561b8f260eSMarshall Clow    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
6571b8f260eSMarshall Clow    explicit reverse_iterator(_Iter __x) : __t(__x), current(__x) {}
6581b8f260eSMarshall Clow    template <class _Up>
6591b8f260eSMarshall Clow        _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
6601b8f260eSMarshall Clow        reverse_iterator(const reverse_iterator<_Up>& __u) : __t(__u.base()), current(__u.base()) {}
6611b8f260eSMarshall Clow    template <class _Up>
6621b8f260eSMarshall Clow        _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
6631b8f260eSMarshall Clow        reverse_iterator& operator=(const reverse_iterator<_Up>& __u)
6641b8f260eSMarshall Clow            { __t = current = __u.base(); return *this; }
6651b8f260eSMarshall Clow    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
6661b8f260eSMarshall Clow    _Iter base() const {return current;}
6671b8f260eSMarshall Clow    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
6681b8f260eSMarshall Clow    reference operator*() const {_Iter __tmp = current; return *--__tmp;}
6691b8f260eSMarshall Clow    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
6701b8f260eSMarshall Clow    pointer  operator->() const {return _VSTD::addressof(operator*());}
6711b8f260eSMarshall Clow    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
6721b8f260eSMarshall Clow    reverse_iterator& operator++() {--current; return *this;}
6731b8f260eSMarshall Clow    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
6741b8f260eSMarshall Clow    reverse_iterator  operator++(int) {reverse_iterator __tmp(*this); --current; return __tmp;}
6751b8f260eSMarshall Clow    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
6761b8f260eSMarshall Clow    reverse_iterator& operator--() {++current; return *this;}
6771b8f260eSMarshall Clow    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
6781b8f260eSMarshall Clow    reverse_iterator  operator--(int) {reverse_iterator __tmp(*this); ++current; return __tmp;}
6791b8f260eSMarshall Clow    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
6801b8f260eSMarshall Clow    reverse_iterator  operator+ (difference_type __n) const {return reverse_iterator(current - __n);}
6811b8f260eSMarshall Clow    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
6821b8f260eSMarshall Clow    reverse_iterator& operator+=(difference_type __n) {current -= __n; return *this;}
6831b8f260eSMarshall Clow    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
6841b8f260eSMarshall Clow    reverse_iterator  operator- (difference_type __n) const {return reverse_iterator(current + __n);}
6851b8f260eSMarshall Clow    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
6861b8f260eSMarshall Clow    reverse_iterator& operator-=(difference_type __n) {current += __n; return *this;}
6871b8f260eSMarshall Clow    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
6881b8f260eSMarshall Clow    reference         operator[](difference_type __n) const {return *(*this + __n);}
6893e519524SHoward Hinnant};
6903e519524SHoward Hinnant
6913e519524SHoward Hinnanttemplate <class _Iter1, class _Iter2>
6921b8f260eSMarshall Clowinline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
6933e519524SHoward Hinnantbool
6943e519524SHoward Hinnantoperator==(const reverse_iterator<_Iter1>& __x, const reverse_iterator<_Iter2>& __y)
6953e519524SHoward Hinnant{
6963e519524SHoward Hinnant    return __x.base() == __y.base();
6973e519524SHoward Hinnant}
6983e519524SHoward Hinnant
6993e519524SHoward Hinnanttemplate <class _Iter1, class _Iter2>
7001b8f260eSMarshall Clowinline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
7013e519524SHoward Hinnantbool
7023e519524SHoward Hinnantoperator<(const reverse_iterator<_Iter1>& __x, const reverse_iterator<_Iter2>& __y)
7033e519524SHoward Hinnant{
7043e519524SHoward Hinnant    return __x.base() > __y.base();
7053e519524SHoward Hinnant}
7063e519524SHoward Hinnant
7073e519524SHoward Hinnanttemplate <class _Iter1, class _Iter2>
7081b8f260eSMarshall Clowinline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
7093e519524SHoward Hinnantbool
7103e519524SHoward Hinnantoperator!=(const reverse_iterator<_Iter1>& __x, const reverse_iterator<_Iter2>& __y)
7113e519524SHoward Hinnant{
7123e519524SHoward Hinnant    return __x.base() != __y.base();
7133e519524SHoward Hinnant}
7143e519524SHoward Hinnant
7153e519524SHoward Hinnanttemplate <class _Iter1, class _Iter2>
7161b8f260eSMarshall Clowinline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
7173e519524SHoward Hinnantbool
7183e519524SHoward Hinnantoperator>(const reverse_iterator<_Iter1>& __x, const reverse_iterator<_Iter2>& __y)
7193e519524SHoward Hinnant{
7203e519524SHoward Hinnant    return __x.base() < __y.base();
7213e519524SHoward Hinnant}
7223e519524SHoward Hinnant
7233e519524SHoward Hinnanttemplate <class _Iter1, class _Iter2>
7241b8f260eSMarshall Clowinline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
7253e519524SHoward Hinnantbool
7263e519524SHoward Hinnantoperator>=(const reverse_iterator<_Iter1>& __x, const reverse_iterator<_Iter2>& __y)
7273e519524SHoward Hinnant{
7283e519524SHoward Hinnant    return __x.base() <= __y.base();
7293e519524SHoward Hinnant}
7303e519524SHoward Hinnant
7313e519524SHoward Hinnanttemplate <class _Iter1, class _Iter2>
7321b8f260eSMarshall Clowinline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
7333e519524SHoward Hinnantbool
7343e519524SHoward Hinnantoperator<=(const reverse_iterator<_Iter1>& __x, const reverse_iterator<_Iter2>& __y)
7353e519524SHoward Hinnant{
7363e519524SHoward Hinnant    return __x.base() >= __y.base();
7373e519524SHoward Hinnant}
7383e519524SHoward Hinnant
7392ee83725SMarshall Clow#ifndef _LIBCPP_CXX03_LANG
740947ce6b5SMarshall Clowtemplate <class _Iter1, class _Iter2>
7411b8f260eSMarshall Clowinline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
742947ce6b5SMarshall Clowauto
743947ce6b5SMarshall Clowoperator-(const reverse_iterator<_Iter1>& __x, const reverse_iterator<_Iter2>& __y)
744947ce6b5SMarshall Clow-> decltype(__y.base() - __x.base())
745947ce6b5SMarshall Clow{
746947ce6b5SMarshall Clow    return __y.base() - __x.base();
747947ce6b5SMarshall Clow}
748947ce6b5SMarshall Clow#else
7493e519524SHoward Hinnanttemplate <class _Iter1, class _Iter2>
7503e519524SHoward Hinnantinline _LIBCPP_INLINE_VISIBILITY
7513e519524SHoward Hinnanttypename reverse_iterator<_Iter1>::difference_type
7523e519524SHoward Hinnantoperator-(const reverse_iterator<_Iter1>& __x, const reverse_iterator<_Iter2>& __y)
7533e519524SHoward Hinnant{
7543e519524SHoward Hinnant    return __y.base() - __x.base();
7553e519524SHoward Hinnant}
756947ce6b5SMarshall Clow#endif
7573e519524SHoward Hinnant
7583e519524SHoward Hinnanttemplate <class _Iter>
7591b8f260eSMarshall Clowinline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
7603e519524SHoward Hinnantreverse_iterator<_Iter>
7613e519524SHoward Hinnantoperator+(typename reverse_iterator<_Iter>::difference_type __n, const reverse_iterator<_Iter>& __x)
7623e519524SHoward Hinnant{
7633e519524SHoward Hinnant    return reverse_iterator<_Iter>(__x.base() - __n);
7643e519524SHoward Hinnant}
7653e519524SHoward Hinnant
7666a640a18SMarshall Clow#if _LIBCPP_STD_VER > 11
7676a640a18SMarshall Clowtemplate <class _Iter>
7681b8f260eSMarshall Clowinline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
7696a640a18SMarshall Clowreverse_iterator<_Iter> make_reverse_iterator(_Iter __i)
7706a640a18SMarshall Clow{
7716a640a18SMarshall Clow    return reverse_iterator<_Iter>(__i);
7726a640a18SMarshall Clow}
7736a640a18SMarshall Clow#endif
7746a640a18SMarshall Clow
7753e519524SHoward Hinnanttemplate <class _Container>
776e2f2d1edSEric Fiselierclass _LIBCPP_TEMPLATE_VIS back_insert_iterator
7773e519524SHoward Hinnant    : public iterator<output_iterator_tag,
7783e519524SHoward Hinnant                      void,
7793e519524SHoward Hinnant                      void,
7803e519524SHoward Hinnant                      void,
7818892b4eeSEric Fiselier                      void>
7823e519524SHoward Hinnant{
7833e519524SHoward Hinnantprotected:
7843e519524SHoward Hinnant    _Container* container;
7853e519524SHoward Hinnantpublic:
7863e519524SHoward Hinnant    typedef _Container container_type;
7873e519524SHoward Hinnant
788f519be34SMarshall Clow    _LIBCPP_INLINE_VISIBILITY explicit back_insert_iterator(_Container& __x) : container(_VSTD::addressof(__x)) {}
789e4383379SHoward Hinnant    _LIBCPP_INLINE_VISIBILITY back_insert_iterator& operator=(const typename _Container::value_type& __value_)
790e4383379SHoward Hinnant        {container->push_back(__value_); return *this;}
791046492b9SEric Fiselier#ifndef _LIBCPP_CXX03_LANG
792e4383379SHoward Hinnant    _LIBCPP_INLINE_VISIBILITY back_insert_iterator& operator=(typename _Container::value_type&& __value_)
793e4383379SHoward Hinnant        {container->push_back(_VSTD::move(__value_)); return *this;}
794046492b9SEric Fiselier#endif  // _LIBCPP_CXX03_LANG
7953e519524SHoward Hinnant    _LIBCPP_INLINE_VISIBILITY back_insert_iterator& operator*()     {return *this;}
7963e519524SHoward Hinnant    _LIBCPP_INLINE_VISIBILITY back_insert_iterator& operator++()    {return *this;}
7973e519524SHoward Hinnant    _LIBCPP_INLINE_VISIBILITY back_insert_iterator  operator++(int) {return *this;}
7983e519524SHoward Hinnant};
7993e519524SHoward Hinnant
8003e519524SHoward Hinnanttemplate <class _Container>
8013e519524SHoward Hinnantinline _LIBCPP_INLINE_VISIBILITY
8023e519524SHoward Hinnantback_insert_iterator<_Container>
8033e519524SHoward Hinnantback_inserter(_Container& __x)
8043e519524SHoward Hinnant{
8053e519524SHoward Hinnant    return back_insert_iterator<_Container>(__x);
8063e519524SHoward Hinnant}
8073e519524SHoward Hinnant
8083e519524SHoward Hinnanttemplate <class _Container>
809e2f2d1edSEric Fiselierclass _LIBCPP_TEMPLATE_VIS front_insert_iterator
8103e519524SHoward Hinnant    : public iterator<output_iterator_tag,
8113e519524SHoward Hinnant                      void,
8123e519524SHoward Hinnant                      void,
8133e519524SHoward Hinnant                      void,
8148892b4eeSEric Fiselier                      void>
8153e519524SHoward Hinnant{
8163e519524SHoward Hinnantprotected:
8173e519524SHoward Hinnant    _Container* container;
8183e519524SHoward Hinnantpublic:
8193e519524SHoward Hinnant    typedef _Container container_type;
8203e519524SHoward Hinnant
821f519be34SMarshall Clow    _LIBCPP_INLINE_VISIBILITY explicit front_insert_iterator(_Container& __x) : container(_VSTD::addressof(__x)) {}
822e4383379SHoward Hinnant    _LIBCPP_INLINE_VISIBILITY front_insert_iterator& operator=(const typename _Container::value_type& __value_)
823e4383379SHoward Hinnant        {container->push_front(__value_); return *this;}
824046492b9SEric Fiselier#ifndef _LIBCPP_CXX03_LANG
825e4383379SHoward Hinnant    _LIBCPP_INLINE_VISIBILITY front_insert_iterator& operator=(typename _Container::value_type&& __value_)
826e4383379SHoward Hinnant        {container->push_front(_VSTD::move(__value_)); return *this;}
827046492b9SEric Fiselier#endif  // _LIBCPP_CXX03_LANG
8283e519524SHoward Hinnant    _LIBCPP_INLINE_VISIBILITY front_insert_iterator& operator*()     {return *this;}
8293e519524SHoward Hinnant    _LIBCPP_INLINE_VISIBILITY front_insert_iterator& operator++()    {return *this;}
8303e519524SHoward Hinnant    _LIBCPP_INLINE_VISIBILITY front_insert_iterator  operator++(int) {return *this;}
8313e519524SHoward Hinnant};
8323e519524SHoward Hinnant
8333e519524SHoward Hinnanttemplate <class _Container>
8343e519524SHoward Hinnantinline _LIBCPP_INLINE_VISIBILITY
8353e519524SHoward Hinnantfront_insert_iterator<_Container>
8363e519524SHoward Hinnantfront_inserter(_Container& __x)
8373e519524SHoward Hinnant{
8383e519524SHoward Hinnant    return front_insert_iterator<_Container>(__x);
8393e519524SHoward Hinnant}
8403e519524SHoward Hinnant
8413e519524SHoward Hinnanttemplate <class _Container>
842e2f2d1edSEric Fiselierclass _LIBCPP_TEMPLATE_VIS insert_iterator
8433e519524SHoward Hinnant    : public iterator<output_iterator_tag,
8443e519524SHoward Hinnant                      void,
8453e519524SHoward Hinnant                      void,
8463e519524SHoward Hinnant                      void,
8478892b4eeSEric Fiselier                      void>
8483e519524SHoward Hinnant{
8493e519524SHoward Hinnantprotected:
8503e519524SHoward Hinnant    _Container* container;
8513e519524SHoward Hinnant    typename _Container::iterator iter;
8523e519524SHoward Hinnantpublic:
8533e519524SHoward Hinnant    typedef _Container container_type;
8543e519524SHoward Hinnant
8553e519524SHoward Hinnant    _LIBCPP_INLINE_VISIBILITY insert_iterator(_Container& __x, typename _Container::iterator __i)
856f519be34SMarshall Clow        : container(_VSTD::addressof(__x)), iter(__i) {}
857e4383379SHoward Hinnant    _LIBCPP_INLINE_VISIBILITY insert_iterator& operator=(const typename _Container::value_type& __value_)
858e4383379SHoward Hinnant        {iter = container->insert(iter, __value_); ++iter; return *this;}
859046492b9SEric Fiselier#ifndef _LIBCPP_CXX03_LANG
860e4383379SHoward Hinnant    _LIBCPP_INLINE_VISIBILITY insert_iterator& operator=(typename _Container::value_type&& __value_)
861e4383379SHoward Hinnant        {iter = container->insert(iter, _VSTD::move(__value_)); ++iter; return *this;}
862046492b9SEric Fiselier#endif  // _LIBCPP_CXX03_LANG
8633e519524SHoward Hinnant    _LIBCPP_INLINE_VISIBILITY insert_iterator& operator*()        {return *this;}
8643e519524SHoward Hinnant    _LIBCPP_INLINE_VISIBILITY insert_iterator& operator++()       {return *this;}
8653e519524SHoward Hinnant    _LIBCPP_INLINE_VISIBILITY insert_iterator& operator++(int)    {return *this;}
8663e519524SHoward Hinnant};
8673e519524SHoward Hinnant
8683e519524SHoward Hinnanttemplate <class _Container>
8693e519524SHoward Hinnantinline _LIBCPP_INLINE_VISIBILITY
8703e519524SHoward Hinnantinsert_iterator<_Container>
8713e519524SHoward Hinnantinserter(_Container& __x, typename _Container::iterator __i)
8723e519524SHoward Hinnant{
8733e519524SHoward Hinnant    return insert_iterator<_Container>(__x, __i);
8743e519524SHoward Hinnant}
8753e519524SHoward Hinnant
8763e519524SHoward Hinnanttemplate <class _Tp, class _CharT = char,
8773e519524SHoward Hinnant          class _Traits = char_traits<_CharT>, class _Distance = ptrdiff_t>
878e2f2d1edSEric Fiselierclass _LIBCPP_TEMPLATE_VIS istream_iterator
8793e519524SHoward Hinnant    : public iterator<input_iterator_tag, _Tp, _Distance, const _Tp*, const _Tp&>
8803e519524SHoward Hinnant{
8813e519524SHoward Hinnantpublic:
8823e519524SHoward Hinnant    typedef _CharT char_type;
8833e519524SHoward Hinnant    typedef _Traits traits_type;
8843e519524SHoward Hinnant    typedef basic_istream<_CharT,_Traits> istream_type;
8853e519524SHoward Hinnantprivate:
8863e519524SHoward Hinnant    istream_type* __in_stream_;
8873e519524SHoward Hinnant    _Tp __value_;
8883e519524SHoward Hinnantpublic:
88960d5e0e0SMarshall Clow    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR istream_iterator() : __in_stream_(0), __value_() {}
890bc6a7df0SMarshall Clow    _LIBCPP_INLINE_VISIBILITY istream_iterator(istream_type& __s) : __in_stream_(_VSTD::addressof(__s))
8913e519524SHoward Hinnant        {
8923e519524SHoward Hinnant            if (!(*__in_stream_ >> __value_))
8933e519524SHoward Hinnant                __in_stream_ = 0;
8943e519524SHoward Hinnant        }
8953e519524SHoward Hinnant
8963e519524SHoward Hinnant    _LIBCPP_INLINE_VISIBILITY const _Tp& operator*() const {return __value_;}
897bc6a7df0SMarshall Clow    _LIBCPP_INLINE_VISIBILITY const _Tp* operator->() const {return _VSTD::addressof((operator*()));}
8983e519524SHoward Hinnant    _LIBCPP_INLINE_VISIBILITY istream_iterator& operator++()
8993e519524SHoward Hinnant        {
9003e519524SHoward Hinnant            if (!(*__in_stream_ >> __value_))
9013e519524SHoward Hinnant                __in_stream_ = 0;
9023e519524SHoward Hinnant            return *this;
9033e519524SHoward Hinnant        }
9043e519524SHoward Hinnant    _LIBCPP_INLINE_VISIBILITY istream_iterator  operator++(int)
9053e519524SHoward Hinnant        {istream_iterator __t(*this); ++(*this); return __t;}
9063e519524SHoward Hinnant
907*6f56d3eeSRoger Ferrer Ibanez    template <class _Up, class _CharU, class _TraitsU, class _DistanceU>
9083e519524SHoward Hinnant    friend _LIBCPP_INLINE_VISIBILITY
909*6f56d3eeSRoger Ferrer Ibanez    bool
910*6f56d3eeSRoger Ferrer Ibanez    operator==(const istream_iterator<_Up, _CharU, _TraitsU, _DistanceU>& __x,
911*6f56d3eeSRoger Ferrer Ibanez               const istream_iterator<_Up, _CharU, _TraitsU, _DistanceU>& __y);
9123e519524SHoward Hinnant
913*6f56d3eeSRoger Ferrer Ibanez    template <class _Up, class _CharU, class _TraitsU, class _DistanceU>
9143e519524SHoward Hinnant    friend _LIBCPP_INLINE_VISIBILITY
915*6f56d3eeSRoger Ferrer Ibanez    bool
916*6f56d3eeSRoger Ferrer Ibanez    operator==(const istream_iterator<_Up, _CharU, _TraitsU, _DistanceU>& __x,
917*6f56d3eeSRoger Ferrer Ibanez               const istream_iterator<_Up, _CharU, _TraitsU, _DistanceU>& __y);
9183e519524SHoward Hinnant};
9193e519524SHoward Hinnant
920*6f56d3eeSRoger Ferrer Ibaneztemplate <class _Tp, class _CharT, class _Traits, class _Distance>
921*6f56d3eeSRoger Ferrer Ibanezinline _LIBCPP_INLINE_VISIBILITY
922*6f56d3eeSRoger Ferrer Ibanezbool
923*6f56d3eeSRoger Ferrer Ibanezoperator==(const istream_iterator<_Tp, _CharT, _Traits, _Distance>& __x,
924*6f56d3eeSRoger Ferrer Ibanez           const istream_iterator<_Tp, _CharT, _Traits, _Distance>& __y)
925*6f56d3eeSRoger Ferrer Ibanez{
926*6f56d3eeSRoger Ferrer Ibanez    return __x.__in_stream_ == __y.__in_stream_;
927*6f56d3eeSRoger Ferrer Ibanez}
928*6f56d3eeSRoger Ferrer Ibanez
929*6f56d3eeSRoger Ferrer Ibaneztemplate <class _Tp, class _CharT, class _Traits, class _Distance>
930*6f56d3eeSRoger Ferrer Ibanezinline _LIBCPP_INLINE_VISIBILITY
931*6f56d3eeSRoger Ferrer Ibanezbool
932*6f56d3eeSRoger Ferrer Ibanezoperator!=(const istream_iterator<_Tp, _CharT, _Traits, _Distance>& __x,
933*6f56d3eeSRoger Ferrer Ibanez           const istream_iterator<_Tp, _CharT, _Traits, _Distance>& __y)
934*6f56d3eeSRoger Ferrer Ibanez{
935*6f56d3eeSRoger Ferrer Ibanez    return !(__x == __y);
936*6f56d3eeSRoger Ferrer Ibanez}
937*6f56d3eeSRoger Ferrer Ibanez
9383e519524SHoward Hinnanttemplate <class _Tp, class _CharT = char, class _Traits = char_traits<_CharT> >
939e2f2d1edSEric Fiselierclass _LIBCPP_TEMPLATE_VIS ostream_iterator
9403e519524SHoward Hinnant    : public iterator<output_iterator_tag, void, void, void, void>
9413e519524SHoward Hinnant{
9423e519524SHoward Hinnantpublic:
9433e519524SHoward Hinnant    typedef _CharT char_type;
9443e519524SHoward Hinnant    typedef _Traits traits_type;
9453e519524SHoward Hinnant    typedef basic_ostream<_CharT,_Traits> ostream_type;
9463e519524SHoward Hinnantprivate:
9473e519524SHoward Hinnant    ostream_type* __out_stream_;
9483e519524SHoward Hinnant    const char_type* __delim_;
9493e519524SHoward Hinnantpublic:
950853042cfSMarshall Clow    _LIBCPP_INLINE_VISIBILITY ostream_iterator(ostream_type& __s) _NOEXCEPT
951bc6a7df0SMarshall Clow        : __out_stream_(_VSTD::addressof(__s)), __delim_(0) {}
952853042cfSMarshall Clow    _LIBCPP_INLINE_VISIBILITY ostream_iterator(ostream_type& __s, const _CharT* __delimiter) _NOEXCEPT
953bc6a7df0SMarshall Clow        : __out_stream_(_VSTD::addressof(__s)), __delim_(__delimiter) {}
954e4383379SHoward Hinnant    _LIBCPP_INLINE_VISIBILITY ostream_iterator& operator=(const _Tp& __value_)
9553e519524SHoward Hinnant        {
956e4383379SHoward Hinnant            *__out_stream_ << __value_;
9573e519524SHoward Hinnant            if (__delim_)
9583e519524SHoward Hinnant                *__out_stream_ << __delim_;
9593e519524SHoward Hinnant            return *this;
9603e519524SHoward Hinnant        }
9613e519524SHoward Hinnant
9623e519524SHoward Hinnant    _LIBCPP_INLINE_VISIBILITY ostream_iterator& operator*()     {return *this;}
9633e519524SHoward Hinnant    _LIBCPP_INLINE_VISIBILITY ostream_iterator& operator++()    {return *this;}
9643e519524SHoward Hinnant    _LIBCPP_INLINE_VISIBILITY ostream_iterator& operator++(int) {return *this;}
9653e519524SHoward Hinnant};
9663e519524SHoward Hinnant
9673e519524SHoward Hinnanttemplate<class _CharT, class _Traits>
968e2f2d1edSEric Fiselierclass _LIBCPP_TEMPLATE_VIS istreambuf_iterator
9693e519524SHoward Hinnant    : public iterator<input_iterator_tag, _CharT,
9703e519524SHoward Hinnant                      typename _Traits::off_type, _CharT*,
9713e519524SHoward Hinnant                      _CharT>
9723e519524SHoward Hinnant{
9733e519524SHoward Hinnantpublic:
9743e519524SHoward Hinnant    typedef _CharT                          char_type;
9753e519524SHoward Hinnant    typedef _Traits                         traits_type;
9763e519524SHoward Hinnant    typedef typename _Traits::int_type      int_type;
9773e519524SHoward Hinnant    typedef basic_streambuf<_CharT,_Traits> streambuf_type;
9783e519524SHoward Hinnant    typedef basic_istream<_CharT,_Traits>   istream_type;
9793e519524SHoward Hinnantprivate:
980dfdf5085SHoward Hinnant    mutable streambuf_type* __sbuf_;
9813e519524SHoward Hinnant
9823e519524SHoward Hinnant    class __proxy
9833e519524SHoward Hinnant    {
9843e519524SHoward Hinnant        char_type __keep_;
9853e519524SHoward Hinnant        streambuf_type* __sbuf_;
9863e519524SHoward Hinnant        _LIBCPP_INLINE_VISIBILITY __proxy(char_type __c, streambuf_type* __s)
9873e519524SHoward Hinnant            : __keep_(__c), __sbuf_(__s) {}
9883e519524SHoward Hinnant        friend class istreambuf_iterator;
9893e519524SHoward Hinnant    public:
9903e519524SHoward Hinnant        _LIBCPP_INLINE_VISIBILITY char_type operator*() const {return __keep_;}
9913e519524SHoward Hinnant    };
9923e519524SHoward Hinnant
993848a5374SHoward Hinnant    _LIBCPP_INLINE_VISIBILITY
994dfdf5085SHoward Hinnant    bool __test_for_eof() const
9953e519524SHoward Hinnant    {
9963e519524SHoward Hinnant        if (__sbuf_ && traits_type::eq_int_type(__sbuf_->sgetc(), traits_type::eof()))
9973e519524SHoward Hinnant            __sbuf_ = 0;
998dfdf5085SHoward Hinnant        return __sbuf_ == 0;
9993e519524SHoward Hinnant    }
10003e519524SHoward Hinnantpublic:
1001dfdf5085SHoward Hinnant    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR istreambuf_iterator() _NOEXCEPT : __sbuf_(0) {}
10028e882dcbSHoward Hinnant    _LIBCPP_INLINE_VISIBILITY istreambuf_iterator(istream_type& __s) _NOEXCEPT
1003a96d7458SHoward Hinnant        : __sbuf_(__s.rdbuf()) {}
10048e882dcbSHoward Hinnant    _LIBCPP_INLINE_VISIBILITY istreambuf_iterator(streambuf_type* __s) _NOEXCEPT
1005a96d7458SHoward Hinnant        : __sbuf_(__s) {}
10068e882dcbSHoward Hinnant    _LIBCPP_INLINE_VISIBILITY istreambuf_iterator(const __proxy& __p) _NOEXCEPT
10073e519524SHoward Hinnant        : __sbuf_(__p.__sbuf_) {}
10083e519524SHoward Hinnant
1009c206366fSHoward Hinnant    _LIBCPP_INLINE_VISIBILITY char_type  operator*() const
1010c206366fSHoward Hinnant        {return static_cast<char_type>(__sbuf_->sgetc());}
10113e519524SHoward Hinnant    _LIBCPP_INLINE_VISIBILITY istreambuf_iterator& operator++()
10123e519524SHoward Hinnant        {
1013dfdf5085SHoward Hinnant            __sbuf_->sbumpc();
10143e519524SHoward Hinnant            return *this;
10153e519524SHoward Hinnant        }
10163e519524SHoward Hinnant    _LIBCPP_INLINE_VISIBILITY __proxy              operator++(int)
10173e519524SHoward Hinnant        {
1018dfdf5085SHoward Hinnant            return __proxy(__sbuf_->sbumpc(), __sbuf_);
10193e519524SHoward Hinnant        }
10203e519524SHoward Hinnant
10213e519524SHoward Hinnant    _LIBCPP_INLINE_VISIBILITY bool equal(const istreambuf_iterator& __b) const
1022dfdf5085SHoward Hinnant        {return __test_for_eof() == __b.__test_for_eof();}
10233e519524SHoward Hinnant};
10243e519524SHoward Hinnant
10253e519524SHoward Hinnanttemplate <class _CharT, class _Traits>
10263e519524SHoward Hinnantinline _LIBCPP_INLINE_VISIBILITY
10273e519524SHoward Hinnantbool operator==(const istreambuf_iterator<_CharT,_Traits>& __a,
10283e519524SHoward Hinnant                const istreambuf_iterator<_CharT,_Traits>& __b)
10293e519524SHoward Hinnant                {return __a.equal(__b);}
10303e519524SHoward Hinnant
10313e519524SHoward Hinnanttemplate <class _CharT, class _Traits>
10323e519524SHoward Hinnantinline _LIBCPP_INLINE_VISIBILITY
10333e519524SHoward Hinnantbool operator!=(const istreambuf_iterator<_CharT,_Traits>& __a,
10343e519524SHoward Hinnant                const istreambuf_iterator<_CharT,_Traits>& __b)
10353e519524SHoward Hinnant                {return !__a.equal(__b);}
10363e519524SHoward Hinnant
10373e519524SHoward Hinnanttemplate <class _CharT, class _Traits>
1038e2f2d1edSEric Fiselierclass _LIBCPP_TEMPLATE_VIS ostreambuf_iterator
10393e519524SHoward Hinnant    : public iterator<output_iterator_tag, void, void, void, void>
10403e519524SHoward Hinnant{
10413e519524SHoward Hinnantpublic:
10423e519524SHoward Hinnant    typedef _CharT                          char_type;
10433e519524SHoward Hinnant    typedef _Traits                         traits_type;
10443e519524SHoward Hinnant    typedef basic_streambuf<_CharT,_Traits> streambuf_type;
10453e519524SHoward Hinnant    typedef basic_ostream<_CharT,_Traits>   ostream_type;
10463e519524SHoward Hinnantprivate:
10473e519524SHoward Hinnant    streambuf_type* __sbuf_;
10483e519524SHoward Hinnantpublic:
10498e882dcbSHoward Hinnant    _LIBCPP_INLINE_VISIBILITY ostreambuf_iterator(ostream_type& __s) _NOEXCEPT
10503e519524SHoward Hinnant        : __sbuf_(__s.rdbuf()) {}
10518e882dcbSHoward Hinnant    _LIBCPP_INLINE_VISIBILITY ostreambuf_iterator(streambuf_type* __s) _NOEXCEPT
10523e519524SHoward Hinnant        : __sbuf_(__s) {}
10533e519524SHoward Hinnant    _LIBCPP_INLINE_VISIBILITY ostreambuf_iterator& operator=(_CharT __c)
10543e519524SHoward Hinnant        {
10553e519524SHoward Hinnant            if (__sbuf_ && traits_type::eq_int_type(__sbuf_->sputc(__c), traits_type::eof()))
10563e519524SHoward Hinnant                __sbuf_ = 0;
10573e519524SHoward Hinnant            return *this;
10583e519524SHoward Hinnant        }
10593e519524SHoward Hinnant    _LIBCPP_INLINE_VISIBILITY ostreambuf_iterator& operator*()     {return *this;}
10603e519524SHoward Hinnant    _LIBCPP_INLINE_VISIBILITY ostreambuf_iterator& operator++()    {return *this;}
10613e519524SHoward Hinnant    _LIBCPP_INLINE_VISIBILITY ostreambuf_iterator& operator++(int) {return *this;}
10628e882dcbSHoward Hinnant    _LIBCPP_INLINE_VISIBILITY bool failed() const _NOEXCEPT {return __sbuf_ == 0;}
106392b5940fSHoward Hinnant
1064b5c63a2eSHoward Hinnant#if !defined(__APPLE__) || \
1065b5c63a2eSHoward Hinnant    (defined(__MAC_OS_X_VERSION_MIN_REQUIRED) && __MAC_OS_X_VERSION_MIN_REQUIRED > __MAC_10_8) || \
1066b5c63a2eSHoward Hinnant    (defined(__IPHONE_OS_VERSION_MIN_REQUIRED) && __IPHONE_OS_VERSION_MIN_REQUIRED > __IPHONE_6_0)
1067b5c63a2eSHoward Hinnant
106892b5940fSHoward Hinnant    template <class _Ch, class _Tr>
106992b5940fSHoward Hinnant    friend
107092b5940fSHoward Hinnant    _LIBCPP_HIDDEN
107192b5940fSHoward Hinnant    ostreambuf_iterator<_Ch, _Tr>
107292b5940fSHoward Hinnant    __pad_and_output(ostreambuf_iterator<_Ch, _Tr> __s,
107392b5940fSHoward Hinnant                     const _Ch* __ob, const _Ch* __op, const _Ch* __oe,
107492b5940fSHoward Hinnant                     ios_base& __iob, _Ch __fl);
1075b5c63a2eSHoward Hinnant#endif
10763e519524SHoward Hinnant};
10773e519524SHoward Hinnant
10783e519524SHoward Hinnanttemplate <class _Iter>
1079e2f2d1edSEric Fiselierclass _LIBCPP_TEMPLATE_VIS move_iterator
10803e519524SHoward Hinnant{
10813e519524SHoward Hinnantprivate:
10823e519524SHoward Hinnant    _Iter __i;
10833e519524SHoward Hinnantpublic:
10843e519524SHoward Hinnant    typedef _Iter                                            iterator_type;
10853e519524SHoward Hinnant    typedef typename iterator_traits<iterator_type>::iterator_category iterator_category;
10863e519524SHoward Hinnant    typedef typename iterator_traits<iterator_type>::value_type value_type;
10873e519524SHoward Hinnant    typedef typename iterator_traits<iterator_type>::difference_type difference_type;
108805333fc8SMarshall Clow    typedef iterator_type pointer;
1089046492b9SEric Fiselier#ifndef _LIBCPP_CXX03_LANG
1090906c5085SEric Fiselier    typedef typename iterator_traits<iterator_type>::reference __reference;
1091906c5085SEric Fiselier    typedef typename conditional<
1092906c5085SEric Fiselier            is_reference<__reference>::value,
1093906c5085SEric Fiselier            typename remove_reference<__reference>::type&&,
1094906c5085SEric Fiselier            __reference
1095906c5085SEric Fiselier        >::type reference;
10963e519524SHoward Hinnant#else
10973e519524SHoward Hinnant    typedef typename iterator_traits<iterator_type>::reference reference;
10983e519524SHoward Hinnant#endif
10993e519524SHoward Hinnant
1100720ef472SMarshall Clow    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
1101720ef472SMarshall Clow    move_iterator() : __i() {}
1102720ef472SMarshall Clow    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
1103720ef472SMarshall Clow    explicit move_iterator(_Iter __x) : __i(__x) {}
1104720ef472SMarshall Clow    template <class _Up>
1105720ef472SMarshall Clow      _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
1106720ef472SMarshall Clow      move_iterator(const move_iterator<_Up>& __u) : __i(__u.base()) {}
1107720ef472SMarshall Clow    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 _Iter base() const {return __i;}
1108720ef472SMarshall Clow    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
1109720ef472SMarshall Clow    reference operator*() const { return static_cast<reference>(*__i); }
1110720ef472SMarshall Clow    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
1111720ef472SMarshall Clow    pointer  operator->() const { return __i;}
1112720ef472SMarshall Clow    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
1113720ef472SMarshall Clow    move_iterator& operator++() {++__i; return *this;}
1114720ef472SMarshall Clow    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
1115720ef472SMarshall Clow    move_iterator  operator++(int) {move_iterator __tmp(*this); ++__i; return __tmp;}
1116720ef472SMarshall Clow    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
1117720ef472SMarshall Clow    move_iterator& operator--() {--__i; return *this;}
1118720ef472SMarshall Clow    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
1119720ef472SMarshall Clow    move_iterator  operator--(int) {move_iterator __tmp(*this); --__i; return __tmp;}
1120720ef472SMarshall Clow    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
1121720ef472SMarshall Clow    move_iterator  operator+ (difference_type __n) const {return move_iterator(__i + __n);}
1122720ef472SMarshall Clow    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
1123720ef472SMarshall Clow    move_iterator& operator+=(difference_type __n) {__i += __n; return *this;}
1124720ef472SMarshall Clow    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
1125720ef472SMarshall Clow    move_iterator  operator- (difference_type __n) const {return move_iterator(__i - __n);}
1126720ef472SMarshall Clow    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
1127720ef472SMarshall Clow    move_iterator& operator-=(difference_type __n) {__i -= __n; return *this;}
1128720ef472SMarshall Clow    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
1129720ef472SMarshall Clow    reference operator[](difference_type __n) const { return static_cast<reference>(__i[__n]); }
11303e519524SHoward Hinnant};
11313e519524SHoward Hinnant
11323e519524SHoward Hinnanttemplate <class _Iter1, class _Iter2>
1133720ef472SMarshall Clowinline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
11343e519524SHoward Hinnantbool
11353e519524SHoward Hinnantoperator==(const move_iterator<_Iter1>& __x, const move_iterator<_Iter2>& __y)
11363e519524SHoward Hinnant{
11373e519524SHoward Hinnant    return __x.base() == __y.base();
11383e519524SHoward Hinnant}
11393e519524SHoward Hinnant
11403e519524SHoward Hinnanttemplate <class _Iter1, class _Iter2>
1141720ef472SMarshall Clowinline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
11423e519524SHoward Hinnantbool
11433e519524SHoward Hinnantoperator<(const move_iterator<_Iter1>& __x, const move_iterator<_Iter2>& __y)
11443e519524SHoward Hinnant{
11453e519524SHoward Hinnant    return __x.base() < __y.base();
11463e519524SHoward Hinnant}
11473e519524SHoward Hinnant
11483e519524SHoward Hinnanttemplate <class _Iter1, class _Iter2>
1149720ef472SMarshall Clowinline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
11503e519524SHoward Hinnantbool
11513e519524SHoward Hinnantoperator!=(const move_iterator<_Iter1>& __x, const move_iterator<_Iter2>& __y)
11523e519524SHoward Hinnant{
11533e519524SHoward Hinnant    return __x.base() != __y.base();
11543e519524SHoward Hinnant}
11553e519524SHoward Hinnant
11563e519524SHoward Hinnanttemplate <class _Iter1, class _Iter2>
1157720ef472SMarshall Clowinline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
11583e519524SHoward Hinnantbool
11593e519524SHoward Hinnantoperator>(const move_iterator<_Iter1>& __x, const move_iterator<_Iter2>& __y)
11603e519524SHoward Hinnant{
11613e519524SHoward Hinnant    return __x.base() > __y.base();
11623e519524SHoward Hinnant}
11633e519524SHoward Hinnant
11643e519524SHoward Hinnanttemplate <class _Iter1, class _Iter2>
1165720ef472SMarshall Clowinline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
11663e519524SHoward Hinnantbool
11673e519524SHoward Hinnantoperator>=(const move_iterator<_Iter1>& __x, const move_iterator<_Iter2>& __y)
11683e519524SHoward Hinnant{
11693e519524SHoward Hinnant    return __x.base() >= __y.base();
11703e519524SHoward Hinnant}
11713e519524SHoward Hinnant
11723e519524SHoward Hinnanttemplate <class _Iter1, class _Iter2>
1173720ef472SMarshall Clowinline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
11743e519524SHoward Hinnantbool
11753e519524SHoward Hinnantoperator<=(const move_iterator<_Iter1>& __x, const move_iterator<_Iter2>& __y)
11763e519524SHoward Hinnant{
11773e519524SHoward Hinnant    return __x.base() <= __y.base();
11783e519524SHoward Hinnant}
11793e519524SHoward Hinnant
11802ee83725SMarshall Clow#ifndef _LIBCPP_CXX03_LANG
1181947ce6b5SMarshall Clowtemplate <class _Iter1, class _Iter2>
1182720ef472SMarshall Clowinline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
1183947ce6b5SMarshall Clowauto
1184947ce6b5SMarshall Clowoperator-(const move_iterator<_Iter1>& __x, const move_iterator<_Iter2>& __y)
1185947ce6b5SMarshall Clow-> decltype(__x.base() - __y.base())
1186947ce6b5SMarshall Clow{
1187947ce6b5SMarshall Clow    return __x.base() - __y.base();
1188947ce6b5SMarshall Clow}
1189947ce6b5SMarshall Clow#else
11903e519524SHoward Hinnanttemplate <class _Iter1, class _Iter2>
11913e519524SHoward Hinnantinline _LIBCPP_INLINE_VISIBILITY
11923e519524SHoward Hinnanttypename move_iterator<_Iter1>::difference_type
11933e519524SHoward Hinnantoperator-(const move_iterator<_Iter1>& __x, const move_iterator<_Iter2>& __y)
11943e519524SHoward Hinnant{
11953e519524SHoward Hinnant    return __x.base() - __y.base();
11963e519524SHoward Hinnant}
1197947ce6b5SMarshall Clow#endif
11983e519524SHoward Hinnant
11993e519524SHoward Hinnanttemplate <class _Iter>
1200720ef472SMarshall Clowinline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
12013e519524SHoward Hinnantmove_iterator<_Iter>
12023e519524SHoward Hinnantoperator+(typename move_iterator<_Iter>::difference_type __n, const move_iterator<_Iter>& __x)
12033e519524SHoward Hinnant{
12043e519524SHoward Hinnant    return move_iterator<_Iter>(__x.base() + __n);
12053e519524SHoward Hinnant}
12063e519524SHoward Hinnant
12073e519524SHoward Hinnanttemplate <class _Iter>
1208720ef472SMarshall Clowinline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
12093e519524SHoward Hinnantmove_iterator<_Iter>
121054c83368SMarshall Clowmake_move_iterator(_Iter __i)
12113e519524SHoward Hinnant{
12123e519524SHoward Hinnant    return move_iterator<_Iter>(__i);
12133e519524SHoward Hinnant}
12143e519524SHoward Hinnant
12153e519524SHoward Hinnant// __wrap_iter
12163e519524SHoward Hinnant
12173e519524SHoward Hinnanttemplate <class _Iter> class __wrap_iter;
12183e519524SHoward Hinnant
12193e519524SHoward Hinnanttemplate <class _Iter1, class _Iter2>
1220aeb85680SHoward Hinnant_LIBCPP_INLINE_VISIBILITY
12213e519524SHoward Hinnantbool
122214bd0bf0SEric Fiselieroperator==(const __wrap_iter<_Iter1>&, const __wrap_iter<_Iter2>&) _NOEXCEPT_DEBUG;
12233e519524SHoward Hinnant
12243e519524SHoward Hinnanttemplate <class _Iter1, class _Iter2>
1225aeb85680SHoward Hinnant_LIBCPP_INLINE_VISIBILITY
12263e519524SHoward Hinnantbool
122714bd0bf0SEric Fiselieroperator<(const __wrap_iter<_Iter1>&, const __wrap_iter<_Iter2>&) _NOEXCEPT_DEBUG;
12283e519524SHoward Hinnant
12293e519524SHoward Hinnanttemplate <class _Iter1, class _Iter2>
1230aeb85680SHoward Hinnant_LIBCPP_INLINE_VISIBILITY
12313e519524SHoward Hinnantbool
123214bd0bf0SEric Fiselieroperator!=(const __wrap_iter<_Iter1>&, const __wrap_iter<_Iter2>&) _NOEXCEPT_DEBUG;
12333e519524SHoward Hinnant
12343e519524SHoward Hinnanttemplate <class _Iter1, class _Iter2>
1235aeb85680SHoward Hinnant_LIBCPP_INLINE_VISIBILITY
12363e519524SHoward Hinnantbool
123714bd0bf0SEric Fiselieroperator>(const __wrap_iter<_Iter1>&, const __wrap_iter<_Iter2>&) _NOEXCEPT_DEBUG;
12383e519524SHoward Hinnant
12393e519524SHoward Hinnanttemplate <class _Iter1, class _Iter2>
1240aeb85680SHoward Hinnant_LIBCPP_INLINE_VISIBILITY
12413e519524SHoward Hinnantbool
124214bd0bf0SEric Fiselieroperator>=(const __wrap_iter<_Iter1>&, const __wrap_iter<_Iter2>&) _NOEXCEPT_DEBUG;
12433e519524SHoward Hinnant
12443e519524SHoward Hinnanttemplate <class _Iter1, class _Iter2>
1245aeb85680SHoward Hinnant_LIBCPP_INLINE_VISIBILITY
12463e519524SHoward Hinnantbool
124714bd0bf0SEric Fiselieroperator<=(const __wrap_iter<_Iter1>&, const __wrap_iter<_Iter2>&) _NOEXCEPT_DEBUG;
12483e519524SHoward Hinnant
12492ee83725SMarshall Clow#ifndef _LIBCPP_CXX03_LANG
1250947ce6b5SMarshall Clowtemplate <class _Iter1, class _Iter2>
1251947ce6b5SMarshall Clow_LIBCPP_INLINE_VISIBILITY
1252947ce6b5SMarshall Clowauto
125314bd0bf0SEric Fiselieroperator-(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter2>& __y) _NOEXCEPT_DEBUG
1254947ce6b5SMarshall Clow-> decltype(__x.base() - __y.base());
1255947ce6b5SMarshall Clow#else
12563e519524SHoward Hinnanttemplate <class _Iter1, class _Iter2>
1257aeb85680SHoward Hinnant_LIBCPP_INLINE_VISIBILITY
12583e519524SHoward Hinnanttypename __wrap_iter<_Iter1>::difference_type
125914bd0bf0SEric Fiselieroperator-(const __wrap_iter<_Iter1>&, const __wrap_iter<_Iter2>&) _NOEXCEPT_DEBUG;
1260947ce6b5SMarshall Clow#endif
12613e519524SHoward Hinnant
12623e519524SHoward Hinnanttemplate <class _Iter>
1263aeb85680SHoward Hinnant_LIBCPP_INLINE_VISIBILITY
12643e519524SHoward Hinnant__wrap_iter<_Iter>
126514bd0bf0SEric Fiselieroperator+(typename __wrap_iter<_Iter>::difference_type, __wrap_iter<_Iter>) _NOEXCEPT_DEBUG;
12663e519524SHoward Hinnant
1267aeb85680SHoward Hinnanttemplate <class _Ip, class _Op> _Op _LIBCPP_INLINE_VISIBILITY copy(_Ip, _Ip, _Op);
1268aeb85680SHoward Hinnanttemplate <class _B1, class _B2> _B2 _LIBCPP_INLINE_VISIBILITY copy_backward(_B1, _B1, _B2);
1269aeb85680SHoward Hinnanttemplate <class _Ip, class _Op> _Op _LIBCPP_INLINE_VISIBILITY move(_Ip, _Ip, _Op);
1270aeb85680SHoward Hinnanttemplate <class _B1, class _B2> _B2 _LIBCPP_INLINE_VISIBILITY move_backward(_B1, _B1, _B2);
12713e519524SHoward Hinnant
127214bd0bf0SEric Fiselier#if _LIBCPP_DEBUG_LEVEL < 2
127314bd0bf0SEric Fiselier
12743e519524SHoward Hinnanttemplate <class _Tp>
1275aeb85680SHoward Hinnant_LIBCPP_INLINE_VISIBILITY
12763e519524SHoward Hinnanttypename enable_if
12773e519524SHoward Hinnant<
1278ca740483SHoward Hinnant    is_trivially_copy_assignable<_Tp>::value,
12793e519524SHoward Hinnant    _Tp*
12803e519524SHoward Hinnant>::type
12813e519524SHoward Hinnant__unwrap_iter(__wrap_iter<_Tp*>);
12823e519524SHoward Hinnant
128314bd0bf0SEric Fiselier#else
128414bd0bf0SEric Fiselier
128514bd0bf0SEric Fiseliertemplate <class _Tp>
128614bd0bf0SEric Fiselierinline _LIBCPP_INLINE_VISIBILITY
128714bd0bf0SEric Fiseliertypename enable_if
128814bd0bf0SEric Fiselier<
128914bd0bf0SEric Fiselier    is_trivially_copy_assignable<_Tp>::value,
129014bd0bf0SEric Fiselier    __wrap_iter<_Tp*>
129114bd0bf0SEric Fiselier>::type
129214bd0bf0SEric Fiselier__unwrap_iter(__wrap_iter<_Tp*> __i);
129314bd0bf0SEric Fiselier
129414bd0bf0SEric Fiselier#endif
129514bd0bf0SEric Fiselier
12963e519524SHoward Hinnanttemplate <class _Iter>
12973e519524SHoward Hinnantclass __wrap_iter
12983e519524SHoward Hinnant{
12993e519524SHoward Hinnantpublic:
13003e519524SHoward Hinnant    typedef _Iter                                                      iterator_type;
13013e519524SHoward Hinnant    typedef typename iterator_traits<iterator_type>::iterator_category iterator_category;
13023e519524SHoward Hinnant    typedef typename iterator_traits<iterator_type>::value_type        value_type;
13033e519524SHoward Hinnant    typedef typename iterator_traits<iterator_type>::difference_type   difference_type;
13043e519524SHoward Hinnant    typedef typename iterator_traits<iterator_type>::pointer           pointer;
13053e519524SHoward Hinnant    typedef typename iterator_traits<iterator_type>::reference         reference;
13063e519524SHoward Hinnantprivate:
13073e519524SHoward Hinnant    iterator_type __i;
13083e519524SHoward Hinnantpublic:
130914bd0bf0SEric Fiselier    _LIBCPP_INLINE_VISIBILITY __wrap_iter() _NOEXCEPT_DEBUG
131007186a7dSMarshall Clow#if _LIBCPP_STD_VER > 11
131107186a7dSMarshall Clow                : __i{}
131207186a7dSMarshall Clow#endif
1313c36bfc49SHoward Hinnant    {
1314c36bfc49SHoward Hinnant#if _LIBCPP_DEBUG_LEVEL >= 2
1315c36bfc49SHoward Hinnant        __get_db()->__insert_i(this);
1316c36bfc49SHoward Hinnant#endif
1317c36bfc49SHoward Hinnant    }
13183e519524SHoward Hinnant    template <class _Up> _LIBCPP_INLINE_VISIBILITY __wrap_iter(const __wrap_iter<_Up>& __u,
131914bd0bf0SEric Fiselier        typename enable_if<is_convertible<_Up, iterator_type>::value>::type* = 0) _NOEXCEPT_DEBUG
1320f554add5SHoward Hinnant        : __i(__u.base())
1321f554add5SHoward Hinnant    {
1322cec9af9eSHoward Hinnant#if _LIBCPP_DEBUG_LEVEL >= 2
1323f554add5SHoward Hinnant        __get_db()->__iterator_copy(this, &__u);
1324f554add5SHoward Hinnant#endif
1325f554add5SHoward Hinnant    }
1326cec9af9eSHoward Hinnant#if _LIBCPP_DEBUG_LEVEL >= 2
1327f554add5SHoward Hinnant    _LIBCPP_INLINE_VISIBILITY
1328f554add5SHoward Hinnant    __wrap_iter(const __wrap_iter& __x)
1329f554add5SHoward Hinnant        : __i(__x.base())
1330f554add5SHoward Hinnant    {
1331f554add5SHoward Hinnant        __get_db()->__iterator_copy(this, &__x);
1332f554add5SHoward Hinnant    }
1333f554add5SHoward Hinnant    _LIBCPP_INLINE_VISIBILITY
1334f554add5SHoward Hinnant    __wrap_iter& operator=(const __wrap_iter& __x)
1335f554add5SHoward Hinnant    {
1336f554add5SHoward Hinnant        if (this != &__x)
1337f554add5SHoward Hinnant        {
1338f554add5SHoward Hinnant            __get_db()->__iterator_copy(this, &__x);
1339f554add5SHoward Hinnant            __i = __x.__i;
1340f554add5SHoward Hinnant        }
1341f554add5SHoward Hinnant        return *this;
1342f554add5SHoward Hinnant    }
1343f554add5SHoward Hinnant    _LIBCPP_INLINE_VISIBILITY
1344f554add5SHoward Hinnant    ~__wrap_iter()
1345f554add5SHoward Hinnant    {
1346f554add5SHoward Hinnant        __get_db()->__erase_i(this);
1347f554add5SHoward Hinnant    }
1348f554add5SHoward Hinnant#endif
134914bd0bf0SEric Fiselier    _LIBCPP_INLINE_VISIBILITY reference operator*() const _NOEXCEPT_DEBUG
1350f554add5SHoward Hinnant    {
1351cec9af9eSHoward Hinnant#if _LIBCPP_DEBUG_LEVEL >= 2
1352f554add5SHoward Hinnant        _LIBCPP_ASSERT(__get_const_db()->__dereferenceable(this),
1353f554add5SHoward Hinnant                       "Attempted to dereference a non-dereferenceable iterator");
1354cec9af9eSHoward Hinnant#endif
1355f554add5SHoward Hinnant        return *__i;
1356f554add5SHoward Hinnant    }
135714bd0bf0SEric Fiselier    _LIBCPP_INLINE_VISIBILITY pointer  operator->() const _NOEXCEPT_DEBUG
13583ec1f00bSHoward Hinnant    {
13593ec1f00bSHoward Hinnant#if _LIBCPP_DEBUG_LEVEL >= 2
13603ec1f00bSHoward Hinnant        _LIBCPP_ASSERT(__get_const_db()->__dereferenceable(this),
13613ec1f00bSHoward Hinnant                       "Attempted to dereference a non-dereferenceable iterator");
13623ec1f00bSHoward Hinnant#endif
136305333fc8SMarshall Clow        return (pointer)_VSTD::addressof(*__i);
13643ec1f00bSHoward Hinnant    }
136514bd0bf0SEric Fiselier    _LIBCPP_INLINE_VISIBILITY __wrap_iter& operator++() _NOEXCEPT_DEBUG
1366f554add5SHoward Hinnant    {
1367cec9af9eSHoward Hinnant#if _LIBCPP_DEBUG_LEVEL >= 2
1368f554add5SHoward Hinnant        _LIBCPP_ASSERT(__get_const_db()->__dereferenceable(this),
1369f554add5SHoward Hinnant                       "Attempted to increment non-incrementable iterator");
1370cec9af9eSHoward Hinnant#endif
1371f554add5SHoward Hinnant        ++__i;
1372f554add5SHoward Hinnant        return *this;
1373f554add5SHoward Hinnant    }
137414bd0bf0SEric Fiselier    _LIBCPP_INLINE_VISIBILITY __wrap_iter  operator++(int) _NOEXCEPT_DEBUG
1375f554add5SHoward Hinnant        {__wrap_iter __tmp(*this); ++(*this); return __tmp;}
137614bd0bf0SEric Fiselier    _LIBCPP_INLINE_VISIBILITY __wrap_iter& operator--() _NOEXCEPT_DEBUG
1377f554add5SHoward Hinnant    {
1378cec9af9eSHoward Hinnant#if _LIBCPP_DEBUG_LEVEL >= 2
1379f554add5SHoward Hinnant        _LIBCPP_ASSERT(__get_const_db()->__decrementable(this),
1380f554add5SHoward Hinnant                       "Attempted to decrement non-decrementable iterator");
1381cec9af9eSHoward Hinnant#endif
1382f554add5SHoward Hinnant        --__i;
1383f554add5SHoward Hinnant        return *this;
1384f554add5SHoward Hinnant    }
138514bd0bf0SEric Fiselier    _LIBCPP_INLINE_VISIBILITY __wrap_iter  operator--(int) _NOEXCEPT_DEBUG
1386f554add5SHoward Hinnant        {__wrap_iter __tmp(*this); --(*this); return __tmp;}
138714bd0bf0SEric Fiselier    _LIBCPP_INLINE_VISIBILITY __wrap_iter  operator+ (difference_type __n) const _NOEXCEPT_DEBUG
1388f554add5SHoward Hinnant        {__wrap_iter __w(*this); __w += __n; return __w;}
138914bd0bf0SEric Fiselier    _LIBCPP_INLINE_VISIBILITY __wrap_iter& operator+=(difference_type __n) _NOEXCEPT_DEBUG
1390f554add5SHoward Hinnant    {
1391cec9af9eSHoward Hinnant#if _LIBCPP_DEBUG_LEVEL >= 2
1392f554add5SHoward Hinnant        _LIBCPP_ASSERT(__get_const_db()->__addable(this, __n),
1393f554add5SHoward Hinnant                   "Attempted to add/subtract iterator outside of valid range");
1394cec9af9eSHoward Hinnant#endif
1395f554add5SHoward Hinnant        __i += __n;
1396f554add5SHoward Hinnant        return *this;
1397f554add5SHoward Hinnant    }
139814bd0bf0SEric Fiselier    _LIBCPP_INLINE_VISIBILITY __wrap_iter  operator- (difference_type __n) const _NOEXCEPT_DEBUG
1399f554add5SHoward Hinnant        {return *this + (-__n);}
140014bd0bf0SEric Fiselier    _LIBCPP_INLINE_VISIBILITY __wrap_iter& operator-=(difference_type __n) _NOEXCEPT_DEBUG
1401f554add5SHoward Hinnant        {*this += -__n; return *this;}
140214bd0bf0SEric Fiselier    _LIBCPP_INLINE_VISIBILITY reference        operator[](difference_type __n) const _NOEXCEPT_DEBUG
1403f554add5SHoward Hinnant    {
1404cec9af9eSHoward Hinnant#if _LIBCPP_DEBUG_LEVEL >= 2
1405f554add5SHoward Hinnant        _LIBCPP_ASSERT(__get_const_db()->__subscriptable(this, __n),
1406f554add5SHoward Hinnant                   "Attempted to subscript iterator outside of valid range");
1407cec9af9eSHoward Hinnant#endif
1408f554add5SHoward Hinnant        return __i[__n];
1409f554add5SHoward Hinnant    }
14103e519524SHoward Hinnant
141114bd0bf0SEric Fiselier    _LIBCPP_INLINE_VISIBILITY iterator_type base() const _NOEXCEPT_DEBUG {return __i;}
14123e519524SHoward Hinnant
14133e519524SHoward Hinnantprivate:
1414cec9af9eSHoward Hinnant#if _LIBCPP_DEBUG_LEVEL >= 2
1415f554add5SHoward Hinnant    _LIBCPP_INLINE_VISIBILITY __wrap_iter(const void* __p, iterator_type __x) : __i(__x)
1416f554add5SHoward Hinnant    {
1417f554add5SHoward Hinnant        __get_db()->__insert_ic(this, __p);
1418f554add5SHoward Hinnant    }
1419fc88dbd2SHoward Hinnant#else
142014bd0bf0SEric Fiselier    _LIBCPP_INLINE_VISIBILITY __wrap_iter(iterator_type __x) _NOEXCEPT_DEBUG : __i(__x) {}
1421f554add5SHoward Hinnant#endif
14223e519524SHoward Hinnant
14233e519524SHoward Hinnant    template <class _Up> friend class __wrap_iter;
14243e519524SHoward Hinnant    template <class _CharT, class _Traits, class _Alloc> friend class basic_string;
1425e2f2d1edSEric Fiselier    template <class _Tp, class _Alloc> friend class _LIBCPP_TEMPLATE_VIS vector;
14263e519524SHoward Hinnant
14273e519524SHoward Hinnant    template <class _Iter1, class _Iter2>
14283e519524SHoward Hinnant    friend
14293e519524SHoward Hinnant    bool
143014bd0bf0SEric Fiselier    operator==(const __wrap_iter<_Iter1>&, const __wrap_iter<_Iter2>&) _NOEXCEPT_DEBUG;
14313e519524SHoward Hinnant
14323e519524SHoward Hinnant    template <class _Iter1, class _Iter2>
14333e519524SHoward Hinnant    friend
14343e519524SHoward Hinnant    bool
143514bd0bf0SEric Fiselier    operator<(const __wrap_iter<_Iter1>&, const __wrap_iter<_Iter2>&) _NOEXCEPT_DEBUG;
14363e519524SHoward Hinnant
14373e519524SHoward Hinnant    template <class _Iter1, class _Iter2>
14383e519524SHoward Hinnant    friend
14393e519524SHoward Hinnant    bool
144014bd0bf0SEric Fiselier    operator!=(const __wrap_iter<_Iter1>&, const __wrap_iter<_Iter2>&) _NOEXCEPT_DEBUG;
14413e519524SHoward Hinnant
14423e519524SHoward Hinnant    template <class _Iter1, class _Iter2>
14433e519524SHoward Hinnant    friend
14443e519524SHoward Hinnant    bool
144514bd0bf0SEric Fiselier    operator>(const __wrap_iter<_Iter1>&, const __wrap_iter<_Iter2>&) _NOEXCEPT_DEBUG;
14463e519524SHoward Hinnant
14473e519524SHoward Hinnant    template <class _Iter1, class _Iter2>
14483e519524SHoward Hinnant    friend
14493e519524SHoward Hinnant    bool
145014bd0bf0SEric Fiselier    operator>=(const __wrap_iter<_Iter1>&, const __wrap_iter<_Iter2>&) _NOEXCEPT_DEBUG;
14513e519524SHoward Hinnant
14523e519524SHoward Hinnant    template <class _Iter1, class _Iter2>
14533e519524SHoward Hinnant    friend
14543e519524SHoward Hinnant    bool
145514bd0bf0SEric Fiselier    operator<=(const __wrap_iter<_Iter1>&, const __wrap_iter<_Iter2>&) _NOEXCEPT_DEBUG;
14563e519524SHoward Hinnant
14572ee83725SMarshall Clow#ifndef _LIBCPP_CXX03_LANG
1458947ce6b5SMarshall Clow    template <class _Iter1, class _Iter2>
1459947ce6b5SMarshall Clow    friend
1460947ce6b5SMarshall Clow    auto
146114bd0bf0SEric Fiselier    operator-(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter2>& __y) _NOEXCEPT_DEBUG
1462947ce6b5SMarshall Clow    -> decltype(__x.base() - __y.base());
1463947ce6b5SMarshall Clow#else
14643e519524SHoward Hinnant    template <class _Iter1, class _Iter2>
14653e519524SHoward Hinnant    friend
14663e519524SHoward Hinnant    typename __wrap_iter<_Iter1>::difference_type
146714bd0bf0SEric Fiselier    operator-(const __wrap_iter<_Iter1>&, const __wrap_iter<_Iter2>&) _NOEXCEPT_DEBUG;
1468947ce6b5SMarshall Clow#endif
14693e519524SHoward Hinnant
14703e519524SHoward Hinnant    template <class _Iter1>
14713e519524SHoward Hinnant    friend
14723e519524SHoward Hinnant    __wrap_iter<_Iter1>
147314bd0bf0SEric Fiselier    operator+(typename __wrap_iter<_Iter1>::difference_type, __wrap_iter<_Iter1>) _NOEXCEPT_DEBUG;
14743e519524SHoward Hinnant
1475c003db1fSHoward Hinnant    template <class _Ip, class _Op> friend _Op copy(_Ip, _Ip, _Op);
14763e519524SHoward Hinnant    template <class _B1, class _B2> friend _B2 copy_backward(_B1, _B1, _B2);
1477c003db1fSHoward Hinnant    template <class _Ip, class _Op> friend _Op move(_Ip, _Ip, _Op);
14783e519524SHoward Hinnant    template <class _B1, class _B2> friend _B2 move_backward(_B1, _B1, _B2);
14793e519524SHoward Hinnant
148014bd0bf0SEric Fiselier#if _LIBCPP_DEBUG_LEVEL < 2
14813e519524SHoward Hinnant    template <class _Tp>
14823e519524SHoward Hinnant    friend
14833e519524SHoward Hinnant    typename enable_if
14843e519524SHoward Hinnant    <
1485ca740483SHoward Hinnant        is_trivially_copy_assignable<_Tp>::value,
14863e519524SHoward Hinnant        _Tp*
14873e519524SHoward Hinnant    >::type
14883e519524SHoward Hinnant    __unwrap_iter(__wrap_iter<_Tp*>);
148914bd0bf0SEric Fiselier#else
149014bd0bf0SEric Fiselier  template <class _Tp>
149114bd0bf0SEric Fiselier  inline _LIBCPP_INLINE_VISIBILITY
149214bd0bf0SEric Fiselier  typename enable_if
149314bd0bf0SEric Fiselier  <
149414bd0bf0SEric Fiselier      is_trivially_copy_assignable<_Tp>::value,
149514bd0bf0SEric Fiselier      __wrap_iter<_Tp*>
149614bd0bf0SEric Fiselier  >::type
149714bd0bf0SEric Fiselier  __unwrap_iter(__wrap_iter<_Tp*> __i);
149814bd0bf0SEric Fiselier#endif
14993e519524SHoward Hinnant};
15003e519524SHoward Hinnant
15013e519524SHoward Hinnanttemplate <class _Iter1, class _Iter2>
15023e519524SHoward Hinnantinline _LIBCPP_INLINE_VISIBILITY
15033e519524SHoward Hinnantbool
150414bd0bf0SEric Fiselieroperator==(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter2>& __y) _NOEXCEPT_DEBUG
15053e519524SHoward Hinnant{
15063e519524SHoward Hinnant    return __x.base() == __y.base();
15073e519524SHoward Hinnant}
15083e519524SHoward Hinnant
15093e519524SHoward Hinnanttemplate <class _Iter1, class _Iter2>
15103e519524SHoward Hinnantinline _LIBCPP_INLINE_VISIBILITY
15113e519524SHoward Hinnantbool
151214bd0bf0SEric Fiselieroperator<(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter2>& __y) _NOEXCEPT_DEBUG
15133e519524SHoward Hinnant{
1514cec9af9eSHoward Hinnant#if _LIBCPP_DEBUG_LEVEL >= 2
151542a3046eSHoward Hinnant    _LIBCPP_ASSERT(__get_const_db()->__less_than_comparable(&__x, &__y),
1516f554add5SHoward Hinnant                   "Attempted to compare incomparable iterators");
1517cec9af9eSHoward Hinnant#endif
15183e519524SHoward Hinnant    return __x.base() < __y.base();
15193e519524SHoward Hinnant}
15203e519524SHoward Hinnant
15213e519524SHoward Hinnanttemplate <class _Iter1, class _Iter2>
15223e519524SHoward Hinnantinline _LIBCPP_INLINE_VISIBILITY
15233e519524SHoward Hinnantbool
152414bd0bf0SEric Fiselieroperator!=(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter2>& __y) _NOEXCEPT_DEBUG
15253e519524SHoward Hinnant{
1526f554add5SHoward Hinnant    return !(__x == __y);
15273e519524SHoward Hinnant}
15283e519524SHoward Hinnant
15293e519524SHoward Hinnanttemplate <class _Iter1, class _Iter2>
15303e519524SHoward Hinnantinline _LIBCPP_INLINE_VISIBILITY
15313e519524SHoward Hinnantbool
153214bd0bf0SEric Fiselieroperator>(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter2>& __y) _NOEXCEPT_DEBUG
15333e519524SHoward Hinnant{
1534f554add5SHoward Hinnant    return __y < __x;
15353e519524SHoward Hinnant}
15363e519524SHoward Hinnant
15373e519524SHoward Hinnanttemplate <class _Iter1, class _Iter2>
15383e519524SHoward Hinnantinline _LIBCPP_INLINE_VISIBILITY
15393e519524SHoward Hinnantbool
154014bd0bf0SEric Fiselieroperator>=(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter2>& __y) _NOEXCEPT_DEBUG
15413e519524SHoward Hinnant{
1542f554add5SHoward Hinnant    return !(__x < __y);
15433e519524SHoward Hinnant}
15443e519524SHoward Hinnant
15453e519524SHoward Hinnanttemplate <class _Iter1, class _Iter2>
15463e519524SHoward Hinnantinline _LIBCPP_INLINE_VISIBILITY
15473e519524SHoward Hinnantbool
154814bd0bf0SEric Fiselieroperator<=(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter2>& __y) _NOEXCEPT_DEBUG
15493e519524SHoward Hinnant{
1550f554add5SHoward Hinnant    return !(__y < __x);
15513e519524SHoward Hinnant}
15523e519524SHoward Hinnant
15536e551ae1SHoward Hinnanttemplate <class _Iter1>
15546e551ae1SHoward Hinnantinline _LIBCPP_INLINE_VISIBILITY
15556e551ae1SHoward Hinnantbool
155614bd0bf0SEric Fiselieroperator!=(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter1>& __y) _NOEXCEPT_DEBUG
15576e551ae1SHoward Hinnant{
15586e551ae1SHoward Hinnant    return !(__x == __y);
15596e551ae1SHoward Hinnant}
15606e551ae1SHoward Hinnant
15616e551ae1SHoward Hinnanttemplate <class _Iter1>
15626e551ae1SHoward Hinnantinline _LIBCPP_INLINE_VISIBILITY
15636e551ae1SHoward Hinnantbool
156414bd0bf0SEric Fiselieroperator>(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter1>& __y) _NOEXCEPT_DEBUG
15656e551ae1SHoward Hinnant{
15666e551ae1SHoward Hinnant    return __y < __x;
15676e551ae1SHoward Hinnant}
15686e551ae1SHoward Hinnant
15696e551ae1SHoward Hinnanttemplate <class _Iter1>
15706e551ae1SHoward Hinnantinline _LIBCPP_INLINE_VISIBILITY
15716e551ae1SHoward Hinnantbool
157214bd0bf0SEric Fiselieroperator>=(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter1>& __y) _NOEXCEPT_DEBUG
15736e551ae1SHoward Hinnant{
15746e551ae1SHoward Hinnant    return !(__x < __y);
15756e551ae1SHoward Hinnant}
15766e551ae1SHoward Hinnant
15776e551ae1SHoward Hinnanttemplate <class _Iter1>
15786e551ae1SHoward Hinnantinline _LIBCPP_INLINE_VISIBILITY
15796e551ae1SHoward Hinnantbool
158014bd0bf0SEric Fiselieroperator<=(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter1>& __y) _NOEXCEPT_DEBUG
15816e551ae1SHoward Hinnant{
15826e551ae1SHoward Hinnant    return !(__y < __x);
15836e551ae1SHoward Hinnant}
15846e551ae1SHoward Hinnant
15852ee83725SMarshall Clow#ifndef _LIBCPP_CXX03_LANG
1586947ce6b5SMarshall Clowtemplate <class _Iter1, class _Iter2>
1587947ce6b5SMarshall Clowinline _LIBCPP_INLINE_VISIBILITY
1588947ce6b5SMarshall Clowauto
158914bd0bf0SEric Fiselieroperator-(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter2>& __y) _NOEXCEPT_DEBUG
1590947ce6b5SMarshall Clow-> decltype(__x.base() - __y.base())
1591947ce6b5SMarshall Clow{
1592947ce6b5SMarshall Clow#if _LIBCPP_DEBUG_LEVEL >= 2
1593947ce6b5SMarshall Clow    _LIBCPP_ASSERT(__get_const_db()->__less_than_comparable(&__x, &__y),
1594947ce6b5SMarshall Clow                   "Attempted to subtract incompatible iterators");
1595947ce6b5SMarshall Clow#endif
1596947ce6b5SMarshall Clow    return __x.base() - __y.base();
1597947ce6b5SMarshall Clow}
1598947ce6b5SMarshall Clow#else
15993e519524SHoward Hinnanttemplate <class _Iter1, class _Iter2>
16003e519524SHoward Hinnantinline _LIBCPP_INLINE_VISIBILITY
16013e519524SHoward Hinnanttypename __wrap_iter<_Iter1>::difference_type
160214bd0bf0SEric Fiselieroperator-(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter2>& __y) _NOEXCEPT_DEBUG
16033e519524SHoward Hinnant{
1604cec9af9eSHoward Hinnant#if _LIBCPP_DEBUG_LEVEL >= 2
160542a3046eSHoward Hinnant    _LIBCPP_ASSERT(__get_const_db()->__less_than_comparable(&__x, &__y),
1606f554add5SHoward Hinnant                   "Attempted to subtract incompatible iterators");
1607cec9af9eSHoward Hinnant#endif
16083e519524SHoward Hinnant    return __x.base() - __y.base();
16093e519524SHoward Hinnant}
1610947ce6b5SMarshall Clow#endif
16113e519524SHoward Hinnant
16123e519524SHoward Hinnanttemplate <class _Iter>
16133e519524SHoward Hinnantinline _LIBCPP_INLINE_VISIBILITY
16143e519524SHoward Hinnant__wrap_iter<_Iter>
16153e519524SHoward Hinnantoperator+(typename __wrap_iter<_Iter>::difference_type __n,
161614bd0bf0SEric Fiselier          __wrap_iter<_Iter> __x) _NOEXCEPT_DEBUG
16173e519524SHoward Hinnant{
1618f554add5SHoward Hinnant    __x += __n;
1619f554add5SHoward Hinnant    return __x;
16203e519524SHoward Hinnant}
16213e519524SHoward Hinnant
162276b4afc0SMarshall Clowtemplate <class _Iter>
162376b4afc0SMarshall Clowstruct __libcpp_is_trivial_iterator
162476b4afc0SMarshall Clow    : public _LIBCPP_BOOL_CONSTANT(is_pointer<_Iter>::value) {};
162576b4afc0SMarshall Clow
162676b4afc0SMarshall Clowtemplate <class _Iter>
162776b4afc0SMarshall Clowstruct __libcpp_is_trivial_iterator<move_iterator<_Iter> >
162876b4afc0SMarshall Clow    : public _LIBCPP_BOOL_CONSTANT(__libcpp_is_trivial_iterator<_Iter>::value) {};
162976b4afc0SMarshall Clow
163076b4afc0SMarshall Clowtemplate <class _Iter>
163176b4afc0SMarshall Clowstruct __libcpp_is_trivial_iterator<reverse_iterator<_Iter> >
163276b4afc0SMarshall Clow    : public _LIBCPP_BOOL_CONSTANT(__libcpp_is_trivial_iterator<_Iter>::value) {};
163376b4afc0SMarshall Clow
163476b4afc0SMarshall Clowtemplate <class _Iter>
163576b4afc0SMarshall Clowstruct __libcpp_is_trivial_iterator<__wrap_iter<_Iter> >
163676b4afc0SMarshall Clow    : public _LIBCPP_BOOL_CONSTANT(__libcpp_is_trivial_iterator<_Iter>::value) {};
163776b4afc0SMarshall Clow
163876b4afc0SMarshall Clow
16393772a46aSMarshall Clowtemplate <class _Tp, size_t _Np>
16406c3f5ffbSMarshall Clowinline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
16413772a46aSMarshall Clow_Tp*
16423772a46aSMarshall Clowbegin(_Tp (&__array)[_Np])
16433772a46aSMarshall Clow{
16443772a46aSMarshall Clow    return __array;
16453772a46aSMarshall Clow}
16463772a46aSMarshall Clow
16473772a46aSMarshall Clowtemplate <class _Tp, size_t _Np>
16486c3f5ffbSMarshall Clowinline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
16493772a46aSMarshall Clow_Tp*
16503772a46aSMarshall Clowend(_Tp (&__array)[_Np])
16513772a46aSMarshall Clow{
16523772a46aSMarshall Clow    return __array + _Np;
16533772a46aSMarshall Clow}
16543772a46aSMarshall Clow
165554613ab4SEric Fiselier#if !defined(_LIBCPP_CXX03_LANG)
1656c66a611bSMarshall Clow
1657c003db1fSHoward Hinnanttemplate <class _Cp>
1658020b623aSMarshall Clowinline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
16593e519524SHoward Hinnantauto
1660c003db1fSHoward Hinnantbegin(_Cp& __c) -> decltype(__c.begin())
16613e519524SHoward Hinnant{
16623e519524SHoward Hinnant    return __c.begin();
16633e519524SHoward Hinnant}
16643e519524SHoward Hinnant
1665c003db1fSHoward Hinnanttemplate <class _Cp>
1666020b623aSMarshall Clowinline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
16673e519524SHoward Hinnantauto
1668c003db1fSHoward Hinnantbegin(const _Cp& __c) -> decltype(__c.begin())
16693e519524SHoward Hinnant{
16703e519524SHoward Hinnant    return __c.begin();
16713e519524SHoward Hinnant}
16723e519524SHoward Hinnant
1673c003db1fSHoward Hinnanttemplate <class _Cp>
1674020b623aSMarshall Clowinline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
16753e519524SHoward Hinnantauto
1676c003db1fSHoward Hinnantend(_Cp& __c) -> decltype(__c.end())
16773e519524SHoward Hinnant{
16783e519524SHoward Hinnant    return __c.end();
16793e519524SHoward Hinnant}
16803e519524SHoward Hinnant
1681c003db1fSHoward Hinnanttemplate <class _Cp>
1682020b623aSMarshall Clowinline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
16833e519524SHoward Hinnantauto
1684c003db1fSHoward Hinnantend(const _Cp& __c) -> decltype(__c.end())
16853e519524SHoward Hinnant{
16863e519524SHoward Hinnant    return __c.end();
16873e519524SHoward Hinnant}
16883e519524SHoward Hinnant
16891e548c72SMarshall Clow#if _LIBCPP_STD_VER > 11
16901e548c72SMarshall Clow
16913772a46aSMarshall Clowtemplate <class _Tp, size_t _Np>
1692020b623aSMarshall Clowinline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
16933772a46aSMarshall Clowreverse_iterator<_Tp*> rbegin(_Tp (&__array)[_Np])
16943772a46aSMarshall Clow{
16953772a46aSMarshall Clow    return reverse_iterator<_Tp*>(__array + _Np);
16963772a46aSMarshall Clow}
16973772a46aSMarshall Clow
16983772a46aSMarshall Clowtemplate <class _Tp, size_t _Np>
1699020b623aSMarshall Clowinline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
17003772a46aSMarshall Clowreverse_iterator<_Tp*> rend(_Tp (&__array)[_Np])
17013772a46aSMarshall Clow{
17023772a46aSMarshall Clow    return reverse_iterator<_Tp*>(__array);
17033772a46aSMarshall Clow}
17043772a46aSMarshall Clow
17053772a46aSMarshall Clowtemplate <class _Ep>
1706020b623aSMarshall Clowinline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
17073772a46aSMarshall Clowreverse_iterator<const _Ep*> rbegin(initializer_list<_Ep> __il)
17083772a46aSMarshall Clow{
17093772a46aSMarshall Clow    return reverse_iterator<const _Ep*>(__il.end());
17103772a46aSMarshall Clow}
17113772a46aSMarshall Clow
17123772a46aSMarshall Clowtemplate <class _Ep>
1713020b623aSMarshall Clowinline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
17143772a46aSMarshall Clowreverse_iterator<const _Ep*> rend(initializer_list<_Ep> __il)
17153772a46aSMarshall Clow{
17163772a46aSMarshall Clow    return reverse_iterator<const _Ep*>(__il.begin());
17173772a46aSMarshall Clow}
17183772a46aSMarshall Clow
17191e548c72SMarshall Clowtemplate <class _Cp>
17206c3f5ffbSMarshall Clowinline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
17217725546aSMarshall Clowauto cbegin(const _Cp& __c) -> decltype(_VSTD::begin(__c))
17221e548c72SMarshall Clow{
17237725546aSMarshall Clow    return _VSTD::begin(__c);
17241e548c72SMarshall Clow}
17251e548c72SMarshall Clow
17261e548c72SMarshall Clowtemplate <class _Cp>
17276c3f5ffbSMarshall Clowinline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
17287725546aSMarshall Clowauto cend(const _Cp& __c) -> decltype(_VSTD::end(__c))
17291e548c72SMarshall Clow{
17307725546aSMarshall Clow    return _VSTD::end(__c);
17311e548c72SMarshall Clow}
17321e548c72SMarshall Clow
17331e548c72SMarshall Clowtemplate <class _Cp>
1734020b623aSMarshall Clowinline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
17351e548c72SMarshall Clowauto rbegin(_Cp& __c) -> decltype(__c.rbegin())
17361e548c72SMarshall Clow{
17371e548c72SMarshall Clow    return __c.rbegin();
17381e548c72SMarshall Clow}
17391e548c72SMarshall Clow
17401e548c72SMarshall Clowtemplate <class _Cp>
1741020b623aSMarshall Clowinline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
17421e548c72SMarshall Clowauto rbegin(const _Cp& __c) -> decltype(__c.rbegin())
17431e548c72SMarshall Clow{
17441e548c72SMarshall Clow    return __c.rbegin();
17451e548c72SMarshall Clow}
17461e548c72SMarshall Clow
17471e548c72SMarshall Clowtemplate <class _Cp>
1748020b623aSMarshall Clowinline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
17491e548c72SMarshall Clowauto rend(_Cp& __c) -> decltype(__c.rend())
17501e548c72SMarshall Clow{
17511e548c72SMarshall Clow    return __c.rend();
17521e548c72SMarshall Clow}
17531e548c72SMarshall Clow
17541e548c72SMarshall Clowtemplate <class _Cp>
1755020b623aSMarshall Clowinline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
17561e548c72SMarshall Clowauto rend(const _Cp& __c) -> decltype(__c.rend())
17571e548c72SMarshall Clow{
17581e548c72SMarshall Clow    return __c.rend();
17591e548c72SMarshall Clow}
17601e548c72SMarshall Clow
17611e548c72SMarshall Clowtemplate <class _Cp>
1762020b623aSMarshall Clowinline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
17637725546aSMarshall Clowauto crbegin(const _Cp& __c) -> decltype(_VSTD::rbegin(__c))
17641e548c72SMarshall Clow{
17657725546aSMarshall Clow    return _VSTD::rbegin(__c);
17661e548c72SMarshall Clow}
17671e548c72SMarshall Clow
17681e548c72SMarshall Clowtemplate <class _Cp>
1769020b623aSMarshall Clowinline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
17707725546aSMarshall Clowauto crend(const _Cp& __c) -> decltype(_VSTD::rend(__c))
17711e548c72SMarshall Clow{
17727725546aSMarshall Clow    return _VSTD::rend(__c);
17731e548c72SMarshall Clow}
17741e548c72SMarshall Clow
17751e548c72SMarshall Clow#endif
17761e548c72SMarshall Clow
17771e548c72SMarshall Clow
177854613ab4SEric Fiselier#else  // defined(_LIBCPP_CXX03_LANG)
17793e519524SHoward Hinnant
1780c003db1fSHoward Hinnanttemplate <class _Cp>
1781848a5374SHoward Hinnantinline _LIBCPP_INLINE_VISIBILITY
1782c003db1fSHoward Hinnanttypename _Cp::iterator
1783c003db1fSHoward Hinnantbegin(_Cp& __c)
17843e519524SHoward Hinnant{
17853e519524SHoward Hinnant    return __c.begin();
17863e519524SHoward Hinnant}
17873e519524SHoward Hinnant
1788c003db1fSHoward Hinnanttemplate <class _Cp>
1789848a5374SHoward Hinnantinline _LIBCPP_INLINE_VISIBILITY
1790c003db1fSHoward Hinnanttypename _Cp::const_iterator
1791c003db1fSHoward Hinnantbegin(const _Cp& __c)
17923e519524SHoward Hinnant{
17933e519524SHoward Hinnant    return __c.begin();
17943e519524SHoward Hinnant}
17953e519524SHoward Hinnant
1796c003db1fSHoward Hinnanttemplate <class _Cp>
1797848a5374SHoward Hinnantinline _LIBCPP_INLINE_VISIBILITY
1798c003db1fSHoward Hinnanttypename _Cp::iterator
1799c003db1fSHoward Hinnantend(_Cp& __c)
18003e519524SHoward Hinnant{
18013e519524SHoward Hinnant    return __c.end();
18023e519524SHoward Hinnant}
18033e519524SHoward Hinnant
1804c003db1fSHoward Hinnanttemplate <class _Cp>
1805848a5374SHoward Hinnantinline _LIBCPP_INLINE_VISIBILITY
1806c003db1fSHoward Hinnanttypename _Cp::const_iterator
1807c003db1fSHoward Hinnantend(const _Cp& __c)
18083e519524SHoward Hinnant{
18093e519524SHoward Hinnant    return __c.end();
18103e519524SHoward Hinnant}
18113e519524SHoward Hinnant
181254613ab4SEric Fiselier#endif  // !defined(_LIBCPP_CXX03_LANG)
18133e519524SHoward Hinnant
1814ad755104SMarshall Clow#if _LIBCPP_STD_VER > 14
1815d1dcda19SMarshall Clow
1816d1dcda19SMarshall Clow// #if _LIBCPP_STD_VER > 11
1817d1dcda19SMarshall Clow// template <>
1818d1dcda19SMarshall Clow// struct _LIBCPP_TEMPLATE_VIS plus<void>
1819d1dcda19SMarshall Clow// {
1820d1dcda19SMarshall Clow//     template <class _T1, class _T2>
1821d1dcda19SMarshall Clow//     _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
1822d1dcda19SMarshall Clow//     auto operator()(_T1&& __t, _T2&& __u) const
1823d1dcda19SMarshall Clow//     _NOEXCEPT_(noexcept(_VSTD::forward<_T1>(__t) + _VSTD::forward<_T2>(__u)))
1824d1dcda19SMarshall Clow//     -> decltype        (_VSTD::forward<_T1>(__t) + _VSTD::forward<_T2>(__u))
1825d1dcda19SMarshall Clow//         { return        _VSTD::forward<_T1>(__t) + _VSTD::forward<_T2>(__u); }
1826d1dcda19SMarshall Clow//     typedef void is_transparent;
1827d1dcda19SMarshall Clow// };
1828d1dcda19SMarshall Clow// #endif
1829d1dcda19SMarshall Clow
183088d21343SMarshall Clowtemplate <class _Cont>
183125a7ba45SMarshall Clowinline _LIBCPP_INLINE_VISIBILITY
1832d1dcda19SMarshall Clowconstexpr auto size(const _Cont& __c)
1833d1dcda19SMarshall Clow_NOEXCEPT_(noexcept(__c.size()))
1834d1dcda19SMarshall Clow-> decltype        (__c.size())
1835d1dcda19SMarshall Clow{ return            __c.size(); }
1836ad755104SMarshall Clow
183788d21343SMarshall Clowtemplate <class _Tp, size_t _Sz>
183825a7ba45SMarshall Clowinline _LIBCPP_INLINE_VISIBILITY
1839fd838227SEric Fiselierconstexpr size_t size(const _Tp (&)[_Sz]) noexcept { return _Sz; }
1840ad755104SMarshall Clow
184188d21343SMarshall Clowtemplate <class _Cont>
184225a7ba45SMarshall Clow_LIBCPP_NODISCARD_AFTER_CXX17 inline _LIBCPP_INLINE_VISIBILITY
1843d1dcda19SMarshall Clowconstexpr auto empty(const _Cont& __c)
1844d1dcda19SMarshall Clow_NOEXCEPT_(noexcept(__c.empty()))
1845d1dcda19SMarshall Clow-> decltype        (__c.empty())
1846d1dcda19SMarshall Clow{ return            __c.empty(); }
1847ad755104SMarshall Clow
184888d21343SMarshall Clowtemplate <class _Tp, size_t _Sz>
184925a7ba45SMarshall Clow_LIBCPP_NODISCARD_AFTER_CXX17 inline _LIBCPP_INLINE_VISIBILITY
1850fd838227SEric Fiselierconstexpr bool empty(const _Tp (&)[_Sz]) noexcept { return false; }
1851ad755104SMarshall Clow
1852ad755104SMarshall Clowtemplate <class _Ep>
185325a7ba45SMarshall Clow_LIBCPP_NODISCARD_AFTER_CXX17 inline _LIBCPP_INLINE_VISIBILITY
1854ad755104SMarshall Clowconstexpr bool empty(initializer_list<_Ep> __il) noexcept { return __il.size() == 0; }
1855ad755104SMarshall Clow
185688d21343SMarshall Clowtemplate <class _Cont> constexpr
185725a7ba45SMarshall Clowinline _LIBCPP_INLINE_VISIBILITY
1858d1dcda19SMarshall Clowauto data(_Cont& __c)
1859d1dcda19SMarshall Clow_NOEXCEPT_(noexcept(__c.data()))
1860d1dcda19SMarshall Clow-> decltype        (__c.data())
1861d1dcda19SMarshall Clow{ return            __c.data(); }
1862ad755104SMarshall Clow
186388d21343SMarshall Clowtemplate <class _Cont> constexpr
186425a7ba45SMarshall Clowinline _LIBCPP_INLINE_VISIBILITY
1865d1dcda19SMarshall Clowauto data(const _Cont& __c)
1866d1dcda19SMarshall Clow_NOEXCEPT_(noexcept(__c.data()))
1867d1dcda19SMarshall Clow-> decltype        (__c.data())
1868d1dcda19SMarshall Clow{ return            __c.data(); }
1869ad755104SMarshall Clow
187088d21343SMarshall Clowtemplate <class _Tp, size_t _Sz>
187125a7ba45SMarshall Clowinline _LIBCPP_INLINE_VISIBILITY
187288d21343SMarshall Clowconstexpr _Tp* data(_Tp (&__array)[_Sz]) noexcept { return __array; }
1873ad755104SMarshall Clow
1874ad755104SMarshall Clowtemplate <class _Ep>
187525a7ba45SMarshall Clowinline _LIBCPP_INLINE_VISIBILITY
1876ad755104SMarshall Clowconstexpr const _Ep* data(initializer_list<_Ep> __il) noexcept { return __il.begin(); }
1877ad755104SMarshall Clow#endif
1878ad755104SMarshall Clow
1879ad755104SMarshall Clow
18803e519524SHoward Hinnant_LIBCPP_END_NAMESPACE_STD
18813e519524SHoward Hinnant
18823e519524SHoward Hinnant#endif  // _LIBCPP_ITERATOR
1883