13e519524SHoward Hinnant// -*- C++ -*-
23e519524SHoward Hinnant//===-------------------------- iterator ----------------------------------===//
33e519524SHoward Hinnant//
457b08b09SChandler Carruth// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
557b08b09SChandler Carruth// See https://llvm.org/LICENSE.txt for license information.
657b08b09SChandler Carruth// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
73e519524SHoward Hinnant//
83e519524SHoward Hinnant//===----------------------------------------------------------------------===//
93e519524SHoward Hinnant
103e519524SHoward Hinnant#ifndef _LIBCPP_ITERATOR
113e519524SHoward Hinnant#define _LIBCPP_ITERATOR
123e519524SHoward Hinnant
133e519524SHoward Hinnant/*
143e519524SHoward Hinnant    iterator synopsis
153e519524SHoward Hinnant
163e519524SHoward Hinnantnamespace std
173e519524SHoward Hinnant{
183e519524SHoward Hinnant
193e519524SHoward Hinnanttemplate<class Iterator>
203e519524SHoward Hinnantstruct iterator_traits
213e519524SHoward Hinnant{
223e519524SHoward Hinnant    typedef typename Iterator::difference_type difference_type;
233e519524SHoward Hinnant    typedef typename Iterator::value_type value_type;
243e519524SHoward Hinnant    typedef typename Iterator::pointer pointer;
253e519524SHoward Hinnant    typedef typename Iterator::reference reference;
263e519524SHoward Hinnant    typedef typename Iterator::iterator_category iterator_category;
273e519524SHoward Hinnant};
283e519524SHoward Hinnant
293e519524SHoward Hinnanttemplate<class T>
303e519524SHoward Hinnantstruct iterator_traits<T*>
313e519524SHoward Hinnant{
323e519524SHoward Hinnant    typedef ptrdiff_t difference_type;
333e519524SHoward Hinnant    typedef T value_type;
343e519524SHoward Hinnant    typedef T* pointer;
353e519524SHoward Hinnant    typedef T& reference;
363e519524SHoward Hinnant    typedef random_access_iterator_tag iterator_category;
373e519524SHoward Hinnant};
383e519524SHoward Hinnant
393e519524SHoward Hinnanttemplate<class Category, class T, class Distance = ptrdiff_t,
403e519524SHoward Hinnant         class Pointer = T*, class Reference = T&>
413e519524SHoward Hinnantstruct iterator
423e519524SHoward Hinnant{
433e519524SHoward Hinnant    typedef T         value_type;
443e519524SHoward Hinnant    typedef Distance  difference_type;
453e519524SHoward Hinnant    typedef Pointer   pointer;
463e519524SHoward Hinnant    typedef Reference reference;
473e519524SHoward Hinnant    typedef Category  iterator_category;
483e519524SHoward Hinnant};
493e519524SHoward Hinnant
503e519524SHoward Hinnantstruct input_iterator_tag  {};
513e519524SHoward Hinnantstruct output_iterator_tag {};
523e519524SHoward Hinnantstruct forward_iterator_tag       : public input_iterator_tag         {};
533e519524SHoward Hinnantstruct bidirectional_iterator_tag : public forward_iterator_tag       {};
543e519524SHoward Hinnantstruct random_access_iterator_tag : public bidirectional_iterator_tag {};
553e519524SHoward Hinnant
56f51ee632SMarshall Clow// 27.4.3, iterator operations
573e519524SHoward Hinnant// extension: second argument not conforming to C++03
58f51ee632SMarshall Clowtemplate <class InputIterator>  // constexpr in C++17
59f51ee632SMarshall Clow  constexpr void advance(InputIterator& i,
603e519524SHoward Hinnant             typename iterator_traits<InputIterator>::difference_type n);
613e519524SHoward Hinnant
62f51ee632SMarshall Clowtemplate <class InputIterator>  // constexpr in C++17
63f51ee632SMarshall Clow  constexpr typename iterator_traits<InputIterator>::difference_type
643e519524SHoward Hinnant    distance(InputIterator first, InputIterator last);
653e519524SHoward Hinnant
66f51ee632SMarshall Clowtemplate <class InputIterator>  // constexpr in C++17
67f51ee632SMarshall Clow  constexpr InputIterator next(InputIterator x,
68f51ee632SMarshall Clowtypename iterator_traits<InputIterator>::difference_type n = 1);
69f51ee632SMarshall Clow
70f51ee632SMarshall Clowtemplate <class BidirectionalIterator>  // constexpr in C++17
71f51ee632SMarshall Clow  constexpr BidirectionalIterator prev(BidirectionalIterator x,
72f51ee632SMarshall Clow    typename iterator_traits<BidirectionalIterator>::difference_type n = 1);
73f51ee632SMarshall Clow
743e519524SHoward Hinnanttemplate <class Iterator>
753e519524SHoward Hinnantclass reverse_iterator
763e519524SHoward Hinnant    : public iterator<typename iterator_traits<Iterator>::iterator_category,
773e519524SHoward Hinnant                      typename iterator_traits<Iterator>::value_type,
783e519524SHoward Hinnant                      typename iterator_traits<Iterator>::difference_type,
793e519524SHoward Hinnant                      typename iterator_traits<Iterator>::pointer,
803e519524SHoward Hinnant                      typename iterator_traits<Iterator>::reference>
813e519524SHoward Hinnant{
823e519524SHoward Hinnantprotected:
833e519524SHoward Hinnant    Iterator current;
843e519524SHoward Hinnantpublic:
853e519524SHoward Hinnant    typedef Iterator                                            iterator_type;
863e519524SHoward Hinnant    typedef typename iterator_traits<Iterator>::difference_type difference_type;
873e519524SHoward Hinnant    typedef typename iterator_traits<Iterator>::reference       reference;
883e519524SHoward Hinnant    typedef typename iterator_traits<Iterator>::pointer         pointer;
893e519524SHoward Hinnant
901b8f260eSMarshall Clow    constexpr reverse_iterator();
911b8f260eSMarshall Clow    constexpr explicit reverse_iterator(Iterator x);
921b8f260eSMarshall Clow    template <class U> constexpr reverse_iterator(const reverse_iterator<U>& u);
931b8f260eSMarshall Clow    template <class U> constexpr reverse_iterator& operator=(const reverse_iterator<U>& u);
941b8f260eSMarshall Clow    constexpr Iterator base() const;
951b8f260eSMarshall Clow    constexpr reference operator*() const;
961b8f260eSMarshall Clow    constexpr pointer   operator->() const;
971b8f260eSMarshall Clow    constexpr reverse_iterator& operator++();
981b8f260eSMarshall Clow    constexpr reverse_iterator  operator++(int);
991b8f260eSMarshall Clow    constexpr reverse_iterator& operator--();
1001b8f260eSMarshall Clow    constexpr reverse_iterator  operator--(int);
1011b8f260eSMarshall Clow    constexpr reverse_iterator  operator+ (difference_type n) const;
1021b8f260eSMarshall Clow    constexpr reverse_iterator& operator+=(difference_type n);
1031b8f260eSMarshall Clow    constexpr reverse_iterator  operator- (difference_type n) const;
1041b8f260eSMarshall Clow    constexpr reverse_iterator& operator-=(difference_type n);
1051b8f260eSMarshall Clow    constexpr reference         operator[](difference_type n) const;
1063e519524SHoward Hinnant};
1073e519524SHoward Hinnant
1083e519524SHoward Hinnanttemplate <class Iterator1, class Iterator2>
1091b8f260eSMarshall Clowconstexpr bool                          // constexpr in C++17
1103e519524SHoward Hinnantoperator==(const reverse_iterator<Iterator1>& x, const reverse_iterator<Iterator2>& y);
1113e519524SHoward Hinnant
1123e519524SHoward Hinnanttemplate <class Iterator1, class Iterator2>
1131b8f260eSMarshall Clowconstexpr bool                          // constexpr in C++17
1143e519524SHoward Hinnantoperator<(const reverse_iterator<Iterator1>& x, const reverse_iterator<Iterator2>& y);
1153e519524SHoward Hinnant
1163e519524SHoward Hinnanttemplate <class Iterator1, class Iterator2>
1171b8f260eSMarshall Clowconstexpr bool                          // constexpr in C++17
1183e519524SHoward Hinnantoperator!=(const reverse_iterator<Iterator1>& x, const reverse_iterator<Iterator2>& y);
1193e519524SHoward Hinnant
1203e519524SHoward Hinnanttemplate <class Iterator1, class Iterator2>
1211b8f260eSMarshall Clowconstexpr bool                          // constexpr in C++17
1223e519524SHoward Hinnantoperator>(const reverse_iterator<Iterator1>& x, const reverse_iterator<Iterator2>& y);
1233e519524SHoward Hinnant
1243e519524SHoward Hinnanttemplate <class Iterator1, class Iterator2>
1251b8f260eSMarshall Clowconstexpr bool                          // constexpr in C++17
1263e519524SHoward Hinnantoperator>=(const reverse_iterator<Iterator1>& x, const reverse_iterator<Iterator2>& y);
1273e519524SHoward Hinnant
1283e519524SHoward Hinnanttemplate <class Iterator1, class Iterator2>
1291b8f260eSMarshall Clowconstexpr bool                          // constexpr in C++17
1303e519524SHoward Hinnantoperator<=(const reverse_iterator<Iterator1>& x, const reverse_iterator<Iterator2>& y);
1313e519524SHoward Hinnant
1323e519524SHoward Hinnanttemplate <class Iterator1, class Iterator2>
1331b8f260eSMarshall Clowconstexpr auto
134947ce6b5SMarshall Clowoperator-(const reverse_iterator<Iterator1>& x, const reverse_iterator<Iterator2>& y)
1351b8f260eSMarshall Clow-> decltype(__y.base() - __x.base());   // constexpr in C++17
1363e519524SHoward Hinnant
1373e519524SHoward Hinnanttemplate <class Iterator>
1381b8f260eSMarshall Clowconstexpr reverse_iterator<Iterator>
1391b8f260eSMarshall Clowoperator+(typename reverse_iterator<Iterator>::difference_type n,
1401b8f260eSMarshall Clow          const reverse_iterator<Iterator>& x);   // constexpr in C++17
1413e519524SHoward Hinnant
1421b8f260eSMarshall Clowtemplate <class Iterator>
1431b8f260eSMarshall Clowconstexpr reverse_iterator<Iterator> make_reverse_iterator(Iterator i); // C++14, constexpr in C++17
1446a640a18SMarshall Clow
1453e519524SHoward Hinnanttemplate <class Container>
1463e519524SHoward Hinnantclass back_insert_iterator
1473e519524SHoward Hinnant{
1483e519524SHoward Hinnantprotected:
1493e519524SHoward Hinnant    Container* container;
1503e519524SHoward Hinnantpublic:
1513e519524SHoward Hinnant    typedef Container                   container_type;
1523e519524SHoward Hinnant    typedef void                        value_type;
1533e519524SHoward Hinnant    typedef void                        difference_type;
1548892b4eeSEric Fiselier    typedef void                        reference;
1553e519524SHoward Hinnant    typedef void                        pointer;
1563e519524SHoward Hinnant
1573e519524SHoward Hinnant    explicit back_insert_iterator(Container& x);
15803976c1bSHoward Hinnant    back_insert_iterator& operator=(const typename Container::value_type& value);
1593e519524SHoward Hinnant    back_insert_iterator& operator*();
1603e519524SHoward Hinnant    back_insert_iterator& operator++();
1613e519524SHoward Hinnant    back_insert_iterator  operator++(int);
1623e519524SHoward Hinnant};
1633e519524SHoward Hinnant
1643e519524SHoward Hinnanttemplate <class Container> back_insert_iterator<Container> back_inserter(Container& x);
1653e519524SHoward Hinnant
1663e519524SHoward Hinnanttemplate <class Container>
1673e519524SHoward Hinnantclass front_insert_iterator
1683e519524SHoward Hinnant{
1693e519524SHoward Hinnantprotected:
1703e519524SHoward Hinnant    Container* container;
1713e519524SHoward Hinnantpublic:
1723e519524SHoward Hinnant    typedef Container                    container_type;
1733e519524SHoward Hinnant    typedef void                         value_type;
1743e519524SHoward Hinnant    typedef void                         difference_type;
1758892b4eeSEric Fiselier    typedef void                         reference;
1763e519524SHoward Hinnant    typedef void                         pointer;
1773e519524SHoward Hinnant
1783e519524SHoward Hinnant    explicit front_insert_iterator(Container& x);
17903976c1bSHoward Hinnant    front_insert_iterator& operator=(const typename Container::value_type& value);
1803e519524SHoward Hinnant    front_insert_iterator& operator*();
1813e519524SHoward Hinnant    front_insert_iterator& operator++();
1823e519524SHoward Hinnant    front_insert_iterator  operator++(int);
1833e519524SHoward Hinnant};
1843e519524SHoward Hinnant
1853e519524SHoward Hinnanttemplate <class Container> front_insert_iterator<Container> front_inserter(Container& x);
1863e519524SHoward Hinnant
1873e519524SHoward Hinnanttemplate <class Container>
1883e519524SHoward Hinnantclass insert_iterator
1893e519524SHoward Hinnant{
1903e519524SHoward Hinnantprotected:
1913e519524SHoward Hinnant    Container* container;
1923e519524SHoward Hinnant    typename Container::iterator iter;
1933e519524SHoward Hinnantpublic:
1943e519524SHoward Hinnant    typedef Container              container_type;
1953e519524SHoward Hinnant    typedef void                   value_type;
1963e519524SHoward Hinnant    typedef void                   difference_type;
1978892b4eeSEric Fiselier    typedef void                   reference;
1983e519524SHoward Hinnant    typedef void                   pointer;
1993e519524SHoward Hinnant
2003e519524SHoward Hinnant    insert_iterator(Container& x, typename Container::iterator i);
20103976c1bSHoward Hinnant    insert_iterator& operator=(const typename Container::value_type& value);
2023e519524SHoward Hinnant    insert_iterator& operator*();
2033e519524SHoward Hinnant    insert_iterator& operator++();
2043e519524SHoward Hinnant    insert_iterator& operator++(int);
2053e519524SHoward Hinnant};
2063e519524SHoward Hinnant
2073e519524SHoward Hinnanttemplate <class Container, class Iterator>
2083e519524SHoward Hinnantinsert_iterator<Container> inserter(Container& x, Iterator i);
2093e519524SHoward Hinnant
210947ce6b5SMarshall Clowtemplate <class Iterator>
211947ce6b5SMarshall Clowclass move_iterator {
212947ce6b5SMarshall Clowpublic:
213947ce6b5SMarshall Clow    typedef Iterator                                              iterator_type;
214947ce6b5SMarshall Clow    typedef typename iterator_traits<Iterator>::difference_type   difference_type;
215947ce6b5SMarshall Clow    typedef Iterator                                              pointer;
216947ce6b5SMarshall Clow    typedef typename iterator_traits<Iterator>::value_type        value_type;
217947ce6b5SMarshall Clow    typedef typename iterator_traits<Iterator>::iterator_category iterator_category;
218947ce6b5SMarshall Clow    typedef value_type&&                                          reference;
219947ce6b5SMarshall Clow
220720ef472SMarshall Clow    constexpr move_iterator();  // all the constexprs are in C++17
221720ef472SMarshall Clow    constexpr explicit move_iterator(Iterator i);
222720ef472SMarshall Clow    template <class U>
223720ef472SMarshall Clow      constexpr move_iterator(const move_iterator<U>& u);
224720ef472SMarshall Clow    template <class U>
225720ef472SMarshall Clow      constexpr move_iterator& operator=(const move_iterator<U>& u);
226720ef472SMarshall Clow    constexpr iterator_type base() const;
227720ef472SMarshall Clow    constexpr reference operator*() const;
228720ef472SMarshall Clow    constexpr pointer operator->() const;
229720ef472SMarshall Clow    constexpr move_iterator& operator++();
230720ef472SMarshall Clow    constexpr move_iterator operator++(int);
231720ef472SMarshall Clow    constexpr move_iterator& operator--();
232720ef472SMarshall Clow    constexpr move_iterator operator--(int);
233720ef472SMarshall Clow    constexpr move_iterator operator+(difference_type n) const;
234720ef472SMarshall Clow    constexpr move_iterator& operator+=(difference_type n);
235720ef472SMarshall Clow    constexpr move_iterator operator-(difference_type n) const;
236720ef472SMarshall Clow    constexpr move_iterator& operator-=(difference_type n);
237720ef472SMarshall Clow    constexpr unspecified operator[](difference_type n) const;
238947ce6b5SMarshall Clowprivate:
239947ce6b5SMarshall Clow    Iterator current; // exposition only
240947ce6b5SMarshall Clow};
241947ce6b5SMarshall Clow
242947ce6b5SMarshall Clowtemplate <class Iterator1, class Iterator2>
243720ef472SMarshall Clowconstexpr bool   // constexpr in C++17
244947ce6b5SMarshall Clowoperator==(const move_iterator<Iterator1>& x, const move_iterator<Iterator2>& y);
245947ce6b5SMarshall Clow
246947ce6b5SMarshall Clowtemplate <class Iterator1, class Iterator2>
247720ef472SMarshall Clowconstexpr bool   // constexpr in C++17
248947ce6b5SMarshall Clowoperator!=(const move_iterator<Iterator1>& x, const move_iterator<Iterator2>& y);
249947ce6b5SMarshall Clow
250947ce6b5SMarshall Clowtemplate <class Iterator1, class Iterator2>
251720ef472SMarshall Clowconstexpr bool   // constexpr in C++17
252947ce6b5SMarshall Clowoperator<(const move_iterator<Iterator1>& x, const move_iterator<Iterator2>& y);
253947ce6b5SMarshall Clow
254947ce6b5SMarshall Clowtemplate <class Iterator1, class Iterator2>
255720ef472SMarshall Clowconstexpr bool   // constexpr in C++17
256947ce6b5SMarshall Clowoperator<=(const move_iterator<Iterator1>& x, const move_iterator<Iterator2>& y);
257947ce6b5SMarshall Clow
258947ce6b5SMarshall Clowtemplate <class Iterator1, class Iterator2>
259720ef472SMarshall Clowconstexpr bool   // constexpr in C++17
260947ce6b5SMarshall Clowoperator>(const move_iterator<Iterator1>& x, const move_iterator<Iterator2>& y);
261947ce6b5SMarshall Clow
262947ce6b5SMarshall Clowtemplate <class Iterator1, class Iterator2>
263720ef472SMarshall Clowconstexpr bool   // constexpr in C++17
264947ce6b5SMarshall Clowoperator>=(const move_iterator<Iterator1>& x, const move_iterator<Iterator2>& y);
265947ce6b5SMarshall Clow
266947ce6b5SMarshall Clowtemplate <class Iterator1, class Iterator2>
267720ef472SMarshall Clowconstexpr auto   // constexpr in C++17
268947ce6b5SMarshall Clowoperator-(const move_iterator<Iterator1>& x,
269947ce6b5SMarshall Clow          const move_iterator<Iterator2>& y) -> decltype(x.base() - y.base());
270947ce6b5SMarshall Clow
271947ce6b5SMarshall Clowtemplate <class Iterator>
272720ef472SMarshall Clowconstexpr move_iterator<Iterator> operator+(   // constexpr in C++17
273720ef472SMarshall Clow            typename move_iterator<Iterator>::difference_type n,
274947ce6b5SMarshall Clow            const move_iterator<Iterator>& x);
275947ce6b5SMarshall Clow
276720ef472SMarshall Clowtemplate <class Iterator>   // constexpr in C++17
277720ef472SMarshall Clowconstexpr  move_iterator<Iterator> make_move_iterator(const Iterator& i);
278947ce6b5SMarshall Clow
279947ce6b5SMarshall Clow
2803e519524SHoward Hinnanttemplate <class T, class charT = char, class traits = char_traits<charT>, class Distance = ptrdiff_t>
2813e519524SHoward Hinnantclass istream_iterator
2823e519524SHoward Hinnant    : public iterator<input_iterator_tag, T, Distance, const T*, const T&>
2833e519524SHoward Hinnant{
2843e519524SHoward Hinnantpublic:
2853e519524SHoward Hinnant    typedef charT char_type;
2863e519524SHoward Hinnant    typedef traits traits_type;
2873e519524SHoward Hinnant    typedef basic_istream<charT,traits> istream_type;
2883e519524SHoward Hinnant
28960d5e0e0SMarshall Clow    constexpr istream_iterator();
2903e519524SHoward Hinnant    istream_iterator(istream_type& s);
2913e519524SHoward Hinnant    istream_iterator(const istream_iterator& x);
2923e519524SHoward Hinnant    ~istream_iterator();
2933e519524SHoward Hinnant
2943e519524SHoward Hinnant    const T& operator*() const;
2953e519524SHoward Hinnant    const T* operator->() const;
2963e519524SHoward Hinnant    istream_iterator& operator++();
2973e519524SHoward Hinnant    istream_iterator  operator++(int);
2983e519524SHoward Hinnant};
2993e519524SHoward Hinnant
3003e519524SHoward Hinnanttemplate <class T, class charT, class traits, class Distance>
3013e519524SHoward Hinnantbool operator==(const istream_iterator<T,charT,traits,Distance>& x,
3023e519524SHoward Hinnant                const istream_iterator<T,charT,traits,Distance>& y);
3033e519524SHoward Hinnanttemplate <class T, class charT, class traits, class Distance>
3043e519524SHoward Hinnantbool operator!=(const istream_iterator<T,charT,traits,Distance>& x,
3053e519524SHoward Hinnant                const istream_iterator<T,charT,traits,Distance>& y);
3063e519524SHoward Hinnant
3073e519524SHoward Hinnanttemplate <class T, class charT = char, class traits = char_traits<charT> >
3083e519524SHoward Hinnantclass ostream_iterator
3093e519524SHoward Hinnant    : public iterator<output_iterator_tag, void, void, void ,void>
3103e519524SHoward Hinnant{
3113e519524SHoward Hinnantpublic:
3123e519524SHoward Hinnant    typedef charT char_type;
3133e519524SHoward Hinnant    typedef traits traits_type;
3143e519524SHoward Hinnant    typedef basic_ostream<charT,traits> ostream_type;
3153e519524SHoward Hinnant
3163e519524SHoward Hinnant    ostream_iterator(ostream_type& s);
3173e519524SHoward Hinnant    ostream_iterator(ostream_type& s, const charT* delimiter);
3183e519524SHoward Hinnant    ostream_iterator(const ostream_iterator& x);
3193e519524SHoward Hinnant    ~ostream_iterator();
3203e519524SHoward Hinnant    ostream_iterator& operator=(const T& value);
3213e519524SHoward Hinnant
3223e519524SHoward Hinnant    ostream_iterator& operator*();
3233e519524SHoward Hinnant    ostream_iterator& operator++();
3243e519524SHoward Hinnant    ostream_iterator& operator++(int);
3253e519524SHoward Hinnant};
3263e519524SHoward Hinnant
3273e519524SHoward Hinnanttemplate<class charT, class traits = char_traits<charT> >
3283e519524SHoward Hinnantclass istreambuf_iterator
3293e519524SHoward Hinnant    : public iterator<input_iterator_tag, charT,
3303e519524SHoward Hinnant                      typename traits::off_type, unspecified,
3313e519524SHoward Hinnant                      charT>
3323e519524SHoward Hinnant{
3333e519524SHoward Hinnantpublic:
3343e519524SHoward Hinnant    typedef charT                         char_type;
3353e519524SHoward Hinnant    typedef traits                        traits_type;
3363e519524SHoward Hinnant    typedef typename traits::int_type     int_type;
3373e519524SHoward Hinnant    typedef basic_streambuf<charT,traits> streambuf_type;
3383e519524SHoward Hinnant    typedef basic_istream<charT,traits>   istream_type;
3393e519524SHoward Hinnant
3408e882dcbSHoward Hinnant    istreambuf_iterator() noexcept;
3418e882dcbSHoward Hinnant    istreambuf_iterator(istream_type& s) noexcept;
3428e882dcbSHoward Hinnant    istreambuf_iterator(streambuf_type* s) noexcept;
3438e882dcbSHoward Hinnant    istreambuf_iterator(a-private-type) noexcept;
3443e519524SHoward Hinnant
3453e519524SHoward Hinnant    charT                operator*() const;
3463e519524SHoward Hinnant    pointer operator->() const;
3473e519524SHoward Hinnant    istreambuf_iterator& operator++();
3483e519524SHoward Hinnant    a-private-type       operator++(int);
3493e519524SHoward Hinnant
3503e519524SHoward Hinnant    bool equal(const istreambuf_iterator& b) const;
3513e519524SHoward Hinnant};
3523e519524SHoward Hinnant
3533e519524SHoward Hinnanttemplate <class charT, class traits>
3543e519524SHoward Hinnantbool operator==(const istreambuf_iterator<charT,traits>& a,
3553e519524SHoward Hinnant                const istreambuf_iterator<charT,traits>& b);
3563e519524SHoward Hinnanttemplate <class charT, class traits>
3573e519524SHoward Hinnantbool operator!=(const istreambuf_iterator<charT,traits>& a,
3583e519524SHoward Hinnant                const istreambuf_iterator<charT,traits>& b);
3593e519524SHoward Hinnant
3603e519524SHoward Hinnanttemplate <class charT, class traits = char_traits<charT> >
3613e519524SHoward Hinnantclass ostreambuf_iterator
3623e519524SHoward Hinnant    : public iterator<output_iterator_tag, void, void, void, void>
3633e519524SHoward Hinnant{
3643e519524SHoward Hinnantpublic:
3653e519524SHoward Hinnant    typedef charT                         char_type;
3663e519524SHoward Hinnant    typedef traits                        traits_type;
3673e519524SHoward Hinnant    typedef basic_streambuf<charT,traits> streambuf_type;
3683e519524SHoward Hinnant    typedef basic_ostream<charT,traits>   ostream_type;
3693e519524SHoward Hinnant
3708e882dcbSHoward Hinnant    ostreambuf_iterator(ostream_type& s) noexcept;
3718e882dcbSHoward Hinnant    ostreambuf_iterator(streambuf_type* s) noexcept;
3723e519524SHoward Hinnant    ostreambuf_iterator& operator=(charT c);
3733e519524SHoward Hinnant    ostreambuf_iterator& operator*();
3743e519524SHoward Hinnant    ostreambuf_iterator& operator++();
3753e519524SHoward Hinnant    ostreambuf_iterator& operator++(int);
3768e882dcbSHoward Hinnant    bool failed() const noexcept;
3773e519524SHoward Hinnant};
3783e519524SHoward Hinnant
379020b623aSMarshall Clowtemplate <class C> constexpr auto begin(C& c) -> decltype(c.begin());
380020b623aSMarshall Clowtemplate <class C> constexpr auto begin(const C& c) -> decltype(c.begin());
381020b623aSMarshall Clowtemplate <class C> constexpr auto end(C& c) -> decltype(c.end());
382020b623aSMarshall Clowtemplate <class C> constexpr auto end(const C& c) -> decltype(c.end());
383020b623aSMarshall Clowtemplate <class T, size_t N> constexpr T* begin(T (&array)[N]);
384020b623aSMarshall Clowtemplate <class T, size_t N> constexpr T* end(T (&array)[N]);
3853e519524SHoward Hinnant
386020b623aSMarshall Clowtemplate <class C> auto constexpr cbegin(const C& c) -> decltype(std::begin(c));        // C++14
387020b623aSMarshall Clowtemplate <class C> auto constexpr cend(const C& c) -> decltype(std::end(c));            // C++14
388020b623aSMarshall Clowtemplate <class C> auto constexpr rbegin(C& c) -> decltype(c.rbegin());                 // C++14
389020b623aSMarshall Clowtemplate <class C> auto constexpr rbegin(const C& c) -> decltype(c.rbegin());           // C++14
390020b623aSMarshall Clowtemplate <class C> auto constexpr rend(C& c) -> decltype(c.rend());                     // C++14
391020b623aSMarshall Clowtemplate <class C> constexpr auto rend(const C& c) -> decltype(c.rend());               // C++14
392020b623aSMarshall Clowtemplate <class E> reverse_iterator<const E*> constexpr rbegin(initializer_list<E> il); // C++14
393020b623aSMarshall Clowtemplate <class E> reverse_iterator<const E*> constexpr rend(initializer_list<E> il);   // C++14
394020b623aSMarshall Clowtemplate <class T, size_t N> reverse_iterator<T*> constexpr rbegin(T (&array)[N]);      // C++14
395020b623aSMarshall Clowtemplate <class T, size_t N> reverse_iterator<T*> constexpr rend(T (&array)[N]);        // C++14
396020b623aSMarshall Clowtemplate <class C> constexpr auto crbegin(const C& c) -> decltype(std::rbegin(c));      // C++14
397020b623aSMarshall Clowtemplate <class C> constexpr auto crend(const C& c) -> decltype(std::rend(c));          // C++14
3981e548c72SMarshall Clow
399ad755104SMarshall Clow// 24.8, container access:
400ad755104SMarshall Clowtemplate <class C> constexpr auto size(const C& c) -> decltype(c.size());         // C++17
401ad755104SMarshall Clowtemplate <class T, size_t N> constexpr size_t size(const T (&array)[N]) noexcept; // C++17
4027d3986eaSMarshall Clow
4037d3986eaSMarshall Clowtemplate <class C> constexpr auto ssize(const C& c)
4047d3986eaSMarshall Clow    -> common_type_t<ptrdiff_t, make_signed_t<decltype(c.size())>>;				       // C++20
4057d3986eaSMarshall Clowtemplate <class T, ptrdiff_t> constexpr ptrdiff_t ssize(const T (&array)[N]) noexcept; // C++20
4067d3986eaSMarshall Clow
407ad755104SMarshall Clowtemplate <class C> constexpr auto empty(const C& c) -> decltype(c.empty());       // C++17
408ad755104SMarshall Clowtemplate <class T, size_t N> constexpr bool empty(const T (&array)[N]) noexcept;  // C++17
409ad755104SMarshall Clowtemplate <class E> constexpr bool empty(initializer_list<E> il) noexcept;         // C++17
410ad755104SMarshall Clowtemplate <class C> constexpr auto data(C& c) -> decltype(c.data());               // C++17
411ad755104SMarshall Clowtemplate <class C> constexpr auto data(const C& c) -> decltype(c.data());         // C++17
412ad755104SMarshall Clowtemplate <class T, size_t N> constexpr T* data(T (&array)[N]) noexcept;           // C++17
413ad755104SMarshall Clowtemplate <class E> constexpr const E* data(initializer_list<E> il) noexcept;      // C++17
414ad755104SMarshall Clow
4153e519524SHoward Hinnant}  // std
4163e519524SHoward Hinnant
4173e519524SHoward Hinnant*/
4183e519524SHoward Hinnant
4193e519524SHoward Hinnant#include <__config>
42039c193b1SEric Fiselier#include <iosfwd> // for forward declarations of vector and string.
421c204c130SMarshall Clow#include <__functional_base>
4223e519524SHoward Hinnant#include <type_traits>
4233e519524SHoward Hinnant#include <cstddef>
4241e548c72SMarshall Clow#include <initializer_list>
425f56972e2SMarshall Clow#include <version>
426b56e8587SMarshall Clow#ifdef __APPLE__
427b5c63a2eSHoward Hinnant#include <Availability.h>
428b5c63a2eSHoward Hinnant#endif
429b5c63a2eSHoward Hinnant
43042a3046eSHoward Hinnant#include <__debug>
4313e519524SHoward Hinnant
432073458b1SHoward Hinnant#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
4333e519524SHoward Hinnant#pragma GCC system_header
434073458b1SHoward Hinnant#endif
4353e519524SHoward Hinnant
4363e519524SHoward Hinnant_LIBCPP_BEGIN_NAMESPACE_STD
4376624fcbaSEric Fiseliertemplate <class _Iter>
4386624fcbaSEric Fiselierstruct _LIBCPP_TEMPLATE_VIS iterator_traits;
4393e519524SHoward Hinnant
440e2f2d1edSEric Fiselierstruct _LIBCPP_TEMPLATE_VIS input_iterator_tag {};
441e2f2d1edSEric Fiselierstruct _LIBCPP_TEMPLATE_VIS output_iterator_tag {};
442e2f2d1edSEric Fiselierstruct _LIBCPP_TEMPLATE_VIS forward_iterator_tag       : public input_iterator_tag {};
443e2f2d1edSEric Fiselierstruct _LIBCPP_TEMPLATE_VIS bidirectional_iterator_tag : public forward_iterator_tag {};
444e2f2d1edSEric Fiselierstruct _LIBCPP_TEMPLATE_VIS random_access_iterator_tag : public bidirectional_iterator_tag {};
44545d048c2SEric Fiselier#if _LIBCPP_STD_VER > 17
44645d048c2SEric Fiselier// TODO(EricWF)  contiguous_iterator_tag is provided as an extension prior to
44745d048c2SEric Fiselier//  C++20 to allow optimizations for users providing wrapped iterator types.
44845d048c2SEric Fiselierstruct _LIBCPP_TEMPLATE_VIS contiguous_iterator_tag: public random_access_iterator_tag { };
44945d048c2SEric Fiselier#endif
4503e519524SHoward Hinnant
4516624fcbaSEric Fiseliertemplate <class _Iter>
4526624fcbaSEric Fiselierstruct __iter_traits_cache {
4536624fcbaSEric Fiselier  using type = _If<
4546624fcbaSEric Fiselier    __is_primary_template<iterator_traits<_Iter> >::value,
4556624fcbaSEric Fiselier    _Iter,
4566624fcbaSEric Fiselier    iterator_traits<_Iter>
4576624fcbaSEric Fiselier  >;
4586624fcbaSEric Fiselier};
4596624fcbaSEric Fiseliertemplate <class _Iter>
4606624fcbaSEric Fiselierusing _ITER_TRAITS = typename __iter_traits_cache<_Iter>::type;
4616624fcbaSEric Fiselier
4626624fcbaSEric Fiselierstruct __iter_concept_concept_test {
4636624fcbaSEric Fiselier  template <class _Iter>
4646624fcbaSEric Fiselier  using _Apply = typename _ITER_TRAITS<_Iter>::iterator_concept;
4656624fcbaSEric Fiselier};
4666624fcbaSEric Fiselierstruct __iter_concept_category_test {
4676624fcbaSEric Fiselier  template <class _Iter>
4686624fcbaSEric Fiselier  using _Apply = typename _ITER_TRAITS<_Iter>::iterator_category;
4696624fcbaSEric Fiselier};
4706624fcbaSEric Fiselierstruct __iter_concept_random_fallback {
4716624fcbaSEric Fiselier  template <class _Iter>
4726624fcbaSEric Fiselier  using _Apply = _EnableIf<
4736624fcbaSEric Fiselier                          __is_primary_template<iterator_traits<_Iter> >::value,
4746624fcbaSEric Fiselier                          random_access_iterator_tag
4756624fcbaSEric Fiselier                        >;
4766624fcbaSEric Fiselier};
4776624fcbaSEric Fiselier
4786624fcbaSEric Fiseliertemplate <class _Iter, class _Tester> struct __test_iter_concept
4796624fcbaSEric Fiselier    : _IsValidExpansion<_Tester::template _Apply, _Iter>,
4806624fcbaSEric Fiselier      _Tester
4816624fcbaSEric Fiselier{
4826624fcbaSEric Fiselier};
4836624fcbaSEric Fiselier
4846624fcbaSEric Fiseliertemplate <class _Iter>
4856624fcbaSEric Fiselierstruct __iter_concept_cache {
4866624fcbaSEric Fiselier  using type = _Or<
4876624fcbaSEric Fiselier    __test_iter_concept<_Iter, __iter_concept_concept_test>,
4886624fcbaSEric Fiselier    __test_iter_concept<_Iter, __iter_concept_category_test>,
4896624fcbaSEric Fiselier    __test_iter_concept<_Iter, __iter_concept_random_fallback>
4906624fcbaSEric Fiselier  >;
4916624fcbaSEric Fiselier};
4926624fcbaSEric Fiselier
4936624fcbaSEric Fiseliertemplate <class _Iter>
4946624fcbaSEric Fiselierusing _ITER_CONCEPT = typename __iter_concept_cache<_Iter>::type::template _Apply<_Iter>;
4956624fcbaSEric Fiselier
4966624fcbaSEric Fiselier
4973e519524SHoward Hinnanttemplate <class _Tp>
498d4fa0381SMarshall Clowstruct __has_iterator_typedefs
499d4fa0381SMarshall Clow{
500d4fa0381SMarshall Clowprivate:
501d4fa0381SMarshall Clow    struct __two {char __lx; char __lxx;};
502d4fa0381SMarshall Clow    template <class _Up> static __two __test(...);
503d4fa0381SMarshall Clow    template <class _Up> static char __test(typename std::__void_t<typename _Up::iterator_category>::type* = 0,
504d4fa0381SMarshall Clow    										typename std::__void_t<typename _Up::difference_type>::type* = 0,
505d4fa0381SMarshall Clow    										typename std::__void_t<typename _Up::value_type>::type* = 0,
506d4fa0381SMarshall Clow    										typename std::__void_t<typename _Up::reference>::type* = 0,
507d4fa0381SMarshall Clow    										typename std::__void_t<typename _Up::pointer>::type* = 0
508d4fa0381SMarshall Clow    										);
509d4fa0381SMarshall Clowpublic:
510d4fa0381SMarshall Clow    static const bool value = sizeof(__test<_Tp>(0,0,0,0,0)) == 1;
511d4fa0381SMarshall Clow};
512d4fa0381SMarshall Clow
513d4fa0381SMarshall Clow
514d4fa0381SMarshall Clowtemplate <class _Tp>
5153e519524SHoward Hinnantstruct __has_iterator_category
5163e519524SHoward Hinnant{
5173e519524SHoward Hinnantprivate:
51854d333a6SHoward Hinnant    struct __two {char __lx; char __lxx;};
5193e519524SHoward Hinnant    template <class _Up> static __two __test(...);
5203e519524SHoward Hinnant    template <class _Up> static char __test(typename _Up::iterator_category* = 0);
5213e519524SHoward Hinnantpublic:
5223e519524SHoward Hinnant    static const bool value = sizeof(__test<_Tp>(0)) == 1;
5233e519524SHoward Hinnant};
5243e519524SHoward Hinnant
5250724bf67SMarshall Clowtemplate <class _Iter, bool> struct __iterator_traits_impl {};
5263e519524SHoward Hinnant
5273e519524SHoward Hinnanttemplate <class _Iter>
5280724bf67SMarshall Clowstruct __iterator_traits_impl<_Iter, true>
5293e519524SHoward Hinnant{
5303e519524SHoward Hinnant    typedef typename _Iter::difference_type   difference_type;
5313e519524SHoward Hinnant    typedef typename _Iter::value_type        value_type;
5323e519524SHoward Hinnant    typedef typename _Iter::pointer           pointer;
5333e519524SHoward Hinnant    typedef typename _Iter::reference         reference;
5343e519524SHoward Hinnant    typedef typename _Iter::iterator_category iterator_category;
5353e519524SHoward Hinnant};
5363e519524SHoward Hinnant
5373e519524SHoward Hinnanttemplate <class _Iter, bool> struct __iterator_traits {};
5383e519524SHoward Hinnant
5393e519524SHoward Hinnanttemplate <class _Iter>
5403e519524SHoward Hinnantstruct __iterator_traits<_Iter, true>
5410724bf67SMarshall Clow    :  __iterator_traits_impl
5423e519524SHoward Hinnant      <
5433e519524SHoward Hinnant        _Iter,
5443e519524SHoward Hinnant        is_convertible<typename _Iter::iterator_category, input_iterator_tag>::value ||
5453e519524SHoward Hinnant        is_convertible<typename _Iter::iterator_category, output_iterator_tag>::value
5463e519524SHoward Hinnant      >
5473e519524SHoward Hinnant{};
5483e519524SHoward Hinnant
5493e519524SHoward Hinnant// iterator_traits<Iterator> will only have the nested types if Iterator::iterator_category
5503e519524SHoward Hinnant//    exists.  Else iterator_traits<Iterator> will be an empty class.  This is a
5513e519524SHoward Hinnant//    conforming extension which allows some programs to compile and behave as
5523e519524SHoward Hinnant//    the client expects instead of failing at compile time.
5533e519524SHoward Hinnant
5543e519524SHoward Hinnanttemplate <class _Iter>
555e2f2d1edSEric Fiselierstruct _LIBCPP_TEMPLATE_VIS iterator_traits
5566624fcbaSEric Fiselier    : __iterator_traits<_Iter, __has_iterator_typedefs<_Iter>::value> {
5576624fcbaSEric Fiselier
5586624fcbaSEric Fiselier  using __primary_template = iterator_traits;
5596624fcbaSEric Fiselier};
5603e519524SHoward Hinnant
5613e519524SHoward Hinnanttemplate<class _Tp>
562e2f2d1edSEric Fiselierstruct _LIBCPP_TEMPLATE_VIS iterator_traits<_Tp*>
5633e519524SHoward Hinnant{
5643e519524SHoward Hinnant    typedef ptrdiff_t difference_type;
565ffcfd923SMarshall Clow    typedef typename remove_cv<_Tp>::type value_type;
5663e519524SHoward Hinnant    typedef _Tp* pointer;
5673e519524SHoward Hinnant    typedef _Tp& reference;
5683e519524SHoward Hinnant    typedef random_access_iterator_tag iterator_category;
56945d048c2SEric Fiselier#if _LIBCPP_STD_VER > 17
57045d048c2SEric Fiselier    typedef contiguous_iterator_tag    iterator_concept;
57145d048c2SEric Fiselier#endif
5723e519524SHoward Hinnant};
5733e519524SHoward Hinnant
5743e519524SHoward Hinnanttemplate <class _Tp, class _Up, bool = __has_iterator_category<iterator_traits<_Tp> >::value>
5753e519524SHoward Hinnantstruct __has_iterator_category_convertible_to
5763e519524SHoward Hinnant    : public integral_constant<bool, is_convertible<typename iterator_traits<_Tp>::iterator_category, _Up>::value>
5773e519524SHoward Hinnant{};
5783e519524SHoward Hinnant
5793e519524SHoward Hinnanttemplate <class _Tp, class _Up>
5803e519524SHoward Hinnantstruct __has_iterator_category_convertible_to<_Tp, _Up, false> : public false_type {};
5813e519524SHoward Hinnant
5823e519524SHoward Hinnanttemplate <class _Tp>
583*f82dba01SEric Fiselierstruct __is_cpp17_input_iterator : public __has_iterator_category_convertible_to<_Tp, input_iterator_tag> {};
5843e519524SHoward Hinnant
5853e519524SHoward Hinnanttemplate <class _Tp>
586*f82dba01SEric Fiselierstruct __is_cpp17_forward_iterator : public __has_iterator_category_convertible_to<_Tp, forward_iterator_tag> {};
5873e519524SHoward Hinnant
5883e519524SHoward Hinnanttemplate <class _Tp>
589*f82dba01SEric Fiselierstruct __is_cpp17_bidirectional_iterator : public __has_iterator_category_convertible_to<_Tp, bidirectional_iterator_tag> {};
5903e519524SHoward Hinnant
5913e519524SHoward Hinnanttemplate <class _Tp>
592*f82dba01SEric Fiselierstruct __is_cpp17_random_access_iterator : public __has_iterator_category_convertible_to<_Tp, random_access_iterator_tag> {};
5933e519524SHoward Hinnant
59445d048c2SEric Fiselier#if _LIBCPP_STD_VER > 17
59545d048c2SEric Fiseliertemplate <class _Tp>
596*f82dba01SEric Fiselierstruct __is_cpp17_contiguous_iterator : public __has_iterator_category_convertible_to<_Tp, contiguous_iterator_tag> {};
597*f82dba01SEric Fiselier#else
598*f82dba01SEric Fiseliertemplate <class _Tp>
599*f82dba01SEric Fiselierstruct __is_cpp17_contiguous_iterator : public false_type {};
60045d048c2SEric Fiselier#endif
60145d048c2SEric Fiselier
602*f82dba01SEric Fiselier
60376b4afc0SMarshall Clowtemplate <class _Tp>
604*f82dba01SEric Fiselierstruct __is_exactly_cpp17_input_iterator
60576b4afc0SMarshall Clow    : public integral_constant<bool,
60676b4afc0SMarshall Clow         __has_iterator_category_convertible_to<_Tp, input_iterator_tag>::value &&
60776b4afc0SMarshall Clow        !__has_iterator_category_convertible_to<_Tp, forward_iterator_tag>::value> {};
60876b4afc0SMarshall Clow
609f2f7d72fSLouis Dionne#ifndef _LIBCPP_HAS_NO_DEDUCTION_GUIDES
610f2f7d72fSLouis Dionnetemplate<class _InputIterator>
611f2f7d72fSLouis Dionneusing __iter_value_type = typename iterator_traits<_InputIterator>::value_type;
612f2f7d72fSLouis Dionne
613f2f7d72fSLouis Dionnetemplate<class _InputIterator>
614f2f7d72fSLouis Dionneusing __iter_key_type = remove_const_t<typename iterator_traits<_InputIterator>::value_type::first_type>;
615f2f7d72fSLouis Dionne
616f2f7d72fSLouis Dionnetemplate<class _InputIterator>
617f2f7d72fSLouis Dionneusing __iter_mapped_type = typename iterator_traits<_InputIterator>::value_type::second_type;
618f2f7d72fSLouis Dionne
619f2f7d72fSLouis Dionnetemplate<class _InputIterator>
620f2f7d72fSLouis Dionneusing __iter_to_alloc_type = pair<
621f2f7d72fSLouis Dionne    add_const_t<typename iterator_traits<_InputIterator>::value_type::first_type>,
622f2f7d72fSLouis Dionne    typename iterator_traits<_InputIterator>::value_type::second_type>;
623f2f7d72fSLouis Dionne#endif
624f2f7d72fSLouis Dionne
6253e519524SHoward Hinnanttemplate<class _Category, class _Tp, class _Distance = ptrdiff_t,
6263e519524SHoward Hinnant         class _Pointer = _Tp*, class _Reference = _Tp&>
627e2f2d1edSEric Fiselierstruct _LIBCPP_TEMPLATE_VIS iterator
6283e519524SHoward Hinnant{
6293e519524SHoward Hinnant    typedef _Tp        value_type;
6303e519524SHoward Hinnant    typedef _Distance  difference_type;
6313e519524SHoward Hinnant    typedef _Pointer   pointer;
6323e519524SHoward Hinnant    typedef _Reference reference;
6333e519524SHoward Hinnant    typedef _Category  iterator_category;
6343e519524SHoward Hinnant};
6353e519524SHoward Hinnant
6363e519524SHoward Hinnanttemplate <class _InputIter>
637f51ee632SMarshall Clowinline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
6383e519524SHoward Hinnantvoid __advance(_InputIter& __i,
6393e519524SHoward Hinnant             typename iterator_traits<_InputIter>::difference_type __n, input_iterator_tag)
6403e519524SHoward Hinnant{
6413e519524SHoward Hinnant    for (; __n > 0; --__n)
6423e519524SHoward Hinnant        ++__i;
6433e519524SHoward Hinnant}
6443e519524SHoward Hinnant
6453e519524SHoward Hinnanttemplate <class _BiDirIter>
646f51ee632SMarshall Clowinline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
6473e519524SHoward Hinnantvoid __advance(_BiDirIter& __i,
6483e519524SHoward Hinnant             typename iterator_traits<_BiDirIter>::difference_type __n, bidirectional_iterator_tag)
6493e519524SHoward Hinnant{
6503e519524SHoward Hinnant    if (__n >= 0)
6513e519524SHoward Hinnant        for (; __n > 0; --__n)
6523e519524SHoward Hinnant            ++__i;
6533e519524SHoward Hinnant    else
6543e519524SHoward Hinnant        for (; __n < 0; ++__n)
6553e519524SHoward Hinnant            --__i;
6563e519524SHoward Hinnant}
6573e519524SHoward Hinnant
6583e519524SHoward Hinnanttemplate <class _RandIter>
659f51ee632SMarshall Clowinline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
6603e519524SHoward Hinnantvoid __advance(_RandIter& __i,
6613e519524SHoward Hinnant             typename iterator_traits<_RandIter>::difference_type __n, random_access_iterator_tag)
6623e519524SHoward Hinnant{
6633e519524SHoward Hinnant   __i += __n;
6643e519524SHoward Hinnant}
6653e519524SHoward Hinnant
6663e519524SHoward Hinnanttemplate <class _InputIter>
667f51ee632SMarshall Clowinline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
6683e519524SHoward Hinnantvoid advance(_InputIter& __i,
6693e519524SHoward Hinnant             typename iterator_traits<_InputIter>::difference_type __n)
6703e519524SHoward Hinnant{
671*f82dba01SEric Fiselier    _LIBCPP_ASSERT(__n >= 0 || __is_cpp17_bidirectional_iterator<_InputIter>::value,
672e1cd11d8SMarshall Clow                       "Attempt to advance(it, -n) on a non-bidi iterator");
6733e519524SHoward Hinnant    __advance(__i, __n, typename iterator_traits<_InputIter>::iterator_category());
6743e519524SHoward Hinnant}
6753e519524SHoward Hinnant
6763e519524SHoward Hinnanttemplate <class _InputIter>
677f51ee632SMarshall Clowinline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
6783e519524SHoward Hinnanttypename iterator_traits<_InputIter>::difference_type
6793e519524SHoward Hinnant__distance(_InputIter __first, _InputIter __last, input_iterator_tag)
6803e519524SHoward Hinnant{
6813e519524SHoward Hinnant    typename iterator_traits<_InputIter>::difference_type __r(0);
6823e519524SHoward Hinnant    for (; __first != __last; ++__first)
6833e519524SHoward Hinnant        ++__r;
6843e519524SHoward Hinnant    return __r;
6853e519524SHoward Hinnant}
6863e519524SHoward Hinnant
6873e519524SHoward Hinnanttemplate <class _RandIter>
688f51ee632SMarshall Clowinline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
6893e519524SHoward Hinnanttypename iterator_traits<_RandIter>::difference_type
6903e519524SHoward Hinnant__distance(_RandIter __first, _RandIter __last, random_access_iterator_tag)
6913e519524SHoward Hinnant{
6923e519524SHoward Hinnant    return __last - __first;
6933e519524SHoward Hinnant}
6943e519524SHoward Hinnant
6953e519524SHoward Hinnanttemplate <class _InputIter>
696f51ee632SMarshall Clowinline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
6973e519524SHoward Hinnanttypename iterator_traits<_InputIter>::difference_type
6983e519524SHoward Hinnantdistance(_InputIter __first, _InputIter __last)
6993e519524SHoward Hinnant{
7003e519524SHoward Hinnant    return __distance(__first, __last, typename iterator_traits<_InputIter>::iterator_category());
7013e519524SHoward Hinnant}
7023e519524SHoward Hinnant
703e5f1288fSMarshall Clowtemplate <class _InputIter>
704f51ee632SMarshall Clowinline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
7053e2ef408SRachel Craiktypename enable_if
7063e2ef408SRachel Craik<
707*f82dba01SEric Fiselier    __is_cpp17_input_iterator<_InputIter>::value,
708e5f1288fSMarshall Clow    _InputIter
7093e2ef408SRachel Craik>::type
710e5f1288fSMarshall Clownext(_InputIter __x,
7113e2ef408SRachel Craik     typename iterator_traits<_InputIter>::difference_type __n = 1)
7123e519524SHoward Hinnant{
713*f82dba01SEric Fiselier    _LIBCPP_ASSERT(__n >= 0 || __is_cpp17_bidirectional_iterator<_InputIter>::value,
714e1cd11d8SMarshall Clow                       "Attempt to next(it, -n) on a non-bidi iterator");
715e1cd11d8SMarshall Clow
716ce48a113SHoward Hinnant    _VSTD::advance(__x, __n);
7173e519524SHoward Hinnant    return __x;
7183e519524SHoward Hinnant}
7193e519524SHoward Hinnant
720e1cd11d8SMarshall Clowtemplate <class _InputIter>
721f51ee632SMarshall Clowinline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
7223e2ef408SRachel Craiktypename enable_if
7233e2ef408SRachel Craik<
724*f82dba01SEric Fiselier    __is_cpp17_input_iterator<_InputIter>::value,
725e1cd11d8SMarshall Clow    _InputIter
7263e2ef408SRachel Craik>::type
727e1cd11d8SMarshall Clowprev(_InputIter __x,
728e1cd11d8SMarshall Clow     typename iterator_traits<_InputIter>::difference_type __n = 1)
7293e519524SHoward Hinnant{
730*f82dba01SEric Fiselier    _LIBCPP_ASSERT(__n <= 0 || __is_cpp17_bidirectional_iterator<_InputIter>::value,
731e1cd11d8SMarshall Clow                       "Attempt to prev(it, +n) on a non-bidi iterator");
732ce48a113SHoward Hinnant    _VSTD::advance(__x, -__n);
7333e519524SHoward Hinnant    return __x;
7343e519524SHoward Hinnant}
7353e519524SHoward Hinnant
736e02ed1c2SEric Fiselier
737e02ed1c2SEric Fiseliertemplate <class _Tp, class = void>
738e02ed1c2SEric Fiselierstruct __is_stashing_iterator : false_type {};
739e02ed1c2SEric Fiselier
740e02ed1c2SEric Fiseliertemplate <class _Tp>
741e02ed1c2SEric Fiselierstruct __is_stashing_iterator<_Tp, typename __void_t<typename _Tp::__stashing_iterator_tag>::type>
742e02ed1c2SEric Fiselier  : true_type {};
743e02ed1c2SEric Fiselier
7443e519524SHoward Hinnanttemplate <class _Iter>
745e2f2d1edSEric Fiselierclass _LIBCPP_TEMPLATE_VIS reverse_iterator
7463e519524SHoward Hinnant    : public iterator<typename iterator_traits<_Iter>::iterator_category,
7473e519524SHoward Hinnant                      typename iterator_traits<_Iter>::value_type,
7483e519524SHoward Hinnant                      typename iterator_traits<_Iter>::difference_type,
7493e519524SHoward Hinnant                      typename iterator_traits<_Iter>::pointer,
7503e519524SHoward Hinnant                      typename iterator_traits<_Iter>::reference>
7513e519524SHoward Hinnant{
7523b83496dSMarshall Clowprivate:
7531b8f260eSMarshall Clow    /*mutable*/ _Iter __t;  // no longer used as of LWG #2360, not removed due to ABI break
754e02ed1c2SEric Fiselier
755e02ed1c2SEric Fiselier    static_assert(!__is_stashing_iterator<_Iter>::value,
756e02ed1c2SEric Fiselier      "The specified iterator type cannot be used with reverse_iterator; "
757e02ed1c2SEric Fiselier      "Using stashing iterators with reverse_iterator causes undefined behavior");
758e02ed1c2SEric Fiselier
759b2d74f29SMarshall Clowprotected:
760b2d74f29SMarshall Clow    _Iter current;
7613e519524SHoward Hinnantpublic:
7623e519524SHoward Hinnant    typedef _Iter                                            iterator_type;
7633e519524SHoward Hinnant    typedef typename iterator_traits<_Iter>::difference_type difference_type;
7643e519524SHoward Hinnant    typedef typename iterator_traits<_Iter>::reference       reference;
7653e519524SHoward Hinnant    typedef typename iterator_traits<_Iter>::pointer         pointer;
7663e519524SHoward Hinnant
7671b8f260eSMarshall Clow    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
7681b8f260eSMarshall Clow    reverse_iterator() : __t(), current() {}
7691b8f260eSMarshall Clow    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
7701b8f260eSMarshall Clow    explicit reverse_iterator(_Iter __x) : __t(__x), current(__x) {}
7711b8f260eSMarshall Clow    template <class _Up>
7721b8f260eSMarshall Clow        _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
7731b8f260eSMarshall Clow        reverse_iterator(const reverse_iterator<_Up>& __u) : __t(__u.base()), current(__u.base()) {}
7741b8f260eSMarshall Clow    template <class _Up>
7751b8f260eSMarshall Clow        _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
7761b8f260eSMarshall Clow        reverse_iterator& operator=(const reverse_iterator<_Up>& __u)
7771b8f260eSMarshall Clow            { __t = current = __u.base(); return *this; }
7781b8f260eSMarshall Clow    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
7791b8f260eSMarshall Clow    _Iter base() const {return current;}
7801b8f260eSMarshall Clow    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
7811b8f260eSMarshall Clow    reference operator*() const {_Iter __tmp = current; return *--__tmp;}
7821b8f260eSMarshall Clow    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
7831b8f260eSMarshall Clow    pointer  operator->() const {return _VSTD::addressof(operator*());}
7841b8f260eSMarshall Clow    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
7851b8f260eSMarshall Clow    reverse_iterator& operator++() {--current; return *this;}
7861b8f260eSMarshall Clow    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
7871b8f260eSMarshall Clow    reverse_iterator  operator++(int) {reverse_iterator __tmp(*this); --current; return __tmp;}
7881b8f260eSMarshall Clow    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
7891b8f260eSMarshall Clow    reverse_iterator& operator--() {++current; return *this;}
7901b8f260eSMarshall Clow    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
7911b8f260eSMarshall Clow    reverse_iterator  operator--(int) {reverse_iterator __tmp(*this); ++current; return __tmp;}
7921b8f260eSMarshall Clow    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
7931b8f260eSMarshall Clow    reverse_iterator  operator+ (difference_type __n) const {return reverse_iterator(current - __n);}
7941b8f260eSMarshall Clow    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
7951b8f260eSMarshall Clow    reverse_iterator& operator+=(difference_type __n) {current -= __n; return *this;}
7961b8f260eSMarshall Clow    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
7971b8f260eSMarshall Clow    reverse_iterator  operator- (difference_type __n) const {return reverse_iterator(current + __n);}
7981b8f260eSMarshall Clow    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
7991b8f260eSMarshall Clow    reverse_iterator& operator-=(difference_type __n) {current += __n; return *this;}
8001b8f260eSMarshall Clow    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
8011b8f260eSMarshall Clow    reference         operator[](difference_type __n) const {return *(*this + __n);}
8023e519524SHoward Hinnant};
8033e519524SHoward Hinnant
8043e519524SHoward Hinnanttemplate <class _Iter1, class _Iter2>
8051b8f260eSMarshall Clowinline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
8063e519524SHoward Hinnantbool
8073e519524SHoward Hinnantoperator==(const reverse_iterator<_Iter1>& __x, const reverse_iterator<_Iter2>& __y)
8083e519524SHoward Hinnant{
8093e519524SHoward Hinnant    return __x.base() == __y.base();
8103e519524SHoward Hinnant}
8113e519524SHoward Hinnant
8123e519524SHoward Hinnanttemplate <class _Iter1, class _Iter2>
8131b8f260eSMarshall Clowinline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
8143e519524SHoward Hinnantbool
8153e519524SHoward Hinnantoperator<(const reverse_iterator<_Iter1>& __x, const reverse_iterator<_Iter2>& __y)
8163e519524SHoward Hinnant{
8173e519524SHoward Hinnant    return __x.base() > __y.base();
8183e519524SHoward Hinnant}
8193e519524SHoward Hinnant
8203e519524SHoward Hinnanttemplate <class _Iter1, class _Iter2>
8211b8f260eSMarshall Clowinline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
8223e519524SHoward Hinnantbool
8233e519524SHoward Hinnantoperator!=(const reverse_iterator<_Iter1>& __x, const reverse_iterator<_Iter2>& __y)
8243e519524SHoward Hinnant{
8253e519524SHoward Hinnant    return __x.base() != __y.base();
8263e519524SHoward Hinnant}
8273e519524SHoward Hinnant
8283e519524SHoward Hinnanttemplate <class _Iter1, class _Iter2>
8291b8f260eSMarshall Clowinline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
8303e519524SHoward Hinnantbool
8313e519524SHoward Hinnantoperator>(const reverse_iterator<_Iter1>& __x, const reverse_iterator<_Iter2>& __y)
8323e519524SHoward Hinnant{
8333e519524SHoward Hinnant    return __x.base() < __y.base();
8343e519524SHoward Hinnant}
8353e519524SHoward Hinnant
8363e519524SHoward Hinnanttemplate <class _Iter1, class _Iter2>
8371b8f260eSMarshall Clowinline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
8383e519524SHoward Hinnantbool
8393e519524SHoward Hinnantoperator>=(const reverse_iterator<_Iter1>& __x, const reverse_iterator<_Iter2>& __y)
8403e519524SHoward Hinnant{
8413e519524SHoward Hinnant    return __x.base() <= __y.base();
8423e519524SHoward Hinnant}
8433e519524SHoward Hinnant
8443e519524SHoward Hinnanttemplate <class _Iter1, class _Iter2>
8451b8f260eSMarshall Clowinline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
8463e519524SHoward Hinnantbool
8473e519524SHoward Hinnantoperator<=(const reverse_iterator<_Iter1>& __x, const reverse_iterator<_Iter2>& __y)
8483e519524SHoward Hinnant{
8493e519524SHoward Hinnant    return __x.base() >= __y.base();
8503e519524SHoward Hinnant}
8513e519524SHoward Hinnant
8522ee83725SMarshall Clow#ifndef _LIBCPP_CXX03_LANG
853947ce6b5SMarshall Clowtemplate <class _Iter1, class _Iter2>
8541b8f260eSMarshall Clowinline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
855947ce6b5SMarshall Clowauto
856947ce6b5SMarshall Clowoperator-(const reverse_iterator<_Iter1>& __x, const reverse_iterator<_Iter2>& __y)
857947ce6b5SMarshall Clow-> decltype(__y.base() - __x.base())
858947ce6b5SMarshall Clow{
859947ce6b5SMarshall Clow    return __y.base() - __x.base();
860947ce6b5SMarshall Clow}
861947ce6b5SMarshall Clow#else
8623e519524SHoward Hinnanttemplate <class _Iter1, class _Iter2>
8633e519524SHoward Hinnantinline _LIBCPP_INLINE_VISIBILITY
8643e519524SHoward Hinnanttypename reverse_iterator<_Iter1>::difference_type
8653e519524SHoward Hinnantoperator-(const reverse_iterator<_Iter1>& __x, const reverse_iterator<_Iter2>& __y)
8663e519524SHoward Hinnant{
8673e519524SHoward Hinnant    return __y.base() - __x.base();
8683e519524SHoward Hinnant}
869947ce6b5SMarshall Clow#endif
8703e519524SHoward Hinnant
8713e519524SHoward Hinnanttemplate <class _Iter>
8721b8f260eSMarshall Clowinline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
8733e519524SHoward Hinnantreverse_iterator<_Iter>
8743e519524SHoward Hinnantoperator+(typename reverse_iterator<_Iter>::difference_type __n, const reverse_iterator<_Iter>& __x)
8753e519524SHoward Hinnant{
8763e519524SHoward Hinnant    return reverse_iterator<_Iter>(__x.base() - __n);
8773e519524SHoward Hinnant}
8783e519524SHoward Hinnant
8796a640a18SMarshall Clow#if _LIBCPP_STD_VER > 11
8806a640a18SMarshall Clowtemplate <class _Iter>
8811b8f260eSMarshall Clowinline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
8826a640a18SMarshall Clowreverse_iterator<_Iter> make_reverse_iterator(_Iter __i)
8836a640a18SMarshall Clow{
8846a640a18SMarshall Clow    return reverse_iterator<_Iter>(__i);
8856a640a18SMarshall Clow}
8866a640a18SMarshall Clow#endif
8876a640a18SMarshall Clow
8883e519524SHoward Hinnanttemplate <class _Container>
889e2f2d1edSEric Fiselierclass _LIBCPP_TEMPLATE_VIS back_insert_iterator
8903e519524SHoward Hinnant    : public iterator<output_iterator_tag,
8913e519524SHoward Hinnant                      void,
8923e519524SHoward Hinnant                      void,
8933e519524SHoward Hinnant                      void,
8948892b4eeSEric Fiselier                      void>
8953e519524SHoward Hinnant{
8963e519524SHoward Hinnantprotected:
8973e519524SHoward Hinnant    _Container* container;
8983e519524SHoward Hinnantpublic:
8993e519524SHoward Hinnant    typedef _Container container_type;
9003e519524SHoward Hinnant
901f519be34SMarshall Clow    _LIBCPP_INLINE_VISIBILITY explicit back_insert_iterator(_Container& __x) : container(_VSTD::addressof(__x)) {}
902e4383379SHoward Hinnant    _LIBCPP_INLINE_VISIBILITY back_insert_iterator& operator=(const typename _Container::value_type& __value_)
903e4383379SHoward Hinnant        {container->push_back(__value_); return *this;}
904046492b9SEric Fiselier#ifndef _LIBCPP_CXX03_LANG
905e4383379SHoward Hinnant    _LIBCPP_INLINE_VISIBILITY back_insert_iterator& operator=(typename _Container::value_type&& __value_)
906e4383379SHoward Hinnant        {container->push_back(_VSTD::move(__value_)); return *this;}
907046492b9SEric Fiselier#endif  // _LIBCPP_CXX03_LANG
9083e519524SHoward Hinnant    _LIBCPP_INLINE_VISIBILITY back_insert_iterator& operator*()     {return *this;}
9093e519524SHoward Hinnant    _LIBCPP_INLINE_VISIBILITY back_insert_iterator& operator++()    {return *this;}
9103e519524SHoward Hinnant    _LIBCPP_INLINE_VISIBILITY back_insert_iterator  operator++(int) {return *this;}
9113e519524SHoward Hinnant};
9123e519524SHoward Hinnant
9133e519524SHoward Hinnanttemplate <class _Container>
9143e519524SHoward Hinnantinline _LIBCPP_INLINE_VISIBILITY
9153e519524SHoward Hinnantback_insert_iterator<_Container>
9163e519524SHoward Hinnantback_inserter(_Container& __x)
9173e519524SHoward Hinnant{
9183e519524SHoward Hinnant    return back_insert_iterator<_Container>(__x);
9193e519524SHoward Hinnant}
9203e519524SHoward Hinnant
9213e519524SHoward Hinnanttemplate <class _Container>
922e2f2d1edSEric Fiselierclass _LIBCPP_TEMPLATE_VIS front_insert_iterator
9233e519524SHoward Hinnant    : public iterator<output_iterator_tag,
9243e519524SHoward Hinnant                      void,
9253e519524SHoward Hinnant                      void,
9263e519524SHoward Hinnant                      void,
9278892b4eeSEric Fiselier                      void>
9283e519524SHoward Hinnant{
9293e519524SHoward Hinnantprotected:
9303e519524SHoward Hinnant    _Container* container;
9313e519524SHoward Hinnantpublic:
9323e519524SHoward Hinnant    typedef _Container container_type;
9333e519524SHoward Hinnant
934f519be34SMarshall Clow    _LIBCPP_INLINE_VISIBILITY explicit front_insert_iterator(_Container& __x) : container(_VSTD::addressof(__x)) {}
935e4383379SHoward Hinnant    _LIBCPP_INLINE_VISIBILITY front_insert_iterator& operator=(const typename _Container::value_type& __value_)
936e4383379SHoward Hinnant        {container->push_front(__value_); return *this;}
937046492b9SEric Fiselier#ifndef _LIBCPP_CXX03_LANG
938e4383379SHoward Hinnant    _LIBCPP_INLINE_VISIBILITY front_insert_iterator& operator=(typename _Container::value_type&& __value_)
939e4383379SHoward Hinnant        {container->push_front(_VSTD::move(__value_)); return *this;}
940046492b9SEric Fiselier#endif  // _LIBCPP_CXX03_LANG
9413e519524SHoward Hinnant    _LIBCPP_INLINE_VISIBILITY front_insert_iterator& operator*()     {return *this;}
9423e519524SHoward Hinnant    _LIBCPP_INLINE_VISIBILITY front_insert_iterator& operator++()    {return *this;}
9433e519524SHoward Hinnant    _LIBCPP_INLINE_VISIBILITY front_insert_iterator  operator++(int) {return *this;}
9443e519524SHoward Hinnant};
9453e519524SHoward Hinnant
9463e519524SHoward Hinnanttemplate <class _Container>
9473e519524SHoward Hinnantinline _LIBCPP_INLINE_VISIBILITY
9483e519524SHoward Hinnantfront_insert_iterator<_Container>
9493e519524SHoward Hinnantfront_inserter(_Container& __x)
9503e519524SHoward Hinnant{
9513e519524SHoward Hinnant    return front_insert_iterator<_Container>(__x);
9523e519524SHoward Hinnant}
9533e519524SHoward Hinnant
9543e519524SHoward Hinnanttemplate <class _Container>
955e2f2d1edSEric Fiselierclass _LIBCPP_TEMPLATE_VIS insert_iterator
9563e519524SHoward Hinnant    : public iterator<output_iterator_tag,
9573e519524SHoward Hinnant                      void,
9583e519524SHoward Hinnant                      void,
9593e519524SHoward Hinnant                      void,
9608892b4eeSEric Fiselier                      void>
9613e519524SHoward Hinnant{
9623e519524SHoward Hinnantprotected:
9633e519524SHoward Hinnant    _Container* container;
9643e519524SHoward Hinnant    typename _Container::iterator iter;
9653e519524SHoward Hinnantpublic:
9663e519524SHoward Hinnant    typedef _Container container_type;
9673e519524SHoward Hinnant
9683e519524SHoward Hinnant    _LIBCPP_INLINE_VISIBILITY insert_iterator(_Container& __x, typename _Container::iterator __i)
969f519be34SMarshall Clow        : container(_VSTD::addressof(__x)), iter(__i) {}
970e4383379SHoward Hinnant    _LIBCPP_INLINE_VISIBILITY insert_iterator& operator=(const typename _Container::value_type& __value_)
971e4383379SHoward Hinnant        {iter = container->insert(iter, __value_); ++iter; return *this;}
972046492b9SEric Fiselier#ifndef _LIBCPP_CXX03_LANG
973e4383379SHoward Hinnant    _LIBCPP_INLINE_VISIBILITY insert_iterator& operator=(typename _Container::value_type&& __value_)
974e4383379SHoward Hinnant        {iter = container->insert(iter, _VSTD::move(__value_)); ++iter; return *this;}
975046492b9SEric Fiselier#endif  // _LIBCPP_CXX03_LANG
9763e519524SHoward Hinnant    _LIBCPP_INLINE_VISIBILITY insert_iterator& operator*()        {return *this;}
9773e519524SHoward Hinnant    _LIBCPP_INLINE_VISIBILITY insert_iterator& operator++()       {return *this;}
9783e519524SHoward Hinnant    _LIBCPP_INLINE_VISIBILITY insert_iterator& operator++(int)    {return *this;}
9793e519524SHoward Hinnant};
9803e519524SHoward Hinnant
9813e519524SHoward Hinnanttemplate <class _Container>
9823e519524SHoward Hinnantinline _LIBCPP_INLINE_VISIBILITY
9833e519524SHoward Hinnantinsert_iterator<_Container>
9843e519524SHoward Hinnantinserter(_Container& __x, typename _Container::iterator __i)
9853e519524SHoward Hinnant{
9863e519524SHoward Hinnant    return insert_iterator<_Container>(__x, __i);
9873e519524SHoward Hinnant}
9883e519524SHoward Hinnant
9893e519524SHoward Hinnanttemplate <class _Tp, class _CharT = char,
9903e519524SHoward Hinnant          class _Traits = char_traits<_CharT>, class _Distance = ptrdiff_t>
991e2f2d1edSEric Fiselierclass _LIBCPP_TEMPLATE_VIS istream_iterator
9923e519524SHoward Hinnant    : public iterator<input_iterator_tag, _Tp, _Distance, const _Tp*, const _Tp&>
9933e519524SHoward Hinnant{
9943e519524SHoward Hinnantpublic:
9953e519524SHoward Hinnant    typedef _CharT char_type;
9963e519524SHoward Hinnant    typedef _Traits traits_type;
9973e519524SHoward Hinnant    typedef basic_istream<_CharT,_Traits> istream_type;
9983e519524SHoward Hinnantprivate:
9993e519524SHoward Hinnant    istream_type* __in_stream_;
10003e519524SHoward Hinnant    _Tp __value_;
10013e519524SHoward Hinnantpublic:
100260d5e0e0SMarshall Clow    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR istream_iterator() : __in_stream_(0), __value_() {}
1003bc6a7df0SMarshall Clow    _LIBCPP_INLINE_VISIBILITY istream_iterator(istream_type& __s) : __in_stream_(_VSTD::addressof(__s))
10043e519524SHoward Hinnant        {
10053e519524SHoward Hinnant            if (!(*__in_stream_ >> __value_))
10063e519524SHoward Hinnant                __in_stream_ = 0;
10073e519524SHoward Hinnant        }
10083e519524SHoward Hinnant
10093e519524SHoward Hinnant    _LIBCPP_INLINE_VISIBILITY const _Tp& operator*() const {return __value_;}
1010bc6a7df0SMarshall Clow    _LIBCPP_INLINE_VISIBILITY const _Tp* operator->() const {return _VSTD::addressof((operator*()));}
10113e519524SHoward Hinnant    _LIBCPP_INLINE_VISIBILITY istream_iterator& operator++()
10123e519524SHoward Hinnant        {
10133e519524SHoward Hinnant            if (!(*__in_stream_ >> __value_))
10143e519524SHoward Hinnant                __in_stream_ = 0;
10153e519524SHoward Hinnant            return *this;
10163e519524SHoward Hinnant        }
10173e519524SHoward Hinnant    _LIBCPP_INLINE_VISIBILITY istream_iterator  operator++(int)
10183e519524SHoward Hinnant        {istream_iterator __t(*this); ++(*this); return __t;}
10193e519524SHoward Hinnant
10206f56d3eeSRoger Ferrer Ibanez    template <class _Up, class _CharU, class _TraitsU, class _DistanceU>
10213e519524SHoward Hinnant    friend _LIBCPP_INLINE_VISIBILITY
10226f56d3eeSRoger Ferrer Ibanez    bool
10236f56d3eeSRoger Ferrer Ibanez    operator==(const istream_iterator<_Up, _CharU, _TraitsU, _DistanceU>& __x,
10246f56d3eeSRoger Ferrer Ibanez               const istream_iterator<_Up, _CharU, _TraitsU, _DistanceU>& __y);
10253e519524SHoward Hinnant
10266f56d3eeSRoger Ferrer Ibanez    template <class _Up, class _CharU, class _TraitsU, class _DistanceU>
10273e519524SHoward Hinnant    friend _LIBCPP_INLINE_VISIBILITY
10286f56d3eeSRoger Ferrer Ibanez    bool
10296f56d3eeSRoger Ferrer Ibanez    operator==(const istream_iterator<_Up, _CharU, _TraitsU, _DistanceU>& __x,
10306f56d3eeSRoger Ferrer Ibanez               const istream_iterator<_Up, _CharU, _TraitsU, _DistanceU>& __y);
10313e519524SHoward Hinnant};
10323e519524SHoward Hinnant
10336f56d3eeSRoger Ferrer Ibaneztemplate <class _Tp, class _CharT, class _Traits, class _Distance>
10346f56d3eeSRoger Ferrer Ibanezinline _LIBCPP_INLINE_VISIBILITY
10356f56d3eeSRoger Ferrer Ibanezbool
10366f56d3eeSRoger Ferrer Ibanezoperator==(const istream_iterator<_Tp, _CharT, _Traits, _Distance>& __x,
10376f56d3eeSRoger Ferrer Ibanez           const istream_iterator<_Tp, _CharT, _Traits, _Distance>& __y)
10386f56d3eeSRoger Ferrer Ibanez{
10396f56d3eeSRoger Ferrer Ibanez    return __x.__in_stream_ == __y.__in_stream_;
10406f56d3eeSRoger Ferrer Ibanez}
10416f56d3eeSRoger Ferrer Ibanez
10426f56d3eeSRoger Ferrer Ibaneztemplate <class _Tp, class _CharT, class _Traits, class _Distance>
10436f56d3eeSRoger Ferrer Ibanezinline _LIBCPP_INLINE_VISIBILITY
10446f56d3eeSRoger Ferrer Ibanezbool
10456f56d3eeSRoger Ferrer Ibanezoperator!=(const istream_iterator<_Tp, _CharT, _Traits, _Distance>& __x,
10466f56d3eeSRoger Ferrer Ibanez           const istream_iterator<_Tp, _CharT, _Traits, _Distance>& __y)
10476f56d3eeSRoger Ferrer Ibanez{
10486f56d3eeSRoger Ferrer Ibanez    return !(__x == __y);
10496f56d3eeSRoger Ferrer Ibanez}
10506f56d3eeSRoger Ferrer Ibanez
10513e519524SHoward Hinnanttemplate <class _Tp, class _CharT = char, class _Traits = char_traits<_CharT> >
1052e2f2d1edSEric Fiselierclass _LIBCPP_TEMPLATE_VIS ostream_iterator
10533e519524SHoward Hinnant    : public iterator<output_iterator_tag, void, void, void, void>
10543e519524SHoward Hinnant{
10553e519524SHoward Hinnantpublic:
10563e519524SHoward Hinnant    typedef _CharT char_type;
10573e519524SHoward Hinnant    typedef _Traits traits_type;
10583e519524SHoward Hinnant    typedef basic_ostream<_CharT,_Traits> ostream_type;
10593e519524SHoward Hinnantprivate:
10603e519524SHoward Hinnant    ostream_type* __out_stream_;
10613e519524SHoward Hinnant    const char_type* __delim_;
10623e519524SHoward Hinnantpublic:
1063853042cfSMarshall Clow    _LIBCPP_INLINE_VISIBILITY ostream_iterator(ostream_type& __s) _NOEXCEPT
1064bc6a7df0SMarshall Clow        : __out_stream_(_VSTD::addressof(__s)), __delim_(0) {}
1065853042cfSMarshall Clow    _LIBCPP_INLINE_VISIBILITY ostream_iterator(ostream_type& __s, const _CharT* __delimiter) _NOEXCEPT
1066bc6a7df0SMarshall Clow        : __out_stream_(_VSTD::addressof(__s)), __delim_(__delimiter) {}
1067e4383379SHoward Hinnant    _LIBCPP_INLINE_VISIBILITY ostream_iterator& operator=(const _Tp& __value_)
10683e519524SHoward Hinnant        {
1069e4383379SHoward Hinnant            *__out_stream_ << __value_;
10703e519524SHoward Hinnant            if (__delim_)
10713e519524SHoward Hinnant                *__out_stream_ << __delim_;
10723e519524SHoward Hinnant            return *this;
10733e519524SHoward Hinnant        }
10743e519524SHoward Hinnant
10753e519524SHoward Hinnant    _LIBCPP_INLINE_VISIBILITY ostream_iterator& operator*()     {return *this;}
10763e519524SHoward Hinnant    _LIBCPP_INLINE_VISIBILITY ostream_iterator& operator++()    {return *this;}
10773e519524SHoward Hinnant    _LIBCPP_INLINE_VISIBILITY ostream_iterator& operator++(int) {return *this;}
10783e519524SHoward Hinnant};
10793e519524SHoward Hinnant
10803e519524SHoward Hinnanttemplate<class _CharT, class _Traits>
1081e2f2d1edSEric Fiselierclass _LIBCPP_TEMPLATE_VIS istreambuf_iterator
10823e519524SHoward Hinnant    : public iterator<input_iterator_tag, _CharT,
10833e519524SHoward Hinnant                      typename _Traits::off_type, _CharT*,
10843e519524SHoward Hinnant                      _CharT>
10853e519524SHoward Hinnant{
10863e519524SHoward Hinnantpublic:
10873e519524SHoward Hinnant    typedef _CharT                          char_type;
10883e519524SHoward Hinnant    typedef _Traits                         traits_type;
10893e519524SHoward Hinnant    typedef typename _Traits::int_type      int_type;
10903e519524SHoward Hinnant    typedef basic_streambuf<_CharT,_Traits> streambuf_type;
10913e519524SHoward Hinnant    typedef basic_istream<_CharT,_Traits>   istream_type;
10923e519524SHoward Hinnantprivate:
1093dfdf5085SHoward Hinnant    mutable streambuf_type* __sbuf_;
10943e519524SHoward Hinnant
10953e519524SHoward Hinnant    class __proxy
10963e519524SHoward Hinnant    {
10973e519524SHoward Hinnant        char_type __keep_;
10983e519524SHoward Hinnant        streambuf_type* __sbuf_;
10993e519524SHoward Hinnant        _LIBCPP_INLINE_VISIBILITY __proxy(char_type __c, streambuf_type* __s)
11003e519524SHoward Hinnant            : __keep_(__c), __sbuf_(__s) {}
11013e519524SHoward Hinnant        friend class istreambuf_iterator;
11023e519524SHoward Hinnant    public:
11033e519524SHoward Hinnant        _LIBCPP_INLINE_VISIBILITY char_type operator*() const {return __keep_;}
11043e519524SHoward Hinnant    };
11053e519524SHoward Hinnant
1106848a5374SHoward Hinnant    _LIBCPP_INLINE_VISIBILITY
1107dfdf5085SHoward Hinnant    bool __test_for_eof() const
11083e519524SHoward Hinnant    {
11093e519524SHoward Hinnant        if (__sbuf_ && traits_type::eq_int_type(__sbuf_->sgetc(), traits_type::eof()))
11103e519524SHoward Hinnant            __sbuf_ = 0;
1111dfdf5085SHoward Hinnant        return __sbuf_ == 0;
11123e519524SHoward Hinnant    }
11133e519524SHoward Hinnantpublic:
1114dfdf5085SHoward Hinnant    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR istreambuf_iterator() _NOEXCEPT : __sbuf_(0) {}
11158e882dcbSHoward Hinnant    _LIBCPP_INLINE_VISIBILITY istreambuf_iterator(istream_type& __s) _NOEXCEPT
1116a96d7458SHoward Hinnant        : __sbuf_(__s.rdbuf()) {}
11178e882dcbSHoward Hinnant    _LIBCPP_INLINE_VISIBILITY istreambuf_iterator(streambuf_type* __s) _NOEXCEPT
1118a96d7458SHoward Hinnant        : __sbuf_(__s) {}
11198e882dcbSHoward Hinnant    _LIBCPP_INLINE_VISIBILITY istreambuf_iterator(const __proxy& __p) _NOEXCEPT
11203e519524SHoward Hinnant        : __sbuf_(__p.__sbuf_) {}
11213e519524SHoward Hinnant
1122c206366fSHoward Hinnant    _LIBCPP_INLINE_VISIBILITY char_type  operator*() const
1123c206366fSHoward Hinnant        {return static_cast<char_type>(__sbuf_->sgetc());}
11243e519524SHoward Hinnant    _LIBCPP_INLINE_VISIBILITY istreambuf_iterator& operator++()
11253e519524SHoward Hinnant        {
1126dfdf5085SHoward Hinnant            __sbuf_->sbumpc();
11273e519524SHoward Hinnant            return *this;
11283e519524SHoward Hinnant        }
11293e519524SHoward Hinnant    _LIBCPP_INLINE_VISIBILITY __proxy              operator++(int)
11303e519524SHoward Hinnant        {
1131dfdf5085SHoward Hinnant            return __proxy(__sbuf_->sbumpc(), __sbuf_);
11323e519524SHoward Hinnant        }
11333e519524SHoward Hinnant
11343e519524SHoward Hinnant    _LIBCPP_INLINE_VISIBILITY bool equal(const istreambuf_iterator& __b) const
1135dfdf5085SHoward Hinnant        {return __test_for_eof() == __b.__test_for_eof();}
11363e519524SHoward Hinnant};
11373e519524SHoward Hinnant
11383e519524SHoward Hinnanttemplate <class _CharT, class _Traits>
11393e519524SHoward Hinnantinline _LIBCPP_INLINE_VISIBILITY
11403e519524SHoward Hinnantbool operator==(const istreambuf_iterator<_CharT,_Traits>& __a,
11413e519524SHoward Hinnant                const istreambuf_iterator<_CharT,_Traits>& __b)
11423e519524SHoward Hinnant                {return __a.equal(__b);}
11433e519524SHoward Hinnant
11443e519524SHoward Hinnanttemplate <class _CharT, class _Traits>
11453e519524SHoward Hinnantinline _LIBCPP_INLINE_VISIBILITY
11463e519524SHoward Hinnantbool operator!=(const istreambuf_iterator<_CharT,_Traits>& __a,
11473e519524SHoward Hinnant                const istreambuf_iterator<_CharT,_Traits>& __b)
11483e519524SHoward Hinnant                {return !__a.equal(__b);}
11493e519524SHoward Hinnant
11503e519524SHoward Hinnanttemplate <class _CharT, class _Traits>
1151e2f2d1edSEric Fiselierclass _LIBCPP_TEMPLATE_VIS ostreambuf_iterator
11523e519524SHoward Hinnant    : public iterator<output_iterator_tag, void, void, void, void>
11533e519524SHoward Hinnant{
11543e519524SHoward Hinnantpublic:
11553e519524SHoward Hinnant    typedef _CharT                          char_type;
11563e519524SHoward Hinnant    typedef _Traits                         traits_type;
11573e519524SHoward Hinnant    typedef basic_streambuf<_CharT,_Traits> streambuf_type;
11583e519524SHoward Hinnant    typedef basic_ostream<_CharT,_Traits>   ostream_type;
11593e519524SHoward Hinnantprivate:
11603e519524SHoward Hinnant    streambuf_type* __sbuf_;
11613e519524SHoward Hinnantpublic:
11628e882dcbSHoward Hinnant    _LIBCPP_INLINE_VISIBILITY ostreambuf_iterator(ostream_type& __s) _NOEXCEPT
11633e519524SHoward Hinnant        : __sbuf_(__s.rdbuf()) {}
11648e882dcbSHoward Hinnant    _LIBCPP_INLINE_VISIBILITY ostreambuf_iterator(streambuf_type* __s) _NOEXCEPT
11653e519524SHoward Hinnant        : __sbuf_(__s) {}
11663e519524SHoward Hinnant    _LIBCPP_INLINE_VISIBILITY ostreambuf_iterator& operator=(_CharT __c)
11673e519524SHoward Hinnant        {
11683e519524SHoward Hinnant            if (__sbuf_ && traits_type::eq_int_type(__sbuf_->sputc(__c), traits_type::eof()))
11693e519524SHoward Hinnant                __sbuf_ = 0;
11703e519524SHoward Hinnant            return *this;
11713e519524SHoward Hinnant        }
11723e519524SHoward Hinnant    _LIBCPP_INLINE_VISIBILITY ostreambuf_iterator& operator*()     {return *this;}
11733e519524SHoward Hinnant    _LIBCPP_INLINE_VISIBILITY ostreambuf_iterator& operator++()    {return *this;}
11743e519524SHoward Hinnant    _LIBCPP_INLINE_VISIBILITY ostreambuf_iterator& operator++(int) {return *this;}
11758e882dcbSHoward Hinnant    _LIBCPP_INLINE_VISIBILITY bool failed() const _NOEXCEPT {return __sbuf_ == 0;}
117692b5940fSHoward Hinnant
117792b5940fSHoward Hinnant    template <class _Ch, class _Tr>
117892b5940fSHoward Hinnant    friend
117992b5940fSHoward Hinnant    _LIBCPP_HIDDEN
118092b5940fSHoward Hinnant    ostreambuf_iterator<_Ch, _Tr>
118192b5940fSHoward Hinnant    __pad_and_output(ostreambuf_iterator<_Ch, _Tr> __s,
118292b5940fSHoward Hinnant                     const _Ch* __ob, const _Ch* __op, const _Ch* __oe,
118392b5940fSHoward Hinnant                     ios_base& __iob, _Ch __fl);
11843e519524SHoward Hinnant};
11853e519524SHoward Hinnant
11863e519524SHoward Hinnanttemplate <class _Iter>
1187e2f2d1edSEric Fiselierclass _LIBCPP_TEMPLATE_VIS move_iterator
11883e519524SHoward Hinnant{
11893e519524SHoward Hinnantprivate:
11903e519524SHoward Hinnant    _Iter __i;
11913e519524SHoward Hinnantpublic:
11923e519524SHoward Hinnant    typedef _Iter                                            iterator_type;
11933e519524SHoward Hinnant    typedef typename iterator_traits<iterator_type>::iterator_category iterator_category;
11943e519524SHoward Hinnant    typedef typename iterator_traits<iterator_type>::value_type value_type;
11953e519524SHoward Hinnant    typedef typename iterator_traits<iterator_type>::difference_type difference_type;
119605333fc8SMarshall Clow    typedef iterator_type pointer;
1197046492b9SEric Fiselier#ifndef _LIBCPP_CXX03_LANG
1198906c5085SEric Fiselier    typedef typename iterator_traits<iterator_type>::reference __reference;
1199906c5085SEric Fiselier    typedef typename conditional<
1200906c5085SEric Fiselier            is_reference<__reference>::value,
1201906c5085SEric Fiselier            typename remove_reference<__reference>::type&&,
1202906c5085SEric Fiselier            __reference
1203906c5085SEric Fiselier        >::type reference;
12043e519524SHoward Hinnant#else
12053e519524SHoward Hinnant    typedef typename iterator_traits<iterator_type>::reference reference;
12063e519524SHoward Hinnant#endif
12073e519524SHoward Hinnant
1208720ef472SMarshall Clow    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
1209720ef472SMarshall Clow    move_iterator() : __i() {}
1210720ef472SMarshall Clow    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
1211720ef472SMarshall Clow    explicit move_iterator(_Iter __x) : __i(__x) {}
1212720ef472SMarshall Clow    template <class _Up>
1213720ef472SMarshall Clow      _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
1214720ef472SMarshall Clow      move_iterator(const move_iterator<_Up>& __u) : __i(__u.base()) {}
1215720ef472SMarshall Clow    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 _Iter base() const {return __i;}
1216720ef472SMarshall Clow    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
1217720ef472SMarshall Clow    reference operator*() const { return static_cast<reference>(*__i); }
1218720ef472SMarshall Clow    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
1219720ef472SMarshall Clow    pointer  operator->() const { return __i;}
1220720ef472SMarshall Clow    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
1221720ef472SMarshall Clow    move_iterator& operator++() {++__i; return *this;}
1222720ef472SMarshall Clow    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
1223720ef472SMarshall Clow    move_iterator  operator++(int) {move_iterator __tmp(*this); ++__i; return __tmp;}
1224720ef472SMarshall Clow    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
1225720ef472SMarshall Clow    move_iterator& operator--() {--__i; return *this;}
1226720ef472SMarshall Clow    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
1227720ef472SMarshall Clow    move_iterator  operator--(int) {move_iterator __tmp(*this); --__i; return __tmp;}
1228720ef472SMarshall Clow    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
1229720ef472SMarshall Clow    move_iterator  operator+ (difference_type __n) const {return move_iterator(__i + __n);}
1230720ef472SMarshall Clow    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
1231720ef472SMarshall Clow    move_iterator& operator+=(difference_type __n) {__i += __n; return *this;}
1232720ef472SMarshall Clow    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
1233720ef472SMarshall Clow    move_iterator  operator- (difference_type __n) const {return move_iterator(__i - __n);}
1234720ef472SMarshall Clow    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
1235720ef472SMarshall Clow    move_iterator& operator-=(difference_type __n) {__i -= __n; return *this;}
1236720ef472SMarshall Clow    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
1237720ef472SMarshall Clow    reference operator[](difference_type __n) const { return static_cast<reference>(__i[__n]); }
12383e519524SHoward Hinnant};
12393e519524SHoward Hinnant
12403e519524SHoward Hinnanttemplate <class _Iter1, class _Iter2>
1241720ef472SMarshall Clowinline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
12423e519524SHoward Hinnantbool
12433e519524SHoward Hinnantoperator==(const move_iterator<_Iter1>& __x, const move_iterator<_Iter2>& __y)
12443e519524SHoward Hinnant{
12453e519524SHoward Hinnant    return __x.base() == __y.base();
12463e519524SHoward Hinnant}
12473e519524SHoward Hinnant
12483e519524SHoward Hinnanttemplate <class _Iter1, class _Iter2>
1249720ef472SMarshall Clowinline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
12503e519524SHoward Hinnantbool
12513e519524SHoward Hinnantoperator<(const move_iterator<_Iter1>& __x, const move_iterator<_Iter2>& __y)
12523e519524SHoward Hinnant{
12533e519524SHoward Hinnant    return __x.base() < __y.base();
12543e519524SHoward Hinnant}
12553e519524SHoward Hinnant
12563e519524SHoward Hinnanttemplate <class _Iter1, class _Iter2>
1257720ef472SMarshall Clowinline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
12583e519524SHoward Hinnantbool
12593e519524SHoward Hinnantoperator!=(const move_iterator<_Iter1>& __x, const move_iterator<_Iter2>& __y)
12603e519524SHoward Hinnant{
12613e519524SHoward Hinnant    return __x.base() != __y.base();
12623e519524SHoward Hinnant}
12633e519524SHoward Hinnant
12643e519524SHoward Hinnanttemplate <class _Iter1, class _Iter2>
1265720ef472SMarshall Clowinline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
12663e519524SHoward Hinnantbool
12673e519524SHoward Hinnantoperator>(const move_iterator<_Iter1>& __x, const move_iterator<_Iter2>& __y)
12683e519524SHoward Hinnant{
12693e519524SHoward Hinnant    return __x.base() > __y.base();
12703e519524SHoward Hinnant}
12713e519524SHoward Hinnant
12723e519524SHoward Hinnanttemplate <class _Iter1, class _Iter2>
1273720ef472SMarshall Clowinline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
12743e519524SHoward Hinnantbool
12753e519524SHoward Hinnantoperator>=(const move_iterator<_Iter1>& __x, const move_iterator<_Iter2>& __y)
12763e519524SHoward Hinnant{
12773e519524SHoward Hinnant    return __x.base() >= __y.base();
12783e519524SHoward Hinnant}
12793e519524SHoward Hinnant
12803e519524SHoward Hinnanttemplate <class _Iter1, class _Iter2>
1281720ef472SMarshall Clowinline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
12823e519524SHoward Hinnantbool
12833e519524SHoward Hinnantoperator<=(const move_iterator<_Iter1>& __x, const move_iterator<_Iter2>& __y)
12843e519524SHoward Hinnant{
12853e519524SHoward Hinnant    return __x.base() <= __y.base();
12863e519524SHoward Hinnant}
12873e519524SHoward Hinnant
12882ee83725SMarshall Clow#ifndef _LIBCPP_CXX03_LANG
1289947ce6b5SMarshall Clowtemplate <class _Iter1, class _Iter2>
1290720ef472SMarshall Clowinline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
1291947ce6b5SMarshall Clowauto
1292947ce6b5SMarshall Clowoperator-(const move_iterator<_Iter1>& __x, const move_iterator<_Iter2>& __y)
1293947ce6b5SMarshall Clow-> decltype(__x.base() - __y.base())
1294947ce6b5SMarshall Clow{
1295947ce6b5SMarshall Clow    return __x.base() - __y.base();
1296947ce6b5SMarshall Clow}
1297947ce6b5SMarshall Clow#else
12983e519524SHoward Hinnanttemplate <class _Iter1, class _Iter2>
12993e519524SHoward Hinnantinline _LIBCPP_INLINE_VISIBILITY
13003e519524SHoward Hinnanttypename move_iterator<_Iter1>::difference_type
13013e519524SHoward Hinnantoperator-(const move_iterator<_Iter1>& __x, const move_iterator<_Iter2>& __y)
13023e519524SHoward Hinnant{
13033e519524SHoward Hinnant    return __x.base() - __y.base();
13043e519524SHoward Hinnant}
1305947ce6b5SMarshall Clow#endif
13063e519524SHoward Hinnant
13073e519524SHoward Hinnanttemplate <class _Iter>
1308720ef472SMarshall Clowinline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
13093e519524SHoward Hinnantmove_iterator<_Iter>
13103e519524SHoward Hinnantoperator+(typename move_iterator<_Iter>::difference_type __n, const move_iterator<_Iter>& __x)
13113e519524SHoward Hinnant{
13123e519524SHoward Hinnant    return move_iterator<_Iter>(__x.base() + __n);
13133e519524SHoward Hinnant}
13143e519524SHoward Hinnant
13153e519524SHoward Hinnanttemplate <class _Iter>
1316720ef472SMarshall Clowinline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
13173e519524SHoward Hinnantmove_iterator<_Iter>
131854c83368SMarshall Clowmake_move_iterator(_Iter __i)
13193e519524SHoward Hinnant{
13203e519524SHoward Hinnant    return move_iterator<_Iter>(__i);
13213e519524SHoward Hinnant}
13223e519524SHoward Hinnant
13233e519524SHoward Hinnant// __wrap_iter
13243e519524SHoward Hinnant
13253e519524SHoward Hinnanttemplate <class _Iter> class __wrap_iter;
13263e519524SHoward Hinnant
13273e519524SHoward Hinnanttemplate <class _Iter1, class _Iter2>
13289cad5025SMarshall Clow_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG
13293e519524SHoward Hinnantbool
133061b302f9SEric Fiselieroperator==(const __wrap_iter<_Iter1>&, const __wrap_iter<_Iter2>&) _NOEXCEPT;
13313e519524SHoward Hinnant
13323e519524SHoward Hinnanttemplate <class _Iter1, class _Iter2>
13339cad5025SMarshall Clow_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG
13343e519524SHoward Hinnantbool
133561b302f9SEric Fiselieroperator<(const __wrap_iter<_Iter1>&, const __wrap_iter<_Iter2>&) _NOEXCEPT;
13363e519524SHoward Hinnant
13373e519524SHoward Hinnanttemplate <class _Iter1, class _Iter2>
13389cad5025SMarshall Clow_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG
13393e519524SHoward Hinnantbool
134061b302f9SEric Fiselieroperator!=(const __wrap_iter<_Iter1>&, const __wrap_iter<_Iter2>&) _NOEXCEPT;
13413e519524SHoward Hinnant
13423e519524SHoward Hinnanttemplate <class _Iter1, class _Iter2>
13439cad5025SMarshall Clow_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG
13443e519524SHoward Hinnantbool
134561b302f9SEric Fiselieroperator>(const __wrap_iter<_Iter1>&, const __wrap_iter<_Iter2>&) _NOEXCEPT;
13463e519524SHoward Hinnant
13473e519524SHoward Hinnanttemplate <class _Iter1, class _Iter2>
13489cad5025SMarshall Clow_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG
13493e519524SHoward Hinnantbool
135061b302f9SEric Fiselieroperator>=(const __wrap_iter<_Iter1>&, const __wrap_iter<_Iter2>&) _NOEXCEPT;
13513e519524SHoward Hinnant
13523e519524SHoward Hinnanttemplate <class _Iter1, class _Iter2>
13539cad5025SMarshall Clow_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG
13543e519524SHoward Hinnantbool
135561b302f9SEric Fiselieroperator<=(const __wrap_iter<_Iter1>&, const __wrap_iter<_Iter2>&) _NOEXCEPT;
13563e519524SHoward Hinnant
13572ee83725SMarshall Clow#ifndef _LIBCPP_CXX03_LANG
1358947ce6b5SMarshall Clowtemplate <class _Iter1, class _Iter2>
13599cad5025SMarshall Clow_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG
1360947ce6b5SMarshall Clowauto
136161b302f9SEric Fiselieroperator-(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter2>& __y) _NOEXCEPT
1362947ce6b5SMarshall Clow-> decltype(__x.base() - __y.base());
1363947ce6b5SMarshall Clow#else
13643e519524SHoward Hinnanttemplate <class _Iter1, class _Iter2>
1365aeb85680SHoward Hinnant_LIBCPP_INLINE_VISIBILITY
13663e519524SHoward Hinnanttypename __wrap_iter<_Iter1>::difference_type
136761b302f9SEric Fiselieroperator-(const __wrap_iter<_Iter1>&, const __wrap_iter<_Iter2>&) _NOEXCEPT;
1368947ce6b5SMarshall Clow#endif
13693e519524SHoward Hinnant
13703e519524SHoward Hinnanttemplate <class _Iter>
13719cad5025SMarshall Clow_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG
13723e519524SHoward Hinnant__wrap_iter<_Iter>
137361b302f9SEric Fiselieroperator+(typename __wrap_iter<_Iter>::difference_type, __wrap_iter<_Iter>) _NOEXCEPT;
13743e519524SHoward Hinnant
137513c90a57SLouis Dionnetemplate <class _Ip, class _Op> _Op _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 copy(_Ip, _Ip, _Op);
137613c90a57SLouis Dionnetemplate <class _B1, class _B2> _B2 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 copy_backward(_B1, _B1, _B2);
1377aeb85680SHoward Hinnanttemplate <class _Ip, class _Op> _Op _LIBCPP_INLINE_VISIBILITY move(_Ip, _Ip, _Op);
1378aeb85680SHoward Hinnanttemplate <class _B1, class _B2> _B2 _LIBCPP_INLINE_VISIBILITY move_backward(_B1, _B1, _B2);
13793e519524SHoward Hinnant
138014bd0bf0SEric Fiselier#if _LIBCPP_DEBUG_LEVEL < 2
138114bd0bf0SEric Fiselier
13823e519524SHoward Hinnanttemplate <class _Tp>
13839cad5025SMarshall Clow_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG
13843e519524SHoward Hinnanttypename enable_if
13853e519524SHoward Hinnant<
1386ca740483SHoward Hinnant    is_trivially_copy_assignable<_Tp>::value,
13873e519524SHoward Hinnant    _Tp*
13883e519524SHoward Hinnant>::type
13893e519524SHoward Hinnant__unwrap_iter(__wrap_iter<_Tp*>);
13903e519524SHoward Hinnant
139114bd0bf0SEric Fiselier#else
139214bd0bf0SEric Fiselier
139314bd0bf0SEric Fiseliertemplate <class _Tp>
13949cad5025SMarshall Clowinline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG
139514bd0bf0SEric Fiseliertypename enable_if
139614bd0bf0SEric Fiselier<
139714bd0bf0SEric Fiselier    is_trivially_copy_assignable<_Tp>::value,
139814bd0bf0SEric Fiselier    __wrap_iter<_Tp*>
139914bd0bf0SEric Fiselier>::type
140014bd0bf0SEric Fiselier__unwrap_iter(__wrap_iter<_Tp*> __i);
140114bd0bf0SEric Fiselier
140214bd0bf0SEric Fiselier#endif
140314bd0bf0SEric Fiselier
14043e519524SHoward Hinnanttemplate <class _Iter>
14053e519524SHoward Hinnantclass __wrap_iter
14063e519524SHoward Hinnant{
14073e519524SHoward Hinnantpublic:
14083e519524SHoward Hinnant    typedef _Iter                                                      iterator_type;
14093e519524SHoward Hinnant    typedef typename iterator_traits<iterator_type>::iterator_category iterator_category;
14103e519524SHoward Hinnant    typedef typename iterator_traits<iterator_type>::value_type        value_type;
14113e519524SHoward Hinnant    typedef typename iterator_traits<iterator_type>::difference_type   difference_type;
14123e519524SHoward Hinnant    typedef typename iterator_traits<iterator_type>::pointer           pointer;
14133e519524SHoward Hinnant    typedef typename iterator_traits<iterator_type>::reference         reference;
14143e519524SHoward Hinnantprivate:
14153e519524SHoward Hinnant    iterator_type __i;
14163e519524SHoward Hinnantpublic:
141761b302f9SEric Fiselier    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG __wrap_iter() _NOEXCEPT
141807186a7dSMarshall Clow#if _LIBCPP_STD_VER > 11
141907186a7dSMarshall Clow                : __i{}
142007186a7dSMarshall Clow#endif
1421c36bfc49SHoward Hinnant    {
1422c36bfc49SHoward Hinnant#if _LIBCPP_DEBUG_LEVEL >= 2
1423c36bfc49SHoward Hinnant        __get_db()->__insert_i(this);
1424c36bfc49SHoward Hinnant#endif
1425c36bfc49SHoward Hinnant    }
14269cad5025SMarshall Clow    template <class _Up> _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG
14279cad5025SMarshall Clow        __wrap_iter(const __wrap_iter<_Up>& __u,
142861b302f9SEric Fiselier            typename enable_if<is_convertible<_Up, iterator_type>::value>::type* = 0) _NOEXCEPT
1429f554add5SHoward Hinnant            : __i(__u.base())
1430f554add5SHoward Hinnant    {
1431cec9af9eSHoward Hinnant#if _LIBCPP_DEBUG_LEVEL >= 2
1432f554add5SHoward Hinnant        __get_db()->__iterator_copy(this, &__u);
1433f554add5SHoward Hinnant#endif
1434f554add5SHoward Hinnant    }
1435cec9af9eSHoward Hinnant#if _LIBCPP_DEBUG_LEVEL >= 2
14369cad5025SMarshall Clow    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG
1437f554add5SHoward Hinnant    __wrap_iter(const __wrap_iter& __x)
1438f554add5SHoward Hinnant        : __i(__x.base())
1439f554add5SHoward Hinnant    {
1440f554add5SHoward Hinnant        __get_db()->__iterator_copy(this, &__x);
1441f554add5SHoward Hinnant    }
14429cad5025SMarshall Clow    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG
1443f554add5SHoward Hinnant    __wrap_iter& operator=(const __wrap_iter& __x)
1444f554add5SHoward Hinnant    {
1445f554add5SHoward Hinnant        if (this != &__x)
1446f554add5SHoward Hinnant        {
1447f554add5SHoward Hinnant            __get_db()->__iterator_copy(this, &__x);
1448f554add5SHoward Hinnant            __i = __x.__i;
1449f554add5SHoward Hinnant        }
1450f554add5SHoward Hinnant        return *this;
1451f554add5SHoward Hinnant    }
14529cad5025SMarshall Clow    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG
1453f554add5SHoward Hinnant    ~__wrap_iter()
1454f554add5SHoward Hinnant    {
1455f554add5SHoward Hinnant        __get_db()->__erase_i(this);
1456f554add5SHoward Hinnant    }
1457f554add5SHoward Hinnant#endif
145861b302f9SEric Fiselier    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG reference operator*() const _NOEXCEPT
1459f554add5SHoward Hinnant    {
1460cec9af9eSHoward Hinnant#if _LIBCPP_DEBUG_LEVEL >= 2
1461f554add5SHoward Hinnant        _LIBCPP_ASSERT(__get_const_db()->__dereferenceable(this),
1462f554add5SHoward Hinnant                       "Attempted to dereference a non-dereferenceable iterator");
1463cec9af9eSHoward Hinnant#endif
1464f554add5SHoward Hinnant        return *__i;
1465f554add5SHoward Hinnant    }
146661b302f9SEric Fiselier    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG pointer  operator->() const _NOEXCEPT
14673ec1f00bSHoward Hinnant    {
14683ec1f00bSHoward Hinnant#if _LIBCPP_DEBUG_LEVEL >= 2
14693ec1f00bSHoward Hinnant        _LIBCPP_ASSERT(__get_const_db()->__dereferenceable(this),
14703ec1f00bSHoward Hinnant                       "Attempted to dereference a non-dereferenceable iterator");
14713ec1f00bSHoward Hinnant#endif
147205333fc8SMarshall Clow        return (pointer)_VSTD::addressof(*__i);
14733ec1f00bSHoward Hinnant    }
147461b302f9SEric Fiselier    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG __wrap_iter& operator++() _NOEXCEPT
1475f554add5SHoward Hinnant    {
1476cec9af9eSHoward Hinnant#if _LIBCPP_DEBUG_LEVEL >= 2
1477f554add5SHoward Hinnant        _LIBCPP_ASSERT(__get_const_db()->__dereferenceable(this),
1478f554add5SHoward Hinnant                       "Attempted to increment non-incrementable iterator");
1479cec9af9eSHoward Hinnant#endif
1480f554add5SHoward Hinnant        ++__i;
1481f554add5SHoward Hinnant        return *this;
1482f554add5SHoward Hinnant    }
148361b302f9SEric Fiselier    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG __wrap_iter  operator++(int) _NOEXCEPT
1484f554add5SHoward Hinnant        {__wrap_iter __tmp(*this); ++(*this); return __tmp;}
14854ce0a916SMarshall Clow
148661b302f9SEric Fiselier    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG __wrap_iter& operator--() _NOEXCEPT
1487f554add5SHoward Hinnant    {
1488cec9af9eSHoward Hinnant#if _LIBCPP_DEBUG_LEVEL >= 2
1489f554add5SHoward Hinnant        _LIBCPP_ASSERT(__get_const_db()->__decrementable(this),
1490f554add5SHoward Hinnant                       "Attempted to decrement non-decrementable iterator");
1491cec9af9eSHoward Hinnant#endif
1492f554add5SHoward Hinnant        --__i;
1493f554add5SHoward Hinnant        return *this;
1494f554add5SHoward Hinnant    }
149561b302f9SEric Fiselier    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG __wrap_iter  operator--(int) _NOEXCEPT
1496f554add5SHoward Hinnant        {__wrap_iter __tmp(*this); --(*this); return __tmp;}
149761b302f9SEric Fiselier    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG __wrap_iter  operator+ (difference_type __n) const _NOEXCEPT
1498f554add5SHoward Hinnant        {__wrap_iter __w(*this); __w += __n; return __w;}
149961b302f9SEric Fiselier    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG __wrap_iter& operator+=(difference_type __n) _NOEXCEPT
1500f554add5SHoward Hinnant    {
1501cec9af9eSHoward Hinnant#if _LIBCPP_DEBUG_LEVEL >= 2
1502f554add5SHoward Hinnant        _LIBCPP_ASSERT(__get_const_db()->__addable(this, __n),
1503f554add5SHoward Hinnant                   "Attempted to add/subtract iterator outside of valid range");
1504cec9af9eSHoward Hinnant#endif
1505f554add5SHoward Hinnant        __i += __n;
1506f554add5SHoward Hinnant        return *this;
1507f554add5SHoward Hinnant    }
150861b302f9SEric Fiselier    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG __wrap_iter  operator- (difference_type __n) const _NOEXCEPT
1509f554add5SHoward Hinnant        {return *this + (-__n);}
151061b302f9SEric Fiselier    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG __wrap_iter& operator-=(difference_type __n) _NOEXCEPT
1511f554add5SHoward Hinnant        {*this += -__n; return *this;}
151261b302f9SEric Fiselier    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG reference    operator[](difference_type __n) const _NOEXCEPT
1513f554add5SHoward Hinnant    {
1514cec9af9eSHoward Hinnant#if _LIBCPP_DEBUG_LEVEL >= 2
1515f554add5SHoward Hinnant        _LIBCPP_ASSERT(__get_const_db()->__subscriptable(this, __n),
1516f554add5SHoward Hinnant                   "Attempted to subscript iterator outside of valid range");
1517cec9af9eSHoward Hinnant#endif
1518f554add5SHoward Hinnant        return __i[__n];
1519f554add5SHoward Hinnant    }
15203e519524SHoward Hinnant
152161b302f9SEric Fiselier    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG iterator_type base() const _NOEXCEPT {return __i;}
15223e519524SHoward Hinnant
15233e519524SHoward Hinnantprivate:
1524cec9af9eSHoward Hinnant#if _LIBCPP_DEBUG_LEVEL >= 2
15259cad5025SMarshall Clow    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG __wrap_iter(const void* __p, iterator_type __x) : __i(__x)
1526f554add5SHoward Hinnant    {
1527f554add5SHoward Hinnant        __get_db()->__insert_ic(this, __p);
1528f554add5SHoward Hinnant    }
1529fc88dbd2SHoward Hinnant#else
153061b302f9SEric Fiselier    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG __wrap_iter(iterator_type __x) _NOEXCEPT : __i(__x) {}
1531f554add5SHoward Hinnant#endif
15323e519524SHoward Hinnant
15333e519524SHoward Hinnant    template <class _Up> friend class __wrap_iter;
15343e519524SHoward Hinnant    template <class _CharT, class _Traits, class _Alloc> friend class basic_string;
1535e2f2d1edSEric Fiselier    template <class _Tp, class _Alloc> friend class _LIBCPP_TEMPLATE_VIS vector;
15367ad06a93SMarshall Clow    template <class _Tp, size_t> friend class _LIBCPP_TEMPLATE_VIS span;
15373e519524SHoward Hinnant
15383e519524SHoward Hinnant    template <class _Iter1, class _Iter2>
15399cad5025SMarshall Clow    _LIBCPP_CONSTEXPR_IF_NODEBUG friend
15403e519524SHoward Hinnant    bool
154161b302f9SEric Fiselier    operator==(const __wrap_iter<_Iter1>&, const __wrap_iter<_Iter2>&) _NOEXCEPT;
15423e519524SHoward Hinnant
15433e519524SHoward Hinnant    template <class _Iter1, class _Iter2>
15449cad5025SMarshall Clow    _LIBCPP_CONSTEXPR_IF_NODEBUG friend
15453e519524SHoward Hinnant    bool
154661b302f9SEric Fiselier    operator<(const __wrap_iter<_Iter1>&, const __wrap_iter<_Iter2>&) _NOEXCEPT;
15473e519524SHoward Hinnant
15483e519524SHoward Hinnant    template <class _Iter1, class _Iter2>
15499cad5025SMarshall Clow    _LIBCPP_CONSTEXPR_IF_NODEBUG friend
15503e519524SHoward Hinnant    bool
155161b302f9SEric Fiselier    operator!=(const __wrap_iter<_Iter1>&, const __wrap_iter<_Iter2>&) _NOEXCEPT;
15523e519524SHoward Hinnant
15533e519524SHoward Hinnant    template <class _Iter1, class _Iter2>
15549cad5025SMarshall Clow    _LIBCPP_CONSTEXPR_IF_NODEBUG friend
15553e519524SHoward Hinnant    bool
155661b302f9SEric Fiselier    operator>(const __wrap_iter<_Iter1>&, const __wrap_iter<_Iter2>&) _NOEXCEPT;
15573e519524SHoward Hinnant
15583e519524SHoward Hinnant    template <class _Iter1, class _Iter2>
15599cad5025SMarshall Clow    _LIBCPP_CONSTEXPR_IF_NODEBUG friend
15603e519524SHoward Hinnant    bool
156161b302f9SEric Fiselier    operator>=(const __wrap_iter<_Iter1>&, const __wrap_iter<_Iter2>&) _NOEXCEPT;
15623e519524SHoward Hinnant
15633e519524SHoward Hinnant    template <class _Iter1, class _Iter2>
15649cad5025SMarshall Clow    _LIBCPP_CONSTEXPR_IF_NODEBUG friend
15653e519524SHoward Hinnant    bool
156661b302f9SEric Fiselier    operator<=(const __wrap_iter<_Iter1>&, const __wrap_iter<_Iter2>&) _NOEXCEPT;
15673e519524SHoward Hinnant
15682ee83725SMarshall Clow#ifndef _LIBCPP_CXX03_LANG
1569947ce6b5SMarshall Clow    template <class _Iter1, class _Iter2>
15709cad5025SMarshall Clow    _LIBCPP_CONSTEXPR_IF_NODEBUG friend
1571947ce6b5SMarshall Clow    auto
157261b302f9SEric Fiselier    operator-(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter2>& __y) _NOEXCEPT
1573947ce6b5SMarshall Clow    -> decltype(__x.base() - __y.base());
1574947ce6b5SMarshall Clow#else
15753e519524SHoward Hinnant    template <class _Iter1, class _Iter2>
15769cad5025SMarshall Clow    _LIBCPP_CONSTEXPR_IF_NODEBUG friend
15773e519524SHoward Hinnant    typename __wrap_iter<_Iter1>::difference_type
157861b302f9SEric Fiselier    operator-(const __wrap_iter<_Iter1>&, const __wrap_iter<_Iter2>&) _NOEXCEPT;
1579947ce6b5SMarshall Clow#endif
15803e519524SHoward Hinnant
15813e519524SHoward Hinnant    template <class _Iter1>
15829cad5025SMarshall Clow    _LIBCPP_CONSTEXPR_IF_NODEBUG friend
15833e519524SHoward Hinnant    __wrap_iter<_Iter1>
158461b302f9SEric Fiselier    operator+(typename __wrap_iter<_Iter1>::difference_type, __wrap_iter<_Iter1>) _NOEXCEPT;
15853e519524SHoward Hinnant
158613c90a57SLouis Dionne    template <class _Ip, class _Op> friend _LIBCPP_CONSTEXPR_AFTER_CXX17 _Op copy(_Ip, _Ip, _Op);
158713c90a57SLouis Dionne    template <class _B1, class _B2> friend _LIBCPP_CONSTEXPR_AFTER_CXX17 _B2 copy_backward(_B1, _B1, _B2);
1588c003db1fSHoward Hinnant    template <class _Ip, class _Op> friend _Op move(_Ip, _Ip, _Op);
15893e519524SHoward Hinnant    template <class _B1, class _B2> friend _B2 move_backward(_B1, _B1, _B2);
15903e519524SHoward Hinnant
159114bd0bf0SEric Fiselier#if _LIBCPP_DEBUG_LEVEL < 2
15923e519524SHoward Hinnant    template <class _Tp>
15939cad5025SMarshall Clow    _LIBCPP_CONSTEXPR_IF_NODEBUG friend
15943e519524SHoward Hinnant    typename enable_if
15953e519524SHoward Hinnant    <
1596ca740483SHoward Hinnant        is_trivially_copy_assignable<_Tp>::value,
15973e519524SHoward Hinnant        _Tp*
15983e519524SHoward Hinnant    >::type
15993e519524SHoward Hinnant    __unwrap_iter(__wrap_iter<_Tp*>);
160014bd0bf0SEric Fiselier#else
160114bd0bf0SEric Fiselier  template <class _Tp>
16029cad5025SMarshall Clow  inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG
160314bd0bf0SEric Fiselier  typename enable_if
160414bd0bf0SEric Fiselier  <
160514bd0bf0SEric Fiselier      is_trivially_copy_assignable<_Tp>::value,
160614bd0bf0SEric Fiselier      __wrap_iter<_Tp*>
160714bd0bf0SEric Fiselier  >::type
160814bd0bf0SEric Fiselier  __unwrap_iter(__wrap_iter<_Tp*> __i);
160914bd0bf0SEric Fiselier#endif
16103e519524SHoward Hinnant};
16113e519524SHoward Hinnant
16123e519524SHoward Hinnanttemplate <class _Iter1, class _Iter2>
16139cad5025SMarshall Clowinline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG
16143e519524SHoward Hinnantbool
161561b302f9SEric Fiselieroperator==(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter2>& __y) _NOEXCEPT
16163e519524SHoward Hinnant{
16173e519524SHoward Hinnant    return __x.base() == __y.base();
16183e519524SHoward Hinnant}
16193e519524SHoward Hinnant
16203e519524SHoward Hinnanttemplate <class _Iter1, class _Iter2>
16219cad5025SMarshall Clowinline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG
16223e519524SHoward Hinnantbool
162361b302f9SEric Fiselieroperator<(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter2>& __y) _NOEXCEPT
16243e519524SHoward Hinnant{
1625cec9af9eSHoward Hinnant#if _LIBCPP_DEBUG_LEVEL >= 2
162642a3046eSHoward Hinnant    _LIBCPP_ASSERT(__get_const_db()->__less_than_comparable(&__x, &__y),
1627f554add5SHoward Hinnant                   "Attempted to compare incomparable iterators");
1628cec9af9eSHoward Hinnant#endif
16293e519524SHoward Hinnant    return __x.base() < __y.base();
16303e519524SHoward Hinnant}
16313e519524SHoward Hinnant
16323e519524SHoward Hinnanttemplate <class _Iter1, class _Iter2>
16339cad5025SMarshall Clowinline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG
16343e519524SHoward Hinnantbool
163561b302f9SEric Fiselieroperator!=(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter2>& __y) _NOEXCEPT
16363e519524SHoward Hinnant{
1637f554add5SHoward Hinnant    return !(__x == __y);
16383e519524SHoward Hinnant}
16393e519524SHoward Hinnant
16403e519524SHoward Hinnanttemplate <class _Iter1, class _Iter2>
16419cad5025SMarshall Clowinline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG
16423e519524SHoward Hinnantbool
164361b302f9SEric Fiselieroperator>(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter2>& __y) _NOEXCEPT
16443e519524SHoward Hinnant{
1645f554add5SHoward Hinnant    return __y < __x;
16463e519524SHoward Hinnant}
16473e519524SHoward Hinnant
16483e519524SHoward Hinnanttemplate <class _Iter1, class _Iter2>
16499cad5025SMarshall Clowinline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG
16503e519524SHoward Hinnantbool
165161b302f9SEric Fiselieroperator>=(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter2>& __y) _NOEXCEPT
16523e519524SHoward Hinnant{
1653f554add5SHoward Hinnant    return !(__x < __y);
16543e519524SHoward Hinnant}
16553e519524SHoward Hinnant
16563e519524SHoward Hinnanttemplate <class _Iter1, class _Iter2>
16579cad5025SMarshall Clowinline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG
16583e519524SHoward Hinnantbool
165961b302f9SEric Fiselieroperator<=(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter2>& __y) _NOEXCEPT
16603e519524SHoward Hinnant{
1661f554add5SHoward Hinnant    return !(__y < __x);
16623e519524SHoward Hinnant}
16633e519524SHoward Hinnant
16646e551ae1SHoward Hinnanttemplate <class _Iter1>
16659cad5025SMarshall Clowinline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG
16666e551ae1SHoward Hinnantbool
166761b302f9SEric Fiselieroperator!=(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter1>& __y) _NOEXCEPT
16686e551ae1SHoward Hinnant{
16696e551ae1SHoward Hinnant    return !(__x == __y);
16706e551ae1SHoward Hinnant}
16716e551ae1SHoward Hinnant
16726e551ae1SHoward Hinnanttemplate <class _Iter1>
16739cad5025SMarshall Clowinline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG
16746e551ae1SHoward Hinnantbool
167561b302f9SEric Fiselieroperator>(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter1>& __y) _NOEXCEPT
16766e551ae1SHoward Hinnant{
16776e551ae1SHoward Hinnant    return __y < __x;
16786e551ae1SHoward Hinnant}
16796e551ae1SHoward Hinnant
16806e551ae1SHoward Hinnanttemplate <class _Iter1>
16819cad5025SMarshall Clowinline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG
16826e551ae1SHoward Hinnantbool
168361b302f9SEric Fiselieroperator>=(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter1>& __y) _NOEXCEPT
16846e551ae1SHoward Hinnant{
16856e551ae1SHoward Hinnant    return !(__x < __y);
16866e551ae1SHoward Hinnant}
16876e551ae1SHoward Hinnant
16886e551ae1SHoward Hinnanttemplate <class _Iter1>
16899cad5025SMarshall Clowinline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG
16906e551ae1SHoward Hinnantbool
169161b302f9SEric Fiselieroperator<=(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter1>& __y) _NOEXCEPT
16926e551ae1SHoward Hinnant{
16936e551ae1SHoward Hinnant    return !(__y < __x);
16946e551ae1SHoward Hinnant}
16956e551ae1SHoward Hinnant
16962ee83725SMarshall Clow#ifndef _LIBCPP_CXX03_LANG
1697947ce6b5SMarshall Clowtemplate <class _Iter1, class _Iter2>
16989cad5025SMarshall Clowinline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG
1699947ce6b5SMarshall Clowauto
170061b302f9SEric Fiselieroperator-(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter2>& __y) _NOEXCEPT
1701947ce6b5SMarshall Clow-> decltype(__x.base() - __y.base())
1702947ce6b5SMarshall Clow{
1703947ce6b5SMarshall Clow#if _LIBCPP_DEBUG_LEVEL >= 2
1704947ce6b5SMarshall Clow    _LIBCPP_ASSERT(__get_const_db()->__less_than_comparable(&__x, &__y),
1705947ce6b5SMarshall Clow                   "Attempted to subtract incompatible iterators");
1706947ce6b5SMarshall Clow#endif
1707947ce6b5SMarshall Clow    return __x.base() - __y.base();
1708947ce6b5SMarshall Clow}
1709947ce6b5SMarshall Clow#else
17103e519524SHoward Hinnanttemplate <class _Iter1, class _Iter2>
17119cad5025SMarshall Clowinline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG
17123e519524SHoward Hinnanttypename __wrap_iter<_Iter1>::difference_type
171361b302f9SEric Fiselieroperator-(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter2>& __y) _NOEXCEPT
17143e519524SHoward Hinnant{
1715cec9af9eSHoward Hinnant#if _LIBCPP_DEBUG_LEVEL >= 2
171642a3046eSHoward Hinnant    _LIBCPP_ASSERT(__get_const_db()->__less_than_comparable(&__x, &__y),
1717f554add5SHoward Hinnant                   "Attempted to subtract incompatible iterators");
1718cec9af9eSHoward Hinnant#endif
17193e519524SHoward Hinnant    return __x.base() - __y.base();
17203e519524SHoward Hinnant}
1721947ce6b5SMarshall Clow#endif
17223e519524SHoward Hinnant
17233e519524SHoward Hinnanttemplate <class _Iter>
17249cad5025SMarshall Clowinline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG
17253e519524SHoward Hinnant__wrap_iter<_Iter>
17263e519524SHoward Hinnantoperator+(typename __wrap_iter<_Iter>::difference_type __n,
172761b302f9SEric Fiselier          __wrap_iter<_Iter> __x) _NOEXCEPT
17283e519524SHoward Hinnant{
1729f554add5SHoward Hinnant    __x += __n;
1730f554add5SHoward Hinnant    return __x;
17313e519524SHoward Hinnant}
17323e519524SHoward Hinnant
173376b4afc0SMarshall Clowtemplate <class _Iter>
173476b4afc0SMarshall Clowstruct __libcpp_is_trivial_iterator
173576b4afc0SMarshall Clow    : public _LIBCPP_BOOL_CONSTANT(is_pointer<_Iter>::value) {};
173676b4afc0SMarshall Clow
173776b4afc0SMarshall Clowtemplate <class _Iter>
173876b4afc0SMarshall Clowstruct __libcpp_is_trivial_iterator<move_iterator<_Iter> >
173976b4afc0SMarshall Clow    : public _LIBCPP_BOOL_CONSTANT(__libcpp_is_trivial_iterator<_Iter>::value) {};
174076b4afc0SMarshall Clow
174176b4afc0SMarshall Clowtemplate <class _Iter>
174276b4afc0SMarshall Clowstruct __libcpp_is_trivial_iterator<reverse_iterator<_Iter> >
174376b4afc0SMarshall Clow    : public _LIBCPP_BOOL_CONSTANT(__libcpp_is_trivial_iterator<_Iter>::value) {};
174476b4afc0SMarshall Clow
174576b4afc0SMarshall Clowtemplate <class _Iter>
174676b4afc0SMarshall Clowstruct __libcpp_is_trivial_iterator<__wrap_iter<_Iter> >
174776b4afc0SMarshall Clow    : public _LIBCPP_BOOL_CONSTANT(__libcpp_is_trivial_iterator<_Iter>::value) {};
174876b4afc0SMarshall Clow
174976b4afc0SMarshall Clow
17503772a46aSMarshall Clowtemplate <class _Tp, size_t _Np>
17512ffa1705SMarshall Clow_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
17523772a46aSMarshall Clow_Tp*
17533772a46aSMarshall Clowbegin(_Tp (&__array)[_Np])
17543772a46aSMarshall Clow{
17553772a46aSMarshall Clow    return __array;
17563772a46aSMarshall Clow}
17573772a46aSMarshall Clow
17583772a46aSMarshall Clowtemplate <class _Tp, size_t _Np>
17592ffa1705SMarshall Clow_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
17603772a46aSMarshall Clow_Tp*
17613772a46aSMarshall Clowend(_Tp (&__array)[_Np])
17623772a46aSMarshall Clow{
17633772a46aSMarshall Clow    return __array + _Np;
17643772a46aSMarshall Clow}
17653772a46aSMarshall Clow
176654613ab4SEric Fiselier#if !defined(_LIBCPP_CXX03_LANG)
1767c66a611bSMarshall Clow
1768c003db1fSHoward Hinnanttemplate <class _Cp>
17692ffa1705SMarshall Clow_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
17703e519524SHoward Hinnantauto
1771c003db1fSHoward Hinnantbegin(_Cp& __c) -> decltype(__c.begin())
17723e519524SHoward Hinnant{
17733e519524SHoward Hinnant    return __c.begin();
17743e519524SHoward Hinnant}
17753e519524SHoward Hinnant
1776c003db1fSHoward Hinnanttemplate <class _Cp>
17772ffa1705SMarshall Clow_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
17783e519524SHoward Hinnantauto
1779c003db1fSHoward Hinnantbegin(const _Cp& __c) -> decltype(__c.begin())
17803e519524SHoward Hinnant{
17813e519524SHoward Hinnant    return __c.begin();
17823e519524SHoward Hinnant}
17833e519524SHoward Hinnant
1784c003db1fSHoward Hinnanttemplate <class _Cp>
17852ffa1705SMarshall Clow_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
17863e519524SHoward Hinnantauto
1787c003db1fSHoward Hinnantend(_Cp& __c) -> decltype(__c.end())
17883e519524SHoward Hinnant{
17893e519524SHoward Hinnant    return __c.end();
17903e519524SHoward Hinnant}
17913e519524SHoward Hinnant
1792c003db1fSHoward Hinnanttemplate <class _Cp>
17932ffa1705SMarshall Clow_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
17943e519524SHoward Hinnantauto
1795c003db1fSHoward Hinnantend(const _Cp& __c) -> decltype(__c.end())
17963e519524SHoward Hinnant{
17973e519524SHoward Hinnant    return __c.end();
17983e519524SHoward Hinnant}
17993e519524SHoward Hinnant
18001e548c72SMarshall Clow#if _LIBCPP_STD_VER > 11
18011e548c72SMarshall Clow
18023772a46aSMarshall Clowtemplate <class _Tp, size_t _Np>
18032ffa1705SMarshall Clow_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
18043772a46aSMarshall Clowreverse_iterator<_Tp*> rbegin(_Tp (&__array)[_Np])
18053772a46aSMarshall Clow{
18063772a46aSMarshall Clow    return reverse_iterator<_Tp*>(__array + _Np);
18073772a46aSMarshall Clow}
18083772a46aSMarshall Clow
18093772a46aSMarshall Clowtemplate <class _Tp, size_t _Np>
18102ffa1705SMarshall Clow_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
18113772a46aSMarshall Clowreverse_iterator<_Tp*> rend(_Tp (&__array)[_Np])
18123772a46aSMarshall Clow{
18133772a46aSMarshall Clow    return reverse_iterator<_Tp*>(__array);
18143772a46aSMarshall Clow}
18153772a46aSMarshall Clow
18163772a46aSMarshall Clowtemplate <class _Ep>
18172ffa1705SMarshall Clow_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
18183772a46aSMarshall Clowreverse_iterator<const _Ep*> rbegin(initializer_list<_Ep> __il)
18193772a46aSMarshall Clow{
18203772a46aSMarshall Clow    return reverse_iterator<const _Ep*>(__il.end());
18213772a46aSMarshall Clow}
18223772a46aSMarshall Clow
18233772a46aSMarshall Clowtemplate <class _Ep>
18242ffa1705SMarshall Clow_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
18253772a46aSMarshall Clowreverse_iterator<const _Ep*> rend(initializer_list<_Ep> __il)
18263772a46aSMarshall Clow{
18273772a46aSMarshall Clow    return reverse_iterator<const _Ep*>(__il.begin());
18283772a46aSMarshall Clow}
18293772a46aSMarshall Clow
18301e548c72SMarshall Clowtemplate <class _Cp>
18312ffa1705SMarshall Clow_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
18327725546aSMarshall Clowauto cbegin(const _Cp& __c) -> decltype(_VSTD::begin(__c))
18331e548c72SMarshall Clow{
18347725546aSMarshall Clow    return _VSTD::begin(__c);
18351e548c72SMarshall Clow}
18361e548c72SMarshall Clow
18371e548c72SMarshall Clowtemplate <class _Cp>
18382ffa1705SMarshall Clow_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
18397725546aSMarshall Clowauto cend(const _Cp& __c) -> decltype(_VSTD::end(__c))
18401e548c72SMarshall Clow{
18417725546aSMarshall Clow    return _VSTD::end(__c);
18421e548c72SMarshall Clow}
18431e548c72SMarshall Clow
18441e548c72SMarshall Clowtemplate <class _Cp>
18452ffa1705SMarshall Clow_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
18461e548c72SMarshall Clowauto rbegin(_Cp& __c) -> decltype(__c.rbegin())
18471e548c72SMarshall Clow{
18481e548c72SMarshall Clow    return __c.rbegin();
18491e548c72SMarshall Clow}
18501e548c72SMarshall Clow
18511e548c72SMarshall Clowtemplate <class _Cp>
18522ffa1705SMarshall Clow_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
18531e548c72SMarshall Clowauto rbegin(const _Cp& __c) -> decltype(__c.rbegin())
18541e548c72SMarshall Clow{
18551e548c72SMarshall Clow    return __c.rbegin();
18561e548c72SMarshall Clow}
18571e548c72SMarshall Clow
18581e548c72SMarshall Clowtemplate <class _Cp>
18592ffa1705SMarshall Clow_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
18601e548c72SMarshall Clowauto rend(_Cp& __c) -> decltype(__c.rend())
18611e548c72SMarshall Clow{
18621e548c72SMarshall Clow    return __c.rend();
18631e548c72SMarshall Clow}
18641e548c72SMarshall Clow
18651e548c72SMarshall Clowtemplate <class _Cp>
18662ffa1705SMarshall Clow_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
18671e548c72SMarshall Clowauto rend(const _Cp& __c) -> decltype(__c.rend())
18681e548c72SMarshall Clow{
18691e548c72SMarshall Clow    return __c.rend();
18701e548c72SMarshall Clow}
18711e548c72SMarshall Clow
18721e548c72SMarshall Clowtemplate <class _Cp>
18732ffa1705SMarshall Clow_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
18747725546aSMarshall Clowauto crbegin(const _Cp& __c) -> decltype(_VSTD::rbegin(__c))
18751e548c72SMarshall Clow{
18767725546aSMarshall Clow    return _VSTD::rbegin(__c);
18771e548c72SMarshall Clow}
18781e548c72SMarshall Clow
18791e548c72SMarshall Clowtemplate <class _Cp>
18802ffa1705SMarshall Clow_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
18817725546aSMarshall Clowauto crend(const _Cp& __c) -> decltype(_VSTD::rend(__c))
18821e548c72SMarshall Clow{
18837725546aSMarshall Clow    return _VSTD::rend(__c);
18841e548c72SMarshall Clow}
18851e548c72SMarshall Clow
18861e548c72SMarshall Clow#endif
18871e548c72SMarshall Clow
18881e548c72SMarshall Clow
188954613ab4SEric Fiselier#else  // defined(_LIBCPP_CXX03_LANG)
18903e519524SHoward Hinnant
1891c003db1fSHoward Hinnanttemplate <class _Cp>
18922ffa1705SMarshall Clow_LIBCPP_INLINE_VISIBILITY
1893c003db1fSHoward Hinnanttypename _Cp::iterator
1894c003db1fSHoward Hinnantbegin(_Cp& __c)
18953e519524SHoward Hinnant{
18963e519524SHoward Hinnant    return __c.begin();
18973e519524SHoward Hinnant}
18983e519524SHoward Hinnant
1899c003db1fSHoward Hinnanttemplate <class _Cp>
19002ffa1705SMarshall Clow_LIBCPP_INLINE_VISIBILITY
1901c003db1fSHoward Hinnanttypename _Cp::const_iterator
1902c003db1fSHoward Hinnantbegin(const _Cp& __c)
19033e519524SHoward Hinnant{
19043e519524SHoward Hinnant    return __c.begin();
19053e519524SHoward Hinnant}
19063e519524SHoward Hinnant
1907c003db1fSHoward Hinnanttemplate <class _Cp>
19082ffa1705SMarshall Clow_LIBCPP_INLINE_VISIBILITY
1909c003db1fSHoward Hinnanttypename _Cp::iterator
1910c003db1fSHoward Hinnantend(_Cp& __c)
19113e519524SHoward Hinnant{
19123e519524SHoward Hinnant    return __c.end();
19133e519524SHoward Hinnant}
19143e519524SHoward Hinnant
1915c003db1fSHoward Hinnanttemplate <class _Cp>
19162ffa1705SMarshall Clow_LIBCPP_INLINE_VISIBILITY
1917c003db1fSHoward Hinnanttypename _Cp::const_iterator
1918c003db1fSHoward Hinnantend(const _Cp& __c)
19193e519524SHoward Hinnant{
19203e519524SHoward Hinnant    return __c.end();
19213e519524SHoward Hinnant}
19223e519524SHoward Hinnant
192354613ab4SEric Fiselier#endif  // !defined(_LIBCPP_CXX03_LANG)
19243e519524SHoward Hinnant
1925ad755104SMarshall Clow#if _LIBCPP_STD_VER > 14
1926d1dcda19SMarshall Clow
1927d1dcda19SMarshall Clow// #if _LIBCPP_STD_VER > 11
1928d1dcda19SMarshall Clow// template <>
1929d1dcda19SMarshall Clow// struct _LIBCPP_TEMPLATE_VIS plus<void>
1930d1dcda19SMarshall Clow// {
1931d1dcda19SMarshall Clow//     template <class _T1, class _T2>
1932d1dcda19SMarshall Clow//     _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
1933d1dcda19SMarshall Clow//     auto operator()(_T1&& __t, _T2&& __u) const
1934d1dcda19SMarshall Clow//     _NOEXCEPT_(noexcept(_VSTD::forward<_T1>(__t) + _VSTD::forward<_T2>(__u)))
1935d1dcda19SMarshall Clow//     -> decltype        (_VSTD::forward<_T1>(__t) + _VSTD::forward<_T2>(__u))
1936d1dcda19SMarshall Clow//         { return        _VSTD::forward<_T1>(__t) + _VSTD::forward<_T2>(__u); }
1937d1dcda19SMarshall Clow//     typedef void is_transparent;
1938d1dcda19SMarshall Clow// };
1939d1dcda19SMarshall Clow// #endif
1940d1dcda19SMarshall Clow
194188d21343SMarshall Clowtemplate <class _Cont>
19422ffa1705SMarshall Clow_LIBCPP_INLINE_VISIBILITY
1943d1dcda19SMarshall Clowconstexpr auto size(const _Cont& __c)
1944d1dcda19SMarshall Clow_NOEXCEPT_(noexcept(__c.size()))
1945d1dcda19SMarshall Clow-> decltype        (__c.size())
1946d1dcda19SMarshall Clow{ return            __c.size(); }
1947ad755104SMarshall Clow
194888d21343SMarshall Clowtemplate <class _Tp, size_t _Sz>
19492ffa1705SMarshall Clow_LIBCPP_INLINE_VISIBILITY
1950fd838227SEric Fiselierconstexpr size_t size(const _Tp (&)[_Sz]) noexcept { return _Sz; }
1951ad755104SMarshall Clow
19527d3986eaSMarshall Clow#if _LIBCPP_STD_VER > 17
19537d3986eaSMarshall Clowtemplate <class _Cont>
19542ffa1705SMarshall Clow_LIBCPP_INLINE_VISIBILITY
19557d3986eaSMarshall Clowconstexpr auto ssize(const _Cont& __c)
19567d3986eaSMarshall Clow_NOEXCEPT_(noexcept(static_cast<common_type_t<ptrdiff_t, make_signed_t<decltype(__c.size())>>>(__c.size())))
19577d3986eaSMarshall Clow->                              common_type_t<ptrdiff_t, make_signed_t<decltype(__c.size())>>
19587d3986eaSMarshall Clow{ return            static_cast<common_type_t<ptrdiff_t, make_signed_t<decltype(__c.size())>>>(__c.size()); }
19597d3986eaSMarshall Clow
19607d3986eaSMarshall Clowtemplate <class _Tp, ptrdiff_t _Sz>
19612ffa1705SMarshall Clow_LIBCPP_INLINE_VISIBILITY
19627d3986eaSMarshall Clowconstexpr ptrdiff_t ssize(const _Tp (&)[_Sz]) noexcept { return _Sz; }
19637d3986eaSMarshall Clow#endif
19647d3986eaSMarshall Clow
196588d21343SMarshall Clowtemplate <class _Cont>
19662ffa1705SMarshall Clow_LIBCPP_NODISCARD_AFTER_CXX17 _LIBCPP_INLINE_VISIBILITY
1967d1dcda19SMarshall Clowconstexpr auto empty(const _Cont& __c)
1968d1dcda19SMarshall Clow_NOEXCEPT_(noexcept(__c.empty()))
1969d1dcda19SMarshall Clow-> decltype        (__c.empty())
1970d1dcda19SMarshall Clow{ return            __c.empty(); }
1971ad755104SMarshall Clow
197288d21343SMarshall Clowtemplate <class _Tp, size_t _Sz>
19732ffa1705SMarshall Clow_LIBCPP_NODISCARD_AFTER_CXX17 _LIBCPP_INLINE_VISIBILITY
1974fd838227SEric Fiselierconstexpr bool empty(const _Tp (&)[_Sz]) noexcept { return false; }
1975ad755104SMarshall Clow
1976ad755104SMarshall Clowtemplate <class _Ep>
19772ffa1705SMarshall Clow_LIBCPP_NODISCARD_AFTER_CXX17 _LIBCPP_INLINE_VISIBILITY
1978ad755104SMarshall Clowconstexpr bool empty(initializer_list<_Ep> __il) noexcept { return __il.size() == 0; }
1979ad755104SMarshall Clow
198088d21343SMarshall Clowtemplate <class _Cont> constexpr
19812ffa1705SMarshall Clow_LIBCPP_INLINE_VISIBILITY
1982d1dcda19SMarshall Clowauto data(_Cont& __c)
1983d1dcda19SMarshall Clow_NOEXCEPT_(noexcept(__c.data()))
1984d1dcda19SMarshall Clow-> decltype        (__c.data())
1985d1dcda19SMarshall Clow{ return            __c.data(); }
1986ad755104SMarshall Clow
198788d21343SMarshall Clowtemplate <class _Cont> constexpr
19882ffa1705SMarshall Clow_LIBCPP_INLINE_VISIBILITY
1989d1dcda19SMarshall Clowauto data(const _Cont& __c)
1990d1dcda19SMarshall Clow_NOEXCEPT_(noexcept(__c.data()))
1991d1dcda19SMarshall Clow-> decltype        (__c.data())
1992d1dcda19SMarshall Clow{ return            __c.data(); }
1993ad755104SMarshall Clow
199488d21343SMarshall Clowtemplate <class _Tp, size_t _Sz>
19952ffa1705SMarshall Clow_LIBCPP_INLINE_VISIBILITY
199688d21343SMarshall Clowconstexpr _Tp* data(_Tp (&__array)[_Sz]) noexcept { return __array; }
1997ad755104SMarshall Clow
1998ad755104SMarshall Clowtemplate <class _Ep>
19992ffa1705SMarshall Clow_LIBCPP_INLINE_VISIBILITY
2000ad755104SMarshall Clowconstexpr const _Ep* data(initializer_list<_Ep> __il) noexcept { return __il.begin(); }
2001ad755104SMarshall Clow#endif
2002ad755104SMarshall Clow
2003ad755104SMarshall Clow
20043e519524SHoward Hinnant_LIBCPP_END_NAMESPACE_STD
20053e519524SHoward Hinnant
20063e519524SHoward Hinnant#endif  // _LIBCPP_ITERATOR
2007