13e519524SHoward Hinnant// -*- C++ -*-
23e519524SHoward Hinnant//===-------------------------- iterator ----------------------------------===//
33e519524SHoward Hinnant//
457b08b09SChandler Carruth// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
557b08b09SChandler Carruth// See https://llvm.org/LICENSE.txt for license information.
657b08b09SChandler Carruth// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
73e519524SHoward Hinnant//
83e519524SHoward Hinnant//===----------------------------------------------------------------------===//
93e519524SHoward Hinnant
103e519524SHoward Hinnant#ifndef _LIBCPP_ITERATOR
113e519524SHoward Hinnant#define _LIBCPP_ITERATOR
123e519524SHoward Hinnant
133e519524SHoward Hinnant/*
143e519524SHoward Hinnant    iterator synopsis
153e519524SHoward Hinnant
16fe31f11cSChristopher Di Bella#include <concepts>
17fe31f11cSChristopher Di Bella
183e519524SHoward Hinnantnamespace std
193e519524SHoward Hinnant{
20fe31f11cSChristopher Di Bellatemplate<class> struct incrementable_traits;       // since C++20
21f280505aSChristopher Di Bellatemplate<class> struct indirectly_readable_traits; // since C++20
223e519524SHoward Hinnant
233e519524SHoward Hinnanttemplate<class Iterator>
24*9f01ac3bSzoecarverstruct iterator_traits;
253e519524SHoward Hinnant
263e519524SHoward Hinnanttemplate<class T>
27*9f01ac3bSzoecarver  requires is_object_v<T>                    // since C++20
28*9f01ac3bSzoecarverstruct iterator_traits<T*>;
293e519524SHoward Hinnant
300148b653SChristopher Di Bellatemplate<dereferenceable T>
310148b653SChristopher Di Bella  using iter_reference_t = decltype(*declval<T&>());
320148b653SChristopher Di Bella
333e519524SHoward Hinnanttemplate<class Category, class T, class Distance = ptrdiff_t,
343e519524SHoward Hinnant         class Pointer = T*, class Reference = T&>
353e519524SHoward Hinnantstruct iterator
363e519524SHoward Hinnant{
373e519524SHoward Hinnant    typedef T         value_type;
383e519524SHoward Hinnant    typedef Distance  difference_type;
393e519524SHoward Hinnant    typedef Pointer   pointer;
403e519524SHoward Hinnant    typedef Reference reference;
413e519524SHoward Hinnant    typedef Category  iterator_category;
423e519524SHoward Hinnant};
433e519524SHoward Hinnant
443e519524SHoward Hinnantstruct input_iterator_tag  {};
453e519524SHoward Hinnantstruct output_iterator_tag {};
463e519524SHoward Hinnantstruct forward_iterator_tag       : public input_iterator_tag         {};
473e519524SHoward Hinnantstruct bidirectional_iterator_tag : public forward_iterator_tag       {};
483e519524SHoward Hinnantstruct random_access_iterator_tag : public bidirectional_iterator_tag {};
493e519524SHoward Hinnant
50f51ee632SMarshall Clow// 27.4.3, iterator operations
5112b01ab7SLouis Dionnetemplate <class InputIterator, class Distance>  // constexpr in C++17
5212b01ab7SLouis Dionne  constexpr void advance(InputIterator& i, Distance n);
533e519524SHoward Hinnant
54f51ee632SMarshall Clowtemplate <class InputIterator>  // constexpr in C++17
55f51ee632SMarshall Clow  constexpr typename iterator_traits<InputIterator>::difference_type
563e519524SHoward Hinnant    distance(InputIterator first, InputIterator last);
573e519524SHoward Hinnant
58f51ee632SMarshall Clowtemplate <class InputIterator>  // constexpr in C++17
59f51ee632SMarshall Clow  constexpr InputIterator next(InputIterator x,
60f51ee632SMarshall Clowtypename iterator_traits<InputIterator>::difference_type n = 1);
61f51ee632SMarshall Clow
62f51ee632SMarshall Clowtemplate <class BidirectionalIterator>  // constexpr in C++17
63f51ee632SMarshall Clow  constexpr BidirectionalIterator prev(BidirectionalIterator x,
64f51ee632SMarshall Clow    typename iterator_traits<BidirectionalIterator>::difference_type n = 1);
65f51ee632SMarshall Clow
663e519524SHoward Hinnanttemplate <class Iterator>
673e519524SHoward Hinnantclass reverse_iterator
683e519524SHoward Hinnant    : public iterator<typename iterator_traits<Iterator>::iterator_category,
693e519524SHoward Hinnant                      typename iterator_traits<Iterator>::value_type,
703e519524SHoward Hinnant                      typename iterator_traits<Iterator>::difference_type,
713e519524SHoward Hinnant                      typename iterator_traits<Iterator>::pointer,
723e519524SHoward Hinnant                      typename iterator_traits<Iterator>::reference>
733e519524SHoward Hinnant{
743e519524SHoward Hinnantprotected:
753e519524SHoward Hinnant    Iterator current;
763e519524SHoward Hinnantpublic:
773e519524SHoward Hinnant    typedef Iterator                                            iterator_type;
783e519524SHoward Hinnant    typedef typename iterator_traits<Iterator>::difference_type difference_type;
793e519524SHoward Hinnant    typedef typename iterator_traits<Iterator>::reference       reference;
803e519524SHoward Hinnant    typedef typename iterator_traits<Iterator>::pointer         pointer;
813e519524SHoward Hinnant
821b8f260eSMarshall Clow    constexpr reverse_iterator();
831b8f260eSMarshall Clow    constexpr explicit reverse_iterator(Iterator x);
841b8f260eSMarshall Clow    template <class U> constexpr reverse_iterator(const reverse_iterator<U>& u);
851b8f260eSMarshall Clow    template <class U> constexpr reverse_iterator& operator=(const reverse_iterator<U>& u);
861b8f260eSMarshall Clow    constexpr Iterator base() const;
871b8f260eSMarshall Clow    constexpr reference operator*() const;
881b8f260eSMarshall Clow    constexpr pointer   operator->() const;
891b8f260eSMarshall Clow    constexpr reverse_iterator& operator++();
901b8f260eSMarshall Clow    constexpr reverse_iterator  operator++(int);
911b8f260eSMarshall Clow    constexpr reverse_iterator& operator--();
921b8f260eSMarshall Clow    constexpr reverse_iterator  operator--(int);
931b8f260eSMarshall Clow    constexpr reverse_iterator  operator+ (difference_type n) const;
941b8f260eSMarshall Clow    constexpr reverse_iterator& operator+=(difference_type n);
951b8f260eSMarshall Clow    constexpr reverse_iterator  operator- (difference_type n) const;
961b8f260eSMarshall Clow    constexpr reverse_iterator& operator-=(difference_type n);
971b8f260eSMarshall Clow    constexpr reference         operator[](difference_type n) const;
983e519524SHoward Hinnant};
993e519524SHoward Hinnant
1003e519524SHoward Hinnanttemplate <class Iterator1, class Iterator2>
1011b8f260eSMarshall Clowconstexpr bool                          // constexpr in C++17
1023e519524SHoward Hinnantoperator==(const reverse_iterator<Iterator1>& x, const reverse_iterator<Iterator2>& y);
1033e519524SHoward Hinnant
1043e519524SHoward Hinnanttemplate <class Iterator1, class Iterator2>
1051b8f260eSMarshall Clowconstexpr bool                          // constexpr in C++17
1063e519524SHoward Hinnantoperator<(const reverse_iterator<Iterator1>& x, const reverse_iterator<Iterator2>& y);
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 auto
126947ce6b5SMarshall Clowoperator-(const reverse_iterator<Iterator1>& x, const reverse_iterator<Iterator2>& y)
1271b8f260eSMarshall Clow-> decltype(__y.base() - __x.base());   // constexpr in C++17
1283e519524SHoward Hinnant
1293e519524SHoward Hinnanttemplate <class Iterator>
1301b8f260eSMarshall Clowconstexpr reverse_iterator<Iterator>
1311b8f260eSMarshall Clowoperator+(typename reverse_iterator<Iterator>::difference_type n,
1321b8f260eSMarshall Clow          const reverse_iterator<Iterator>& x);   // constexpr in C++17
1333e519524SHoward Hinnant
1341b8f260eSMarshall Clowtemplate <class Iterator>
1351b8f260eSMarshall Clowconstexpr reverse_iterator<Iterator> make_reverse_iterator(Iterator i); // C++14, constexpr in C++17
1366a640a18SMarshall Clow
1373e519524SHoward Hinnanttemplate <class Container>
1383e519524SHoward Hinnantclass back_insert_iterator
1393e519524SHoward Hinnant{
1403e519524SHoward Hinnantprotected:
1413e519524SHoward Hinnant    Container* container;
1423e519524SHoward Hinnantpublic:
1433e519524SHoward Hinnant    typedef Container                   container_type;
1443e519524SHoward Hinnant    typedef void                        value_type;
1453e519524SHoward Hinnant    typedef void                        difference_type;
1468892b4eeSEric Fiselier    typedef void                        reference;
1473e519524SHoward Hinnant    typedef void                        pointer;
1483e519524SHoward Hinnant
14906e2b737SArthur O'Dwyer    explicit back_insert_iterator(Container& x);  // constexpr in C++20
15006e2b737SArthur O'Dwyer    back_insert_iterator& operator=(const typename Container::value_type& value);  // constexpr in C++20
15106e2b737SArthur O'Dwyer    back_insert_iterator& operator*();  // constexpr in C++20
15206e2b737SArthur O'Dwyer    back_insert_iterator& operator++();  // constexpr in C++20
15306e2b737SArthur O'Dwyer    back_insert_iterator  operator++(int);  // constexpr in C++20
1543e519524SHoward Hinnant};
1553e519524SHoward Hinnant
15606e2b737SArthur O'Dwyertemplate <class Container> back_insert_iterator<Container> back_inserter(Container& x);  // constexpr in C++20
1573e519524SHoward Hinnant
1583e519524SHoward Hinnanttemplate <class Container>
1593e519524SHoward Hinnantclass front_insert_iterator
1603e519524SHoward Hinnant{
1613e519524SHoward Hinnantprotected:
1623e519524SHoward Hinnant    Container* container;
1633e519524SHoward Hinnantpublic:
1643e519524SHoward Hinnant    typedef Container                    container_type;
1653e519524SHoward Hinnant    typedef void                         value_type;
1663e519524SHoward Hinnant    typedef void                         difference_type;
1678892b4eeSEric Fiselier    typedef void                         reference;
1683e519524SHoward Hinnant    typedef void                         pointer;
1693e519524SHoward Hinnant
17006e2b737SArthur O'Dwyer    explicit front_insert_iterator(Container& x);  // constexpr in C++20
17106e2b737SArthur O'Dwyer    front_insert_iterator& operator=(const typename Container::value_type& value);  // constexpr in C++20
17206e2b737SArthur O'Dwyer    front_insert_iterator& operator*();  // constexpr in C++20
17306e2b737SArthur O'Dwyer    front_insert_iterator& operator++();  // constexpr in C++20
17406e2b737SArthur O'Dwyer    front_insert_iterator  operator++(int);  // constexpr in C++20
1753e519524SHoward Hinnant};
1763e519524SHoward Hinnant
17706e2b737SArthur O'Dwyertemplate <class Container> front_insert_iterator<Container> front_inserter(Container& x);  // constexpr in C++20
1783e519524SHoward Hinnant
1793e519524SHoward Hinnanttemplate <class Container>
1803e519524SHoward Hinnantclass insert_iterator
1813e519524SHoward Hinnant{
1823e519524SHoward Hinnantprotected:
1833e519524SHoward Hinnant    Container* container;
1843e519524SHoward Hinnant    typename Container::iterator iter;
1853e519524SHoward Hinnantpublic:
1863e519524SHoward Hinnant    typedef Container              container_type;
1873e519524SHoward Hinnant    typedef void                   value_type;
1883e519524SHoward Hinnant    typedef void                   difference_type;
1898892b4eeSEric Fiselier    typedef void                   reference;
1903e519524SHoward Hinnant    typedef void                   pointer;
1913e519524SHoward Hinnant
19206e2b737SArthur O'Dwyer    insert_iterator(Container& x, typename Container::iterator i);  // constexpr in C++20
19306e2b737SArthur O'Dwyer    insert_iterator& operator=(const typename Container::value_type& value);  // constexpr in C++20
19406e2b737SArthur O'Dwyer    insert_iterator& operator*();  // constexpr in C++20
19506e2b737SArthur O'Dwyer    insert_iterator& operator++();  // constexpr in C++20
19606e2b737SArthur O'Dwyer    insert_iterator& operator++(int);  // constexpr in C++20
1973e519524SHoward Hinnant};
1983e519524SHoward Hinnant
1993e519524SHoward Hinnanttemplate <class Container, class Iterator>
20006e2b737SArthur O'Dwyerinsert_iterator<Container> inserter(Container& x, Iterator i);  // constexpr in C++20
2013e519524SHoward Hinnant
202947ce6b5SMarshall Clowtemplate <class Iterator>
203947ce6b5SMarshall Clowclass move_iterator {
204947ce6b5SMarshall Clowpublic:
205947ce6b5SMarshall Clow    typedef Iterator                                              iterator_type;
206947ce6b5SMarshall Clow    typedef typename iterator_traits<Iterator>::difference_type   difference_type;
207947ce6b5SMarshall Clow    typedef Iterator                                              pointer;
208947ce6b5SMarshall Clow    typedef typename iterator_traits<Iterator>::value_type        value_type;
209947ce6b5SMarshall Clow    typedef typename iterator_traits<Iterator>::iterator_category iterator_category;
210947ce6b5SMarshall Clow    typedef value_type&&                                          reference;
211947ce6b5SMarshall Clow
212720ef472SMarshall Clow    constexpr move_iterator();  // all the constexprs are in C++17
213720ef472SMarshall Clow    constexpr explicit move_iterator(Iterator i);
214720ef472SMarshall Clow    template <class U>
215720ef472SMarshall Clow      constexpr move_iterator(const move_iterator<U>& u);
216720ef472SMarshall Clow    template <class U>
217720ef472SMarshall Clow      constexpr move_iterator& operator=(const move_iterator<U>& u);
218720ef472SMarshall Clow    constexpr iterator_type base() const;
219720ef472SMarshall Clow    constexpr reference operator*() const;
220720ef472SMarshall Clow    constexpr pointer operator->() const;
221720ef472SMarshall Clow    constexpr move_iterator& operator++();
222720ef472SMarshall Clow    constexpr move_iterator operator++(int);
223720ef472SMarshall Clow    constexpr move_iterator& operator--();
224720ef472SMarshall Clow    constexpr move_iterator operator--(int);
225720ef472SMarshall Clow    constexpr move_iterator operator+(difference_type n) const;
226720ef472SMarshall Clow    constexpr move_iterator& operator+=(difference_type n);
227720ef472SMarshall Clow    constexpr move_iterator operator-(difference_type n) const;
228720ef472SMarshall Clow    constexpr move_iterator& operator-=(difference_type n);
229720ef472SMarshall Clow    constexpr unspecified operator[](difference_type n) const;
230947ce6b5SMarshall Clowprivate:
231947ce6b5SMarshall Clow    Iterator current; // exposition only
232947ce6b5SMarshall Clow};
233947ce6b5SMarshall Clow
234947ce6b5SMarshall Clowtemplate <class Iterator1, class Iterator2>
235720ef472SMarshall Clowconstexpr bool   // constexpr in C++17
236947ce6b5SMarshall Clowoperator==(const move_iterator<Iterator1>& x, const move_iterator<Iterator2>& y);
237947ce6b5SMarshall Clow
238947ce6b5SMarshall Clowtemplate <class Iterator1, class Iterator2>
239720ef472SMarshall Clowconstexpr bool   // constexpr in C++17
240947ce6b5SMarshall Clowoperator!=(const move_iterator<Iterator1>& x, const move_iterator<Iterator2>& y);
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 auto   // constexpr in C++17
260947ce6b5SMarshall Clowoperator-(const move_iterator<Iterator1>& x,
261947ce6b5SMarshall Clow          const move_iterator<Iterator2>& y) -> decltype(x.base() - y.base());
262947ce6b5SMarshall Clow
263947ce6b5SMarshall Clowtemplate <class Iterator>
264720ef472SMarshall Clowconstexpr move_iterator<Iterator> operator+(   // constexpr in C++17
265720ef472SMarshall Clow            typename move_iterator<Iterator>::difference_type n,
266947ce6b5SMarshall Clow            const move_iterator<Iterator>& x);
267947ce6b5SMarshall Clow
268720ef472SMarshall Clowtemplate <class Iterator>   // constexpr in C++17
269720ef472SMarshall Clowconstexpr  move_iterator<Iterator> make_move_iterator(const Iterator& i);
270947ce6b5SMarshall Clow
271947ce6b5SMarshall Clow
2723e519524SHoward Hinnanttemplate <class T, class charT = char, class traits = char_traits<charT>, class Distance = ptrdiff_t>
2733e519524SHoward Hinnantclass istream_iterator
2743e519524SHoward Hinnant    : public iterator<input_iterator_tag, T, Distance, const T*, const T&>
2753e519524SHoward Hinnant{
2763e519524SHoward Hinnantpublic:
2773e519524SHoward Hinnant    typedef charT char_type;
2783e519524SHoward Hinnant    typedef traits traits_type;
2793e519524SHoward Hinnant    typedef basic_istream<charT,traits> istream_type;
2803e519524SHoward Hinnant
28160d5e0e0SMarshall Clow    constexpr istream_iterator();
2823e519524SHoward Hinnant    istream_iterator(istream_type& s);
2833e519524SHoward Hinnant    istream_iterator(const istream_iterator& x);
2843e519524SHoward Hinnant    ~istream_iterator();
2853e519524SHoward Hinnant
2863e519524SHoward Hinnant    const T& operator*() const;
2873e519524SHoward Hinnant    const T* operator->() const;
2883e519524SHoward Hinnant    istream_iterator& operator++();
2893e519524SHoward Hinnant    istream_iterator  operator++(int);
2903e519524SHoward Hinnant};
2913e519524SHoward Hinnant
2923e519524SHoward Hinnanttemplate <class T, class charT, class traits, class Distance>
2933e519524SHoward Hinnantbool operator==(const istream_iterator<T,charT,traits,Distance>& x,
2943e519524SHoward Hinnant                const istream_iterator<T,charT,traits,Distance>& y);
2953e519524SHoward Hinnanttemplate <class T, class charT, class traits, class Distance>
2963e519524SHoward Hinnantbool operator!=(const istream_iterator<T,charT,traits,Distance>& x,
2973e519524SHoward Hinnant                const istream_iterator<T,charT,traits,Distance>& y);
2983e519524SHoward Hinnant
2993e519524SHoward Hinnanttemplate <class T, class charT = char, class traits = char_traits<charT> >
3003e519524SHoward Hinnantclass ostream_iterator
3013e519524SHoward Hinnant    : public iterator<output_iterator_tag, void, void, void ,void>
3023e519524SHoward Hinnant{
3033e519524SHoward Hinnantpublic:
3043e519524SHoward Hinnant    typedef charT char_type;
3053e519524SHoward Hinnant    typedef traits traits_type;
3063e519524SHoward Hinnant    typedef basic_ostream<charT,traits> ostream_type;
3073e519524SHoward Hinnant
3083e519524SHoward Hinnant    ostream_iterator(ostream_type& s);
3093e519524SHoward Hinnant    ostream_iterator(ostream_type& s, const charT* delimiter);
3103e519524SHoward Hinnant    ostream_iterator(const ostream_iterator& x);
3113e519524SHoward Hinnant    ~ostream_iterator();
3123e519524SHoward Hinnant    ostream_iterator& operator=(const T& value);
3133e519524SHoward Hinnant
3143e519524SHoward Hinnant    ostream_iterator& operator*();
3153e519524SHoward Hinnant    ostream_iterator& operator++();
3163e519524SHoward Hinnant    ostream_iterator& operator++(int);
3173e519524SHoward Hinnant};
3183e519524SHoward Hinnant
3193e519524SHoward Hinnanttemplate<class charT, class traits = char_traits<charT> >
3203e519524SHoward Hinnantclass istreambuf_iterator
3213e519524SHoward Hinnant    : public iterator<input_iterator_tag, charT,
3223e519524SHoward Hinnant                      typename traits::off_type, unspecified,
3233e519524SHoward Hinnant                      charT>
3243e519524SHoward Hinnant{
3253e519524SHoward Hinnantpublic:
3263e519524SHoward Hinnant    typedef charT                         char_type;
3273e519524SHoward Hinnant    typedef traits                        traits_type;
3283e519524SHoward Hinnant    typedef typename traits::int_type     int_type;
3293e519524SHoward Hinnant    typedef basic_streambuf<charT,traits> streambuf_type;
3303e519524SHoward Hinnant    typedef basic_istream<charT,traits>   istream_type;
3313e519524SHoward Hinnant
3328e882dcbSHoward Hinnant    istreambuf_iterator() noexcept;
3338e882dcbSHoward Hinnant    istreambuf_iterator(istream_type& s) noexcept;
3348e882dcbSHoward Hinnant    istreambuf_iterator(streambuf_type* s) noexcept;
3358e882dcbSHoward Hinnant    istreambuf_iterator(a-private-type) noexcept;
3363e519524SHoward Hinnant
3373e519524SHoward Hinnant    charT                operator*() const;
3383e519524SHoward Hinnant    pointer operator->() const;
3393e519524SHoward Hinnant    istreambuf_iterator& operator++();
3403e519524SHoward Hinnant    a-private-type       operator++(int);
3413e519524SHoward Hinnant
3423e519524SHoward Hinnant    bool equal(const istreambuf_iterator& b) const;
3433e519524SHoward Hinnant};
3443e519524SHoward Hinnant
3453e519524SHoward Hinnanttemplate <class charT, class traits>
3463e519524SHoward Hinnantbool operator==(const istreambuf_iterator<charT,traits>& a,
3473e519524SHoward Hinnant                const istreambuf_iterator<charT,traits>& b);
3483e519524SHoward Hinnanttemplate <class charT, class traits>
3493e519524SHoward Hinnantbool operator!=(const istreambuf_iterator<charT,traits>& a,
3503e519524SHoward Hinnant                const istreambuf_iterator<charT,traits>& b);
3513e519524SHoward Hinnant
3523e519524SHoward Hinnanttemplate <class charT, class traits = char_traits<charT> >
3533e519524SHoward Hinnantclass ostreambuf_iterator
3543e519524SHoward Hinnant    : public iterator<output_iterator_tag, void, void, void, void>
3553e519524SHoward Hinnant{
3563e519524SHoward Hinnantpublic:
3573e519524SHoward Hinnant    typedef charT                         char_type;
3583e519524SHoward Hinnant    typedef traits                        traits_type;
3593e519524SHoward Hinnant    typedef basic_streambuf<charT,traits> streambuf_type;
3603e519524SHoward Hinnant    typedef basic_ostream<charT,traits>   ostream_type;
3613e519524SHoward Hinnant
3628e882dcbSHoward Hinnant    ostreambuf_iterator(ostream_type& s) noexcept;
3638e882dcbSHoward Hinnant    ostreambuf_iterator(streambuf_type* s) noexcept;
3643e519524SHoward Hinnant    ostreambuf_iterator& operator=(charT c);
3653e519524SHoward Hinnant    ostreambuf_iterator& operator*();
3663e519524SHoward Hinnant    ostreambuf_iterator& operator++();
3673e519524SHoward Hinnant    ostreambuf_iterator& operator++(int);
3688e882dcbSHoward Hinnant    bool failed() const noexcept;
3693e519524SHoward Hinnant};
3703e519524SHoward Hinnant
371020b623aSMarshall Clowtemplate <class C> constexpr auto begin(C& c) -> decltype(c.begin());
372020b623aSMarshall Clowtemplate <class C> constexpr auto begin(const C& c) -> decltype(c.begin());
373020b623aSMarshall Clowtemplate <class C> constexpr auto end(C& c) -> decltype(c.end());
374020b623aSMarshall Clowtemplate <class C> constexpr auto end(const C& c) -> decltype(c.end());
375020b623aSMarshall Clowtemplate <class T, size_t N> constexpr T* begin(T (&array)[N]);
376020b623aSMarshall Clowtemplate <class T, size_t N> constexpr T* end(T (&array)[N]);
3773e519524SHoward Hinnant
378020b623aSMarshall Clowtemplate <class C> auto constexpr cbegin(const C& c) -> decltype(std::begin(c));        // C++14
379020b623aSMarshall Clowtemplate <class C> auto constexpr cend(const C& c) -> decltype(std::end(c));            // C++14
380020b623aSMarshall Clowtemplate <class C> auto constexpr rbegin(C& c) -> decltype(c.rbegin());                 // C++14
381020b623aSMarshall Clowtemplate <class C> auto constexpr rbegin(const C& c) -> decltype(c.rbegin());           // C++14
382020b623aSMarshall Clowtemplate <class C> auto constexpr rend(C& c) -> decltype(c.rend());                     // C++14
383020b623aSMarshall Clowtemplate <class C> constexpr auto rend(const C& c) -> decltype(c.rend());               // C++14
384020b623aSMarshall Clowtemplate <class E> reverse_iterator<const E*> constexpr rbegin(initializer_list<E> il); // C++14
385020b623aSMarshall Clowtemplate <class E> reverse_iterator<const E*> constexpr rend(initializer_list<E> il);   // C++14
386020b623aSMarshall Clowtemplate <class T, size_t N> reverse_iterator<T*> constexpr rbegin(T (&array)[N]);      // C++14
387020b623aSMarshall Clowtemplate <class T, size_t N> reverse_iterator<T*> constexpr rend(T (&array)[N]);        // C++14
388020b623aSMarshall Clowtemplate <class C> constexpr auto crbegin(const C& c) -> decltype(std::rbegin(c));      // C++14
389020b623aSMarshall Clowtemplate <class C> constexpr auto crend(const C& c) -> decltype(std::rend(c));          // C++14
3901e548c72SMarshall Clow
391ad755104SMarshall Clow// 24.8, container access:
392ad755104SMarshall Clowtemplate <class C> constexpr auto size(const C& c) -> decltype(c.size());         // C++17
393ad755104SMarshall Clowtemplate <class T, size_t N> constexpr size_t size(const T (&array)[N]) noexcept; // C++17
3947d3986eaSMarshall Clow
3957d3986eaSMarshall Clowtemplate <class C> constexpr auto ssize(const C& c)
3967d3986eaSMarshall Clow    -> common_type_t<ptrdiff_t, make_signed_t<decltype(c.size())>>;                    // C++20
3977d3986eaSMarshall Clowtemplate <class T, ptrdiff_t> constexpr ptrdiff_t ssize(const T (&array)[N]) noexcept; // C++20
3987d3986eaSMarshall Clow
399ad755104SMarshall Clowtemplate <class C> constexpr auto empty(const C& c) -> decltype(c.empty());       // C++17
400ad755104SMarshall Clowtemplate <class T, size_t N> constexpr bool empty(const T (&array)[N]) noexcept;  // C++17
401ad755104SMarshall Clowtemplate <class E> constexpr bool empty(initializer_list<E> il) noexcept;         // C++17
402ad755104SMarshall Clowtemplate <class C> constexpr auto data(C& c) -> decltype(c.data());               // C++17
403ad755104SMarshall Clowtemplate <class C> constexpr auto data(const C& c) -> decltype(c.data());         // C++17
404ad755104SMarshall Clowtemplate <class T, size_t N> constexpr T* data(T (&array)[N]) noexcept;           // C++17
405ad755104SMarshall Clowtemplate <class E> constexpr const E* data(initializer_list<E> il) noexcept;      // C++17
406ad755104SMarshall Clow
4073e519524SHoward Hinnant}  // std
4083e519524SHoward Hinnant
4093e519524SHoward Hinnant*/
4103e519524SHoward Hinnant
4113e519524SHoward Hinnant#include <__config>
41239c193b1SEric Fiselier#include <iosfwd> // for forward declarations of vector and string.
413c204c130SMarshall Clow#include <__functional_base>
4143e519524SHoward Hinnant#include <type_traits>
4152d0f1fa4SArthur O'Dwyer#include <compare>
4162d0f1fa4SArthur O'Dwyer#include <concepts>
4173e519524SHoward Hinnant#include <cstddef>
4181e548c72SMarshall Clow#include <initializer_list>
419e0adf7e0Szoecarver#include <__iterator/incrementable_traits.h>
420e0adf7e0Szoecarver#include <__iterator/readable_traits.h>
421f992cfbaSLouis Dionne#include <__memory/addressof.h>
422d41c6d51SArthur O'Dwyer#include <__memory/pointer_traits.h>
423f56972e2SMarshall Clow#include <version>
424b5c63a2eSHoward Hinnant
42542a3046eSHoward Hinnant#include <__debug>
4263e519524SHoward Hinnant
427073458b1SHoward Hinnant#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
4283e519524SHoward Hinnant#pragma GCC system_header
429073458b1SHoward Hinnant#endif
4303e519524SHoward Hinnant
4313e519524SHoward Hinnant_LIBCPP_BEGIN_NAMESPACE_STD
432fe31f11cSChristopher Di Bella
433fe31f11cSChristopher Di Bella#if !defined(_LIBCPP_HAS_NO_RANGES)
4340148b653SChristopher Di Bella
4350148b653SChristopher Di Bella// [iterator.traits]
4360148b653SChristopher Di Bellatemplate<__dereferenceable _Tp>
4370148b653SChristopher Di Bellausing iter_reference_t = decltype(*declval<_Tp&>());
438fe31f11cSChristopher Di Bella#endif // !defined(_LIBCPP_HAS_NO_RANGES)
439fe31f11cSChristopher Di Bella
4406624fcbaSEric Fiseliertemplate <class _Iter>
4416624fcbaSEric Fiselierstruct _LIBCPP_TEMPLATE_VIS iterator_traits;
4423e519524SHoward Hinnant
443e2f2d1edSEric Fiselierstruct _LIBCPP_TEMPLATE_VIS input_iterator_tag {};
444e2f2d1edSEric Fiselierstruct _LIBCPP_TEMPLATE_VIS output_iterator_tag {};
445e2f2d1edSEric Fiselierstruct _LIBCPP_TEMPLATE_VIS forward_iterator_tag       : public input_iterator_tag {};
446e2f2d1edSEric Fiselierstruct _LIBCPP_TEMPLATE_VIS bidirectional_iterator_tag : public forward_iterator_tag {};
447e2f2d1edSEric Fiselierstruct _LIBCPP_TEMPLATE_VIS random_access_iterator_tag : public bidirectional_iterator_tag {};
44845d048c2SEric Fiselier#if _LIBCPP_STD_VER > 17
44945d048c2SEric Fiselierstruct _LIBCPP_TEMPLATE_VIS contiguous_iterator_tag    : public random_access_iterator_tag {};
45045d048c2SEric Fiselier#endif
4513e519524SHoward Hinnant
4526624fcbaSEric Fiseliertemplate <class _Iter>
4536624fcbaSEric Fiselierstruct __iter_traits_cache {
4546624fcbaSEric Fiselier  using type = _If<
4556624fcbaSEric Fiselier    __is_primary_template<iterator_traits<_Iter> >::value,
4566624fcbaSEric Fiselier    _Iter,
4576624fcbaSEric Fiselier    iterator_traits<_Iter>
4586624fcbaSEric Fiselier  >;
4596624fcbaSEric Fiselier};
4606624fcbaSEric Fiseliertemplate <class _Iter>
4616624fcbaSEric Fiselierusing _ITER_TRAITS = typename __iter_traits_cache<_Iter>::type;
4626624fcbaSEric Fiselier
4636624fcbaSEric Fiselierstruct __iter_concept_concept_test {
4646624fcbaSEric Fiselier  template <class _Iter>
4656624fcbaSEric Fiselier  using _Apply = typename _ITER_TRAITS<_Iter>::iterator_concept;
4666624fcbaSEric Fiselier};
4676624fcbaSEric Fiselierstruct __iter_concept_category_test {
4686624fcbaSEric Fiselier  template <class _Iter>
4696624fcbaSEric Fiselier  using _Apply = typename _ITER_TRAITS<_Iter>::iterator_category;
4706624fcbaSEric Fiselier};
4716624fcbaSEric Fiselierstruct __iter_concept_random_fallback {
4726624fcbaSEric Fiselier  template <class _Iter>
4736624fcbaSEric Fiselier  using _Apply = _EnableIf<
4746624fcbaSEric Fiselier                          __is_primary_template<iterator_traits<_Iter> >::value,
4756624fcbaSEric Fiselier                          random_access_iterator_tag
4766624fcbaSEric Fiselier                        >;
4776624fcbaSEric Fiselier};
4786624fcbaSEric Fiselier
4796624fcbaSEric Fiseliertemplate <class _Iter, class _Tester> struct __test_iter_concept
4806624fcbaSEric Fiselier    : _IsValidExpansion<_Tester::template _Apply, _Iter>,
4816624fcbaSEric Fiselier      _Tester
4826624fcbaSEric Fiselier{
4836624fcbaSEric Fiselier};
4846624fcbaSEric Fiselier
4856624fcbaSEric Fiseliertemplate <class _Iter>
4866624fcbaSEric Fiselierstruct __iter_concept_cache {
4876624fcbaSEric Fiselier  using type = _Or<
4886624fcbaSEric Fiselier    __test_iter_concept<_Iter, __iter_concept_concept_test>,
4896624fcbaSEric Fiselier    __test_iter_concept<_Iter, __iter_concept_category_test>,
4906624fcbaSEric Fiselier    __test_iter_concept<_Iter, __iter_concept_random_fallback>
4916624fcbaSEric Fiselier  >;
4926624fcbaSEric Fiselier};
4936624fcbaSEric Fiselier
4946624fcbaSEric Fiseliertemplate <class _Iter>
4956624fcbaSEric Fiselierusing _ITER_CONCEPT = typename __iter_concept_cache<_Iter>::type::template _Apply<_Iter>;
4966624fcbaSEric Fiselier
4976624fcbaSEric Fiselier
4983e519524SHoward Hinnanttemplate <class _Tp>
499d4fa0381SMarshall Clowstruct __has_iterator_typedefs
500d4fa0381SMarshall Clow{
501d4fa0381SMarshall Clowprivate:
502d4fa0381SMarshall Clow    struct __two {char __lx; char __lxx;};
503d4fa0381SMarshall Clow    template <class _Up> static __two __test(...);
504d586f92cSArthur O'Dwyer    template <class _Up> static char __test(typename __void_t<typename _Up::iterator_category>::type* = 0,
505d586f92cSArthur O'Dwyer                                            typename __void_t<typename _Up::difference_type>::type* = 0,
506d586f92cSArthur O'Dwyer                                            typename __void_t<typename _Up::value_type>::type* = 0,
507d586f92cSArthur O'Dwyer                                            typename __void_t<typename _Up::reference>::type* = 0,
508d586f92cSArthur O'Dwyer                                            typename __void_t<typename _Up::pointer>::type* = 0);
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(...);
520527a7fdfSBruce Mitchener    template <class _Up> static char __test(typename _Up::iterator_category* = nullptr);
5213e519524SHoward Hinnantpublic:
522527a7fdfSBruce Mitchener    static const bool value = sizeof(__test<_Tp>(nullptr)) == 1;
5233e519524SHoward Hinnant};
5243e519524SHoward Hinnant
525d41c6d51SArthur O'Dwyertemplate <class _Tp>
526d41c6d51SArthur O'Dwyerstruct __has_iterator_concept
527d41c6d51SArthur O'Dwyer{
528d41c6d51SArthur O'Dwyerprivate:
529d41c6d51SArthur O'Dwyer    struct __two {char __lx; char __lxx;};
530d41c6d51SArthur O'Dwyer    template <class _Up> static __two __test(...);
531d41c6d51SArthur O'Dwyer    template <class _Up> static char __test(typename _Up::iterator_concept* = nullptr);
532d41c6d51SArthur O'Dwyerpublic:
533d41c6d51SArthur O'Dwyer    static const bool value = sizeof(__test<_Tp>(nullptr)) == 1;
534d41c6d51SArthur O'Dwyer};
535d41c6d51SArthur O'Dwyer
5360148b653SChristopher Di Bella#if !defined(_LIBCPP_HAS_NO_RANGES)
5370148b653SChristopher Di Bella
5380148b653SChristopher Di Bella// The `cpp17-*-iterator` exposition-only concepts are easily confused with the Cpp17*Iterator tables,
5390148b653SChristopher Di Bella// so they've been banished to a namespace that makes it obvious they have a niche use-case.
5400148b653SChristopher Di Bellanamespace __iterator_traits_detail {
5410148b653SChristopher Di Bellatemplate<class _Ip>
5420148b653SChristopher Di Bellaconcept __cpp17_iterator =
5430148b653SChristopher Di Bella  requires(_Ip __i) {
5440148b653SChristopher Di Bella    {   *__i } -> __referenceable;
5450148b653SChristopher Di Bella    {  ++__i } -> same_as<_Ip&>;
5460148b653SChristopher Di Bella    { *__i++ } -> __referenceable;
5470148b653SChristopher Di Bella  } &&
5480148b653SChristopher Di Bella  copyable<_Ip>;
5490148b653SChristopher Di Bella
5500148b653SChristopher Di Bellatemplate<class _Ip>
5510148b653SChristopher Di Bellaconcept __cpp17_input_iterator =
5520148b653SChristopher Di Bella  __cpp17_iterator<_Ip> &&
5530148b653SChristopher Di Bella  equality_comparable<_Ip> &&
5540148b653SChristopher Di Bella  requires(_Ip __i) {
5550148b653SChristopher Di Bella    typename incrementable_traits<_Ip>::difference_type;
5560148b653SChristopher Di Bella    typename indirectly_readable_traits<_Ip>::value_type;
5570148b653SChristopher Di Bella    typename common_reference_t<iter_reference_t<_Ip>&&,
5580148b653SChristopher Di Bella                                typename indirectly_readable_traits<_Ip>::value_type&>;
5590148b653SChristopher Di Bella    typename common_reference_t<decltype(*__i++)&&,
5600148b653SChristopher Di Bella                                typename indirectly_readable_traits<_Ip>::value_type&>;
5610148b653SChristopher Di Bella    requires signed_integral<typename incrementable_traits<_Ip>::difference_type>;
5620148b653SChristopher Di Bella  };
5630148b653SChristopher Di Bella
5640148b653SChristopher Di Bellatemplate<class _Ip>
5650148b653SChristopher Di Bellaconcept __cpp17_forward_iterator =
5660148b653SChristopher Di Bella  __cpp17_input_iterator<_Ip> &&
5670148b653SChristopher Di Bella  constructible_from<_Ip> &&
5680148b653SChristopher Di Bella  is_lvalue_reference_v<iter_reference_t<_Ip>> &&
5690148b653SChristopher Di Bella  same_as<remove_cvref_t<iter_reference_t<_Ip>>,
5700148b653SChristopher Di Bella          typename indirectly_readable_traits<_Ip>::value_type> &&
5710148b653SChristopher Di Bella  requires(_Ip __i) {
5720148b653SChristopher Di Bella    {  __i++ } -> convertible_to<_Ip const&>;
5730148b653SChristopher Di Bella    { *__i++ } -> same_as<iter_reference_t<_Ip>>;
5740148b653SChristopher Di Bella  };
5750148b653SChristopher Di Bella
5760148b653SChristopher Di Bellatemplate<class _Ip>
5770148b653SChristopher Di Bellaconcept __cpp17_bidirectional_iterator =
5780148b653SChristopher Di Bella  __cpp17_forward_iterator<_Ip> &&
5790148b653SChristopher Di Bella  requires(_Ip __i) {
5800148b653SChristopher Di Bella    {  --__i } -> same_as<_Ip&>;
5810148b653SChristopher Di Bella    {  __i-- } -> convertible_to<_Ip const&>;
5820148b653SChristopher Di Bella    { *__i-- } -> same_as<iter_reference_t<_Ip>>;
5830148b653SChristopher Di Bella  };
5840148b653SChristopher Di Bella
5850148b653SChristopher Di Bellatemplate<class _Ip>
5860148b653SChristopher Di Bellaconcept __cpp17_random_access_iterator =
5870148b653SChristopher Di Bella  __cpp17_bidirectional_iterator<_Ip> and
5880148b653SChristopher Di Bella  totally_ordered<_Ip> and
5890148b653SChristopher Di Bella  requires(_Ip __i, typename incrementable_traits<_Ip>::difference_type __n) {
5900148b653SChristopher Di Bella    { __i += __n } -> same_as<_Ip&>;
5910148b653SChristopher Di Bella    { __i -= __n } -> same_as<_Ip&>;
5920148b653SChristopher Di Bella    { __i +  __n } -> same_as<_Ip>;
5930148b653SChristopher Di Bella    { __n +  __i } -> same_as<_Ip>;
5940148b653SChristopher Di Bella    { __i -  __n } -> same_as<_Ip>;
5950148b653SChristopher Di Bella    { __i -  __i } -> same_as<decltype(__n)>;
5960148b653SChristopher Di Bella    {  __i[__n]  } -> convertible_to<iter_reference_t<_Ip>>;
5970148b653SChristopher Di Bella  };
5980148b653SChristopher Di Bella} // namespace __iterator_traits_detail
599*9f01ac3bSzoecarver
600*9f01ac3bSzoecarvertemplate<class _Ip>
601*9f01ac3bSzoecarverconcept __has_member_reference = requires { typename _Ip::reference; };
602*9f01ac3bSzoecarver
603*9f01ac3bSzoecarvertemplate<class _Ip>
604*9f01ac3bSzoecarverconcept __has_member_pointer = requires { typename _Ip::pointer; };
605*9f01ac3bSzoecarver
606*9f01ac3bSzoecarvertemplate<class _Ip>
607*9f01ac3bSzoecarverconcept __has_member_iterator_category = requires { typename _Ip::iterator_category; };
608*9f01ac3bSzoecarver
609*9f01ac3bSzoecarvertemplate<class _Ip>
610*9f01ac3bSzoecarverconcept __specifies_members = requires {
611*9f01ac3bSzoecarver    typename _Ip::value_type;
612*9f01ac3bSzoecarver    typename _Ip::difference_type;
613*9f01ac3bSzoecarver    requires __has_member_reference<_Ip>;
614*9f01ac3bSzoecarver    requires __has_member_iterator_category<_Ip>;
615*9f01ac3bSzoecarver  };
616*9f01ac3bSzoecarver
617*9f01ac3bSzoecarvertemplate<class>
618*9f01ac3bSzoecarverstruct __iterator_traits_member_pointer_or_void {
619*9f01ac3bSzoecarver  using type = void;
620*9f01ac3bSzoecarver};
621*9f01ac3bSzoecarver
622*9f01ac3bSzoecarvertemplate<__has_member_pointer _Tp>
623*9f01ac3bSzoecarverstruct __iterator_traits_member_pointer_or_void<_Tp> {
624*9f01ac3bSzoecarver  using type = typename _Tp::pointer;
625*9f01ac3bSzoecarver};
626*9f01ac3bSzoecarver
627*9f01ac3bSzoecarvertemplate<class _Tp>
628*9f01ac3bSzoecarverconcept __cpp17_iterator_missing_members =
629*9f01ac3bSzoecarver  !__specifies_members<_Tp> &&
630*9f01ac3bSzoecarver  __iterator_traits_detail::__cpp17_iterator<_Tp>;
631*9f01ac3bSzoecarver
632*9f01ac3bSzoecarvertemplate<class _Tp>
633*9f01ac3bSzoecarverconcept __cpp17_input_iterator_missing_members =
634*9f01ac3bSzoecarver  __cpp17_iterator_missing_members<_Tp> &&
635*9f01ac3bSzoecarver  __iterator_traits_detail::__cpp17_input_iterator<_Tp>;
636*9f01ac3bSzoecarver
637*9f01ac3bSzoecarver// Otherwise, `pointer` names `void`.
638*9f01ac3bSzoecarvertemplate<class>
639*9f01ac3bSzoecarverstruct __iterator_traits_member_pointer_or_arrow_or_void { using type = void; };
640*9f01ac3bSzoecarver
641*9f01ac3bSzoecarver// [iterator.traits]/3.2.1
642*9f01ac3bSzoecarver// If the qualified-id `I::pointer` is valid and denotes a type, `pointer` names that type.
643*9f01ac3bSzoecarvertemplate<__has_member_pointer _Ip>
644*9f01ac3bSzoecarverstruct __iterator_traits_member_pointer_or_arrow_or_void<_Ip> { using type = typename _Ip::pointer; };
645*9f01ac3bSzoecarver
646*9f01ac3bSzoecarver// Otherwise, if `decltype(declval<I&>().operator->())` is well-formed, then `pointer` names that
647*9f01ac3bSzoecarver// type.
648*9f01ac3bSzoecarvertemplate<class _Ip>
649*9f01ac3bSzoecarverconcept __has_arrow =
650*9f01ac3bSzoecarver  requires(_Ip& __i) {
651*9f01ac3bSzoecarver    __i.operator->();
652*9f01ac3bSzoecarver  };
653*9f01ac3bSzoecarver
654*9f01ac3bSzoecarvertemplate<class _Ip>
655*9f01ac3bSzoecarver  requires __has_arrow<_Ip> && (!__has_member_pointer<_Ip>)
656*9f01ac3bSzoecarverstruct __iterator_traits_member_pointer_or_arrow_or_void<_Ip> {
657*9f01ac3bSzoecarver  using type = decltype(declval<_Ip&>().operator->());
658*9f01ac3bSzoecarver};
659*9f01ac3bSzoecarver
660*9f01ac3bSzoecarver// Otherwise, `reference` names `iter-reference-t<I>`.
661*9f01ac3bSzoecarvertemplate<class _Ip>
662*9f01ac3bSzoecarverstruct __iterator_traits_member_reference { using type = iter_reference_t<_Ip>; };
663*9f01ac3bSzoecarver
664*9f01ac3bSzoecarver// [iterator.traits]/3.2.2
665*9f01ac3bSzoecarver// If the qualified-id `I::reference` is valid and denotes a type, `reference` names that type.
666*9f01ac3bSzoecarvertemplate<__has_member_reference _Ip>
667*9f01ac3bSzoecarverstruct __iterator_traits_member_reference<_Ip> { using type = typename _Ip::reference; };
668*9f01ac3bSzoecarver
669*9f01ac3bSzoecarver// [iterator.traits]/3.2.3.4
670*9f01ac3bSzoecarver// input_iterator_tag
671*9f01ac3bSzoecarvertemplate<class _Ip>
672*9f01ac3bSzoecarverstruct __deduce_iterator_category {
673*9f01ac3bSzoecarver  using type = input_iterator_tag;
674*9f01ac3bSzoecarver};
675*9f01ac3bSzoecarver
676*9f01ac3bSzoecarver// [iterator.traits]/3.2.3.1
677*9f01ac3bSzoecarver// `random_access_iterator_tag` if `I` satisfies `cpp17-random-access-iterator`, or otherwise
678*9f01ac3bSzoecarvertemplate<__iterator_traits_detail::__cpp17_random_access_iterator _Ip>
679*9f01ac3bSzoecarverstruct __deduce_iterator_category<_Ip> {
680*9f01ac3bSzoecarver  using type = random_access_iterator_tag;
681*9f01ac3bSzoecarver};
682*9f01ac3bSzoecarver
683*9f01ac3bSzoecarver// [iterator.traits]/3.2.3.2
684*9f01ac3bSzoecarver// `bidirectional_iterator_tag` if `I` satisfies `cpp17-bidirectional-iterator`, or otherwise
685*9f01ac3bSzoecarvertemplate<__iterator_traits_detail::__cpp17_bidirectional_iterator _Ip>
686*9f01ac3bSzoecarverstruct __deduce_iterator_category<_Ip> {
687*9f01ac3bSzoecarver  using type = bidirectional_iterator_tag;
688*9f01ac3bSzoecarver};
689*9f01ac3bSzoecarver
690*9f01ac3bSzoecarver// [iterator.traits]/3.2.3.3
691*9f01ac3bSzoecarver// `forward_iterator_tag` if `I` satisfies `cpp17-forward-iterator`, or otherwise
692*9f01ac3bSzoecarvertemplate<__iterator_traits_detail::__cpp17_forward_iterator _Ip>
693*9f01ac3bSzoecarverstruct __deduce_iterator_category<_Ip> {
694*9f01ac3bSzoecarver  using type = forward_iterator_tag;
695*9f01ac3bSzoecarver};
696*9f01ac3bSzoecarver
697*9f01ac3bSzoecarvertemplate<class _Ip>
698*9f01ac3bSzoecarverstruct __iterator_traits_iterator_category : __deduce_iterator_category<_Ip> {};
699*9f01ac3bSzoecarver
700*9f01ac3bSzoecarver// [iterator.traits]/3.2.3
701*9f01ac3bSzoecarver// If the qualified-id `I::iterator-category` is valid and denotes a type, `iterator-category` names
702*9f01ac3bSzoecarver// that type.
703*9f01ac3bSzoecarvertemplate<__has_member_iterator_category _Ip>
704*9f01ac3bSzoecarverstruct __iterator_traits_iterator_category<_Ip> {
705*9f01ac3bSzoecarver  using type = typename _Ip::iterator_category;
706*9f01ac3bSzoecarver};
707*9f01ac3bSzoecarver
708*9f01ac3bSzoecarver// otherwise, it names void.
709*9f01ac3bSzoecarvertemplate<class>
710*9f01ac3bSzoecarverstruct __iterator_traits_difference_type { using type = void; };
711*9f01ac3bSzoecarver
712*9f01ac3bSzoecarver// If the qualified-id `incrementable_traits<I>::difference_type` is valid and denotes a type, then
713*9f01ac3bSzoecarver// `difference_type` names that type;
714*9f01ac3bSzoecarvertemplate<class _Ip>
715*9f01ac3bSzoecarverrequires requires { typename incrementable_traits<_Ip>::difference_type; }
716*9f01ac3bSzoecarverstruct __iterator_traits_difference_type<_Ip> {
717*9f01ac3bSzoecarver  using type = typename incrementable_traits<_Ip>::difference_type;
718*9f01ac3bSzoecarver};
719*9f01ac3bSzoecarver
720*9f01ac3bSzoecarver// [iterator.traits]/3.4
721*9f01ac3bSzoecarver// Otherwise, `iterator_traits<I>` has no members by any of the above names.
722*9f01ac3bSzoecarvertemplate<class>
723*9f01ac3bSzoecarverstruct __iterator_traits {};
724*9f01ac3bSzoecarver
725*9f01ac3bSzoecarver// [iterator.traits]/3.1
726*9f01ac3bSzoecarver// If `I` has valid ([temp.deduct]) member types `difference-type`, `value-type`, `reference`, and
727*9f01ac3bSzoecarver// `iterator-category`, then `iterator-traits<I>` has the following publicly accessible members:
728*9f01ac3bSzoecarvertemplate<__specifies_members _Ip>
729*9f01ac3bSzoecarverstruct __iterator_traits<_Ip> {
730*9f01ac3bSzoecarver  using iterator_category  = typename _Ip::iterator_category;
731*9f01ac3bSzoecarver  using value_type         = typename _Ip::value_type;
732*9f01ac3bSzoecarver  using difference_type    = typename _Ip::difference_type;
733*9f01ac3bSzoecarver  using pointer            = typename __iterator_traits_member_pointer_or_void<_Ip>::type;
734*9f01ac3bSzoecarver  using reference          = typename _Ip::reference;
735*9f01ac3bSzoecarver};
736*9f01ac3bSzoecarver
737*9f01ac3bSzoecarver// [iterator.traits]/3.2
738*9f01ac3bSzoecarver// Otherwise, if `I` satisfies the exposition-only concept `cpp17-input-iterator`,
739*9f01ac3bSzoecarver// `iterator-traits<I>` has the following publicly accessible members:
740*9f01ac3bSzoecarvertemplate<__cpp17_input_iterator_missing_members _Ip>
741*9f01ac3bSzoecarverstruct __iterator_traits<_Ip> {
742*9f01ac3bSzoecarver  using iterator_category = typename __iterator_traits_iterator_category<_Ip>::type;
743*9f01ac3bSzoecarver  using value_type        = typename indirectly_readable_traits<_Ip>::value_type;
744*9f01ac3bSzoecarver  using difference_type   = typename incrementable_traits<_Ip>::difference_type;
745*9f01ac3bSzoecarver  using pointer           = typename __iterator_traits_member_pointer_or_arrow_or_void<_Ip>::type;
746*9f01ac3bSzoecarver  using reference         = typename __iterator_traits_member_reference<_Ip>::type;
747*9f01ac3bSzoecarver};
748*9f01ac3bSzoecarver
749*9f01ac3bSzoecarver// Otherwise, if `I` satisfies the exposition-only concept `cpp17-iterator`, then
750*9f01ac3bSzoecarver// `iterator_traits<I>` has the following publicly accessible members:
751*9f01ac3bSzoecarvertemplate<__cpp17_iterator_missing_members _Ip>
752*9f01ac3bSzoecarverstruct __iterator_traits<_Ip> {
753*9f01ac3bSzoecarver  using iterator_category = output_iterator_tag;
754*9f01ac3bSzoecarver  using value_type        = void;
755*9f01ac3bSzoecarver  using difference_type   = typename __iterator_traits_difference_type<_Ip>::type;
756*9f01ac3bSzoecarver  using pointer           = void;
757*9f01ac3bSzoecarver  using reference         = void;
758*9f01ac3bSzoecarver};
759*9f01ac3bSzoecarver
760*9f01ac3bSzoecarvertemplate<class _Ip>
761*9f01ac3bSzoecarverstruct iterator_traits : __iterator_traits<_Ip> {
762*9f01ac3bSzoecarver  using __primary_template = iterator_traits;
763*9f01ac3bSzoecarver};
764*9f01ac3bSzoecarver
765*9f01ac3bSzoecarver#else // !defined(_LIBCPP_HAS_NO_RANGES)
7660148b653SChristopher Di Bella
7673e519524SHoward Hinnanttemplate <class _Iter, bool> struct __iterator_traits {};
7683e519524SHoward Hinnant
769*9f01ac3bSzoecarvertemplate <class _Iter, bool> struct __iterator_traits_impl {};
770*9f01ac3bSzoecarver
771*9f01ac3bSzoecarvertemplate <class _Iter>
772*9f01ac3bSzoecarverstruct __iterator_traits_impl<_Iter, true>
773*9f01ac3bSzoecarver{
774*9f01ac3bSzoecarver    typedef typename _Iter::difference_type   difference_type;
775*9f01ac3bSzoecarver    typedef typename _Iter::value_type        value_type;
776*9f01ac3bSzoecarver    typedef typename _Iter::pointer           pointer;
777*9f01ac3bSzoecarver    typedef typename _Iter::reference         reference;
778*9f01ac3bSzoecarver    typedef typename _Iter::iterator_category iterator_category;
779*9f01ac3bSzoecarver};
780*9f01ac3bSzoecarver
7813e519524SHoward Hinnanttemplate <class _Iter>
7823e519524SHoward Hinnantstruct __iterator_traits<_Iter, true>
7830724bf67SMarshall Clow    :  __iterator_traits_impl
7843e519524SHoward Hinnant      <
7853e519524SHoward Hinnant        _Iter,
7863e519524SHoward Hinnant        is_convertible<typename _Iter::iterator_category, input_iterator_tag>::value ||
7873e519524SHoward Hinnant        is_convertible<typename _Iter::iterator_category, output_iterator_tag>::value
7883e519524SHoward Hinnant      >
7893e519524SHoward Hinnant{};
7903e519524SHoward Hinnant
7913e519524SHoward Hinnant// iterator_traits<Iterator> will only have the nested types if Iterator::iterator_category
7923e519524SHoward Hinnant//    exists.  Else iterator_traits<Iterator> will be an empty class.  This is a
7933e519524SHoward Hinnant//    conforming extension which allows some programs to compile and behave as
7943e519524SHoward Hinnant//    the client expects instead of failing at compile time.
7953e519524SHoward Hinnant
7963e519524SHoward Hinnanttemplate <class _Iter>
797e2f2d1edSEric Fiselierstruct _LIBCPP_TEMPLATE_VIS iterator_traits
7986624fcbaSEric Fiselier    : __iterator_traits<_Iter, __has_iterator_typedefs<_Iter>::value> {
7996624fcbaSEric Fiselier
8006624fcbaSEric Fiselier  using __primary_template = iterator_traits;
8016624fcbaSEric Fiselier};
802*9f01ac3bSzoecarver#endif // !defined(_LIBCPP_HAS_NO_RANGES)
8033e519524SHoward Hinnant
8043e519524SHoward Hinnanttemplate<class _Tp>
805*9f01ac3bSzoecarver#if !defined(_LIBCPP_HAS_NO_RANGES)
806*9f01ac3bSzoecarverrequires is_object_v<_Tp>
807*9f01ac3bSzoecarver#endif
808e2f2d1edSEric Fiselierstruct _LIBCPP_TEMPLATE_VIS iterator_traits<_Tp*>
8093e519524SHoward Hinnant{
8103e519524SHoward Hinnant    typedef ptrdiff_t difference_type;
811ffcfd923SMarshall Clow    typedef typename remove_cv<_Tp>::type value_type;
8123e519524SHoward Hinnant    typedef _Tp* pointer;
8133e519524SHoward Hinnant    typedef _Tp& reference;
8143e519524SHoward Hinnant    typedef random_access_iterator_tag iterator_category;
81545d048c2SEric Fiselier#if _LIBCPP_STD_VER > 17
81645d048c2SEric Fiselier    typedef contiguous_iterator_tag    iterator_concept;
81745d048c2SEric Fiselier#endif
8183e519524SHoward Hinnant};
8193e519524SHoward Hinnant
8203e519524SHoward Hinnanttemplate <class _Tp, class _Up, bool = __has_iterator_category<iterator_traits<_Tp> >::value>
8213e519524SHoward Hinnantstruct __has_iterator_category_convertible_to
822d41c6d51SArthur O'Dwyer    : _BoolConstant<is_convertible<typename iterator_traits<_Tp>::iterator_category, _Up>::value>
8233e519524SHoward Hinnant{};
8243e519524SHoward Hinnant
8253e519524SHoward Hinnanttemplate <class _Tp, class _Up>
826d41c6d51SArthur O'Dwyerstruct __has_iterator_category_convertible_to<_Tp, _Up, false> : false_type {};
827d41c6d51SArthur O'Dwyer
828d41c6d51SArthur O'Dwyertemplate <class _Tp, class _Up, bool = __has_iterator_concept<_Tp>::value>
829d41c6d51SArthur O'Dwyerstruct __has_iterator_concept_convertible_to
830d41c6d51SArthur O'Dwyer    : _BoolConstant<is_convertible<typename _Tp::iterator_concept, _Up>::value>
831d41c6d51SArthur O'Dwyer{};
832d41c6d51SArthur O'Dwyer
833d41c6d51SArthur O'Dwyertemplate <class _Tp, class _Up>
834d41c6d51SArthur O'Dwyerstruct __has_iterator_concept_convertible_to<_Tp, _Up, false> : false_type {};
8353e519524SHoward Hinnant
8363e519524SHoward Hinnanttemplate <class _Tp>
837f82dba01SEric Fiselierstruct __is_cpp17_input_iterator : public __has_iterator_category_convertible_to<_Tp, input_iterator_tag> {};
8383e519524SHoward Hinnant
8393e519524SHoward Hinnanttemplate <class _Tp>
840f82dba01SEric Fiselierstruct __is_cpp17_forward_iterator : public __has_iterator_category_convertible_to<_Tp, forward_iterator_tag> {};
8413e519524SHoward Hinnant
8423e519524SHoward Hinnanttemplate <class _Tp>
843f82dba01SEric Fiselierstruct __is_cpp17_bidirectional_iterator : public __has_iterator_category_convertible_to<_Tp, bidirectional_iterator_tag> {};
8443e519524SHoward Hinnant
8453e519524SHoward Hinnanttemplate <class _Tp>
846f82dba01SEric Fiselierstruct __is_cpp17_random_access_iterator : public __has_iterator_category_convertible_to<_Tp, random_access_iterator_tag> {};
8473e519524SHoward Hinnant
848d41c6d51SArthur O'Dwyer// __is_cpp17_contiguous_iterator determines if an iterator is contiguous,
849d41c6d51SArthur O'Dwyer// either because it advertises itself as such (in C++20) or because it
850d41c6d51SArthur O'Dwyer// is a pointer type or a known trivial wrapper around a pointer type,
851d41c6d51SArthur O'Dwyer// such as __wrap_iter<T*>.
852d41c6d51SArthur O'Dwyer//
85345d048c2SEric Fiselier#if _LIBCPP_STD_VER > 17
85445d048c2SEric Fiseliertemplate <class _Tp>
855d41c6d51SArthur O'Dwyerstruct __is_cpp17_contiguous_iterator : _Or<
856d41c6d51SArthur O'Dwyer    __has_iterator_category_convertible_to<_Tp, contiguous_iterator_tag>,
857d41c6d51SArthur O'Dwyer    __has_iterator_concept_convertible_to<_Tp, contiguous_iterator_tag>
858d41c6d51SArthur O'Dwyer> {};
859f82dba01SEric Fiselier#else
860f82dba01SEric Fiseliertemplate <class _Tp>
861d41c6d51SArthur O'Dwyerstruct __is_cpp17_contiguous_iterator : false_type {};
86245d048c2SEric Fiselier#endif
86345d048c2SEric Fiselier
864d41c6d51SArthur O'Dwyer// Any native pointer which is an iterator is also a contiguous iterator.
865d41c6d51SArthur O'Dwyertemplate <class _Up>
866d41c6d51SArthur O'Dwyerstruct __is_cpp17_contiguous_iterator<_Up*> : true_type {};
867d41c6d51SArthur O'Dwyer
868f82dba01SEric Fiselier
86976b4afc0SMarshall Clowtemplate <class _Tp>
870f82dba01SEric Fiselierstruct __is_exactly_cpp17_input_iterator
87176b4afc0SMarshall Clow    : public integral_constant<bool,
87276b4afc0SMarshall Clow         __has_iterator_category_convertible_to<_Tp, input_iterator_tag>::value &&
87376b4afc0SMarshall Clow        !__has_iterator_category_convertible_to<_Tp, forward_iterator_tag>::value> {};
87476b4afc0SMarshall Clow
875f2f7d72fSLouis Dionne#ifndef _LIBCPP_HAS_NO_DEDUCTION_GUIDES
876f2f7d72fSLouis Dionnetemplate<class _InputIterator>
877f2f7d72fSLouis Dionneusing __iter_value_type = typename iterator_traits<_InputIterator>::value_type;
878f2f7d72fSLouis Dionne
879f2f7d72fSLouis Dionnetemplate<class _InputIterator>
880f2f7d72fSLouis Dionneusing __iter_key_type = remove_const_t<typename iterator_traits<_InputIterator>::value_type::first_type>;
881f2f7d72fSLouis Dionne
882f2f7d72fSLouis Dionnetemplate<class _InputIterator>
883f2f7d72fSLouis Dionneusing __iter_mapped_type = typename iterator_traits<_InputIterator>::value_type::second_type;
884f2f7d72fSLouis Dionne
885f2f7d72fSLouis Dionnetemplate<class _InputIterator>
886f2f7d72fSLouis Dionneusing __iter_to_alloc_type = pair<
887f2f7d72fSLouis Dionne    add_const_t<typename iterator_traits<_InputIterator>::value_type::first_type>,
888f2f7d72fSLouis Dionne    typename iterator_traits<_InputIterator>::value_type::second_type>;
889f2f7d72fSLouis Dionne#endif
890f2f7d72fSLouis Dionne
8913e519524SHoward Hinnanttemplate<class _Category, class _Tp, class _Distance = ptrdiff_t,
8923e519524SHoward Hinnant         class _Pointer = _Tp*, class _Reference = _Tp&>
893e2f2d1edSEric Fiselierstruct _LIBCPP_TEMPLATE_VIS iterator
8943e519524SHoward Hinnant{
8953e519524SHoward Hinnant    typedef _Tp        value_type;
8963e519524SHoward Hinnant    typedef _Distance  difference_type;
8973e519524SHoward Hinnant    typedef _Pointer   pointer;
8983e519524SHoward Hinnant    typedef _Reference reference;
8993e519524SHoward Hinnant    typedef _Category  iterator_category;
9003e519524SHoward Hinnant};
9013e519524SHoward Hinnant
9023e519524SHoward Hinnanttemplate <class _InputIter>
903f51ee632SMarshall Clowinline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
9043e519524SHoward Hinnantvoid __advance(_InputIter& __i,
9053e519524SHoward Hinnant             typename iterator_traits<_InputIter>::difference_type __n, input_iterator_tag)
9063e519524SHoward Hinnant{
9073e519524SHoward Hinnant    for (; __n > 0; --__n)
9083e519524SHoward Hinnant        ++__i;
9093e519524SHoward Hinnant}
9103e519524SHoward Hinnant
9113e519524SHoward Hinnanttemplate <class _BiDirIter>
912f51ee632SMarshall Clowinline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
9133e519524SHoward Hinnantvoid __advance(_BiDirIter& __i,
9143e519524SHoward Hinnant             typename iterator_traits<_BiDirIter>::difference_type __n, bidirectional_iterator_tag)
9153e519524SHoward Hinnant{
9163e519524SHoward Hinnant    if (__n >= 0)
9173e519524SHoward Hinnant        for (; __n > 0; --__n)
9183e519524SHoward Hinnant            ++__i;
9193e519524SHoward Hinnant    else
9203e519524SHoward Hinnant        for (; __n < 0; ++__n)
9213e519524SHoward Hinnant            --__i;
9223e519524SHoward Hinnant}
9233e519524SHoward Hinnant
9243e519524SHoward Hinnanttemplate <class _RandIter>
925f51ee632SMarshall Clowinline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
9263e519524SHoward Hinnantvoid __advance(_RandIter& __i,
9273e519524SHoward Hinnant             typename iterator_traits<_RandIter>::difference_type __n, random_access_iterator_tag)
9283e519524SHoward Hinnant{
9293e519524SHoward Hinnant   __i += __n;
9303e519524SHoward Hinnant}
9313e519524SHoward Hinnant
93212b01ab7SLouis Dionnetemplate <class _InputIter, class _Distance>
933f51ee632SMarshall Clowinline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
93412b01ab7SLouis Dionnevoid advance(_InputIter& __i, _Distance __orig_n)
9353e519524SHoward Hinnant{
93612b01ab7SLouis Dionne    _LIBCPP_ASSERT(__orig_n >= 0 || __is_cpp17_bidirectional_iterator<_InputIter>::value,
93712b01ab7SLouis Dionne                   "Attempt to advance(it, n) with negative n on a non-bidirectional iterator");
938c0428b3cSArthur O'Dwyer    typedef decltype(_VSTD::__convert_to_integral(__orig_n)) _IntegralSize;
93912b01ab7SLouis Dionne    _IntegralSize __n = __orig_n;
940c0428b3cSArthur O'Dwyer    _VSTD::__advance(__i, __n, typename iterator_traits<_InputIter>::iterator_category());
9413e519524SHoward Hinnant}
9423e519524SHoward Hinnant
9433e519524SHoward Hinnanttemplate <class _InputIter>
944f51ee632SMarshall Clowinline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
9453e519524SHoward Hinnanttypename iterator_traits<_InputIter>::difference_type
9463e519524SHoward Hinnant__distance(_InputIter __first, _InputIter __last, input_iterator_tag)
9473e519524SHoward Hinnant{
9483e519524SHoward Hinnant    typename iterator_traits<_InputIter>::difference_type __r(0);
9493e519524SHoward Hinnant    for (; __first != __last; ++__first)
9503e519524SHoward Hinnant        ++__r;
9513e519524SHoward Hinnant    return __r;
9523e519524SHoward Hinnant}
9533e519524SHoward Hinnant
9543e519524SHoward Hinnanttemplate <class _RandIter>
955f51ee632SMarshall Clowinline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
9563e519524SHoward Hinnanttypename iterator_traits<_RandIter>::difference_type
9573e519524SHoward Hinnant__distance(_RandIter __first, _RandIter __last, random_access_iterator_tag)
9583e519524SHoward Hinnant{
9593e519524SHoward Hinnant    return __last - __first;
9603e519524SHoward Hinnant}
9613e519524SHoward Hinnant
9623e519524SHoward Hinnanttemplate <class _InputIter>
963f51ee632SMarshall Clowinline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
9643e519524SHoward Hinnanttypename iterator_traits<_InputIter>::difference_type
9653e519524SHoward Hinnantdistance(_InputIter __first, _InputIter __last)
9663e519524SHoward Hinnant{
967c0428b3cSArthur O'Dwyer    return _VSTD::__distance(__first, __last, typename iterator_traits<_InputIter>::iterator_category());
9683e519524SHoward Hinnant}
9693e519524SHoward Hinnant
970e5f1288fSMarshall Clowtemplate <class _InputIter>
971f51ee632SMarshall Clowinline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
9723e2ef408SRachel Craiktypename enable_if
9733e2ef408SRachel Craik<
974f82dba01SEric Fiselier    __is_cpp17_input_iterator<_InputIter>::value,
975e5f1288fSMarshall Clow    _InputIter
9763e2ef408SRachel Craik>::type
977e5f1288fSMarshall Clownext(_InputIter __x,
9783e2ef408SRachel Craik     typename iterator_traits<_InputIter>::difference_type __n = 1)
9793e519524SHoward Hinnant{
980f82dba01SEric Fiselier    _LIBCPP_ASSERT(__n >= 0 || __is_cpp17_bidirectional_iterator<_InputIter>::value,
98112b01ab7SLouis Dionne                       "Attempt to next(it, n) with negative n on a non-bidirectional iterator");
982e1cd11d8SMarshall Clow
983ce48a113SHoward Hinnant    _VSTD::advance(__x, __n);
9843e519524SHoward Hinnant    return __x;
9853e519524SHoward Hinnant}
9863e519524SHoward Hinnant
987e1cd11d8SMarshall Clowtemplate <class _InputIter>
988f51ee632SMarshall Clowinline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
9893e2ef408SRachel Craiktypename enable_if
9903e2ef408SRachel Craik<
991f82dba01SEric Fiselier    __is_cpp17_input_iterator<_InputIter>::value,
992e1cd11d8SMarshall Clow    _InputIter
9933e2ef408SRachel Craik>::type
994e1cd11d8SMarshall Clowprev(_InputIter __x,
995e1cd11d8SMarshall Clow     typename iterator_traits<_InputIter>::difference_type __n = 1)
9963e519524SHoward Hinnant{
997f82dba01SEric Fiselier    _LIBCPP_ASSERT(__n <= 0 || __is_cpp17_bidirectional_iterator<_InputIter>::value,
99812b01ab7SLouis Dionne                       "Attempt to prev(it, n) with a positive n on a non-bidirectional iterator");
999ce48a113SHoward Hinnant    _VSTD::advance(__x, -__n);
10003e519524SHoward Hinnant    return __x;
10013e519524SHoward Hinnant}
10023e519524SHoward Hinnant
1003e02ed1c2SEric Fiselier
1004e02ed1c2SEric Fiseliertemplate <class _Tp, class = void>
1005e02ed1c2SEric Fiselierstruct __is_stashing_iterator : false_type {};
1006e02ed1c2SEric Fiselier
1007e02ed1c2SEric Fiseliertemplate <class _Tp>
1008e02ed1c2SEric Fiselierstruct __is_stashing_iterator<_Tp, typename __void_t<typename _Tp::__stashing_iterator_tag>::type>
1009e02ed1c2SEric Fiselier  : true_type {};
1010e02ed1c2SEric Fiselier
10113e519524SHoward Hinnanttemplate <class _Iter>
1012e2f2d1edSEric Fiselierclass _LIBCPP_TEMPLATE_VIS reverse_iterator
10133e519524SHoward Hinnant    : public iterator<typename iterator_traits<_Iter>::iterator_category,
10143e519524SHoward Hinnant                      typename iterator_traits<_Iter>::value_type,
10153e519524SHoward Hinnant                      typename iterator_traits<_Iter>::difference_type,
10163e519524SHoward Hinnant                      typename iterator_traits<_Iter>::pointer,
10173e519524SHoward Hinnant                      typename iterator_traits<_Iter>::reference>
10183e519524SHoward Hinnant{
10193b83496dSMarshall Clowprivate:
10201b8f260eSMarshall Clow    /*mutable*/ _Iter __t;  // no longer used as of LWG #2360, not removed due to ABI break
1021e02ed1c2SEric Fiselier
1022e02ed1c2SEric Fiselier    static_assert(!__is_stashing_iterator<_Iter>::value,
1023e02ed1c2SEric Fiselier      "The specified iterator type cannot be used with reverse_iterator; "
1024e02ed1c2SEric Fiselier      "Using stashing iterators with reverse_iterator causes undefined behavior");
1025e02ed1c2SEric Fiselier
1026b2d74f29SMarshall Clowprotected:
1027b2d74f29SMarshall Clow    _Iter current;
10283e519524SHoward Hinnantpublic:
10293e519524SHoward Hinnant    typedef _Iter                                            iterator_type;
10303e519524SHoward Hinnant    typedef typename iterator_traits<_Iter>::difference_type difference_type;
10313e519524SHoward Hinnant    typedef typename iterator_traits<_Iter>::reference       reference;
10323e519524SHoward Hinnant    typedef typename iterator_traits<_Iter>::pointer         pointer;
1033d41c6d51SArthur O'Dwyer    typedef _If<__is_cpp17_random_access_iterator<_Iter>::value,
1034d41c6d51SArthur O'Dwyer        random_access_iterator_tag,
1035d41c6d51SArthur O'Dwyer        typename iterator_traits<_Iter>::iterator_category>  iterator_category;
1036d41c6d51SArthur O'Dwyer#if _LIBCPP_STD_VER > 17
1037d41c6d51SArthur O'Dwyer    typedef _If<__is_cpp17_random_access_iterator<_Iter>::value,
1038d41c6d51SArthur O'Dwyer        random_access_iterator_tag,
1039d41c6d51SArthur O'Dwyer        bidirectional_iterator_tag>                          iterator_concept;
1040d41c6d51SArthur O'Dwyer#endif
10413e519524SHoward Hinnant
10421b8f260eSMarshall Clow    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
10431b8f260eSMarshall Clow    reverse_iterator() : __t(), current() {}
10441b8f260eSMarshall Clow    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
10451b8f260eSMarshall Clow    explicit reverse_iterator(_Iter __x) : __t(__x), current(__x) {}
10461b8f260eSMarshall Clow    template <class _Up>
10471b8f260eSMarshall Clow        _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
10481b8f260eSMarshall Clow        reverse_iterator(const reverse_iterator<_Up>& __u) : __t(__u.base()), current(__u.base()) {}
10491b8f260eSMarshall Clow    template <class _Up>
10501b8f260eSMarshall Clow        _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
10511b8f260eSMarshall Clow        reverse_iterator& operator=(const reverse_iterator<_Up>& __u)
10521b8f260eSMarshall Clow            { __t = current = __u.base(); return *this; }
10531b8f260eSMarshall Clow    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
10541b8f260eSMarshall Clow    _Iter base() const {return current;}
10551b8f260eSMarshall Clow    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
10561b8f260eSMarshall Clow    reference operator*() const {_Iter __tmp = current; return *--__tmp;}
10571b8f260eSMarshall Clow    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
10581b8f260eSMarshall Clow    pointer  operator->() const {return _VSTD::addressof(operator*());}
10591b8f260eSMarshall Clow    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
10601b8f260eSMarshall Clow    reverse_iterator& operator++() {--current; return *this;}
10611b8f260eSMarshall Clow    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
10621b8f260eSMarshall Clow    reverse_iterator  operator++(int) {reverse_iterator __tmp(*this); --current; return __tmp;}
10631b8f260eSMarshall Clow    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
10641b8f260eSMarshall Clow    reverse_iterator& operator--() {++current; return *this;}
10651b8f260eSMarshall Clow    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
10661b8f260eSMarshall Clow    reverse_iterator  operator--(int) {reverse_iterator __tmp(*this); ++current; return __tmp;}
10671b8f260eSMarshall Clow    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
10681b8f260eSMarshall Clow    reverse_iterator  operator+ (difference_type __n) const {return reverse_iterator(current - __n);}
10691b8f260eSMarshall Clow    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
10701b8f260eSMarshall Clow    reverse_iterator& operator+=(difference_type __n) {current -= __n; return *this;}
10711b8f260eSMarshall Clow    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
10721b8f260eSMarshall Clow    reverse_iterator  operator- (difference_type __n) const {return reverse_iterator(current + __n);}
10731b8f260eSMarshall Clow    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
10741b8f260eSMarshall Clow    reverse_iterator& operator-=(difference_type __n) {current += __n; return *this;}
10751b8f260eSMarshall Clow    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
10761b8f260eSMarshall Clow    reference         operator[](difference_type __n) const {return *(*this + __n);}
10773e519524SHoward Hinnant};
10783e519524SHoward Hinnant
10793e519524SHoward Hinnanttemplate <class _Iter1, class _Iter2>
10801b8f260eSMarshall Clowinline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
10813e519524SHoward Hinnantbool
10823e519524SHoward Hinnantoperator==(const reverse_iterator<_Iter1>& __x, const reverse_iterator<_Iter2>& __y)
10833e519524SHoward Hinnant{
10843e519524SHoward Hinnant    return __x.base() == __y.base();
10853e519524SHoward Hinnant}
10863e519524SHoward Hinnant
10873e519524SHoward Hinnanttemplate <class _Iter1, class _Iter2>
10881b8f260eSMarshall Clowinline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
10893e519524SHoward Hinnantbool
10903e519524SHoward Hinnantoperator<(const reverse_iterator<_Iter1>& __x, const reverse_iterator<_Iter2>& __y)
10913e519524SHoward Hinnant{
10923e519524SHoward Hinnant    return __x.base() > __y.base();
10933e519524SHoward Hinnant}
10943e519524SHoward Hinnant
10953e519524SHoward Hinnanttemplate <class _Iter1, class _Iter2>
10961b8f260eSMarshall Clowinline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
10973e519524SHoward Hinnantbool
10983e519524SHoward Hinnantoperator!=(const reverse_iterator<_Iter1>& __x, const reverse_iterator<_Iter2>& __y)
10993e519524SHoward Hinnant{
11003e519524SHoward Hinnant    return __x.base() != __y.base();
11013e519524SHoward Hinnant}
11023e519524SHoward Hinnant
11033e519524SHoward Hinnanttemplate <class _Iter1, class _Iter2>
11041b8f260eSMarshall Clowinline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
11053e519524SHoward Hinnantbool
11063e519524SHoward Hinnantoperator>(const reverse_iterator<_Iter1>& __x, const reverse_iterator<_Iter2>& __y)
11073e519524SHoward Hinnant{
11083e519524SHoward Hinnant    return __x.base() < __y.base();
11093e519524SHoward Hinnant}
11103e519524SHoward Hinnant
11113e519524SHoward Hinnanttemplate <class _Iter1, class _Iter2>
11121b8f260eSMarshall Clowinline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
11133e519524SHoward Hinnantbool
11143e519524SHoward Hinnantoperator>=(const reverse_iterator<_Iter1>& __x, const reverse_iterator<_Iter2>& __y)
11153e519524SHoward Hinnant{
11163e519524SHoward Hinnant    return __x.base() <= __y.base();
11173e519524SHoward Hinnant}
11183e519524SHoward Hinnant
11193e519524SHoward Hinnanttemplate <class _Iter1, class _Iter2>
11201b8f260eSMarshall Clowinline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
11213e519524SHoward Hinnantbool
11223e519524SHoward Hinnantoperator<=(const reverse_iterator<_Iter1>& __x, const reverse_iterator<_Iter2>& __y)
11233e519524SHoward Hinnant{
11243e519524SHoward Hinnant    return __x.base() >= __y.base();
11253e519524SHoward Hinnant}
11263e519524SHoward Hinnant
11272ee83725SMarshall Clow#ifndef _LIBCPP_CXX03_LANG
1128947ce6b5SMarshall Clowtemplate <class _Iter1, class _Iter2>
11291b8f260eSMarshall Clowinline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
1130947ce6b5SMarshall Clowauto
1131947ce6b5SMarshall Clowoperator-(const reverse_iterator<_Iter1>& __x, const reverse_iterator<_Iter2>& __y)
1132947ce6b5SMarshall Clow-> decltype(__y.base() - __x.base())
1133947ce6b5SMarshall Clow{
1134947ce6b5SMarshall Clow    return __y.base() - __x.base();
1135947ce6b5SMarshall Clow}
1136947ce6b5SMarshall Clow#else
11373e519524SHoward Hinnanttemplate <class _Iter1, class _Iter2>
11383e519524SHoward Hinnantinline _LIBCPP_INLINE_VISIBILITY
11393e519524SHoward Hinnanttypename reverse_iterator<_Iter1>::difference_type
11403e519524SHoward Hinnantoperator-(const reverse_iterator<_Iter1>& __x, const reverse_iterator<_Iter2>& __y)
11413e519524SHoward Hinnant{
11423e519524SHoward Hinnant    return __y.base() - __x.base();
11433e519524SHoward Hinnant}
1144947ce6b5SMarshall Clow#endif
11453e519524SHoward Hinnant
11463e519524SHoward Hinnanttemplate <class _Iter>
11471b8f260eSMarshall Clowinline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
11483e519524SHoward Hinnantreverse_iterator<_Iter>
11493e519524SHoward Hinnantoperator+(typename reverse_iterator<_Iter>::difference_type __n, const reverse_iterator<_Iter>& __x)
11503e519524SHoward Hinnant{
11513e519524SHoward Hinnant    return reverse_iterator<_Iter>(__x.base() - __n);
11523e519524SHoward Hinnant}
11533e519524SHoward Hinnant
11546a640a18SMarshall Clow#if _LIBCPP_STD_VER > 11
11556a640a18SMarshall Clowtemplate <class _Iter>
11561b8f260eSMarshall Clowinline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
11576a640a18SMarshall Clowreverse_iterator<_Iter> make_reverse_iterator(_Iter __i)
11586a640a18SMarshall Clow{
11596a640a18SMarshall Clow    return reverse_iterator<_Iter>(__i);
11606a640a18SMarshall Clow}
11616a640a18SMarshall Clow#endif
11626a640a18SMarshall Clow
11633e519524SHoward Hinnanttemplate <class _Container>
1164e2f2d1edSEric Fiselierclass _LIBCPP_TEMPLATE_VIS back_insert_iterator
11653e519524SHoward Hinnant    : public iterator<output_iterator_tag,
11663e519524SHoward Hinnant                      void,
11673e519524SHoward Hinnant                      void,
11683e519524SHoward Hinnant                      void,
11698892b4eeSEric Fiselier                      void>
11703e519524SHoward Hinnant{
11713e519524SHoward Hinnantprotected:
11723e519524SHoward Hinnant    _Container* container;
11733e519524SHoward Hinnantpublic:
11743e519524SHoward Hinnant    typedef _Container container_type;
11753e519524SHoward Hinnant
117606e2b737SArthur O'Dwyer    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 explicit back_insert_iterator(_Container& __x) : container(_VSTD::addressof(__x)) {}
117706e2b737SArthur O'Dwyer    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 back_insert_iterator& operator=(const typename _Container::value_type& __value_)
1178e4383379SHoward Hinnant        {container->push_back(__value_); return *this;}
1179046492b9SEric Fiselier#ifndef _LIBCPP_CXX03_LANG
118006e2b737SArthur O'Dwyer    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 back_insert_iterator& operator=(typename _Container::value_type&& __value_)
1181e4383379SHoward Hinnant        {container->push_back(_VSTD::move(__value_)); return *this;}
1182046492b9SEric Fiselier#endif  // _LIBCPP_CXX03_LANG
118306e2b737SArthur O'Dwyer    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 back_insert_iterator& operator*()     {return *this;}
118406e2b737SArthur O'Dwyer    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 back_insert_iterator& operator++()    {return *this;}
118506e2b737SArthur O'Dwyer    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 back_insert_iterator  operator++(int) {return *this;}
11863e519524SHoward Hinnant};
11873e519524SHoward Hinnant
11883e519524SHoward Hinnanttemplate <class _Container>
118906e2b737SArthur O'Dwyerinline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
11903e519524SHoward Hinnantback_insert_iterator<_Container>
11913e519524SHoward Hinnantback_inserter(_Container& __x)
11923e519524SHoward Hinnant{
11933e519524SHoward Hinnant    return back_insert_iterator<_Container>(__x);
11943e519524SHoward Hinnant}
11953e519524SHoward Hinnant
11963e519524SHoward Hinnanttemplate <class _Container>
1197e2f2d1edSEric Fiselierclass _LIBCPP_TEMPLATE_VIS front_insert_iterator
11983e519524SHoward Hinnant    : public iterator<output_iterator_tag,
11993e519524SHoward Hinnant                      void,
12003e519524SHoward Hinnant                      void,
12013e519524SHoward Hinnant                      void,
12028892b4eeSEric Fiselier                      void>
12033e519524SHoward Hinnant{
12043e519524SHoward Hinnantprotected:
12053e519524SHoward Hinnant    _Container* container;
12063e519524SHoward Hinnantpublic:
12073e519524SHoward Hinnant    typedef _Container container_type;
12083e519524SHoward Hinnant
120906e2b737SArthur O'Dwyer    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 explicit front_insert_iterator(_Container& __x) : container(_VSTD::addressof(__x)) {}
121006e2b737SArthur O'Dwyer    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 front_insert_iterator& operator=(const typename _Container::value_type& __value_)
1211e4383379SHoward Hinnant        {container->push_front(__value_); return *this;}
1212046492b9SEric Fiselier#ifndef _LIBCPP_CXX03_LANG
121306e2b737SArthur O'Dwyer    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 front_insert_iterator& operator=(typename _Container::value_type&& __value_)
1214e4383379SHoward Hinnant        {container->push_front(_VSTD::move(__value_)); return *this;}
1215046492b9SEric Fiselier#endif  // _LIBCPP_CXX03_LANG
121606e2b737SArthur O'Dwyer    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 front_insert_iterator& operator*()     {return *this;}
121706e2b737SArthur O'Dwyer    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 front_insert_iterator& operator++()    {return *this;}
121806e2b737SArthur O'Dwyer    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 front_insert_iterator  operator++(int) {return *this;}
12193e519524SHoward Hinnant};
12203e519524SHoward Hinnant
12213e519524SHoward Hinnanttemplate <class _Container>
122206e2b737SArthur O'Dwyerinline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
12233e519524SHoward Hinnantfront_insert_iterator<_Container>
12243e519524SHoward Hinnantfront_inserter(_Container& __x)
12253e519524SHoward Hinnant{
12263e519524SHoward Hinnant    return front_insert_iterator<_Container>(__x);
12273e519524SHoward Hinnant}
12283e519524SHoward Hinnant
12293e519524SHoward Hinnanttemplate <class _Container>
1230e2f2d1edSEric Fiselierclass _LIBCPP_TEMPLATE_VIS insert_iterator
12313e519524SHoward Hinnant    : public iterator<output_iterator_tag,
12323e519524SHoward Hinnant                      void,
12333e519524SHoward Hinnant                      void,
12343e519524SHoward Hinnant                      void,
12358892b4eeSEric Fiselier                      void>
12363e519524SHoward Hinnant{
12373e519524SHoward Hinnantprotected:
12383e519524SHoward Hinnant    _Container* container;
12393e519524SHoward Hinnant    typename _Container::iterator iter;
12403e519524SHoward Hinnantpublic:
12413e519524SHoward Hinnant    typedef _Container container_type;
12423e519524SHoward Hinnant
124306e2b737SArthur O'Dwyer    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 insert_iterator(_Container& __x, typename _Container::iterator __i)
1244f519be34SMarshall Clow        : container(_VSTD::addressof(__x)), iter(__i) {}
124506e2b737SArthur O'Dwyer    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 insert_iterator& operator=(const typename _Container::value_type& __value_)
1246e4383379SHoward Hinnant        {iter = container->insert(iter, __value_); ++iter; return *this;}
1247046492b9SEric Fiselier#ifndef _LIBCPP_CXX03_LANG
124806e2b737SArthur O'Dwyer    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 insert_iterator& operator=(typename _Container::value_type&& __value_)
1249e4383379SHoward Hinnant        {iter = container->insert(iter, _VSTD::move(__value_)); ++iter; return *this;}
1250046492b9SEric Fiselier#endif  // _LIBCPP_CXX03_LANG
125106e2b737SArthur O'Dwyer    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 insert_iterator& operator*()        {return *this;}
125206e2b737SArthur O'Dwyer    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 insert_iterator& operator++()       {return *this;}
125306e2b737SArthur O'Dwyer    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 insert_iterator& operator++(int)    {return *this;}
12543e519524SHoward Hinnant};
12553e519524SHoward Hinnant
12563e519524SHoward Hinnanttemplate <class _Container>
125706e2b737SArthur O'Dwyerinline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
12583e519524SHoward Hinnantinsert_iterator<_Container>
12593e519524SHoward Hinnantinserter(_Container& __x, typename _Container::iterator __i)
12603e519524SHoward Hinnant{
12613e519524SHoward Hinnant    return insert_iterator<_Container>(__x, __i);
12623e519524SHoward Hinnant}
12633e519524SHoward Hinnant
12643e519524SHoward Hinnanttemplate <class _Tp, class _CharT = char,
12653e519524SHoward Hinnant          class _Traits = char_traits<_CharT>, class _Distance = ptrdiff_t>
1266e2f2d1edSEric Fiselierclass _LIBCPP_TEMPLATE_VIS istream_iterator
12673e519524SHoward Hinnant    : public iterator<input_iterator_tag, _Tp, _Distance, const _Tp*, const _Tp&>
12683e519524SHoward Hinnant{
12693e519524SHoward Hinnantpublic:
12703e519524SHoward Hinnant    typedef _CharT char_type;
12713e519524SHoward Hinnant    typedef _Traits traits_type;
12723e519524SHoward Hinnant    typedef basic_istream<_CharT,_Traits> istream_type;
12733e519524SHoward Hinnantprivate:
12743e519524SHoward Hinnant    istream_type* __in_stream_;
12753e519524SHoward Hinnant    _Tp __value_;
12763e519524SHoward Hinnantpublic:
1277527a7fdfSBruce Mitchener    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR istream_iterator() : __in_stream_(nullptr), __value_() {}
1278bc6a7df0SMarshall Clow    _LIBCPP_INLINE_VISIBILITY istream_iterator(istream_type& __s) : __in_stream_(_VSTD::addressof(__s))
12793e519524SHoward Hinnant        {
12803e519524SHoward Hinnant            if (!(*__in_stream_ >> __value_))
1281527a7fdfSBruce Mitchener                __in_stream_ = nullptr;
12823e519524SHoward Hinnant        }
12833e519524SHoward Hinnant
12843e519524SHoward Hinnant    _LIBCPP_INLINE_VISIBILITY const _Tp& operator*() const {return __value_;}
1285bc6a7df0SMarshall Clow    _LIBCPP_INLINE_VISIBILITY const _Tp* operator->() const {return _VSTD::addressof((operator*()));}
12863e519524SHoward Hinnant    _LIBCPP_INLINE_VISIBILITY istream_iterator& operator++()
12873e519524SHoward Hinnant        {
12883e519524SHoward Hinnant            if (!(*__in_stream_ >> __value_))
1289527a7fdfSBruce Mitchener                __in_stream_ = nullptr;
12903e519524SHoward Hinnant            return *this;
12913e519524SHoward Hinnant        }
12923e519524SHoward Hinnant    _LIBCPP_INLINE_VISIBILITY istream_iterator  operator++(int)
12933e519524SHoward Hinnant        {istream_iterator __t(*this); ++(*this); return __t;}
12943e519524SHoward Hinnant
12956f56d3eeSRoger Ferrer Ibanez    template <class _Up, class _CharU, class _TraitsU, class _DistanceU>
12963e519524SHoward Hinnant    friend _LIBCPP_INLINE_VISIBILITY
12976f56d3eeSRoger Ferrer Ibanez    bool
12986f56d3eeSRoger Ferrer Ibanez    operator==(const istream_iterator<_Up, _CharU, _TraitsU, _DistanceU>& __x,
12996f56d3eeSRoger Ferrer Ibanez               const istream_iterator<_Up, _CharU, _TraitsU, _DistanceU>& __y);
13003e519524SHoward Hinnant
13016f56d3eeSRoger Ferrer Ibanez    template <class _Up, class _CharU, class _TraitsU, class _DistanceU>
13023e519524SHoward Hinnant    friend _LIBCPP_INLINE_VISIBILITY
13036f56d3eeSRoger Ferrer Ibanez    bool
13046f56d3eeSRoger Ferrer Ibanez    operator==(const istream_iterator<_Up, _CharU, _TraitsU, _DistanceU>& __x,
13056f56d3eeSRoger Ferrer Ibanez               const istream_iterator<_Up, _CharU, _TraitsU, _DistanceU>& __y);
13063e519524SHoward Hinnant};
13073e519524SHoward Hinnant
13086f56d3eeSRoger Ferrer Ibaneztemplate <class _Tp, class _CharT, class _Traits, class _Distance>
13096f56d3eeSRoger Ferrer Ibanezinline _LIBCPP_INLINE_VISIBILITY
13106f56d3eeSRoger Ferrer Ibanezbool
13116f56d3eeSRoger Ferrer Ibanezoperator==(const istream_iterator<_Tp, _CharT, _Traits, _Distance>& __x,
13126f56d3eeSRoger Ferrer Ibanez           const istream_iterator<_Tp, _CharT, _Traits, _Distance>& __y)
13136f56d3eeSRoger Ferrer Ibanez{
13146f56d3eeSRoger Ferrer Ibanez    return __x.__in_stream_ == __y.__in_stream_;
13156f56d3eeSRoger Ferrer Ibanez}
13166f56d3eeSRoger Ferrer Ibanez
13176f56d3eeSRoger Ferrer Ibaneztemplate <class _Tp, class _CharT, class _Traits, class _Distance>
13186f56d3eeSRoger Ferrer Ibanezinline _LIBCPP_INLINE_VISIBILITY
13196f56d3eeSRoger Ferrer Ibanezbool
13206f56d3eeSRoger Ferrer Ibanezoperator!=(const istream_iterator<_Tp, _CharT, _Traits, _Distance>& __x,
13216f56d3eeSRoger Ferrer Ibanez           const istream_iterator<_Tp, _CharT, _Traits, _Distance>& __y)
13226f56d3eeSRoger Ferrer Ibanez{
13236f56d3eeSRoger Ferrer Ibanez    return !(__x == __y);
13246f56d3eeSRoger Ferrer Ibanez}
13256f56d3eeSRoger Ferrer Ibanez
13263e519524SHoward Hinnanttemplate <class _Tp, class _CharT = char, class _Traits = char_traits<_CharT> >
1327e2f2d1edSEric Fiselierclass _LIBCPP_TEMPLATE_VIS ostream_iterator
13283e519524SHoward Hinnant    : public iterator<output_iterator_tag, void, void, void, void>
13293e519524SHoward Hinnant{
13303e519524SHoward Hinnantpublic:
133171a16e40SLouis Dionne    typedef output_iterator_tag             iterator_category;
133271a16e40SLouis Dionne    typedef void                            value_type;
133371a16e40SLouis Dionne#if _LIBCPP_STD_VER > 17
133471a16e40SLouis Dionne    typedef std::ptrdiff_t                  difference_type;
133571a16e40SLouis Dionne#else
133671a16e40SLouis Dionne    typedef void                            difference_type;
133771a16e40SLouis Dionne#endif
133871a16e40SLouis Dionne    typedef void                            pointer;
133971a16e40SLouis Dionne    typedef void                            reference;
13403e519524SHoward Hinnant    typedef _CharT                          char_type;
13413e519524SHoward Hinnant    typedef _Traits                         traits_type;
13423e519524SHoward Hinnant    typedef basic_ostream<_CharT, _Traits>  ostream_type;
134371a16e40SLouis Dionne
13443e519524SHoward Hinnantprivate:
13453e519524SHoward Hinnant    ostream_type* __out_stream_;
13463e519524SHoward Hinnant    const char_type* __delim_;
13473e519524SHoward Hinnantpublic:
1348853042cfSMarshall Clow    _LIBCPP_INLINE_VISIBILITY ostream_iterator(ostream_type& __s) _NOEXCEPT
1349527a7fdfSBruce Mitchener        : __out_stream_(_VSTD::addressof(__s)), __delim_(nullptr) {}
1350853042cfSMarshall Clow    _LIBCPP_INLINE_VISIBILITY ostream_iterator(ostream_type& __s, const _CharT* __delimiter) _NOEXCEPT
1351bc6a7df0SMarshall Clow        : __out_stream_(_VSTD::addressof(__s)), __delim_(__delimiter) {}
1352e4383379SHoward Hinnant    _LIBCPP_INLINE_VISIBILITY ostream_iterator& operator=(const _Tp& __value_)
13533e519524SHoward Hinnant        {
1354e4383379SHoward Hinnant            *__out_stream_ << __value_;
13553e519524SHoward Hinnant            if (__delim_)
13563e519524SHoward Hinnant                *__out_stream_ << __delim_;
13573e519524SHoward Hinnant            return *this;
13583e519524SHoward Hinnant        }
13593e519524SHoward Hinnant
13603e519524SHoward Hinnant    _LIBCPP_INLINE_VISIBILITY ostream_iterator& operator*()     {return *this;}
13613e519524SHoward Hinnant    _LIBCPP_INLINE_VISIBILITY ostream_iterator& operator++()    {return *this;}
13623e519524SHoward Hinnant    _LIBCPP_INLINE_VISIBILITY ostream_iterator& operator++(int) {return *this;}
13633e519524SHoward Hinnant};
13643e519524SHoward Hinnant
13653e519524SHoward Hinnanttemplate<class _CharT, class _Traits>
1366e2f2d1edSEric Fiselierclass _LIBCPP_TEMPLATE_VIS istreambuf_iterator
13673e519524SHoward Hinnant    : public iterator<input_iterator_tag, _CharT,
13683e519524SHoward Hinnant                      typename _Traits::off_type, _CharT*,
13693e519524SHoward Hinnant                      _CharT>
13703e519524SHoward Hinnant{
13713e519524SHoward Hinnantpublic:
13723e519524SHoward Hinnant    typedef _CharT                          char_type;
13733e519524SHoward Hinnant    typedef _Traits                         traits_type;
13743e519524SHoward Hinnant    typedef typename _Traits::int_type      int_type;
13753e519524SHoward Hinnant    typedef basic_streambuf<_CharT,_Traits> streambuf_type;
13763e519524SHoward Hinnant    typedef basic_istream<_CharT,_Traits>   istream_type;
13773e519524SHoward Hinnantprivate:
1378dfdf5085SHoward Hinnant    mutable streambuf_type* __sbuf_;
13793e519524SHoward Hinnant
13803e519524SHoward Hinnant    class __proxy
13813e519524SHoward Hinnant    {
13823e519524SHoward Hinnant        char_type __keep_;
13833e519524SHoward Hinnant        streambuf_type* __sbuf_;
13843e519524SHoward Hinnant        _LIBCPP_INLINE_VISIBILITY __proxy(char_type __c, streambuf_type* __s)
13853e519524SHoward Hinnant            : __keep_(__c), __sbuf_(__s) {}
13863e519524SHoward Hinnant        friend class istreambuf_iterator;
13873e519524SHoward Hinnant    public:
13883e519524SHoward Hinnant        _LIBCPP_INLINE_VISIBILITY char_type operator*() const {return __keep_;}
13893e519524SHoward Hinnant    };
13903e519524SHoward Hinnant
1391848a5374SHoward Hinnant    _LIBCPP_INLINE_VISIBILITY
1392dfdf5085SHoward Hinnant    bool __test_for_eof() const
13933e519524SHoward Hinnant    {
13943e519524SHoward Hinnant        if (__sbuf_ && traits_type::eq_int_type(__sbuf_->sgetc(), traits_type::eof()))
1395527a7fdfSBruce Mitchener            __sbuf_ = nullptr;
1396527a7fdfSBruce Mitchener        return __sbuf_ == nullptr;
13973e519524SHoward Hinnant    }
13983e519524SHoward Hinnantpublic:
1399527a7fdfSBruce Mitchener    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR istreambuf_iterator() _NOEXCEPT : __sbuf_(nullptr) {}
14008e882dcbSHoward Hinnant    _LIBCPP_INLINE_VISIBILITY istreambuf_iterator(istream_type& __s) _NOEXCEPT
1401a96d7458SHoward Hinnant        : __sbuf_(__s.rdbuf()) {}
14028e882dcbSHoward Hinnant    _LIBCPP_INLINE_VISIBILITY istreambuf_iterator(streambuf_type* __s) _NOEXCEPT
1403a96d7458SHoward Hinnant        : __sbuf_(__s) {}
14048e882dcbSHoward Hinnant    _LIBCPP_INLINE_VISIBILITY istreambuf_iterator(const __proxy& __p) _NOEXCEPT
14053e519524SHoward Hinnant        : __sbuf_(__p.__sbuf_) {}
14063e519524SHoward Hinnant
1407c206366fSHoward Hinnant    _LIBCPP_INLINE_VISIBILITY char_type  operator*() const
1408c206366fSHoward Hinnant        {return static_cast<char_type>(__sbuf_->sgetc());}
14093e519524SHoward Hinnant    _LIBCPP_INLINE_VISIBILITY istreambuf_iterator& operator++()
14103e519524SHoward Hinnant        {
1411dfdf5085SHoward Hinnant            __sbuf_->sbumpc();
14123e519524SHoward Hinnant            return *this;
14133e519524SHoward Hinnant        }
14143e519524SHoward Hinnant    _LIBCPP_INLINE_VISIBILITY __proxy              operator++(int)
14153e519524SHoward Hinnant        {
1416dfdf5085SHoward Hinnant            return __proxy(__sbuf_->sbumpc(), __sbuf_);
14173e519524SHoward Hinnant        }
14183e519524SHoward Hinnant
14193e519524SHoward Hinnant    _LIBCPP_INLINE_VISIBILITY bool equal(const istreambuf_iterator& __b) const
1420dfdf5085SHoward Hinnant        {return __test_for_eof() == __b.__test_for_eof();}
14213e519524SHoward Hinnant};
14223e519524SHoward Hinnant
14233e519524SHoward Hinnanttemplate <class _CharT, class _Traits>
14243e519524SHoward Hinnantinline _LIBCPP_INLINE_VISIBILITY
14253e519524SHoward Hinnantbool operator==(const istreambuf_iterator<_CharT,_Traits>& __a,
14263e519524SHoward Hinnant                const istreambuf_iterator<_CharT,_Traits>& __b)
14273e519524SHoward Hinnant                {return __a.equal(__b);}
14283e519524SHoward Hinnant
14293e519524SHoward Hinnanttemplate <class _CharT, class _Traits>
14303e519524SHoward Hinnantinline _LIBCPP_INLINE_VISIBILITY
14313e519524SHoward Hinnantbool operator!=(const istreambuf_iterator<_CharT,_Traits>& __a,
14323e519524SHoward Hinnant                const istreambuf_iterator<_CharT,_Traits>& __b)
14333e519524SHoward Hinnant                {return !__a.equal(__b);}
14343e519524SHoward Hinnant
14353e519524SHoward Hinnanttemplate <class _CharT, class _Traits>
1436e2f2d1edSEric Fiselierclass _LIBCPP_TEMPLATE_VIS ostreambuf_iterator
14373e519524SHoward Hinnant    : public iterator<output_iterator_tag, void, void, void, void>
14383e519524SHoward Hinnant{
14393e519524SHoward Hinnantpublic:
144071a16e40SLouis Dionne    typedef output_iterator_tag                 iterator_category;
144171a16e40SLouis Dionne    typedef void                                value_type;
144271a16e40SLouis Dionne#if _LIBCPP_STD_VER > 17
144371a16e40SLouis Dionne    typedef std::ptrdiff_t                      difference_type;
144471a16e40SLouis Dionne#else
144571a16e40SLouis Dionne    typedef void                                difference_type;
144671a16e40SLouis Dionne#endif
144771a16e40SLouis Dionne    typedef void                                pointer;
144871a16e40SLouis Dionne    typedef void                                reference;
14493e519524SHoward Hinnant    typedef _CharT                              char_type;
14503e519524SHoward Hinnant    typedef _Traits                             traits_type;
14513e519524SHoward Hinnant    typedef basic_streambuf<_CharT, _Traits>    streambuf_type;
14523e519524SHoward Hinnant    typedef basic_ostream<_CharT, _Traits>      ostream_type;
145371a16e40SLouis Dionne
14543e519524SHoward Hinnantprivate:
14553e519524SHoward Hinnant    streambuf_type* __sbuf_;
14563e519524SHoward Hinnantpublic:
14578e882dcbSHoward Hinnant    _LIBCPP_INLINE_VISIBILITY ostreambuf_iterator(ostream_type& __s) _NOEXCEPT
14583e519524SHoward Hinnant        : __sbuf_(__s.rdbuf()) {}
14598e882dcbSHoward Hinnant    _LIBCPP_INLINE_VISIBILITY ostreambuf_iterator(streambuf_type* __s) _NOEXCEPT
14603e519524SHoward Hinnant        : __sbuf_(__s) {}
14613e519524SHoward Hinnant    _LIBCPP_INLINE_VISIBILITY ostreambuf_iterator& operator=(_CharT __c)
14623e519524SHoward Hinnant        {
14633e519524SHoward Hinnant            if (__sbuf_ && traits_type::eq_int_type(__sbuf_->sputc(__c), traits_type::eof()))
1464527a7fdfSBruce Mitchener                __sbuf_ = nullptr;
14653e519524SHoward Hinnant            return *this;
14663e519524SHoward Hinnant        }
14673e519524SHoward Hinnant    _LIBCPP_INLINE_VISIBILITY ostreambuf_iterator& operator*()     {return *this;}
14683e519524SHoward Hinnant    _LIBCPP_INLINE_VISIBILITY ostreambuf_iterator& operator++()    {return *this;}
14693e519524SHoward Hinnant    _LIBCPP_INLINE_VISIBILITY ostreambuf_iterator& operator++(int) {return *this;}
1470527a7fdfSBruce Mitchener    _LIBCPP_INLINE_VISIBILITY bool failed() const _NOEXCEPT {return __sbuf_ == nullptr;}
147192b5940fSHoward Hinnant
147292b5940fSHoward Hinnant    template <class _Ch, class _Tr>
147392b5940fSHoward Hinnant    friend
147492b5940fSHoward Hinnant    _LIBCPP_HIDDEN
147592b5940fSHoward Hinnant    ostreambuf_iterator<_Ch, _Tr>
147692b5940fSHoward Hinnant    __pad_and_output(ostreambuf_iterator<_Ch, _Tr> __s,
147792b5940fSHoward Hinnant                     const _Ch* __ob, const _Ch* __op, const _Ch* __oe,
147892b5940fSHoward Hinnant                     ios_base& __iob, _Ch __fl);
14793e519524SHoward Hinnant};
14803e519524SHoward Hinnant
14813e519524SHoward Hinnanttemplate <class _Iter>
1482e2f2d1edSEric Fiselierclass _LIBCPP_TEMPLATE_VIS move_iterator
14833e519524SHoward Hinnant{
14843e519524SHoward Hinnantprivate:
14853e519524SHoward Hinnant    _Iter __i;
14863e519524SHoward Hinnantpublic:
14873e519524SHoward Hinnant    typedef _Iter                                            iterator_type;
14883e519524SHoward Hinnant    typedef typename iterator_traits<iterator_type>::value_type value_type;
14893e519524SHoward Hinnant    typedef typename iterator_traits<iterator_type>::difference_type difference_type;
149005333fc8SMarshall Clow    typedef iterator_type pointer;
1491d41c6d51SArthur O'Dwyer    typedef _If<__is_cpp17_random_access_iterator<_Iter>::value,
1492d41c6d51SArthur O'Dwyer        random_access_iterator_tag,
1493d41c6d51SArthur O'Dwyer        typename iterator_traits<_Iter>::iterator_category>  iterator_category;
1494d41c6d51SArthur O'Dwyer#if _LIBCPP_STD_VER > 17
1495d41c6d51SArthur O'Dwyer    typedef input_iterator_tag                               iterator_concept;
1496d41c6d51SArthur O'Dwyer#endif
1497d41c6d51SArthur O'Dwyer
1498046492b9SEric Fiselier#ifndef _LIBCPP_CXX03_LANG
1499906c5085SEric Fiselier    typedef typename iterator_traits<iterator_type>::reference __reference;
1500906c5085SEric Fiselier    typedef typename conditional<
1501906c5085SEric Fiselier            is_reference<__reference>::value,
1502906c5085SEric Fiselier            typename remove_reference<__reference>::type&&,
1503906c5085SEric Fiselier            __reference
1504906c5085SEric Fiselier        >::type reference;
15053e519524SHoward Hinnant#else
15063e519524SHoward Hinnant    typedef typename iterator_traits<iterator_type>::reference reference;
15073e519524SHoward Hinnant#endif
15083e519524SHoward Hinnant
1509720ef472SMarshall Clow    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
1510720ef472SMarshall Clow    move_iterator() : __i() {}
1511720ef472SMarshall Clow    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
1512720ef472SMarshall Clow    explicit move_iterator(_Iter __x) : __i(__x) {}
1513720ef472SMarshall Clow    template <class _Up>
1514720ef472SMarshall Clow      _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
1515720ef472SMarshall Clow      move_iterator(const move_iterator<_Up>& __u) : __i(__u.base()) {}
1516720ef472SMarshall Clow    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 _Iter base() const {return __i;}
1517720ef472SMarshall Clow    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
1518720ef472SMarshall Clow    reference operator*() const { return static_cast<reference>(*__i); }
1519720ef472SMarshall Clow    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
1520720ef472SMarshall Clow    pointer  operator->() const { return __i;}
1521720ef472SMarshall Clow    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
1522720ef472SMarshall Clow    move_iterator& operator++() {++__i; return *this;}
1523720ef472SMarshall Clow    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
1524720ef472SMarshall Clow    move_iterator  operator++(int) {move_iterator __tmp(*this); ++__i; return __tmp;}
1525720ef472SMarshall Clow    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
1526720ef472SMarshall Clow    move_iterator& operator--() {--__i; return *this;}
1527720ef472SMarshall Clow    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
1528720ef472SMarshall Clow    move_iterator  operator--(int) {move_iterator __tmp(*this); --__i; return __tmp;}
1529720ef472SMarshall Clow    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
1530720ef472SMarshall Clow    move_iterator  operator+ (difference_type __n) const {return move_iterator(__i + __n);}
1531720ef472SMarshall Clow    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
1532720ef472SMarshall Clow    move_iterator& operator+=(difference_type __n) {__i += __n; return *this;}
1533720ef472SMarshall Clow    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
1534720ef472SMarshall Clow    move_iterator  operator- (difference_type __n) const {return move_iterator(__i - __n);}
1535720ef472SMarshall Clow    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
1536720ef472SMarshall Clow    move_iterator& operator-=(difference_type __n) {__i -= __n; return *this;}
1537720ef472SMarshall Clow    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
1538720ef472SMarshall Clow    reference operator[](difference_type __n) const { return static_cast<reference>(__i[__n]); }
15393e519524SHoward Hinnant};
15403e519524SHoward Hinnant
15413e519524SHoward Hinnanttemplate <class _Iter1, class _Iter2>
1542720ef472SMarshall Clowinline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
15433e519524SHoward Hinnantbool
15443e519524SHoward Hinnantoperator==(const move_iterator<_Iter1>& __x, const move_iterator<_Iter2>& __y)
15453e519524SHoward Hinnant{
15463e519524SHoward Hinnant    return __x.base() == __y.base();
15473e519524SHoward Hinnant}
15483e519524SHoward Hinnant
15493e519524SHoward Hinnanttemplate <class _Iter1, class _Iter2>
1550720ef472SMarshall Clowinline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
15513e519524SHoward Hinnantbool
15523e519524SHoward Hinnantoperator<(const move_iterator<_Iter1>& __x, const move_iterator<_Iter2>& __y)
15533e519524SHoward Hinnant{
15543e519524SHoward Hinnant    return __x.base() < __y.base();
15553e519524SHoward Hinnant}
15563e519524SHoward Hinnant
15573e519524SHoward Hinnanttemplate <class _Iter1, class _Iter2>
1558720ef472SMarshall Clowinline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
15593e519524SHoward Hinnantbool
15603e519524SHoward Hinnantoperator!=(const move_iterator<_Iter1>& __x, const move_iterator<_Iter2>& __y)
15613e519524SHoward Hinnant{
15623e519524SHoward Hinnant    return __x.base() != __y.base();
15633e519524SHoward Hinnant}
15643e519524SHoward Hinnant
15653e519524SHoward Hinnanttemplate <class _Iter1, class _Iter2>
1566720ef472SMarshall Clowinline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
15673e519524SHoward Hinnantbool
15683e519524SHoward Hinnantoperator>(const move_iterator<_Iter1>& __x, const move_iterator<_Iter2>& __y)
15693e519524SHoward Hinnant{
15703e519524SHoward Hinnant    return __x.base() > __y.base();
15713e519524SHoward Hinnant}
15723e519524SHoward Hinnant
15733e519524SHoward Hinnanttemplate <class _Iter1, class _Iter2>
1574720ef472SMarshall Clowinline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
15753e519524SHoward Hinnantbool
15763e519524SHoward Hinnantoperator>=(const move_iterator<_Iter1>& __x, const move_iterator<_Iter2>& __y)
15773e519524SHoward Hinnant{
15783e519524SHoward Hinnant    return __x.base() >= __y.base();
15793e519524SHoward Hinnant}
15803e519524SHoward Hinnant
15813e519524SHoward Hinnanttemplate <class _Iter1, class _Iter2>
1582720ef472SMarshall Clowinline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
15833e519524SHoward Hinnantbool
15843e519524SHoward Hinnantoperator<=(const move_iterator<_Iter1>& __x, const move_iterator<_Iter2>& __y)
15853e519524SHoward Hinnant{
15863e519524SHoward Hinnant    return __x.base() <= __y.base();
15873e519524SHoward Hinnant}
15883e519524SHoward Hinnant
15892ee83725SMarshall Clow#ifndef _LIBCPP_CXX03_LANG
1590947ce6b5SMarshall Clowtemplate <class _Iter1, class _Iter2>
1591720ef472SMarshall Clowinline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
1592947ce6b5SMarshall Clowauto
1593947ce6b5SMarshall Clowoperator-(const move_iterator<_Iter1>& __x, const move_iterator<_Iter2>& __y)
1594947ce6b5SMarshall Clow-> decltype(__x.base() - __y.base())
1595947ce6b5SMarshall Clow{
1596947ce6b5SMarshall Clow    return __x.base() - __y.base();
1597947ce6b5SMarshall Clow}
1598947ce6b5SMarshall Clow#else
15993e519524SHoward Hinnanttemplate <class _Iter1, class _Iter2>
16003e519524SHoward Hinnantinline _LIBCPP_INLINE_VISIBILITY
16013e519524SHoward Hinnanttypename move_iterator<_Iter1>::difference_type
16023e519524SHoward Hinnantoperator-(const move_iterator<_Iter1>& __x, const move_iterator<_Iter2>& __y)
16033e519524SHoward Hinnant{
16043e519524SHoward Hinnant    return __x.base() - __y.base();
16053e519524SHoward Hinnant}
1606947ce6b5SMarshall Clow#endif
16073e519524SHoward Hinnant
16083e519524SHoward Hinnanttemplate <class _Iter>
1609720ef472SMarshall Clowinline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
16103e519524SHoward Hinnantmove_iterator<_Iter>
16113e519524SHoward Hinnantoperator+(typename move_iterator<_Iter>::difference_type __n, const move_iterator<_Iter>& __x)
16123e519524SHoward Hinnant{
16133e519524SHoward Hinnant    return move_iterator<_Iter>(__x.base() + __n);
16143e519524SHoward Hinnant}
16153e519524SHoward Hinnant
16163e519524SHoward Hinnanttemplate <class _Iter>
1617720ef472SMarshall Clowinline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
16183e519524SHoward Hinnantmove_iterator<_Iter>
161954c83368SMarshall Clowmake_move_iterator(_Iter __i)
16203e519524SHoward Hinnant{
16213e519524SHoward Hinnant    return move_iterator<_Iter>(__i);
16223e519524SHoward Hinnant}
16233e519524SHoward Hinnant
16243e519524SHoward Hinnant// __wrap_iter
16253e519524SHoward Hinnant
16263e519524SHoward Hinnanttemplate <class _Iter> class __wrap_iter;
16273e519524SHoward Hinnant
16283e519524SHoward Hinnanttemplate <class _Iter1, class _Iter2>
16299cad5025SMarshall Clow_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG
16303e519524SHoward Hinnantbool
163161b302f9SEric Fiselieroperator==(const __wrap_iter<_Iter1>&, const __wrap_iter<_Iter2>&) _NOEXCEPT;
16323e519524SHoward Hinnant
16333e519524SHoward Hinnanttemplate <class _Iter1, class _Iter2>
16349cad5025SMarshall Clow_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG
16353e519524SHoward Hinnantbool
163661b302f9SEric Fiselieroperator<(const __wrap_iter<_Iter1>&, const __wrap_iter<_Iter2>&) _NOEXCEPT;
16373e519524SHoward Hinnant
16383e519524SHoward Hinnanttemplate <class _Iter1, class _Iter2>
16399cad5025SMarshall Clow_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG
16403e519524SHoward Hinnantbool
164161b302f9SEric Fiselieroperator!=(const __wrap_iter<_Iter1>&, const __wrap_iter<_Iter2>&) _NOEXCEPT;
16423e519524SHoward Hinnant
16433e519524SHoward Hinnanttemplate <class _Iter1, class _Iter2>
16449cad5025SMarshall Clow_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG
16453e519524SHoward Hinnantbool
164661b302f9SEric Fiselieroperator>(const __wrap_iter<_Iter1>&, const __wrap_iter<_Iter2>&) _NOEXCEPT;
16473e519524SHoward Hinnant
16483e519524SHoward Hinnanttemplate <class _Iter1, class _Iter2>
16499cad5025SMarshall Clow_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG
16503e519524SHoward Hinnantbool
165161b302f9SEric Fiselieroperator>=(const __wrap_iter<_Iter1>&, const __wrap_iter<_Iter2>&) _NOEXCEPT;
16523e519524SHoward Hinnant
16533e519524SHoward Hinnanttemplate <class _Iter1, class _Iter2>
16549cad5025SMarshall Clow_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG
16553e519524SHoward Hinnantbool
165661b302f9SEric Fiselieroperator<=(const __wrap_iter<_Iter1>&, const __wrap_iter<_Iter2>&) _NOEXCEPT;
16573e519524SHoward Hinnant
16582ee83725SMarshall Clow#ifndef _LIBCPP_CXX03_LANG
1659947ce6b5SMarshall Clowtemplate <class _Iter1, class _Iter2>
16609cad5025SMarshall Clow_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG
1661947ce6b5SMarshall Clowauto
166261b302f9SEric Fiselieroperator-(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter2>& __y) _NOEXCEPT
1663947ce6b5SMarshall Clow-> decltype(__x.base() - __y.base());
1664947ce6b5SMarshall Clow#else
16653e519524SHoward Hinnanttemplate <class _Iter1, class _Iter2>
1666aeb85680SHoward Hinnant_LIBCPP_INLINE_VISIBILITY
16673e519524SHoward Hinnanttypename __wrap_iter<_Iter1>::difference_type
166861b302f9SEric Fiselieroperator-(const __wrap_iter<_Iter1>&, const __wrap_iter<_Iter2>&) _NOEXCEPT;
1669947ce6b5SMarshall Clow#endif
16703e519524SHoward Hinnant
16713e519524SHoward Hinnanttemplate <class _Iter>
16729cad5025SMarshall Clow_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG
16733e519524SHoward Hinnant__wrap_iter<_Iter>
167461b302f9SEric Fiselieroperator+(typename __wrap_iter<_Iter>::difference_type, __wrap_iter<_Iter>) _NOEXCEPT;
16753e519524SHoward Hinnant
167613c90a57SLouis Dionnetemplate <class _Ip, class _Op> _Op _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 copy(_Ip, _Ip, _Op);
167713c90a57SLouis Dionnetemplate <class _B1, class _B2> _B2 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 copy_backward(_B1, _B1, _B2);
16783ed89b51Szoecarvertemplate <class _Ip, class _Op> _Op _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 move(_Ip, _Ip, _Op);
16793ed89b51Szoecarvertemplate <class _B1, class _B2> _B2 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 move_backward(_B1, _B1, _B2);
16803e519524SHoward Hinnant
16813e519524SHoward Hinnanttemplate <class _Iter>
16823e519524SHoward Hinnantclass __wrap_iter
16833e519524SHoward Hinnant{
16843e519524SHoward Hinnantpublic:
16853e519524SHoward Hinnant    typedef _Iter                                                      iterator_type;
16863e519524SHoward Hinnant    typedef typename iterator_traits<iterator_type>::value_type        value_type;
16873e519524SHoward Hinnant    typedef typename iterator_traits<iterator_type>::difference_type   difference_type;
16883e519524SHoward Hinnant    typedef typename iterator_traits<iterator_type>::pointer           pointer;
16893e519524SHoward Hinnant    typedef typename iterator_traits<iterator_type>::reference         reference;
1690d41c6d51SArthur O'Dwyer    typedef typename iterator_traits<iterator_type>::iterator_category iterator_category;
1691d41c6d51SArthur O'Dwyer#if _LIBCPP_STD_VER > 17
1692d41c6d51SArthur O'Dwyer    typedef _If<__is_cpp17_contiguous_iterator<_Iter>::value,
1693d41c6d51SArthur O'Dwyer                contiguous_iterator_tag, iterator_category>            iterator_concept;
1694d41c6d51SArthur O'Dwyer#endif
1695d41c6d51SArthur O'Dwyer
16963e519524SHoward Hinnantprivate:
16973e519524SHoward Hinnant    iterator_type __i;
16983e519524SHoward Hinnantpublic:
169961b302f9SEric Fiselier    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG __wrap_iter() _NOEXCEPT
170007186a7dSMarshall Clow#if _LIBCPP_STD_VER > 11
170107186a7dSMarshall Clow                : __i{}
170207186a7dSMarshall Clow#endif
1703c36bfc49SHoward Hinnant    {
170431e82037SLouis Dionne#if _LIBCPP_DEBUG_LEVEL == 2
1705c36bfc49SHoward Hinnant        __get_db()->__insert_i(this);
1706c36bfc49SHoward Hinnant#endif
1707c36bfc49SHoward Hinnant    }
17089cad5025SMarshall Clow    template <class _Up> _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG
17099cad5025SMarshall Clow        __wrap_iter(const __wrap_iter<_Up>& __u,
1710527a7fdfSBruce Mitchener            typename enable_if<is_convertible<_Up, iterator_type>::value>::type* = nullptr) _NOEXCEPT
1711f554add5SHoward Hinnant            : __i(__u.base())
1712f554add5SHoward Hinnant    {
171331e82037SLouis Dionne#if _LIBCPP_DEBUG_LEVEL == 2
1714f554add5SHoward Hinnant        __get_db()->__iterator_copy(this, &__u);
1715f554add5SHoward Hinnant#endif
1716f554add5SHoward Hinnant    }
171731e82037SLouis Dionne#if _LIBCPP_DEBUG_LEVEL == 2
17189cad5025SMarshall Clow    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG
1719f554add5SHoward Hinnant    __wrap_iter(const __wrap_iter& __x)
1720f554add5SHoward Hinnant        : __i(__x.base())
1721f554add5SHoward Hinnant    {
1722f554add5SHoward Hinnant        __get_db()->__iterator_copy(this, &__x);
1723f554add5SHoward Hinnant    }
17249cad5025SMarshall Clow    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG
1725f554add5SHoward Hinnant    __wrap_iter& operator=(const __wrap_iter& __x)
1726f554add5SHoward Hinnant    {
1727f554add5SHoward Hinnant        if (this != &__x)
1728f554add5SHoward Hinnant        {
1729f554add5SHoward Hinnant            __get_db()->__iterator_copy(this, &__x);
1730f554add5SHoward Hinnant            __i = __x.__i;
1731f554add5SHoward Hinnant        }
1732f554add5SHoward Hinnant        return *this;
1733f554add5SHoward Hinnant    }
17349cad5025SMarshall Clow    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG
1735f554add5SHoward Hinnant    ~__wrap_iter()
1736f554add5SHoward Hinnant    {
1737f554add5SHoward Hinnant        __get_db()->__erase_i(this);
1738f554add5SHoward Hinnant    }
1739f554add5SHoward Hinnant#endif
174061b302f9SEric Fiselier    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG reference operator*() const _NOEXCEPT
1741f554add5SHoward Hinnant    {
174231e82037SLouis Dionne#if _LIBCPP_DEBUG_LEVEL == 2
1743f554add5SHoward Hinnant        _LIBCPP_ASSERT(__get_const_db()->__dereferenceable(this),
1744f554add5SHoward Hinnant                       "Attempted to dereference a non-dereferenceable iterator");
1745cec9af9eSHoward Hinnant#endif
1746f554add5SHoward Hinnant        return *__i;
1747f554add5SHoward Hinnant    }
174861b302f9SEric Fiselier    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG pointer  operator->() const _NOEXCEPT
17493ec1f00bSHoward Hinnant    {
175031e82037SLouis Dionne#if _LIBCPP_DEBUG_LEVEL == 2
17513ec1f00bSHoward Hinnant        _LIBCPP_ASSERT(__get_const_db()->__dereferenceable(this),
17523ec1f00bSHoward Hinnant                       "Attempted to dereference a non-dereferenceable iterator");
17533ec1f00bSHoward Hinnant#endif
175405333fc8SMarshall Clow        return (pointer)_VSTD::addressof(*__i);
17553ec1f00bSHoward Hinnant    }
175661b302f9SEric Fiselier    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG __wrap_iter& operator++() _NOEXCEPT
1757f554add5SHoward Hinnant    {
175831e82037SLouis Dionne#if _LIBCPP_DEBUG_LEVEL == 2
1759f554add5SHoward Hinnant        _LIBCPP_ASSERT(__get_const_db()->__dereferenceable(this),
1760f554add5SHoward Hinnant                       "Attempted to increment non-incrementable iterator");
1761cec9af9eSHoward Hinnant#endif
1762f554add5SHoward Hinnant        ++__i;
1763f554add5SHoward Hinnant        return *this;
1764f554add5SHoward Hinnant    }
176561b302f9SEric Fiselier    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG __wrap_iter  operator++(int) _NOEXCEPT
1766f554add5SHoward Hinnant        {__wrap_iter __tmp(*this); ++(*this); return __tmp;}
17674ce0a916SMarshall Clow
176861b302f9SEric Fiselier    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG __wrap_iter& operator--() _NOEXCEPT
1769f554add5SHoward Hinnant    {
177031e82037SLouis Dionne#if _LIBCPP_DEBUG_LEVEL == 2
1771f554add5SHoward Hinnant        _LIBCPP_ASSERT(__get_const_db()->__decrementable(this),
1772f554add5SHoward Hinnant                       "Attempted to decrement non-decrementable iterator");
1773cec9af9eSHoward Hinnant#endif
1774f554add5SHoward Hinnant        --__i;
1775f554add5SHoward Hinnant        return *this;
1776f554add5SHoward Hinnant    }
177761b302f9SEric Fiselier    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG __wrap_iter  operator--(int) _NOEXCEPT
1778f554add5SHoward Hinnant        {__wrap_iter __tmp(*this); --(*this); return __tmp;}
177961b302f9SEric Fiselier    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG __wrap_iter  operator+ (difference_type __n) const _NOEXCEPT
1780f554add5SHoward Hinnant        {__wrap_iter __w(*this); __w += __n; return __w;}
178161b302f9SEric Fiselier    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG __wrap_iter& operator+=(difference_type __n) _NOEXCEPT
1782f554add5SHoward Hinnant    {
178331e82037SLouis Dionne#if _LIBCPP_DEBUG_LEVEL == 2
1784f554add5SHoward Hinnant        _LIBCPP_ASSERT(__get_const_db()->__addable(this, __n),
1785f554add5SHoward Hinnant                   "Attempted to add/subtract iterator outside of valid range");
1786cec9af9eSHoward Hinnant#endif
1787f554add5SHoward Hinnant        __i += __n;
1788f554add5SHoward Hinnant        return *this;
1789f554add5SHoward Hinnant    }
179061b302f9SEric Fiselier    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG __wrap_iter  operator- (difference_type __n) const _NOEXCEPT
1791f554add5SHoward Hinnant        {return *this + (-__n);}
179261b302f9SEric Fiselier    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG __wrap_iter& operator-=(difference_type __n) _NOEXCEPT
1793f554add5SHoward Hinnant        {*this += -__n; return *this;}
179461b302f9SEric Fiselier    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG reference    operator[](difference_type __n) const _NOEXCEPT
1795f554add5SHoward Hinnant    {
179631e82037SLouis Dionne#if _LIBCPP_DEBUG_LEVEL == 2
1797f554add5SHoward Hinnant        _LIBCPP_ASSERT(__get_const_db()->__subscriptable(this, __n),
1798f554add5SHoward Hinnant                   "Attempted to subscript iterator outside of valid range");
1799cec9af9eSHoward Hinnant#endif
1800f554add5SHoward Hinnant        return __i[__n];
1801f554add5SHoward Hinnant    }
18023e519524SHoward Hinnant
180361b302f9SEric Fiselier    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG iterator_type base() const _NOEXCEPT {return __i;}
18043e519524SHoward Hinnant
18053e519524SHoward Hinnantprivate:
180631e82037SLouis Dionne#if _LIBCPP_DEBUG_LEVEL == 2
18079cad5025SMarshall Clow    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG __wrap_iter(const void* __p, iterator_type __x) : __i(__x)
1808f554add5SHoward Hinnant    {
1809f554add5SHoward Hinnant        __get_db()->__insert_ic(this, __p);
1810f554add5SHoward Hinnant    }
1811fc88dbd2SHoward Hinnant#else
181261b302f9SEric Fiselier    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG __wrap_iter(iterator_type __x) _NOEXCEPT : __i(__x) {}
1813f554add5SHoward Hinnant#endif
18143e519524SHoward Hinnant
18153e519524SHoward Hinnant    template <class _Up> friend class __wrap_iter;
18163e519524SHoward Hinnant    template <class _CharT, class _Traits, class _Alloc> friend class basic_string;
1817e2f2d1edSEric Fiselier    template <class _Tp, class _Alloc> friend class _LIBCPP_TEMPLATE_VIS vector;
18187ad06a93SMarshall Clow    template <class _Tp, size_t> friend class _LIBCPP_TEMPLATE_VIS span;
18193e519524SHoward Hinnant
18203e519524SHoward Hinnant    template <class _Iter1, class _Iter2>
18219cad5025SMarshall Clow    _LIBCPP_CONSTEXPR_IF_NODEBUG friend
18223e519524SHoward Hinnant    bool
182361b302f9SEric Fiselier    operator==(const __wrap_iter<_Iter1>&, const __wrap_iter<_Iter2>&) _NOEXCEPT;
18243e519524SHoward Hinnant
18253e519524SHoward Hinnant    template <class _Iter1, class _Iter2>
18269cad5025SMarshall Clow    _LIBCPP_CONSTEXPR_IF_NODEBUG friend
18273e519524SHoward Hinnant    bool
182861b302f9SEric Fiselier    operator<(const __wrap_iter<_Iter1>&, const __wrap_iter<_Iter2>&) _NOEXCEPT;
18293e519524SHoward Hinnant
18303e519524SHoward Hinnant    template <class _Iter1, class _Iter2>
18319cad5025SMarshall Clow    _LIBCPP_CONSTEXPR_IF_NODEBUG friend
18323e519524SHoward Hinnant    bool
183361b302f9SEric Fiselier    operator!=(const __wrap_iter<_Iter1>&, const __wrap_iter<_Iter2>&) _NOEXCEPT;
18343e519524SHoward Hinnant
18353e519524SHoward Hinnant    template <class _Iter1, class _Iter2>
18369cad5025SMarshall Clow    _LIBCPP_CONSTEXPR_IF_NODEBUG friend
18373e519524SHoward Hinnant    bool
183861b302f9SEric Fiselier    operator>(const __wrap_iter<_Iter1>&, const __wrap_iter<_Iter2>&) _NOEXCEPT;
18393e519524SHoward Hinnant
18403e519524SHoward Hinnant    template <class _Iter1, class _Iter2>
18419cad5025SMarshall Clow    _LIBCPP_CONSTEXPR_IF_NODEBUG friend
18423e519524SHoward Hinnant    bool
184361b302f9SEric Fiselier    operator>=(const __wrap_iter<_Iter1>&, const __wrap_iter<_Iter2>&) _NOEXCEPT;
18443e519524SHoward Hinnant
18453e519524SHoward Hinnant    template <class _Iter1, class _Iter2>
18469cad5025SMarshall Clow    _LIBCPP_CONSTEXPR_IF_NODEBUG friend
18473e519524SHoward Hinnant    bool
184861b302f9SEric Fiselier    operator<=(const __wrap_iter<_Iter1>&, const __wrap_iter<_Iter2>&) _NOEXCEPT;
18493e519524SHoward Hinnant
18502ee83725SMarshall Clow#ifndef _LIBCPP_CXX03_LANG
1851947ce6b5SMarshall Clow    template <class _Iter1, class _Iter2>
18529cad5025SMarshall Clow    _LIBCPP_CONSTEXPR_IF_NODEBUG friend
1853947ce6b5SMarshall Clow    auto
185461b302f9SEric Fiselier    operator-(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter2>& __y) _NOEXCEPT
1855947ce6b5SMarshall Clow    -> decltype(__x.base() - __y.base());
1856947ce6b5SMarshall Clow#else
18573e519524SHoward Hinnant    template <class _Iter1, class _Iter2>
18589cad5025SMarshall Clow    _LIBCPP_CONSTEXPR_IF_NODEBUG friend
18593e519524SHoward Hinnant    typename __wrap_iter<_Iter1>::difference_type
186061b302f9SEric Fiselier    operator-(const __wrap_iter<_Iter1>&, const __wrap_iter<_Iter2>&) _NOEXCEPT;
1861947ce6b5SMarshall Clow#endif
18623e519524SHoward Hinnant
18633e519524SHoward Hinnant    template <class _Iter1>
18649cad5025SMarshall Clow    _LIBCPP_CONSTEXPR_IF_NODEBUG friend
18653e519524SHoward Hinnant    __wrap_iter<_Iter1>
186661b302f9SEric Fiselier    operator+(typename __wrap_iter<_Iter1>::difference_type, __wrap_iter<_Iter1>) _NOEXCEPT;
18673e519524SHoward Hinnant
186813c90a57SLouis Dionne    template <class _Ip, class _Op> friend _LIBCPP_CONSTEXPR_AFTER_CXX17 _Op copy(_Ip, _Ip, _Op);
186913c90a57SLouis Dionne    template <class _B1, class _B2> friend _LIBCPP_CONSTEXPR_AFTER_CXX17 _B2 copy_backward(_B1, _B1, _B2);
18703ed89b51Szoecarver    template <class _Ip, class _Op> friend _LIBCPP_CONSTEXPR_AFTER_CXX17 _Op move(_Ip, _Ip, _Op);
18713ed89b51Szoecarver    template <class _B1, class _B2> friend _LIBCPP_CONSTEXPR_AFTER_CXX17 _B2 move_backward(_B1, _B1, _B2);
18723e519524SHoward Hinnant};
18733e519524SHoward Hinnant
1874d41c6d51SArthur O'Dwyer#if _LIBCPP_STD_VER <= 17
1875d41c6d51SArthur O'Dwyertemplate <class _It>
1876d41c6d51SArthur O'Dwyerstruct __is_cpp17_contiguous_iterator<__wrap_iter<_It> > : __is_cpp17_contiguous_iterator<_It> {};
1877d41c6d51SArthur O'Dwyer#endif
1878d41c6d51SArthur O'Dwyer
1879d41c6d51SArthur O'Dwyertemplate <class _Iter>
1880d41c6d51SArthur O'Dwyer_LIBCPP_CONSTEXPR
1881d41c6d51SArthur O'Dwyer_EnableIf<__is_cpp17_contiguous_iterator<_Iter>::value, decltype(_VSTD::__to_address(declval<_Iter>()))>
1882d41c6d51SArthur O'Dwyer__to_address(__wrap_iter<_Iter> __w) _NOEXCEPT {
1883d41c6d51SArthur O'Dwyer    return _VSTD::__to_address(__w.base());
1884d41c6d51SArthur O'Dwyer}
1885d41c6d51SArthur O'Dwyer
18863e519524SHoward Hinnanttemplate <class _Iter1, class _Iter2>
18879cad5025SMarshall Clowinline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG
18883e519524SHoward Hinnantbool
188961b302f9SEric Fiselieroperator==(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter2>& __y) _NOEXCEPT
18903e519524SHoward Hinnant{
18913e519524SHoward Hinnant    return __x.base() == __y.base();
18923e519524SHoward Hinnant}
18933e519524SHoward Hinnant
18943e519524SHoward Hinnanttemplate <class _Iter1, class _Iter2>
18959cad5025SMarshall Clowinline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG
18963e519524SHoward Hinnantbool
189761b302f9SEric Fiselieroperator<(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter2>& __y) _NOEXCEPT
18983e519524SHoward Hinnant{
189931e82037SLouis Dionne#if _LIBCPP_DEBUG_LEVEL == 2
190042a3046eSHoward Hinnant    _LIBCPP_ASSERT(__get_const_db()->__less_than_comparable(&__x, &__y),
1901f554add5SHoward Hinnant                   "Attempted to compare incomparable iterators");
1902cec9af9eSHoward Hinnant#endif
19033e519524SHoward Hinnant    return __x.base() < __y.base();
19043e519524SHoward Hinnant}
19053e519524SHoward Hinnant
19063e519524SHoward Hinnanttemplate <class _Iter1, class _Iter2>
19079cad5025SMarshall Clowinline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG
19083e519524SHoward Hinnantbool
190961b302f9SEric Fiselieroperator!=(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter2>& __y) _NOEXCEPT
19103e519524SHoward Hinnant{
1911f554add5SHoward Hinnant    return !(__x == __y);
19123e519524SHoward Hinnant}
19133e519524SHoward Hinnant
19143e519524SHoward Hinnanttemplate <class _Iter1, class _Iter2>
19159cad5025SMarshall Clowinline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG
19163e519524SHoward Hinnantbool
191761b302f9SEric Fiselieroperator>(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter2>& __y) _NOEXCEPT
19183e519524SHoward Hinnant{
1919f554add5SHoward Hinnant    return __y < __x;
19203e519524SHoward Hinnant}
19213e519524SHoward Hinnant
19223e519524SHoward Hinnanttemplate <class _Iter1, class _Iter2>
19239cad5025SMarshall Clowinline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG
19243e519524SHoward Hinnantbool
192561b302f9SEric Fiselieroperator>=(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter2>& __y) _NOEXCEPT
19263e519524SHoward Hinnant{
1927f554add5SHoward Hinnant    return !(__x < __y);
19283e519524SHoward Hinnant}
19293e519524SHoward Hinnant
19303e519524SHoward Hinnanttemplate <class _Iter1, class _Iter2>
19319cad5025SMarshall Clowinline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG
19323e519524SHoward Hinnantbool
193361b302f9SEric Fiselieroperator<=(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter2>& __y) _NOEXCEPT
19343e519524SHoward Hinnant{
1935f554add5SHoward Hinnant    return !(__y < __x);
19363e519524SHoward Hinnant}
19373e519524SHoward Hinnant
19386e551ae1SHoward Hinnanttemplate <class _Iter1>
19399cad5025SMarshall Clowinline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG
19406e551ae1SHoward Hinnantbool
194161b302f9SEric Fiselieroperator!=(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter1>& __y) _NOEXCEPT
19426e551ae1SHoward Hinnant{
19436e551ae1SHoward Hinnant    return !(__x == __y);
19446e551ae1SHoward Hinnant}
19456e551ae1SHoward Hinnant
19466e551ae1SHoward Hinnanttemplate <class _Iter1>
19479cad5025SMarshall Clowinline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG
19486e551ae1SHoward Hinnantbool
194961b302f9SEric Fiselieroperator>(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter1>& __y) _NOEXCEPT
19506e551ae1SHoward Hinnant{
19516e551ae1SHoward Hinnant    return __y < __x;
19526e551ae1SHoward Hinnant}
19536e551ae1SHoward Hinnant
19546e551ae1SHoward Hinnanttemplate <class _Iter1>
19559cad5025SMarshall Clowinline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG
19566e551ae1SHoward Hinnantbool
195761b302f9SEric Fiselieroperator>=(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter1>& __y) _NOEXCEPT
19586e551ae1SHoward Hinnant{
19596e551ae1SHoward Hinnant    return !(__x < __y);
19606e551ae1SHoward Hinnant}
19616e551ae1SHoward Hinnant
19626e551ae1SHoward Hinnanttemplate <class _Iter1>
19639cad5025SMarshall Clowinline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG
19646e551ae1SHoward Hinnantbool
196561b302f9SEric Fiselieroperator<=(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter1>& __y) _NOEXCEPT
19666e551ae1SHoward Hinnant{
19676e551ae1SHoward Hinnant    return !(__y < __x);
19686e551ae1SHoward Hinnant}
19696e551ae1SHoward Hinnant
19702ee83725SMarshall Clow#ifndef _LIBCPP_CXX03_LANG
1971947ce6b5SMarshall Clowtemplate <class _Iter1, class _Iter2>
19729cad5025SMarshall Clowinline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG
1973947ce6b5SMarshall Clowauto
197461b302f9SEric Fiselieroperator-(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter2>& __y) _NOEXCEPT
1975947ce6b5SMarshall Clow-> decltype(__x.base() - __y.base())
1976947ce6b5SMarshall Clow{
197731e82037SLouis Dionne#if _LIBCPP_DEBUG_LEVEL == 2
1978947ce6b5SMarshall Clow    _LIBCPP_ASSERT(__get_const_db()->__less_than_comparable(&__x, &__y),
1979947ce6b5SMarshall Clow                   "Attempted to subtract incompatible iterators");
1980947ce6b5SMarshall Clow#endif
1981947ce6b5SMarshall Clow    return __x.base() - __y.base();
1982947ce6b5SMarshall Clow}
1983947ce6b5SMarshall Clow#else
19843e519524SHoward Hinnanttemplate <class _Iter1, class _Iter2>
19859cad5025SMarshall Clowinline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG
19863e519524SHoward Hinnanttypename __wrap_iter<_Iter1>::difference_type
198761b302f9SEric Fiselieroperator-(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter2>& __y) _NOEXCEPT
19883e519524SHoward Hinnant{
198931e82037SLouis Dionne#if _LIBCPP_DEBUG_LEVEL == 2
199042a3046eSHoward Hinnant    _LIBCPP_ASSERT(__get_const_db()->__less_than_comparable(&__x, &__y),
1991f554add5SHoward Hinnant                   "Attempted to subtract incompatible iterators");
1992cec9af9eSHoward Hinnant#endif
19933e519524SHoward Hinnant    return __x.base() - __y.base();
19943e519524SHoward Hinnant}
1995947ce6b5SMarshall Clow#endif
19963e519524SHoward Hinnant
19973e519524SHoward Hinnanttemplate <class _Iter>
19989cad5025SMarshall Clowinline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG
19993e519524SHoward Hinnant__wrap_iter<_Iter>
20003e519524SHoward Hinnantoperator+(typename __wrap_iter<_Iter>::difference_type __n,
200161b302f9SEric Fiselier          __wrap_iter<_Iter> __x) _NOEXCEPT
20023e519524SHoward Hinnant{
2003f554add5SHoward Hinnant    __x += __n;
2004f554add5SHoward Hinnant    return __x;
20053e519524SHoward Hinnant}
20063e519524SHoward Hinnant
200776b4afc0SMarshall Clowtemplate <class _Iter>
200876b4afc0SMarshall Clowstruct __libcpp_is_trivial_iterator
200976b4afc0SMarshall Clow    : public _LIBCPP_BOOL_CONSTANT(is_pointer<_Iter>::value) {};
201076b4afc0SMarshall Clow
201176b4afc0SMarshall Clowtemplate <class _Iter>
201276b4afc0SMarshall Clowstruct __libcpp_is_trivial_iterator<move_iterator<_Iter> >
201376b4afc0SMarshall Clow    : public _LIBCPP_BOOL_CONSTANT(__libcpp_is_trivial_iterator<_Iter>::value) {};
201476b4afc0SMarshall Clow
201576b4afc0SMarshall Clowtemplate <class _Iter>
201676b4afc0SMarshall Clowstruct __libcpp_is_trivial_iterator<reverse_iterator<_Iter> >
201776b4afc0SMarshall Clow    : public _LIBCPP_BOOL_CONSTANT(__libcpp_is_trivial_iterator<_Iter>::value) {};
201876b4afc0SMarshall Clow
201976b4afc0SMarshall Clowtemplate <class _Iter>
202076b4afc0SMarshall Clowstruct __libcpp_is_trivial_iterator<__wrap_iter<_Iter> >
202176b4afc0SMarshall Clow    : public _LIBCPP_BOOL_CONSTANT(__libcpp_is_trivial_iterator<_Iter>::value) {};
202276b4afc0SMarshall Clow
202376b4afc0SMarshall Clow
20243772a46aSMarshall Clowtemplate <class _Tp, size_t _Np>
20252ffa1705SMarshall Clow_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
20263772a46aSMarshall Clow_Tp*
20273772a46aSMarshall Clowbegin(_Tp (&__array)[_Np])
20283772a46aSMarshall Clow{
20293772a46aSMarshall Clow    return __array;
20303772a46aSMarshall Clow}
20313772a46aSMarshall Clow
20323772a46aSMarshall Clowtemplate <class _Tp, size_t _Np>
20332ffa1705SMarshall Clow_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
20343772a46aSMarshall Clow_Tp*
20353772a46aSMarshall Clowend(_Tp (&__array)[_Np])
20363772a46aSMarshall Clow{
20373772a46aSMarshall Clow    return __array + _Np;
20383772a46aSMarshall Clow}
20393772a46aSMarshall Clow
204054613ab4SEric Fiselier#if !defined(_LIBCPP_CXX03_LANG)
2041c66a611bSMarshall Clow
2042c003db1fSHoward Hinnanttemplate <class _Cp>
20432ffa1705SMarshall Clow_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
20443e519524SHoward Hinnantauto
2045c003db1fSHoward Hinnantbegin(_Cp& __c) -> decltype(__c.begin())
20463e519524SHoward Hinnant{
20473e519524SHoward Hinnant    return __c.begin();
20483e519524SHoward Hinnant}
20493e519524SHoward Hinnant
2050c003db1fSHoward Hinnanttemplate <class _Cp>
20512ffa1705SMarshall Clow_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
20523e519524SHoward Hinnantauto
2053c003db1fSHoward Hinnantbegin(const _Cp& __c) -> decltype(__c.begin())
20543e519524SHoward Hinnant{
20553e519524SHoward Hinnant    return __c.begin();
20563e519524SHoward Hinnant}
20573e519524SHoward Hinnant
2058c003db1fSHoward Hinnanttemplate <class _Cp>
20592ffa1705SMarshall Clow_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
20603e519524SHoward Hinnantauto
2061c003db1fSHoward Hinnantend(_Cp& __c) -> decltype(__c.end())
20623e519524SHoward Hinnant{
20633e519524SHoward Hinnant    return __c.end();
20643e519524SHoward Hinnant}
20653e519524SHoward Hinnant
2066c003db1fSHoward Hinnanttemplate <class _Cp>
20672ffa1705SMarshall Clow_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
20683e519524SHoward Hinnantauto
2069c003db1fSHoward Hinnantend(const _Cp& __c) -> decltype(__c.end())
20703e519524SHoward Hinnant{
20713e519524SHoward Hinnant    return __c.end();
20723e519524SHoward Hinnant}
20733e519524SHoward Hinnant
20741e548c72SMarshall Clow#if _LIBCPP_STD_VER > 11
20751e548c72SMarshall Clow
20763772a46aSMarshall Clowtemplate <class _Tp, size_t _Np>
20772ffa1705SMarshall Clow_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
20783772a46aSMarshall Clowreverse_iterator<_Tp*> rbegin(_Tp (&__array)[_Np])
20793772a46aSMarshall Clow{
20803772a46aSMarshall Clow    return reverse_iterator<_Tp*>(__array + _Np);
20813772a46aSMarshall Clow}
20823772a46aSMarshall Clow
20833772a46aSMarshall Clowtemplate <class _Tp, size_t _Np>
20842ffa1705SMarshall Clow_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
20853772a46aSMarshall Clowreverse_iterator<_Tp*> rend(_Tp (&__array)[_Np])
20863772a46aSMarshall Clow{
20873772a46aSMarshall Clow    return reverse_iterator<_Tp*>(__array);
20883772a46aSMarshall Clow}
20893772a46aSMarshall Clow
20903772a46aSMarshall Clowtemplate <class _Ep>
20912ffa1705SMarshall Clow_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
20923772a46aSMarshall Clowreverse_iterator<const _Ep*> rbegin(initializer_list<_Ep> __il)
20933772a46aSMarshall Clow{
20943772a46aSMarshall Clow    return reverse_iterator<const _Ep*>(__il.end());
20953772a46aSMarshall Clow}
20963772a46aSMarshall Clow
20973772a46aSMarshall Clowtemplate <class _Ep>
20982ffa1705SMarshall Clow_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
20993772a46aSMarshall Clowreverse_iterator<const _Ep*> rend(initializer_list<_Ep> __il)
21003772a46aSMarshall Clow{
21013772a46aSMarshall Clow    return reverse_iterator<const _Ep*>(__il.begin());
21023772a46aSMarshall Clow}
21033772a46aSMarshall Clow
21041e548c72SMarshall Clowtemplate <class _Cp>
21052ffa1705SMarshall Clow_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
21067725546aSMarshall Clowauto cbegin(const _Cp& __c) -> decltype(_VSTD::begin(__c))
21071e548c72SMarshall Clow{
21087725546aSMarshall Clow    return _VSTD::begin(__c);
21091e548c72SMarshall Clow}
21101e548c72SMarshall Clow
21111e548c72SMarshall Clowtemplate <class _Cp>
21122ffa1705SMarshall Clow_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
21137725546aSMarshall Clowauto cend(const _Cp& __c) -> decltype(_VSTD::end(__c))
21141e548c72SMarshall Clow{
21157725546aSMarshall Clow    return _VSTD::end(__c);
21161e548c72SMarshall Clow}
21171e548c72SMarshall Clow
21181e548c72SMarshall Clowtemplate <class _Cp>
21192ffa1705SMarshall Clow_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
21201e548c72SMarshall Clowauto rbegin(_Cp& __c) -> decltype(__c.rbegin())
21211e548c72SMarshall Clow{
21221e548c72SMarshall Clow    return __c.rbegin();
21231e548c72SMarshall Clow}
21241e548c72SMarshall Clow
21251e548c72SMarshall Clowtemplate <class _Cp>
21262ffa1705SMarshall Clow_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
21271e548c72SMarshall Clowauto rbegin(const _Cp& __c) -> decltype(__c.rbegin())
21281e548c72SMarshall Clow{
21291e548c72SMarshall Clow    return __c.rbegin();
21301e548c72SMarshall Clow}
21311e548c72SMarshall Clow
21321e548c72SMarshall Clowtemplate <class _Cp>
21332ffa1705SMarshall Clow_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
21341e548c72SMarshall Clowauto rend(_Cp& __c) -> decltype(__c.rend())
21351e548c72SMarshall Clow{
21361e548c72SMarshall Clow    return __c.rend();
21371e548c72SMarshall Clow}
21381e548c72SMarshall Clow
21391e548c72SMarshall Clowtemplate <class _Cp>
21402ffa1705SMarshall Clow_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
21411e548c72SMarshall Clowauto rend(const _Cp& __c) -> decltype(__c.rend())
21421e548c72SMarshall Clow{
21431e548c72SMarshall Clow    return __c.rend();
21441e548c72SMarshall Clow}
21451e548c72SMarshall Clow
21461e548c72SMarshall Clowtemplate <class _Cp>
21472ffa1705SMarshall Clow_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
21487725546aSMarshall Clowauto crbegin(const _Cp& __c) -> decltype(_VSTD::rbegin(__c))
21491e548c72SMarshall Clow{
21507725546aSMarshall Clow    return _VSTD::rbegin(__c);
21511e548c72SMarshall Clow}
21521e548c72SMarshall Clow
21531e548c72SMarshall Clowtemplate <class _Cp>
21542ffa1705SMarshall Clow_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
21557725546aSMarshall Clowauto crend(const _Cp& __c) -> decltype(_VSTD::rend(__c))
21561e548c72SMarshall Clow{
21577725546aSMarshall Clow    return _VSTD::rend(__c);
21581e548c72SMarshall Clow}
21591e548c72SMarshall Clow
21601e548c72SMarshall Clow#endif
21611e548c72SMarshall Clow
21621e548c72SMarshall Clow
216354613ab4SEric Fiselier#else  // defined(_LIBCPP_CXX03_LANG)
21643e519524SHoward Hinnant
2165c003db1fSHoward Hinnanttemplate <class _Cp>
21662ffa1705SMarshall Clow_LIBCPP_INLINE_VISIBILITY
2167c003db1fSHoward Hinnanttypename _Cp::iterator
2168c003db1fSHoward Hinnantbegin(_Cp& __c)
21693e519524SHoward Hinnant{
21703e519524SHoward Hinnant    return __c.begin();
21713e519524SHoward Hinnant}
21723e519524SHoward Hinnant
2173c003db1fSHoward Hinnanttemplate <class _Cp>
21742ffa1705SMarshall Clow_LIBCPP_INLINE_VISIBILITY
2175c003db1fSHoward Hinnanttypename _Cp::const_iterator
2176c003db1fSHoward Hinnantbegin(const _Cp& __c)
21773e519524SHoward Hinnant{
21783e519524SHoward Hinnant    return __c.begin();
21793e519524SHoward Hinnant}
21803e519524SHoward Hinnant
2181c003db1fSHoward Hinnanttemplate <class _Cp>
21822ffa1705SMarshall Clow_LIBCPP_INLINE_VISIBILITY
2183c003db1fSHoward Hinnanttypename _Cp::iterator
2184c003db1fSHoward Hinnantend(_Cp& __c)
21853e519524SHoward Hinnant{
21863e519524SHoward Hinnant    return __c.end();
21873e519524SHoward Hinnant}
21883e519524SHoward Hinnant
2189c003db1fSHoward Hinnanttemplate <class _Cp>
21902ffa1705SMarshall Clow_LIBCPP_INLINE_VISIBILITY
2191c003db1fSHoward Hinnanttypename _Cp::const_iterator
2192c003db1fSHoward Hinnantend(const _Cp& __c)
21933e519524SHoward Hinnant{
21943e519524SHoward Hinnant    return __c.end();
21953e519524SHoward Hinnant}
21963e519524SHoward Hinnant
219754613ab4SEric Fiselier#endif  // !defined(_LIBCPP_CXX03_LANG)
21983e519524SHoward Hinnant
2199ad755104SMarshall Clow#if _LIBCPP_STD_VER > 14
2200d1dcda19SMarshall Clow
2201d1dcda19SMarshall Clow// #if _LIBCPP_STD_VER > 11
2202d1dcda19SMarshall Clow// template <>
2203d1dcda19SMarshall Clow// struct _LIBCPP_TEMPLATE_VIS plus<void>
2204d1dcda19SMarshall Clow// {
2205d1dcda19SMarshall Clow//     template <class _T1, class _T2>
2206d1dcda19SMarshall Clow//     _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
2207d1dcda19SMarshall Clow//     auto operator()(_T1&& __t, _T2&& __u) const
2208d1dcda19SMarshall Clow//     _NOEXCEPT_(noexcept(_VSTD::forward<_T1>(__t) + _VSTD::forward<_T2>(__u)))
2209d1dcda19SMarshall Clow//     -> decltype        (_VSTD::forward<_T1>(__t) + _VSTD::forward<_T2>(__u))
2210d1dcda19SMarshall Clow//         { return        _VSTD::forward<_T1>(__t) + _VSTD::forward<_T2>(__u); }
2211d1dcda19SMarshall Clow//     typedef void is_transparent;
2212d1dcda19SMarshall Clow// };
2213d1dcda19SMarshall Clow// #endif
2214d1dcda19SMarshall Clow
221588d21343SMarshall Clowtemplate <class _Cont>
22162ffa1705SMarshall Clow_LIBCPP_INLINE_VISIBILITY
2217d1dcda19SMarshall Clowconstexpr auto size(const _Cont& __c)
2218d1dcda19SMarshall Clow_NOEXCEPT_(noexcept(__c.size()))
2219d1dcda19SMarshall Clow-> decltype        (__c.size())
2220d1dcda19SMarshall Clow{ return            __c.size(); }
2221ad755104SMarshall Clow
222288d21343SMarshall Clowtemplate <class _Tp, size_t _Sz>
22232ffa1705SMarshall Clow_LIBCPP_INLINE_VISIBILITY
2224fd838227SEric Fiselierconstexpr size_t size(const _Tp (&)[_Sz]) noexcept { return _Sz; }
2225ad755104SMarshall Clow
22267d3986eaSMarshall Clow#if _LIBCPP_STD_VER > 17
22277d3986eaSMarshall Clowtemplate <class _Cont>
22282ffa1705SMarshall Clow_LIBCPP_INLINE_VISIBILITY
22297d3986eaSMarshall Clowconstexpr auto ssize(const _Cont& __c)
22307d3986eaSMarshall Clow_NOEXCEPT_(noexcept(static_cast<common_type_t<ptrdiff_t, make_signed_t<decltype(__c.size())>>>(__c.size())))
22317d3986eaSMarshall Clow->                              common_type_t<ptrdiff_t, make_signed_t<decltype(__c.size())>>
22327d3986eaSMarshall Clow{ return            static_cast<common_type_t<ptrdiff_t, make_signed_t<decltype(__c.size())>>>(__c.size()); }
22337d3986eaSMarshall Clow
22347d3986eaSMarshall Clowtemplate <class _Tp, ptrdiff_t _Sz>
22352ffa1705SMarshall Clow_LIBCPP_INLINE_VISIBILITY
22367d3986eaSMarshall Clowconstexpr ptrdiff_t ssize(const _Tp (&)[_Sz]) noexcept { return _Sz; }
22377d3986eaSMarshall Clow#endif
22387d3986eaSMarshall Clow
223988d21343SMarshall Clowtemplate <class _Cont>
22402ffa1705SMarshall Clow_LIBCPP_NODISCARD_AFTER_CXX17 _LIBCPP_INLINE_VISIBILITY
2241d1dcda19SMarshall Clowconstexpr auto empty(const _Cont& __c)
2242d1dcda19SMarshall Clow_NOEXCEPT_(noexcept(__c.empty()))
2243d1dcda19SMarshall Clow-> decltype        (__c.empty())
2244d1dcda19SMarshall Clow{ return            __c.empty(); }
2245ad755104SMarshall Clow
224688d21343SMarshall Clowtemplate <class _Tp, size_t _Sz>
22472ffa1705SMarshall Clow_LIBCPP_NODISCARD_AFTER_CXX17 _LIBCPP_INLINE_VISIBILITY
2248fd838227SEric Fiselierconstexpr bool empty(const _Tp (&)[_Sz]) noexcept { return false; }
2249ad755104SMarshall Clow
2250ad755104SMarshall Clowtemplate <class _Ep>
22512ffa1705SMarshall Clow_LIBCPP_NODISCARD_AFTER_CXX17 _LIBCPP_INLINE_VISIBILITY
2252ad755104SMarshall Clowconstexpr bool empty(initializer_list<_Ep> __il) noexcept { return __il.size() == 0; }
2253ad755104SMarshall Clow
225488d21343SMarshall Clowtemplate <class _Cont> constexpr
22552ffa1705SMarshall Clow_LIBCPP_INLINE_VISIBILITY
2256d1dcda19SMarshall Clowauto data(_Cont& __c)
2257d1dcda19SMarshall Clow_NOEXCEPT_(noexcept(__c.data()))
2258d1dcda19SMarshall Clow-> decltype        (__c.data())
2259d1dcda19SMarshall Clow{ return            __c.data(); }
2260ad755104SMarshall Clow
226188d21343SMarshall Clowtemplate <class _Cont> constexpr
22622ffa1705SMarshall Clow_LIBCPP_INLINE_VISIBILITY
2263d1dcda19SMarshall Clowauto data(const _Cont& __c)
2264d1dcda19SMarshall Clow_NOEXCEPT_(noexcept(__c.data()))
2265d1dcda19SMarshall Clow-> decltype        (__c.data())
2266d1dcda19SMarshall Clow{ return            __c.data(); }
2267ad755104SMarshall Clow
226888d21343SMarshall Clowtemplate <class _Tp, size_t _Sz>
22692ffa1705SMarshall Clow_LIBCPP_INLINE_VISIBILITY
227088d21343SMarshall Clowconstexpr _Tp* data(_Tp (&__array)[_Sz]) noexcept { return __array; }
2271ad755104SMarshall Clow
2272ad755104SMarshall Clowtemplate <class _Ep>
22732ffa1705SMarshall Clow_LIBCPP_INLINE_VISIBILITY
2274ad755104SMarshall Clowconstexpr const _Ep* data(initializer_list<_Ep> __il) noexcept { return __il.begin(); }
2275ad755104SMarshall Clow#endif
2276ad755104SMarshall Clow
22772ac6babcSArthur O'Dwyertemplate <class _Container, class _Predicate>
22782ac6babcSArthur O'Dwyertypename _Container::size_type
22792ac6babcSArthur O'Dwyer__libcpp_erase_if_container(_Container& __c, _Predicate& __pred) {
22802ac6babcSArthur O'Dwyer  typename _Container::size_type __old_size = __c.size();
22812ac6babcSArthur O'Dwyer
22822ac6babcSArthur O'Dwyer  const typename _Container::iterator __last = __c.end();
22832ac6babcSArthur O'Dwyer  for (typename _Container::iterator __iter = __c.begin(); __iter != __last;) {
22842ac6babcSArthur O'Dwyer    if (__pred(*__iter))
22852ac6babcSArthur O'Dwyer      __iter = __c.erase(__iter);
22862ac6babcSArthur O'Dwyer    else
22872ac6babcSArthur O'Dwyer      ++__iter;
22882ac6babcSArthur O'Dwyer  }
22892ac6babcSArthur O'Dwyer
22902ac6babcSArthur O'Dwyer  return __old_size - __c.size();
22912ac6babcSArthur O'Dwyer}
2292ad755104SMarshall Clow
22933e519524SHoward Hinnant_LIBCPP_END_NAMESPACE_STD
22943e519524SHoward Hinnant
22953e519524SHoward Hinnant#endif  // _LIBCPP_ITERATOR
2296