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
219816d43cSChristopher Di Bellatemplate<class T>
229816d43cSChristopher Di Bella  using iter_difference_t = see below;             // since C++20
239816d43cSChristopher Di Bella
24f280505aSChristopher Di Bellatemplate<class> struct indirectly_readable_traits; // since C++20
259816d43cSChristopher Di Bellatemplate<class T>
269816d43cSChristopher Di Bella  using iter_value_t = see below;                  // since C++20
273e519524SHoward Hinnant
283e519524SHoward Hinnanttemplate<class Iterator>
299f01ac3bSzoecarverstruct iterator_traits;
303e519524SHoward Hinnant
313e519524SHoward Hinnanttemplate<class T>
329f01ac3bSzoecarver  requires is_object_v<T>                    // since C++20
339f01ac3bSzoecarverstruct iterator_traits<T*>;
343e519524SHoward Hinnant
350148b653SChristopher Di Bellatemplate<dereferenceable T>
360148b653SChristopher Di Bella  using iter_reference_t = decltype(*declval<T&>());
370148b653SChristopher Di Bella
3897e383aaSLouis Dionnenamespace ranges::inline unspecified {
3997e383aaSLouis Dionne    inline constexpr unspecified iter_move = unspecified; // since C++20, nodiscard as an extension
4097e383aaSLouis Dionne}}
4197e383aaSLouis Dionne
4297e383aaSLouis Dionnetemplate<dereferenceable T>
4397e383aaSLouis Dionne  requires ...
4497e383aaSLouis Dionneusing iter_rvalue_reference_t = decltype(ranges::iter_move(declval<T&>())); // since C++20
4597e383aaSLouis Dionne
46*57ebf3d0SLouis Dionne// [iterator.concepts], iterator concepts
47*57ebf3d0SLouis Dionne// [iterator.concept.readable], concept indirectly_readable
48*57ebf3d0SLouis Dionnetemplate<class In>
49*57ebf3d0SLouis Dionne  concept indirectly_readable = see below;                // since C++20
50*57ebf3d0SLouis Dionne
51*57ebf3d0SLouis Dionne// [iterator.concept.writable], concept indirectly_writable
52*57ebf3d0SLouis Dionnetemplate<class Out, class T>
53*57ebf3d0SLouis Dionne  concept indirectly_writable = see below;                // since C++20
54*57ebf3d0SLouis Dionne
553e519524SHoward Hinnanttemplate<class Category, class T, class Distance = ptrdiff_t,
563e519524SHoward Hinnant         class Pointer = T*, class Reference = T&>
573e519524SHoward Hinnantstruct iterator
583e519524SHoward Hinnant{
593e519524SHoward Hinnant    typedef T         value_type;
603e519524SHoward Hinnant    typedef Distance  difference_type;
613e519524SHoward Hinnant    typedef Pointer   pointer;
623e519524SHoward Hinnant    typedef Reference reference;
633e519524SHoward Hinnant    typedef Category  iterator_category;
643e519524SHoward Hinnant};
653e519524SHoward Hinnant
663e519524SHoward Hinnantstruct input_iterator_tag  {};
673e519524SHoward Hinnantstruct output_iterator_tag {};
683e519524SHoward Hinnantstruct forward_iterator_tag       : public input_iterator_tag         {};
693e519524SHoward Hinnantstruct bidirectional_iterator_tag : public forward_iterator_tag       {};
703e519524SHoward Hinnantstruct random_access_iterator_tag : public bidirectional_iterator_tag {};
713e519524SHoward Hinnant
72f51ee632SMarshall Clow// 27.4.3, iterator operations
7312b01ab7SLouis Dionnetemplate <class InputIterator, class Distance>  // constexpr in C++17
7412b01ab7SLouis Dionne  constexpr void advance(InputIterator& i, Distance n);
753e519524SHoward Hinnant
76f51ee632SMarshall Clowtemplate <class InputIterator>  // constexpr in C++17
77f51ee632SMarshall Clow  constexpr typename iterator_traits<InputIterator>::difference_type
783e519524SHoward Hinnant    distance(InputIterator first, InputIterator last);
793e519524SHoward Hinnant
80f51ee632SMarshall Clowtemplate <class InputIterator>  // constexpr in C++17
81f51ee632SMarshall Clow  constexpr InputIterator next(InputIterator x,
82f51ee632SMarshall Clowtypename iterator_traits<InputIterator>::difference_type n = 1);
83f51ee632SMarshall Clow
84f51ee632SMarshall Clowtemplate <class BidirectionalIterator>  // constexpr in C++17
85f51ee632SMarshall Clow  constexpr BidirectionalIterator prev(BidirectionalIterator x,
86f51ee632SMarshall Clow    typename iterator_traits<BidirectionalIterator>::difference_type n = 1);
87f51ee632SMarshall Clow
883e519524SHoward Hinnanttemplate <class Iterator>
893e519524SHoward Hinnantclass reverse_iterator
903e519524SHoward Hinnant    : public iterator<typename iterator_traits<Iterator>::iterator_category,
913e519524SHoward Hinnant                      typename iterator_traits<Iterator>::value_type,
923e519524SHoward Hinnant                      typename iterator_traits<Iterator>::difference_type,
933e519524SHoward Hinnant                      typename iterator_traits<Iterator>::pointer,
943e519524SHoward Hinnant                      typename iterator_traits<Iterator>::reference>
953e519524SHoward Hinnant{
963e519524SHoward Hinnantprotected:
973e519524SHoward Hinnant    Iterator current;
983e519524SHoward Hinnantpublic:
993e519524SHoward Hinnant    typedef Iterator                                            iterator_type;
1003e519524SHoward Hinnant    typedef typename iterator_traits<Iterator>::difference_type difference_type;
1013e519524SHoward Hinnant    typedef typename iterator_traits<Iterator>::reference       reference;
1023e519524SHoward Hinnant    typedef typename iterator_traits<Iterator>::pointer         pointer;
1033e519524SHoward Hinnant
1041b8f260eSMarshall Clow    constexpr reverse_iterator();
1051b8f260eSMarshall Clow    constexpr explicit reverse_iterator(Iterator x);
1061b8f260eSMarshall Clow    template <class U> constexpr reverse_iterator(const reverse_iterator<U>& u);
1071b8f260eSMarshall Clow    template <class U> constexpr reverse_iterator& operator=(const reverse_iterator<U>& u);
1081b8f260eSMarshall Clow    constexpr Iterator base() const;
1091b8f260eSMarshall Clow    constexpr reference operator*() const;
1101b8f260eSMarshall Clow    constexpr pointer   operator->() const;
1111b8f260eSMarshall Clow    constexpr reverse_iterator& operator++();
1121b8f260eSMarshall Clow    constexpr reverse_iterator  operator++(int);
1131b8f260eSMarshall Clow    constexpr reverse_iterator& operator--();
1141b8f260eSMarshall Clow    constexpr reverse_iterator  operator--(int);
1151b8f260eSMarshall Clow    constexpr reverse_iterator  operator+ (difference_type n) const;
1161b8f260eSMarshall Clow    constexpr reverse_iterator& operator+=(difference_type n);
1171b8f260eSMarshall Clow    constexpr reverse_iterator  operator- (difference_type n) const;
1181b8f260eSMarshall Clow    constexpr reverse_iterator& operator-=(difference_type n);
1191b8f260eSMarshall Clow    constexpr reference         operator[](difference_type n) const;
1203e519524SHoward Hinnant};
1213e519524SHoward Hinnant
1223e519524SHoward Hinnanttemplate <class Iterator1, class Iterator2>
1231b8f260eSMarshall Clowconstexpr bool                          // constexpr in C++17
1243e519524SHoward Hinnantoperator==(const reverse_iterator<Iterator1>& x, const reverse_iterator<Iterator2>& y);
1253e519524SHoward Hinnant
1263e519524SHoward Hinnanttemplate <class Iterator1, class Iterator2>
1271b8f260eSMarshall Clowconstexpr bool                          // constexpr in C++17
1283e519524SHoward Hinnantoperator<(const reverse_iterator<Iterator1>& x, const reverse_iterator<Iterator2>& y);
1293e519524SHoward Hinnant
1303e519524SHoward Hinnanttemplate <class Iterator1, class Iterator2>
1311b8f260eSMarshall Clowconstexpr bool                          // constexpr in C++17
1323e519524SHoward Hinnantoperator!=(const reverse_iterator<Iterator1>& x, const reverse_iterator<Iterator2>& y);
1333e519524SHoward Hinnant
1343e519524SHoward Hinnanttemplate <class Iterator1, class Iterator2>
1351b8f260eSMarshall Clowconstexpr bool                          // constexpr in C++17
1363e519524SHoward Hinnantoperator>(const reverse_iterator<Iterator1>& x, const reverse_iterator<Iterator2>& y);
1373e519524SHoward Hinnant
1383e519524SHoward Hinnanttemplate <class Iterator1, class Iterator2>
1391b8f260eSMarshall Clowconstexpr bool                          // constexpr in C++17
1403e519524SHoward Hinnantoperator>=(const reverse_iterator<Iterator1>& x, const reverse_iterator<Iterator2>& y);
1413e519524SHoward Hinnant
1423e519524SHoward Hinnanttemplate <class Iterator1, class Iterator2>
1431b8f260eSMarshall Clowconstexpr bool                          // constexpr in C++17
1443e519524SHoward Hinnantoperator<=(const reverse_iterator<Iterator1>& x, const reverse_iterator<Iterator2>& y);
1453e519524SHoward Hinnant
1463e519524SHoward Hinnanttemplate <class Iterator1, class Iterator2>
1471b8f260eSMarshall Clowconstexpr auto
148947ce6b5SMarshall Clowoperator-(const reverse_iterator<Iterator1>& x, const reverse_iterator<Iterator2>& y)
1491b8f260eSMarshall Clow-> decltype(__y.base() - __x.base());   // constexpr in C++17
1503e519524SHoward Hinnant
1513e519524SHoward Hinnanttemplate <class Iterator>
1521b8f260eSMarshall Clowconstexpr reverse_iterator<Iterator>
1531b8f260eSMarshall Clowoperator+(typename reverse_iterator<Iterator>::difference_type n,
1541b8f260eSMarshall Clow          const reverse_iterator<Iterator>& x);   // constexpr in C++17
1553e519524SHoward Hinnant
1561b8f260eSMarshall Clowtemplate <class Iterator>
1571b8f260eSMarshall Clowconstexpr reverse_iterator<Iterator> make_reverse_iterator(Iterator i); // C++14, constexpr in C++17
1586a640a18SMarshall Clow
1593e519524SHoward Hinnanttemplate <class Container>
1603e519524SHoward Hinnantclass back_insert_iterator
1613e519524SHoward Hinnant{
1623e519524SHoward Hinnantprotected:
1633e519524SHoward Hinnant    Container* container;
1643e519524SHoward Hinnantpublic:
1653e519524SHoward Hinnant    typedef Container                   container_type;
1663e519524SHoward Hinnant    typedef void                        value_type;
1673e519524SHoward Hinnant    typedef void                        difference_type;
1688892b4eeSEric Fiselier    typedef void                        reference;
1693e519524SHoward Hinnant    typedef void                        pointer;
1703e519524SHoward Hinnant
17106e2b737SArthur O'Dwyer    explicit back_insert_iterator(Container& x);  // constexpr in C++20
17206e2b737SArthur O'Dwyer    back_insert_iterator& operator=(const typename Container::value_type& value);  // constexpr in C++20
17306e2b737SArthur O'Dwyer    back_insert_iterator& operator*();  // constexpr in C++20
17406e2b737SArthur O'Dwyer    back_insert_iterator& operator++();  // constexpr in C++20
17506e2b737SArthur O'Dwyer    back_insert_iterator  operator++(int);  // constexpr in C++20
1763e519524SHoward Hinnant};
1773e519524SHoward Hinnant
17806e2b737SArthur O'Dwyertemplate <class Container> back_insert_iterator<Container> back_inserter(Container& x);  // constexpr in C++20
1793e519524SHoward Hinnant
1803e519524SHoward Hinnanttemplate <class Container>
1813e519524SHoward Hinnantclass front_insert_iterator
1823e519524SHoward Hinnant{
1833e519524SHoward Hinnantprotected:
1843e519524SHoward Hinnant    Container* container;
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    explicit front_insert_iterator(Container& x);  // constexpr in C++20
19306e2b737SArthur O'Dwyer    front_insert_iterator& operator=(const typename Container::value_type& value);  // constexpr in C++20
19406e2b737SArthur O'Dwyer    front_insert_iterator& operator*();  // constexpr in C++20
19506e2b737SArthur O'Dwyer    front_insert_iterator& operator++();  // constexpr in C++20
19606e2b737SArthur O'Dwyer    front_insert_iterator  operator++(int);  // constexpr in C++20
1973e519524SHoward Hinnant};
1983e519524SHoward Hinnant
19906e2b737SArthur O'Dwyertemplate <class Container> front_insert_iterator<Container> front_inserter(Container& x);  // constexpr in C++20
2003e519524SHoward Hinnant
2013e519524SHoward Hinnanttemplate <class Container>
2023e519524SHoward Hinnantclass insert_iterator
2033e519524SHoward Hinnant{
2043e519524SHoward Hinnantprotected:
2053e519524SHoward Hinnant    Container* container;
2063e519524SHoward Hinnant    typename Container::iterator iter;
2073e519524SHoward Hinnantpublic:
2083e519524SHoward Hinnant    typedef Container              container_type;
2093e519524SHoward Hinnant    typedef void                   value_type;
2103e519524SHoward Hinnant    typedef void                   difference_type;
2118892b4eeSEric Fiselier    typedef void                   reference;
2123e519524SHoward Hinnant    typedef void                   pointer;
2133e519524SHoward Hinnant
21406e2b737SArthur O'Dwyer    insert_iterator(Container& x, typename Container::iterator i);  // constexpr in C++20
21506e2b737SArthur O'Dwyer    insert_iterator& operator=(const typename Container::value_type& value);  // constexpr in C++20
21606e2b737SArthur O'Dwyer    insert_iterator& operator*();  // constexpr in C++20
21706e2b737SArthur O'Dwyer    insert_iterator& operator++();  // constexpr in C++20
21806e2b737SArthur O'Dwyer    insert_iterator& operator++(int);  // constexpr in C++20
2193e519524SHoward Hinnant};
2203e519524SHoward Hinnant
2213e519524SHoward Hinnanttemplate <class Container, class Iterator>
22206e2b737SArthur O'Dwyerinsert_iterator<Container> inserter(Container& x, Iterator i);  // constexpr in C++20
2233e519524SHoward Hinnant
224947ce6b5SMarshall Clowtemplate <class Iterator>
225947ce6b5SMarshall Clowclass move_iterator {
226947ce6b5SMarshall Clowpublic:
227947ce6b5SMarshall Clow    typedef Iterator                                              iterator_type;
228947ce6b5SMarshall Clow    typedef typename iterator_traits<Iterator>::difference_type   difference_type;
229947ce6b5SMarshall Clow    typedef Iterator                                              pointer;
230947ce6b5SMarshall Clow    typedef typename iterator_traits<Iterator>::value_type        value_type;
231947ce6b5SMarshall Clow    typedef typename iterator_traits<Iterator>::iterator_category iterator_category;
232947ce6b5SMarshall Clow    typedef value_type&&                                          reference;
233947ce6b5SMarshall Clow
234720ef472SMarshall Clow    constexpr move_iterator();  // all the constexprs are in C++17
235720ef472SMarshall Clow    constexpr explicit move_iterator(Iterator i);
236720ef472SMarshall Clow    template <class U>
237720ef472SMarshall Clow      constexpr move_iterator(const move_iterator<U>& u);
238720ef472SMarshall Clow    template <class U>
239720ef472SMarshall Clow      constexpr move_iterator& operator=(const move_iterator<U>& u);
240720ef472SMarshall Clow    constexpr iterator_type base() const;
241720ef472SMarshall Clow    constexpr reference operator*() const;
242720ef472SMarshall Clow    constexpr pointer operator->() const;
243720ef472SMarshall Clow    constexpr move_iterator& operator++();
244720ef472SMarshall Clow    constexpr move_iterator operator++(int);
245720ef472SMarshall Clow    constexpr move_iterator& operator--();
246720ef472SMarshall Clow    constexpr move_iterator operator--(int);
247720ef472SMarshall Clow    constexpr move_iterator operator+(difference_type n) const;
248720ef472SMarshall Clow    constexpr move_iterator& operator+=(difference_type n);
249720ef472SMarshall Clow    constexpr move_iterator operator-(difference_type n) const;
250720ef472SMarshall Clow    constexpr move_iterator& operator-=(difference_type n);
251720ef472SMarshall Clow    constexpr unspecified operator[](difference_type n) const;
252947ce6b5SMarshall Clowprivate:
253947ce6b5SMarshall Clow    Iterator current; // exposition only
254947ce6b5SMarshall Clow};
255947ce6b5SMarshall Clow
256947ce6b5SMarshall Clowtemplate <class Iterator1, class Iterator2>
257720ef472SMarshall Clowconstexpr bool   // constexpr in C++17
258947ce6b5SMarshall Clowoperator==(const move_iterator<Iterator1>& x, const move_iterator<Iterator2>& y);
259947ce6b5SMarshall Clow
260947ce6b5SMarshall Clowtemplate <class Iterator1, class Iterator2>
261720ef472SMarshall Clowconstexpr bool   // constexpr in C++17
262947ce6b5SMarshall Clowoperator!=(const move_iterator<Iterator1>& x, const move_iterator<Iterator2>& y);
263947ce6b5SMarshall Clow
264947ce6b5SMarshall Clowtemplate <class Iterator1, class Iterator2>
265720ef472SMarshall Clowconstexpr bool   // constexpr in C++17
266947ce6b5SMarshall Clowoperator<(const move_iterator<Iterator1>& x, const move_iterator<Iterator2>& y);
267947ce6b5SMarshall Clow
268947ce6b5SMarshall Clowtemplate <class Iterator1, class Iterator2>
269720ef472SMarshall Clowconstexpr bool   // constexpr in C++17
270947ce6b5SMarshall Clowoperator<=(const move_iterator<Iterator1>& x, const move_iterator<Iterator2>& y);
271947ce6b5SMarshall Clow
272947ce6b5SMarshall Clowtemplate <class Iterator1, class Iterator2>
273720ef472SMarshall Clowconstexpr bool   // constexpr in C++17
274947ce6b5SMarshall Clowoperator>(const move_iterator<Iterator1>& x, const move_iterator<Iterator2>& y);
275947ce6b5SMarshall Clow
276947ce6b5SMarshall Clowtemplate <class Iterator1, class Iterator2>
277720ef472SMarshall Clowconstexpr bool   // constexpr in C++17
278947ce6b5SMarshall Clowoperator>=(const move_iterator<Iterator1>& x, const move_iterator<Iterator2>& y);
279947ce6b5SMarshall Clow
280947ce6b5SMarshall Clowtemplate <class Iterator1, class Iterator2>
281720ef472SMarshall Clowconstexpr auto   // constexpr in C++17
282947ce6b5SMarshall Clowoperator-(const move_iterator<Iterator1>& x,
283947ce6b5SMarshall Clow          const move_iterator<Iterator2>& y) -> decltype(x.base() - y.base());
284947ce6b5SMarshall Clow
285947ce6b5SMarshall Clowtemplate <class Iterator>
286720ef472SMarshall Clowconstexpr move_iterator<Iterator> operator+(   // constexpr in C++17
287720ef472SMarshall Clow            typename move_iterator<Iterator>::difference_type n,
288947ce6b5SMarshall Clow            const move_iterator<Iterator>& x);
289947ce6b5SMarshall Clow
290720ef472SMarshall Clowtemplate <class Iterator>   // constexpr in C++17
291720ef472SMarshall Clowconstexpr  move_iterator<Iterator> make_move_iterator(const Iterator& i);
292947ce6b5SMarshall Clow
293947ce6b5SMarshall Clow
2943e519524SHoward Hinnanttemplate <class T, class charT = char, class traits = char_traits<charT>, class Distance = ptrdiff_t>
2953e519524SHoward Hinnantclass istream_iterator
2963e519524SHoward Hinnant    : public iterator<input_iterator_tag, T, Distance, const T*, const T&>
2973e519524SHoward Hinnant{
2983e519524SHoward Hinnantpublic:
2993e519524SHoward Hinnant    typedef charT char_type;
3003e519524SHoward Hinnant    typedef traits traits_type;
3013e519524SHoward Hinnant    typedef basic_istream<charT,traits> istream_type;
3023e519524SHoward Hinnant
30360d5e0e0SMarshall Clow    constexpr istream_iterator();
3043e519524SHoward Hinnant    istream_iterator(istream_type& s);
3053e519524SHoward Hinnant    istream_iterator(const istream_iterator& x);
3063e519524SHoward Hinnant    ~istream_iterator();
3073e519524SHoward Hinnant
3083e519524SHoward Hinnant    const T& operator*() const;
3093e519524SHoward Hinnant    const T* operator->() const;
3103e519524SHoward Hinnant    istream_iterator& operator++();
3113e519524SHoward Hinnant    istream_iterator  operator++(int);
3123e519524SHoward Hinnant};
3133e519524SHoward Hinnant
3143e519524SHoward Hinnanttemplate <class T, class charT, class traits, class Distance>
3153e519524SHoward Hinnantbool operator==(const istream_iterator<T,charT,traits,Distance>& x,
3163e519524SHoward Hinnant                const istream_iterator<T,charT,traits,Distance>& y);
3173e519524SHoward Hinnanttemplate <class T, class charT, class traits, class Distance>
3183e519524SHoward Hinnantbool operator!=(const istream_iterator<T,charT,traits,Distance>& x,
3193e519524SHoward Hinnant                const istream_iterator<T,charT,traits,Distance>& y);
3203e519524SHoward Hinnant
3213e519524SHoward Hinnanttemplate <class T, class charT = char, class traits = char_traits<charT> >
3223e519524SHoward Hinnantclass ostream_iterator
3233e519524SHoward Hinnant    : public iterator<output_iterator_tag, void, void, void ,void>
3243e519524SHoward Hinnant{
3253e519524SHoward Hinnantpublic:
3263e519524SHoward Hinnant    typedef charT char_type;
3273e519524SHoward Hinnant    typedef traits traits_type;
3283e519524SHoward Hinnant    typedef basic_ostream<charT,traits> ostream_type;
3293e519524SHoward Hinnant
3303e519524SHoward Hinnant    ostream_iterator(ostream_type& s);
3313e519524SHoward Hinnant    ostream_iterator(ostream_type& s, const charT* delimiter);
3323e519524SHoward Hinnant    ostream_iterator(const ostream_iterator& x);
3333e519524SHoward Hinnant    ~ostream_iterator();
3343e519524SHoward Hinnant    ostream_iterator& operator=(const T& value);
3353e519524SHoward Hinnant
3363e519524SHoward Hinnant    ostream_iterator& operator*();
3373e519524SHoward Hinnant    ostream_iterator& operator++();
3383e519524SHoward Hinnant    ostream_iterator& operator++(int);
3393e519524SHoward Hinnant};
3403e519524SHoward Hinnant
3413e519524SHoward Hinnanttemplate<class charT, class traits = char_traits<charT> >
3423e519524SHoward Hinnantclass istreambuf_iterator
3433e519524SHoward Hinnant    : public iterator<input_iterator_tag, charT,
3443e519524SHoward Hinnant                      typename traits::off_type, unspecified,
3453e519524SHoward Hinnant                      charT>
3463e519524SHoward Hinnant{
3473e519524SHoward Hinnantpublic:
3483e519524SHoward Hinnant    typedef charT                         char_type;
3493e519524SHoward Hinnant    typedef traits                        traits_type;
3503e519524SHoward Hinnant    typedef typename traits::int_type     int_type;
3513e519524SHoward Hinnant    typedef basic_streambuf<charT,traits> streambuf_type;
3523e519524SHoward Hinnant    typedef basic_istream<charT,traits>   istream_type;
3533e519524SHoward Hinnant
3548e882dcbSHoward Hinnant    istreambuf_iterator() noexcept;
3558e882dcbSHoward Hinnant    istreambuf_iterator(istream_type& s) noexcept;
3568e882dcbSHoward Hinnant    istreambuf_iterator(streambuf_type* s) noexcept;
3578e882dcbSHoward Hinnant    istreambuf_iterator(a-private-type) noexcept;
3583e519524SHoward Hinnant
3593e519524SHoward Hinnant    charT                operator*() const;
3603e519524SHoward Hinnant    pointer operator->() const;
3613e519524SHoward Hinnant    istreambuf_iterator& operator++();
3623e519524SHoward Hinnant    a-private-type       operator++(int);
3633e519524SHoward Hinnant
3643e519524SHoward Hinnant    bool equal(const istreambuf_iterator& b) const;
3653e519524SHoward Hinnant};
3663e519524SHoward Hinnant
3673e519524SHoward Hinnanttemplate <class charT, class traits>
3683e519524SHoward Hinnantbool operator==(const istreambuf_iterator<charT,traits>& a,
3693e519524SHoward Hinnant                const istreambuf_iterator<charT,traits>& b);
3703e519524SHoward Hinnanttemplate <class charT, class traits>
3713e519524SHoward Hinnantbool operator!=(const istreambuf_iterator<charT,traits>& a,
3723e519524SHoward Hinnant                const istreambuf_iterator<charT,traits>& b);
3733e519524SHoward Hinnant
3743e519524SHoward Hinnanttemplate <class charT, class traits = char_traits<charT> >
3753e519524SHoward Hinnantclass ostreambuf_iterator
3763e519524SHoward Hinnant    : public iterator<output_iterator_tag, void, void, void, void>
3773e519524SHoward Hinnant{
3783e519524SHoward Hinnantpublic:
3793e519524SHoward Hinnant    typedef charT                         char_type;
3803e519524SHoward Hinnant    typedef traits                        traits_type;
3813e519524SHoward Hinnant    typedef basic_streambuf<charT,traits> streambuf_type;
3823e519524SHoward Hinnant    typedef basic_ostream<charT,traits>   ostream_type;
3833e519524SHoward Hinnant
3848e882dcbSHoward Hinnant    ostreambuf_iterator(ostream_type& s) noexcept;
3858e882dcbSHoward Hinnant    ostreambuf_iterator(streambuf_type* s) noexcept;
3863e519524SHoward Hinnant    ostreambuf_iterator& operator=(charT c);
3873e519524SHoward Hinnant    ostreambuf_iterator& operator*();
3883e519524SHoward Hinnant    ostreambuf_iterator& operator++();
3893e519524SHoward Hinnant    ostreambuf_iterator& operator++(int);
3908e882dcbSHoward Hinnant    bool failed() const noexcept;
3913e519524SHoward Hinnant};
3923e519524SHoward Hinnant
393020b623aSMarshall Clowtemplate <class C> constexpr auto begin(C& c) -> decltype(c.begin());
394020b623aSMarshall Clowtemplate <class C> constexpr auto begin(const C& c) -> decltype(c.begin());
395020b623aSMarshall Clowtemplate <class C> constexpr auto end(C& c) -> decltype(c.end());
396020b623aSMarshall Clowtemplate <class C> constexpr auto end(const C& c) -> decltype(c.end());
397020b623aSMarshall Clowtemplate <class T, size_t N> constexpr T* begin(T (&array)[N]);
398020b623aSMarshall Clowtemplate <class T, size_t N> constexpr T* end(T (&array)[N]);
3993e519524SHoward Hinnant
400020b623aSMarshall Clowtemplate <class C> auto constexpr cbegin(const C& c) -> decltype(std::begin(c));        // C++14
401020b623aSMarshall Clowtemplate <class C> auto constexpr cend(const C& c) -> decltype(std::end(c));            // C++14
402020b623aSMarshall Clowtemplate <class C> auto constexpr rbegin(C& c) -> decltype(c.rbegin());                 // C++14
403020b623aSMarshall Clowtemplate <class C> auto constexpr rbegin(const C& c) -> decltype(c.rbegin());           // C++14
404020b623aSMarshall Clowtemplate <class C> auto constexpr rend(C& c) -> decltype(c.rend());                     // C++14
405020b623aSMarshall Clowtemplate <class C> constexpr auto rend(const C& c) -> decltype(c.rend());               // C++14
406020b623aSMarshall Clowtemplate <class E> reverse_iterator<const E*> constexpr rbegin(initializer_list<E> il); // C++14
407020b623aSMarshall Clowtemplate <class E> reverse_iterator<const E*> constexpr rend(initializer_list<E> il);   // C++14
408020b623aSMarshall Clowtemplate <class T, size_t N> reverse_iterator<T*> constexpr rbegin(T (&array)[N]);      // C++14
409020b623aSMarshall Clowtemplate <class T, size_t N> reverse_iterator<T*> constexpr rend(T (&array)[N]);        // C++14
410020b623aSMarshall Clowtemplate <class C> constexpr auto crbegin(const C& c) -> decltype(std::rbegin(c));      // C++14
411020b623aSMarshall Clowtemplate <class C> constexpr auto crend(const C& c) -> decltype(std::rend(c));          // C++14
4121e548c72SMarshall Clow
413ad755104SMarshall Clow// 24.8, container access:
414ad755104SMarshall Clowtemplate <class C> constexpr auto size(const C& c) -> decltype(c.size());         // C++17
415ad755104SMarshall Clowtemplate <class T, size_t N> constexpr size_t size(const T (&array)[N]) noexcept; // C++17
4167d3986eaSMarshall Clow
4177d3986eaSMarshall Clowtemplate <class C> constexpr auto ssize(const C& c)
4187d3986eaSMarshall Clow    -> common_type_t<ptrdiff_t, make_signed_t<decltype(c.size())>>;                    // C++20
4197d3986eaSMarshall Clowtemplate <class T, ptrdiff_t> constexpr ptrdiff_t ssize(const T (&array)[N]) noexcept; // C++20
4207d3986eaSMarshall Clow
421ad755104SMarshall Clowtemplate <class C> constexpr auto empty(const C& c) -> decltype(c.empty());       // C++17
422ad755104SMarshall Clowtemplate <class T, size_t N> constexpr bool empty(const T (&array)[N]) noexcept;  // C++17
423ad755104SMarshall Clowtemplate <class E> constexpr bool empty(initializer_list<E> il) noexcept;         // C++17
424ad755104SMarshall Clowtemplate <class C> constexpr auto data(C& c) -> decltype(c.data());               // C++17
425ad755104SMarshall Clowtemplate <class C> constexpr auto data(const C& c) -> decltype(c.data());         // C++17
426ad755104SMarshall Clowtemplate <class T, size_t N> constexpr T* data(T (&array)[N]) noexcept;           // C++17
427ad755104SMarshall Clowtemplate <class E> constexpr const E* data(initializer_list<E> il) noexcept;      // C++17
428ad755104SMarshall Clow
4293e519524SHoward Hinnant}  // std
4303e519524SHoward Hinnant
4313e519524SHoward Hinnant*/
4323e519524SHoward Hinnant
4333e519524SHoward Hinnant#include <__config>
43439c193b1SEric Fiselier#include <iosfwd> // for forward declarations of vector and string.
435c204c130SMarshall Clow#include <__functional_base>
4363e519524SHoward Hinnant#include <type_traits>
4372d0f1fa4SArthur O'Dwyer#include <compare>
438120fa829Szoecarver#include <concepts> // Mandated by the Standard.
4393e519524SHoward Hinnant#include <cstddef>
4401e548c72SMarshall Clow#include <initializer_list>
441*57ebf3d0SLouis Dionne#include <__iterator/concepts.h>
442e0adf7e0Szoecarver#include <__iterator/incrementable_traits.h>
44397e383aaSLouis Dionne#include <__iterator/iter_move.h>
444120fa829Szoecarver#include <__iterator/iterator_traits.h>
445e0adf7e0Szoecarver#include <__iterator/readable_traits.h>
446f992cfbaSLouis Dionne#include <__memory/addressof.h>
447d41c6d51SArthur O'Dwyer#include <__memory/pointer_traits.h>
448f56972e2SMarshall Clow#include <version>
449b5c63a2eSHoward Hinnant
45042a3046eSHoward Hinnant#include <__debug>
4513e519524SHoward Hinnant
452073458b1SHoward Hinnant#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
4533e519524SHoward Hinnant#pragma GCC system_header
454073458b1SHoward Hinnant#endif
4553e519524SHoward Hinnant
4563e519524SHoward Hinnant_LIBCPP_BEGIN_NAMESPACE_STD
457fe31f11cSChristopher Di Bella
4583e519524SHoward Hinnanttemplate<class _Category, class _Tp, class _Distance = ptrdiff_t,
4593e519524SHoward Hinnant         class _Pointer = _Tp*, class _Reference = _Tp&>
460e2f2d1edSEric Fiselierstruct _LIBCPP_TEMPLATE_VIS iterator
4613e519524SHoward Hinnant{
4623e519524SHoward Hinnant    typedef _Tp        value_type;
4633e519524SHoward Hinnant    typedef _Distance  difference_type;
4643e519524SHoward Hinnant    typedef _Pointer   pointer;
4653e519524SHoward Hinnant    typedef _Reference reference;
4663e519524SHoward Hinnant    typedef _Category  iterator_category;
4673e519524SHoward Hinnant};
4683e519524SHoward Hinnant
4693e519524SHoward Hinnanttemplate <class _InputIter>
470f51ee632SMarshall Clowinline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
4713e519524SHoward Hinnantvoid __advance(_InputIter& __i,
4723e519524SHoward Hinnant             typename iterator_traits<_InputIter>::difference_type __n, input_iterator_tag)
4733e519524SHoward Hinnant{
4743e519524SHoward Hinnant    for (; __n > 0; --__n)
4753e519524SHoward Hinnant        ++__i;
4763e519524SHoward Hinnant}
4773e519524SHoward Hinnant
4783e519524SHoward Hinnanttemplate <class _BiDirIter>
479f51ee632SMarshall Clowinline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
4803e519524SHoward Hinnantvoid __advance(_BiDirIter& __i,
4813e519524SHoward Hinnant             typename iterator_traits<_BiDirIter>::difference_type __n, bidirectional_iterator_tag)
4823e519524SHoward Hinnant{
4833e519524SHoward Hinnant    if (__n >= 0)
4843e519524SHoward Hinnant        for (; __n > 0; --__n)
4853e519524SHoward Hinnant            ++__i;
4863e519524SHoward Hinnant    else
4873e519524SHoward Hinnant        for (; __n < 0; ++__n)
4883e519524SHoward Hinnant            --__i;
4893e519524SHoward Hinnant}
4903e519524SHoward Hinnant
4913e519524SHoward Hinnanttemplate <class _RandIter>
492f51ee632SMarshall Clowinline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
4933e519524SHoward Hinnantvoid __advance(_RandIter& __i,
4943e519524SHoward Hinnant             typename iterator_traits<_RandIter>::difference_type __n, random_access_iterator_tag)
4953e519524SHoward Hinnant{
4963e519524SHoward Hinnant   __i += __n;
4973e519524SHoward Hinnant}
4983e519524SHoward Hinnant
49912b01ab7SLouis Dionnetemplate <class _InputIter, class _Distance>
500f51ee632SMarshall Clowinline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
50112b01ab7SLouis Dionnevoid advance(_InputIter& __i, _Distance __orig_n)
5023e519524SHoward Hinnant{
50312b01ab7SLouis Dionne    _LIBCPP_ASSERT(__orig_n >= 0 || __is_cpp17_bidirectional_iterator<_InputIter>::value,
50412b01ab7SLouis Dionne                   "Attempt to advance(it, n) with negative n on a non-bidirectional iterator");
505c0428b3cSArthur O'Dwyer    typedef decltype(_VSTD::__convert_to_integral(__orig_n)) _IntegralSize;
50612b01ab7SLouis Dionne    _IntegralSize __n = __orig_n;
507c0428b3cSArthur O'Dwyer    _VSTD::__advance(__i, __n, typename iterator_traits<_InputIter>::iterator_category());
5083e519524SHoward Hinnant}
5093e519524SHoward Hinnant
5103e519524SHoward Hinnanttemplate <class _InputIter>
511f51ee632SMarshall Clowinline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
5123e519524SHoward Hinnanttypename iterator_traits<_InputIter>::difference_type
5133e519524SHoward Hinnant__distance(_InputIter __first, _InputIter __last, input_iterator_tag)
5143e519524SHoward Hinnant{
5153e519524SHoward Hinnant    typename iterator_traits<_InputIter>::difference_type __r(0);
5163e519524SHoward Hinnant    for (; __first != __last; ++__first)
5173e519524SHoward Hinnant        ++__r;
5183e519524SHoward Hinnant    return __r;
5193e519524SHoward Hinnant}
5203e519524SHoward Hinnant
5213e519524SHoward Hinnanttemplate <class _RandIter>
522f51ee632SMarshall Clowinline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
5233e519524SHoward Hinnanttypename iterator_traits<_RandIter>::difference_type
5243e519524SHoward Hinnant__distance(_RandIter __first, _RandIter __last, random_access_iterator_tag)
5253e519524SHoward Hinnant{
5263e519524SHoward Hinnant    return __last - __first;
5273e519524SHoward Hinnant}
5283e519524SHoward Hinnant
5293e519524SHoward Hinnanttemplate <class _InputIter>
530f51ee632SMarshall Clowinline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
5313e519524SHoward Hinnanttypename iterator_traits<_InputIter>::difference_type
5323e519524SHoward Hinnantdistance(_InputIter __first, _InputIter __last)
5333e519524SHoward Hinnant{
534c0428b3cSArthur O'Dwyer    return _VSTD::__distance(__first, __last, typename iterator_traits<_InputIter>::iterator_category());
5353e519524SHoward Hinnant}
5363e519524SHoward Hinnant
537e5f1288fSMarshall Clowtemplate <class _InputIter>
538f51ee632SMarshall Clowinline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
5393e2ef408SRachel Craiktypename enable_if
5403e2ef408SRachel Craik<
541f82dba01SEric Fiselier    __is_cpp17_input_iterator<_InputIter>::value,
542e5f1288fSMarshall Clow    _InputIter
5433e2ef408SRachel Craik>::type
544e5f1288fSMarshall Clownext(_InputIter __x,
5453e2ef408SRachel Craik     typename iterator_traits<_InputIter>::difference_type __n = 1)
5463e519524SHoward Hinnant{
547f82dba01SEric Fiselier    _LIBCPP_ASSERT(__n >= 0 || __is_cpp17_bidirectional_iterator<_InputIter>::value,
54812b01ab7SLouis Dionne                       "Attempt to next(it, n) with negative n on a non-bidirectional iterator");
549e1cd11d8SMarshall Clow
550ce48a113SHoward Hinnant    _VSTD::advance(__x, __n);
5513e519524SHoward Hinnant    return __x;
5523e519524SHoward Hinnant}
5533e519524SHoward Hinnant
554e1cd11d8SMarshall Clowtemplate <class _InputIter>
555f51ee632SMarshall Clowinline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
5563e2ef408SRachel Craiktypename enable_if
5573e2ef408SRachel Craik<
558f82dba01SEric Fiselier    __is_cpp17_input_iterator<_InputIter>::value,
559e1cd11d8SMarshall Clow    _InputIter
5603e2ef408SRachel Craik>::type
561e1cd11d8SMarshall Clowprev(_InputIter __x,
562e1cd11d8SMarshall Clow     typename iterator_traits<_InputIter>::difference_type __n = 1)
5633e519524SHoward Hinnant{
564f82dba01SEric Fiselier    _LIBCPP_ASSERT(__n <= 0 || __is_cpp17_bidirectional_iterator<_InputIter>::value,
56512b01ab7SLouis Dionne                       "Attempt to prev(it, n) with a positive n on a non-bidirectional iterator");
566ce48a113SHoward Hinnant    _VSTD::advance(__x, -__n);
5673e519524SHoward Hinnant    return __x;
5683e519524SHoward Hinnant}
5693e519524SHoward Hinnant
570e02ed1c2SEric Fiselier
571e02ed1c2SEric Fiseliertemplate <class _Tp, class = void>
572e02ed1c2SEric Fiselierstruct __is_stashing_iterator : false_type {};
573e02ed1c2SEric Fiselier
574e02ed1c2SEric Fiseliertemplate <class _Tp>
575e02ed1c2SEric Fiselierstruct __is_stashing_iterator<_Tp, typename __void_t<typename _Tp::__stashing_iterator_tag>::type>
576e02ed1c2SEric Fiselier  : true_type {};
577e02ed1c2SEric Fiselier
5783e519524SHoward Hinnanttemplate <class _Iter>
579e2f2d1edSEric Fiselierclass _LIBCPP_TEMPLATE_VIS reverse_iterator
5803e519524SHoward Hinnant    : public iterator<typename iterator_traits<_Iter>::iterator_category,
5813e519524SHoward Hinnant                      typename iterator_traits<_Iter>::value_type,
5823e519524SHoward Hinnant                      typename iterator_traits<_Iter>::difference_type,
5833e519524SHoward Hinnant                      typename iterator_traits<_Iter>::pointer,
5843e519524SHoward Hinnant                      typename iterator_traits<_Iter>::reference>
5853e519524SHoward Hinnant{
5863b83496dSMarshall Clowprivate:
5871b8f260eSMarshall Clow    /*mutable*/ _Iter __t;  // no longer used as of LWG #2360, not removed due to ABI break
588e02ed1c2SEric Fiselier
589e02ed1c2SEric Fiselier    static_assert(!__is_stashing_iterator<_Iter>::value,
590e02ed1c2SEric Fiselier      "The specified iterator type cannot be used with reverse_iterator; "
591e02ed1c2SEric Fiselier      "Using stashing iterators with reverse_iterator causes undefined behavior");
592e02ed1c2SEric Fiselier
593b2d74f29SMarshall Clowprotected:
594b2d74f29SMarshall Clow    _Iter current;
5953e519524SHoward Hinnantpublic:
5963e519524SHoward Hinnant    typedef _Iter                                            iterator_type;
5973e519524SHoward Hinnant    typedef typename iterator_traits<_Iter>::difference_type difference_type;
5983e519524SHoward Hinnant    typedef typename iterator_traits<_Iter>::reference       reference;
5993e519524SHoward Hinnant    typedef typename iterator_traits<_Iter>::pointer         pointer;
600d41c6d51SArthur O'Dwyer    typedef _If<__is_cpp17_random_access_iterator<_Iter>::value,
601d41c6d51SArthur O'Dwyer        random_access_iterator_tag,
602d41c6d51SArthur O'Dwyer        typename iterator_traits<_Iter>::iterator_category>  iterator_category;
603d41c6d51SArthur O'Dwyer#if _LIBCPP_STD_VER > 17
604d41c6d51SArthur O'Dwyer    typedef _If<__is_cpp17_random_access_iterator<_Iter>::value,
605d41c6d51SArthur O'Dwyer        random_access_iterator_tag,
606d41c6d51SArthur O'Dwyer        bidirectional_iterator_tag>                          iterator_concept;
607d41c6d51SArthur O'Dwyer#endif
6083e519524SHoward Hinnant
6091b8f260eSMarshall Clow    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
6101b8f260eSMarshall Clow    reverse_iterator() : __t(), current() {}
6111b8f260eSMarshall Clow    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
6121b8f260eSMarshall Clow    explicit reverse_iterator(_Iter __x) : __t(__x), current(__x) {}
6131b8f260eSMarshall Clow    template <class _Up>
6141b8f260eSMarshall Clow        _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
6151b8f260eSMarshall Clow        reverse_iterator(const reverse_iterator<_Up>& __u) : __t(__u.base()), current(__u.base()) {}
6161b8f260eSMarshall Clow    template <class _Up>
6171b8f260eSMarshall Clow        _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
6181b8f260eSMarshall Clow        reverse_iterator& operator=(const reverse_iterator<_Up>& __u)
6191b8f260eSMarshall Clow            { __t = current = __u.base(); return *this; }
6201b8f260eSMarshall Clow    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
6211b8f260eSMarshall Clow    _Iter base() const {return current;}
6221b8f260eSMarshall Clow    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
6231b8f260eSMarshall Clow    reference operator*() const {_Iter __tmp = current; return *--__tmp;}
6241b8f260eSMarshall Clow    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
6251b8f260eSMarshall Clow    pointer  operator->() const {return _VSTD::addressof(operator*());}
6261b8f260eSMarshall Clow    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
6271b8f260eSMarshall Clow    reverse_iterator& operator++() {--current; return *this;}
6281b8f260eSMarshall Clow    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
6291b8f260eSMarshall Clow    reverse_iterator  operator++(int) {reverse_iterator __tmp(*this); --current; return __tmp;}
6301b8f260eSMarshall Clow    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
6311b8f260eSMarshall Clow    reverse_iterator& operator--() {++current; return *this;}
6321b8f260eSMarshall Clow    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
6331b8f260eSMarshall Clow    reverse_iterator  operator--(int) {reverse_iterator __tmp(*this); ++current; return __tmp;}
6341b8f260eSMarshall Clow    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
6351b8f260eSMarshall Clow    reverse_iterator  operator+ (difference_type __n) const {return reverse_iterator(current - __n);}
6361b8f260eSMarshall Clow    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
6371b8f260eSMarshall Clow    reverse_iterator& operator+=(difference_type __n) {current -= __n; return *this;}
6381b8f260eSMarshall Clow    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
6391b8f260eSMarshall Clow    reverse_iterator  operator- (difference_type __n) const {return reverse_iterator(current + __n);}
6401b8f260eSMarshall Clow    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
6411b8f260eSMarshall Clow    reverse_iterator& operator-=(difference_type __n) {current += __n; return *this;}
6421b8f260eSMarshall Clow    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
6431b8f260eSMarshall Clow    reference         operator[](difference_type __n) const {return *(*this + __n);}
6443e519524SHoward Hinnant};
6453e519524SHoward Hinnant
6463e519524SHoward Hinnanttemplate <class _Iter1, class _Iter2>
6471b8f260eSMarshall Clowinline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
6483e519524SHoward Hinnantbool
6493e519524SHoward Hinnantoperator==(const reverse_iterator<_Iter1>& __x, const reverse_iterator<_Iter2>& __y)
6503e519524SHoward Hinnant{
6513e519524SHoward Hinnant    return __x.base() == __y.base();
6523e519524SHoward Hinnant}
6533e519524SHoward Hinnant
6543e519524SHoward Hinnanttemplate <class _Iter1, class _Iter2>
6551b8f260eSMarshall Clowinline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
6563e519524SHoward Hinnantbool
6573e519524SHoward Hinnantoperator<(const reverse_iterator<_Iter1>& __x, const reverse_iterator<_Iter2>& __y)
6583e519524SHoward Hinnant{
6593e519524SHoward Hinnant    return __x.base() > __y.base();
6603e519524SHoward Hinnant}
6613e519524SHoward Hinnant
6623e519524SHoward Hinnanttemplate <class _Iter1, class _Iter2>
6631b8f260eSMarshall Clowinline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
6643e519524SHoward Hinnantbool
6653e519524SHoward Hinnantoperator!=(const reverse_iterator<_Iter1>& __x, const reverse_iterator<_Iter2>& __y)
6663e519524SHoward Hinnant{
6673e519524SHoward Hinnant    return __x.base() != __y.base();
6683e519524SHoward Hinnant}
6693e519524SHoward Hinnant
6703e519524SHoward Hinnanttemplate <class _Iter1, class _Iter2>
6711b8f260eSMarshall Clowinline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
6723e519524SHoward Hinnantbool
6733e519524SHoward Hinnantoperator>(const reverse_iterator<_Iter1>& __x, const reverse_iterator<_Iter2>& __y)
6743e519524SHoward Hinnant{
6753e519524SHoward Hinnant    return __x.base() < __y.base();
6763e519524SHoward Hinnant}
6773e519524SHoward Hinnant
6783e519524SHoward Hinnanttemplate <class _Iter1, class _Iter2>
6791b8f260eSMarshall Clowinline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
6803e519524SHoward Hinnantbool
6813e519524SHoward Hinnantoperator>=(const reverse_iterator<_Iter1>& __x, const reverse_iterator<_Iter2>& __y)
6823e519524SHoward Hinnant{
6833e519524SHoward Hinnant    return __x.base() <= __y.base();
6843e519524SHoward Hinnant}
6853e519524SHoward Hinnant
6863e519524SHoward Hinnanttemplate <class _Iter1, class _Iter2>
6871b8f260eSMarshall Clowinline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
6883e519524SHoward Hinnantbool
6893e519524SHoward Hinnantoperator<=(const reverse_iterator<_Iter1>& __x, const reverse_iterator<_Iter2>& __y)
6903e519524SHoward Hinnant{
6913e519524SHoward Hinnant    return __x.base() >= __y.base();
6923e519524SHoward Hinnant}
6933e519524SHoward Hinnant
6942ee83725SMarshall Clow#ifndef _LIBCPP_CXX03_LANG
695947ce6b5SMarshall Clowtemplate <class _Iter1, class _Iter2>
6961b8f260eSMarshall Clowinline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
697947ce6b5SMarshall Clowauto
698947ce6b5SMarshall Clowoperator-(const reverse_iterator<_Iter1>& __x, const reverse_iterator<_Iter2>& __y)
699947ce6b5SMarshall Clow-> decltype(__y.base() - __x.base())
700947ce6b5SMarshall Clow{
701947ce6b5SMarshall Clow    return __y.base() - __x.base();
702947ce6b5SMarshall Clow}
703947ce6b5SMarshall Clow#else
7043e519524SHoward Hinnanttemplate <class _Iter1, class _Iter2>
7053e519524SHoward Hinnantinline _LIBCPP_INLINE_VISIBILITY
7063e519524SHoward Hinnanttypename reverse_iterator<_Iter1>::difference_type
7073e519524SHoward Hinnantoperator-(const reverse_iterator<_Iter1>& __x, const reverse_iterator<_Iter2>& __y)
7083e519524SHoward Hinnant{
7093e519524SHoward Hinnant    return __y.base() - __x.base();
7103e519524SHoward Hinnant}
711947ce6b5SMarshall Clow#endif
7123e519524SHoward Hinnant
7133e519524SHoward Hinnanttemplate <class _Iter>
7141b8f260eSMarshall Clowinline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
7153e519524SHoward Hinnantreverse_iterator<_Iter>
7163e519524SHoward Hinnantoperator+(typename reverse_iterator<_Iter>::difference_type __n, const reverse_iterator<_Iter>& __x)
7173e519524SHoward Hinnant{
7183e519524SHoward Hinnant    return reverse_iterator<_Iter>(__x.base() - __n);
7193e519524SHoward Hinnant}
7203e519524SHoward Hinnant
7216a640a18SMarshall Clow#if _LIBCPP_STD_VER > 11
7226a640a18SMarshall Clowtemplate <class _Iter>
7231b8f260eSMarshall Clowinline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
7246a640a18SMarshall Clowreverse_iterator<_Iter> make_reverse_iterator(_Iter __i)
7256a640a18SMarshall Clow{
7266a640a18SMarshall Clow    return reverse_iterator<_Iter>(__i);
7276a640a18SMarshall Clow}
7286a640a18SMarshall Clow#endif
7296a640a18SMarshall Clow
7303e519524SHoward Hinnanttemplate <class _Container>
731e2f2d1edSEric Fiselierclass _LIBCPP_TEMPLATE_VIS back_insert_iterator
7323e519524SHoward Hinnant    : public iterator<output_iterator_tag,
7333e519524SHoward Hinnant                      void,
7343e519524SHoward Hinnant                      void,
7353e519524SHoward Hinnant                      void,
7368892b4eeSEric Fiselier                      void>
7373e519524SHoward Hinnant{
7383e519524SHoward Hinnantprotected:
7393e519524SHoward Hinnant    _Container* container;
7403e519524SHoward Hinnantpublic:
7413e519524SHoward Hinnant    typedef _Container container_type;
7423e519524SHoward Hinnant
74306e2b737SArthur O'Dwyer    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 explicit back_insert_iterator(_Container& __x) : container(_VSTD::addressof(__x)) {}
74406e2b737SArthur O'Dwyer    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 back_insert_iterator& operator=(const typename _Container::value_type& __value_)
745e4383379SHoward Hinnant        {container->push_back(__value_); return *this;}
746046492b9SEric Fiselier#ifndef _LIBCPP_CXX03_LANG
74706e2b737SArthur O'Dwyer    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 back_insert_iterator& operator=(typename _Container::value_type&& __value_)
748e4383379SHoward Hinnant        {container->push_back(_VSTD::move(__value_)); return *this;}
749046492b9SEric Fiselier#endif // _LIBCPP_CXX03_LANG
75006e2b737SArthur O'Dwyer    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 back_insert_iterator& operator*()     {return *this;}
75106e2b737SArthur O'Dwyer    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 back_insert_iterator& operator++()    {return *this;}
75206e2b737SArthur O'Dwyer    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 back_insert_iterator  operator++(int) {return *this;}
7533e519524SHoward Hinnant};
7543e519524SHoward Hinnant
7553e519524SHoward Hinnanttemplate <class _Container>
75606e2b737SArthur O'Dwyerinline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
7573e519524SHoward Hinnantback_insert_iterator<_Container>
7583e519524SHoward Hinnantback_inserter(_Container& __x)
7593e519524SHoward Hinnant{
7603e519524SHoward Hinnant    return back_insert_iterator<_Container>(__x);
7613e519524SHoward Hinnant}
7623e519524SHoward Hinnant
7633e519524SHoward Hinnanttemplate <class _Container>
764e2f2d1edSEric Fiselierclass _LIBCPP_TEMPLATE_VIS front_insert_iterator
7653e519524SHoward Hinnant    : public iterator<output_iterator_tag,
7663e519524SHoward Hinnant                      void,
7673e519524SHoward Hinnant                      void,
7683e519524SHoward Hinnant                      void,
7698892b4eeSEric Fiselier                      void>
7703e519524SHoward Hinnant{
7713e519524SHoward Hinnantprotected:
7723e519524SHoward Hinnant    _Container* container;
7733e519524SHoward Hinnantpublic:
7743e519524SHoward Hinnant    typedef _Container container_type;
7753e519524SHoward Hinnant
77606e2b737SArthur O'Dwyer    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 explicit front_insert_iterator(_Container& __x) : container(_VSTD::addressof(__x)) {}
77706e2b737SArthur O'Dwyer    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 front_insert_iterator& operator=(const typename _Container::value_type& __value_)
778e4383379SHoward Hinnant        {container->push_front(__value_); return *this;}
779046492b9SEric Fiselier#ifndef _LIBCPP_CXX03_LANG
78006e2b737SArthur O'Dwyer    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 front_insert_iterator& operator=(typename _Container::value_type&& __value_)
781e4383379SHoward Hinnant        {container->push_front(_VSTD::move(__value_)); return *this;}
782046492b9SEric Fiselier#endif // _LIBCPP_CXX03_LANG
78306e2b737SArthur O'Dwyer    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 front_insert_iterator& operator*()     {return *this;}
78406e2b737SArthur O'Dwyer    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 front_insert_iterator& operator++()    {return *this;}
78506e2b737SArthur O'Dwyer    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 front_insert_iterator  operator++(int) {return *this;}
7863e519524SHoward Hinnant};
7873e519524SHoward Hinnant
7883e519524SHoward Hinnanttemplate <class _Container>
78906e2b737SArthur O'Dwyerinline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
7903e519524SHoward Hinnantfront_insert_iterator<_Container>
7913e519524SHoward Hinnantfront_inserter(_Container& __x)
7923e519524SHoward Hinnant{
7933e519524SHoward Hinnant    return front_insert_iterator<_Container>(__x);
7943e519524SHoward Hinnant}
7953e519524SHoward Hinnant
7963e519524SHoward Hinnanttemplate <class _Container>
797e2f2d1edSEric Fiselierclass _LIBCPP_TEMPLATE_VIS insert_iterator
7983e519524SHoward Hinnant    : public iterator<output_iterator_tag,
7993e519524SHoward Hinnant                      void,
8003e519524SHoward Hinnant                      void,
8013e519524SHoward Hinnant                      void,
8028892b4eeSEric Fiselier                      void>
8033e519524SHoward Hinnant{
8043e519524SHoward Hinnantprotected:
8053e519524SHoward Hinnant    _Container* container;
8063e519524SHoward Hinnant    typename _Container::iterator iter;
8073e519524SHoward Hinnantpublic:
8083e519524SHoward Hinnant    typedef _Container container_type;
8093e519524SHoward Hinnant
81006e2b737SArthur O'Dwyer    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 insert_iterator(_Container& __x, typename _Container::iterator __i)
811f519be34SMarshall Clow        : container(_VSTD::addressof(__x)), iter(__i) {}
81206e2b737SArthur O'Dwyer    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 insert_iterator& operator=(const typename _Container::value_type& __value_)
813e4383379SHoward Hinnant        {iter = container->insert(iter, __value_); ++iter; return *this;}
814046492b9SEric Fiselier#ifndef _LIBCPP_CXX03_LANG
81506e2b737SArthur O'Dwyer    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 insert_iterator& operator=(typename _Container::value_type&& __value_)
816e4383379SHoward Hinnant        {iter = container->insert(iter, _VSTD::move(__value_)); ++iter; return *this;}
817046492b9SEric Fiselier#endif // _LIBCPP_CXX03_LANG
81806e2b737SArthur O'Dwyer    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 insert_iterator& operator*()        {return *this;}
81906e2b737SArthur O'Dwyer    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 insert_iterator& operator++()       {return *this;}
82006e2b737SArthur O'Dwyer    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 insert_iterator& operator++(int)    {return *this;}
8213e519524SHoward Hinnant};
8223e519524SHoward Hinnant
8233e519524SHoward Hinnanttemplate <class _Container>
82406e2b737SArthur O'Dwyerinline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
8253e519524SHoward Hinnantinsert_iterator<_Container>
8263e519524SHoward Hinnantinserter(_Container& __x, typename _Container::iterator __i)
8273e519524SHoward Hinnant{
8283e519524SHoward Hinnant    return insert_iterator<_Container>(__x, __i);
8293e519524SHoward Hinnant}
8303e519524SHoward Hinnant
8313e519524SHoward Hinnanttemplate <class _Tp, class _CharT = char,
8323e519524SHoward Hinnant          class _Traits = char_traits<_CharT>, class _Distance = ptrdiff_t>
833e2f2d1edSEric Fiselierclass _LIBCPP_TEMPLATE_VIS istream_iterator
8343e519524SHoward Hinnant    : public iterator<input_iterator_tag, _Tp, _Distance, const _Tp*, const _Tp&>
8353e519524SHoward Hinnant{
8363e519524SHoward Hinnantpublic:
8373e519524SHoward Hinnant    typedef _CharT char_type;
8383e519524SHoward Hinnant    typedef _Traits traits_type;
8393e519524SHoward Hinnant    typedef basic_istream<_CharT,_Traits> istream_type;
8403e519524SHoward Hinnantprivate:
8413e519524SHoward Hinnant    istream_type* __in_stream_;
8423e519524SHoward Hinnant    _Tp __value_;
8433e519524SHoward Hinnantpublic:
844527a7fdfSBruce Mitchener    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR istream_iterator() : __in_stream_(nullptr), __value_() {}
845bc6a7df0SMarshall Clow    _LIBCPP_INLINE_VISIBILITY istream_iterator(istream_type& __s) : __in_stream_(_VSTD::addressof(__s))
8463e519524SHoward Hinnant        {
8473e519524SHoward Hinnant            if (!(*__in_stream_ >> __value_))
848527a7fdfSBruce Mitchener                __in_stream_ = nullptr;
8493e519524SHoward Hinnant        }
8503e519524SHoward Hinnant
8513e519524SHoward Hinnant    _LIBCPP_INLINE_VISIBILITY const _Tp& operator*() const {return __value_;}
852bc6a7df0SMarshall Clow    _LIBCPP_INLINE_VISIBILITY const _Tp* operator->() const {return _VSTD::addressof((operator*()));}
8533e519524SHoward Hinnant    _LIBCPP_INLINE_VISIBILITY istream_iterator& operator++()
8543e519524SHoward Hinnant        {
8553e519524SHoward Hinnant            if (!(*__in_stream_ >> __value_))
856527a7fdfSBruce Mitchener                __in_stream_ = nullptr;
8573e519524SHoward Hinnant            return *this;
8583e519524SHoward Hinnant        }
8593e519524SHoward Hinnant    _LIBCPP_INLINE_VISIBILITY istream_iterator  operator++(int)
8603e519524SHoward Hinnant        {istream_iterator __t(*this); ++(*this); return __t;}
8613e519524SHoward Hinnant
8626f56d3eeSRoger Ferrer Ibanez    template <class _Up, class _CharU, class _TraitsU, class _DistanceU>
8633e519524SHoward Hinnant    friend _LIBCPP_INLINE_VISIBILITY
8646f56d3eeSRoger Ferrer Ibanez    bool
8656f56d3eeSRoger Ferrer Ibanez    operator==(const istream_iterator<_Up, _CharU, _TraitsU, _DistanceU>& __x,
8666f56d3eeSRoger Ferrer Ibanez               const istream_iterator<_Up, _CharU, _TraitsU, _DistanceU>& __y);
8673e519524SHoward Hinnant
8686f56d3eeSRoger Ferrer Ibanez    template <class _Up, class _CharU, class _TraitsU, class _DistanceU>
8693e519524SHoward Hinnant    friend _LIBCPP_INLINE_VISIBILITY
8706f56d3eeSRoger Ferrer Ibanez    bool
8716f56d3eeSRoger Ferrer Ibanez    operator==(const istream_iterator<_Up, _CharU, _TraitsU, _DistanceU>& __x,
8726f56d3eeSRoger Ferrer Ibanez               const istream_iterator<_Up, _CharU, _TraitsU, _DistanceU>& __y);
8733e519524SHoward Hinnant};
8743e519524SHoward Hinnant
8756f56d3eeSRoger Ferrer Ibaneztemplate <class _Tp, class _CharT, class _Traits, class _Distance>
8766f56d3eeSRoger Ferrer Ibanezinline _LIBCPP_INLINE_VISIBILITY
8776f56d3eeSRoger Ferrer Ibanezbool
8786f56d3eeSRoger Ferrer Ibanezoperator==(const istream_iterator<_Tp, _CharT, _Traits, _Distance>& __x,
8796f56d3eeSRoger Ferrer Ibanez           const istream_iterator<_Tp, _CharT, _Traits, _Distance>& __y)
8806f56d3eeSRoger Ferrer Ibanez{
8816f56d3eeSRoger Ferrer Ibanez    return __x.__in_stream_ == __y.__in_stream_;
8826f56d3eeSRoger Ferrer Ibanez}
8836f56d3eeSRoger Ferrer Ibanez
8846f56d3eeSRoger Ferrer Ibaneztemplate <class _Tp, class _CharT, class _Traits, class _Distance>
8856f56d3eeSRoger Ferrer Ibanezinline _LIBCPP_INLINE_VISIBILITY
8866f56d3eeSRoger Ferrer Ibanezbool
8876f56d3eeSRoger Ferrer Ibanezoperator!=(const istream_iterator<_Tp, _CharT, _Traits, _Distance>& __x,
8886f56d3eeSRoger Ferrer Ibanez           const istream_iterator<_Tp, _CharT, _Traits, _Distance>& __y)
8896f56d3eeSRoger Ferrer Ibanez{
8906f56d3eeSRoger Ferrer Ibanez    return !(__x == __y);
8916f56d3eeSRoger Ferrer Ibanez}
8926f56d3eeSRoger Ferrer Ibanez
8933e519524SHoward Hinnanttemplate <class _Tp, class _CharT = char, class _Traits = char_traits<_CharT> >
894e2f2d1edSEric Fiselierclass _LIBCPP_TEMPLATE_VIS ostream_iterator
8953e519524SHoward Hinnant    : public iterator<output_iterator_tag, void, void, void, void>
8963e519524SHoward Hinnant{
8973e519524SHoward Hinnantpublic:
89871a16e40SLouis Dionne    typedef output_iterator_tag             iterator_category;
89971a16e40SLouis Dionne    typedef void                            value_type;
90071a16e40SLouis Dionne#if _LIBCPP_STD_VER > 17
90171a16e40SLouis Dionne    typedef std::ptrdiff_t                  difference_type;
90271a16e40SLouis Dionne#else
90371a16e40SLouis Dionne    typedef void                            difference_type;
90471a16e40SLouis Dionne#endif
90571a16e40SLouis Dionne    typedef void                            pointer;
90671a16e40SLouis Dionne    typedef void                            reference;
9073e519524SHoward Hinnant    typedef _CharT                          char_type;
9083e519524SHoward Hinnant    typedef _Traits                         traits_type;
9093e519524SHoward Hinnant    typedef basic_ostream<_CharT, _Traits>  ostream_type;
91071a16e40SLouis Dionne
9113e519524SHoward Hinnantprivate:
9123e519524SHoward Hinnant    ostream_type* __out_stream_;
9133e519524SHoward Hinnant    const char_type* __delim_;
9143e519524SHoward Hinnantpublic:
915853042cfSMarshall Clow    _LIBCPP_INLINE_VISIBILITY ostream_iterator(ostream_type& __s) _NOEXCEPT
916527a7fdfSBruce Mitchener        : __out_stream_(_VSTD::addressof(__s)), __delim_(nullptr) {}
917853042cfSMarshall Clow    _LIBCPP_INLINE_VISIBILITY ostream_iterator(ostream_type& __s, const _CharT* __delimiter) _NOEXCEPT
918bc6a7df0SMarshall Clow        : __out_stream_(_VSTD::addressof(__s)), __delim_(__delimiter) {}
919e4383379SHoward Hinnant    _LIBCPP_INLINE_VISIBILITY ostream_iterator& operator=(const _Tp& __value_)
9203e519524SHoward Hinnant        {
921e4383379SHoward Hinnant            *__out_stream_ << __value_;
9223e519524SHoward Hinnant            if (__delim_)
9233e519524SHoward Hinnant                *__out_stream_ << __delim_;
9243e519524SHoward Hinnant            return *this;
9253e519524SHoward Hinnant        }
9263e519524SHoward Hinnant
9273e519524SHoward Hinnant    _LIBCPP_INLINE_VISIBILITY ostream_iterator& operator*()     {return *this;}
9283e519524SHoward Hinnant    _LIBCPP_INLINE_VISIBILITY ostream_iterator& operator++()    {return *this;}
9293e519524SHoward Hinnant    _LIBCPP_INLINE_VISIBILITY ostream_iterator& operator++(int) {return *this;}
9303e519524SHoward Hinnant};
9313e519524SHoward Hinnant
9323e519524SHoward Hinnanttemplate<class _CharT, class _Traits>
933e2f2d1edSEric Fiselierclass _LIBCPP_TEMPLATE_VIS istreambuf_iterator
9343e519524SHoward Hinnant    : public iterator<input_iterator_tag, _CharT,
9353e519524SHoward Hinnant                      typename _Traits::off_type, _CharT*,
9363e519524SHoward Hinnant                      _CharT>
9373e519524SHoward Hinnant{
9383e519524SHoward Hinnantpublic:
9393e519524SHoward Hinnant    typedef _CharT                          char_type;
9403e519524SHoward Hinnant    typedef _Traits                         traits_type;
9413e519524SHoward Hinnant    typedef typename _Traits::int_type      int_type;
9423e519524SHoward Hinnant    typedef basic_streambuf<_CharT,_Traits> streambuf_type;
9433e519524SHoward Hinnant    typedef basic_istream<_CharT,_Traits>   istream_type;
9443e519524SHoward Hinnantprivate:
945dfdf5085SHoward Hinnant    mutable streambuf_type* __sbuf_;
9463e519524SHoward Hinnant
9473e519524SHoward Hinnant    class __proxy
9483e519524SHoward Hinnant    {
9493e519524SHoward Hinnant        char_type __keep_;
9503e519524SHoward Hinnant        streambuf_type* __sbuf_;
9513e519524SHoward Hinnant        _LIBCPP_INLINE_VISIBILITY __proxy(char_type __c, streambuf_type* __s)
9523e519524SHoward Hinnant            : __keep_(__c), __sbuf_(__s) {}
9533e519524SHoward Hinnant        friend class istreambuf_iterator;
9543e519524SHoward Hinnant    public:
9553e519524SHoward Hinnant        _LIBCPP_INLINE_VISIBILITY char_type operator*() const {return __keep_;}
9563e519524SHoward Hinnant    };
9573e519524SHoward Hinnant
958848a5374SHoward Hinnant    _LIBCPP_INLINE_VISIBILITY
959dfdf5085SHoward Hinnant    bool __test_for_eof() const
9603e519524SHoward Hinnant    {
9613e519524SHoward Hinnant        if (__sbuf_ && traits_type::eq_int_type(__sbuf_->sgetc(), traits_type::eof()))
962527a7fdfSBruce Mitchener            __sbuf_ = nullptr;
963527a7fdfSBruce Mitchener        return __sbuf_ == nullptr;
9643e519524SHoward Hinnant    }
9653e519524SHoward Hinnantpublic:
966527a7fdfSBruce Mitchener    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR istreambuf_iterator() _NOEXCEPT : __sbuf_(nullptr) {}
9678e882dcbSHoward Hinnant    _LIBCPP_INLINE_VISIBILITY istreambuf_iterator(istream_type& __s) _NOEXCEPT
968a96d7458SHoward Hinnant        : __sbuf_(__s.rdbuf()) {}
9698e882dcbSHoward Hinnant    _LIBCPP_INLINE_VISIBILITY istreambuf_iterator(streambuf_type* __s) _NOEXCEPT
970a96d7458SHoward Hinnant        : __sbuf_(__s) {}
9718e882dcbSHoward Hinnant    _LIBCPP_INLINE_VISIBILITY istreambuf_iterator(const __proxy& __p) _NOEXCEPT
9723e519524SHoward Hinnant        : __sbuf_(__p.__sbuf_) {}
9733e519524SHoward Hinnant
974c206366fSHoward Hinnant    _LIBCPP_INLINE_VISIBILITY char_type  operator*() const
975c206366fSHoward Hinnant        {return static_cast<char_type>(__sbuf_->sgetc());}
9763e519524SHoward Hinnant    _LIBCPP_INLINE_VISIBILITY istreambuf_iterator& operator++()
9773e519524SHoward Hinnant        {
978dfdf5085SHoward Hinnant            __sbuf_->sbumpc();
9793e519524SHoward Hinnant            return *this;
9803e519524SHoward Hinnant        }
9813e519524SHoward Hinnant    _LIBCPP_INLINE_VISIBILITY __proxy              operator++(int)
9823e519524SHoward Hinnant        {
983dfdf5085SHoward Hinnant            return __proxy(__sbuf_->sbumpc(), __sbuf_);
9843e519524SHoward Hinnant        }
9853e519524SHoward Hinnant
9863e519524SHoward Hinnant    _LIBCPP_INLINE_VISIBILITY bool equal(const istreambuf_iterator& __b) const
987dfdf5085SHoward Hinnant        {return __test_for_eof() == __b.__test_for_eof();}
9883e519524SHoward Hinnant};
9893e519524SHoward Hinnant
9903e519524SHoward Hinnanttemplate <class _CharT, class _Traits>
9913e519524SHoward Hinnantinline _LIBCPP_INLINE_VISIBILITY
9923e519524SHoward Hinnantbool operator==(const istreambuf_iterator<_CharT,_Traits>& __a,
9933e519524SHoward Hinnant                const istreambuf_iterator<_CharT,_Traits>& __b)
9943e519524SHoward Hinnant                {return __a.equal(__b);}
9953e519524SHoward Hinnant
9963e519524SHoward Hinnanttemplate <class _CharT, class _Traits>
9973e519524SHoward Hinnantinline _LIBCPP_INLINE_VISIBILITY
9983e519524SHoward Hinnantbool operator!=(const istreambuf_iterator<_CharT,_Traits>& __a,
9993e519524SHoward Hinnant                const istreambuf_iterator<_CharT,_Traits>& __b)
10003e519524SHoward Hinnant                {return !__a.equal(__b);}
10013e519524SHoward Hinnant
10023e519524SHoward Hinnanttemplate <class _CharT, class _Traits>
1003e2f2d1edSEric Fiselierclass _LIBCPP_TEMPLATE_VIS ostreambuf_iterator
10043e519524SHoward Hinnant    : public iterator<output_iterator_tag, void, void, void, void>
10053e519524SHoward Hinnant{
10063e519524SHoward Hinnantpublic:
100771a16e40SLouis Dionne    typedef output_iterator_tag                 iterator_category;
100871a16e40SLouis Dionne    typedef void                                value_type;
100971a16e40SLouis Dionne#if _LIBCPP_STD_VER > 17
101071a16e40SLouis Dionne    typedef std::ptrdiff_t                      difference_type;
101171a16e40SLouis Dionne#else
101271a16e40SLouis Dionne    typedef void                                difference_type;
101371a16e40SLouis Dionne#endif
101471a16e40SLouis Dionne    typedef void                                pointer;
101571a16e40SLouis Dionne    typedef void                                reference;
10163e519524SHoward Hinnant    typedef _CharT                              char_type;
10173e519524SHoward Hinnant    typedef _Traits                             traits_type;
10183e519524SHoward Hinnant    typedef basic_streambuf<_CharT, _Traits>    streambuf_type;
10193e519524SHoward Hinnant    typedef basic_ostream<_CharT, _Traits>      ostream_type;
102071a16e40SLouis Dionne
10213e519524SHoward Hinnantprivate:
10223e519524SHoward Hinnant    streambuf_type* __sbuf_;
10233e519524SHoward Hinnantpublic:
10248e882dcbSHoward Hinnant    _LIBCPP_INLINE_VISIBILITY ostreambuf_iterator(ostream_type& __s) _NOEXCEPT
10253e519524SHoward Hinnant        : __sbuf_(__s.rdbuf()) {}
10268e882dcbSHoward Hinnant    _LIBCPP_INLINE_VISIBILITY ostreambuf_iterator(streambuf_type* __s) _NOEXCEPT
10273e519524SHoward Hinnant        : __sbuf_(__s) {}
10283e519524SHoward Hinnant    _LIBCPP_INLINE_VISIBILITY ostreambuf_iterator& operator=(_CharT __c)
10293e519524SHoward Hinnant        {
10303e519524SHoward Hinnant            if (__sbuf_ && traits_type::eq_int_type(__sbuf_->sputc(__c), traits_type::eof()))
1031527a7fdfSBruce Mitchener                __sbuf_ = nullptr;
10323e519524SHoward Hinnant            return *this;
10333e519524SHoward Hinnant        }
10343e519524SHoward Hinnant    _LIBCPP_INLINE_VISIBILITY ostreambuf_iterator& operator*()     {return *this;}
10353e519524SHoward Hinnant    _LIBCPP_INLINE_VISIBILITY ostreambuf_iterator& operator++()    {return *this;}
10363e519524SHoward Hinnant    _LIBCPP_INLINE_VISIBILITY ostreambuf_iterator& operator++(int) {return *this;}
1037527a7fdfSBruce Mitchener    _LIBCPP_INLINE_VISIBILITY bool failed() const _NOEXCEPT {return __sbuf_ == nullptr;}
103892b5940fSHoward Hinnant
103992b5940fSHoward Hinnant    template <class _Ch, class _Tr>
104092b5940fSHoward Hinnant    friend
104192b5940fSHoward Hinnant    _LIBCPP_HIDDEN
104292b5940fSHoward Hinnant    ostreambuf_iterator<_Ch, _Tr>
104392b5940fSHoward Hinnant    __pad_and_output(ostreambuf_iterator<_Ch, _Tr> __s,
104492b5940fSHoward Hinnant                     const _Ch* __ob, const _Ch* __op, const _Ch* __oe,
104592b5940fSHoward Hinnant                     ios_base& __iob, _Ch __fl);
10463e519524SHoward Hinnant};
10473e519524SHoward Hinnant
10483e519524SHoward Hinnanttemplate <class _Iter>
1049e2f2d1edSEric Fiselierclass _LIBCPP_TEMPLATE_VIS move_iterator
10503e519524SHoward Hinnant{
10513e519524SHoward Hinnantprivate:
10523e519524SHoward Hinnant    _Iter __i;
10533e519524SHoward Hinnantpublic:
10543e519524SHoward Hinnant    typedef _Iter                                            iterator_type;
10553e519524SHoward Hinnant    typedef typename iterator_traits<iterator_type>::value_type value_type;
10563e519524SHoward Hinnant    typedef typename iterator_traits<iterator_type>::difference_type difference_type;
105705333fc8SMarshall Clow    typedef iterator_type pointer;
1058d41c6d51SArthur O'Dwyer    typedef _If<__is_cpp17_random_access_iterator<_Iter>::value,
1059d41c6d51SArthur O'Dwyer        random_access_iterator_tag,
1060d41c6d51SArthur O'Dwyer        typename iterator_traits<_Iter>::iterator_category>  iterator_category;
1061d41c6d51SArthur O'Dwyer#if _LIBCPP_STD_VER > 17
1062d41c6d51SArthur O'Dwyer    typedef input_iterator_tag                               iterator_concept;
1063d41c6d51SArthur O'Dwyer#endif
1064d41c6d51SArthur O'Dwyer
1065046492b9SEric Fiselier#ifndef _LIBCPP_CXX03_LANG
1066906c5085SEric Fiselier    typedef typename iterator_traits<iterator_type>::reference __reference;
1067906c5085SEric Fiselier    typedef typename conditional<
1068906c5085SEric Fiselier            is_reference<__reference>::value,
1069906c5085SEric Fiselier            typename remove_reference<__reference>::type&&,
1070906c5085SEric Fiselier            __reference
1071906c5085SEric Fiselier        >::type reference;
10723e519524SHoward Hinnant#else
10733e519524SHoward Hinnant    typedef typename iterator_traits<iterator_type>::reference reference;
10743e519524SHoward Hinnant#endif
10753e519524SHoward Hinnant
1076720ef472SMarshall Clow    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
1077720ef472SMarshall Clow    move_iterator() : __i() {}
1078720ef472SMarshall Clow    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
1079720ef472SMarshall Clow    explicit move_iterator(_Iter __x) : __i(__x) {}
1080720ef472SMarshall Clow    template <class _Up>
1081720ef472SMarshall Clow      _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
1082720ef472SMarshall Clow      move_iterator(const move_iterator<_Up>& __u) : __i(__u.base()) {}
1083720ef472SMarshall Clow    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 _Iter base() const {return __i;}
1084720ef472SMarshall Clow    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
1085720ef472SMarshall Clow    reference operator*() const { return static_cast<reference>(*__i); }
1086720ef472SMarshall Clow    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
1087720ef472SMarshall Clow    pointer  operator->() const { return __i;}
1088720ef472SMarshall Clow    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
1089720ef472SMarshall Clow    move_iterator& operator++() {++__i; return *this;}
1090720ef472SMarshall Clow    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
1091720ef472SMarshall Clow    move_iterator  operator++(int) {move_iterator __tmp(*this); ++__i; return __tmp;}
1092720ef472SMarshall Clow    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
1093720ef472SMarshall Clow    move_iterator& operator--() {--__i; return *this;}
1094720ef472SMarshall Clow    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
1095720ef472SMarshall Clow    move_iterator  operator--(int) {move_iterator __tmp(*this); --__i; return __tmp;}
1096720ef472SMarshall Clow    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
1097720ef472SMarshall Clow    move_iterator  operator+ (difference_type __n) const {return move_iterator(__i + __n);}
1098720ef472SMarshall Clow    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
1099720ef472SMarshall Clow    move_iterator& operator+=(difference_type __n) {__i += __n; return *this;}
1100720ef472SMarshall Clow    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
1101720ef472SMarshall Clow    move_iterator  operator- (difference_type __n) const {return move_iterator(__i - __n);}
1102720ef472SMarshall Clow    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
1103720ef472SMarshall Clow    move_iterator& operator-=(difference_type __n) {__i -= __n; return *this;}
1104720ef472SMarshall Clow    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
1105720ef472SMarshall Clow    reference operator[](difference_type __n) const { return static_cast<reference>(__i[__n]); }
11063e519524SHoward Hinnant};
11073e519524SHoward Hinnant
11083e519524SHoward Hinnanttemplate <class _Iter1, class _Iter2>
1109720ef472SMarshall Clowinline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
11103e519524SHoward Hinnantbool
11113e519524SHoward Hinnantoperator==(const move_iterator<_Iter1>& __x, const move_iterator<_Iter2>& __y)
11123e519524SHoward Hinnant{
11133e519524SHoward Hinnant    return __x.base() == __y.base();
11143e519524SHoward Hinnant}
11153e519524SHoward Hinnant
11163e519524SHoward Hinnanttemplate <class _Iter1, class _Iter2>
1117720ef472SMarshall Clowinline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
11183e519524SHoward Hinnantbool
11193e519524SHoward Hinnantoperator<(const move_iterator<_Iter1>& __x, const move_iterator<_Iter2>& __y)
11203e519524SHoward Hinnant{
11213e519524SHoward Hinnant    return __x.base() < __y.base();
11223e519524SHoward Hinnant}
11233e519524SHoward Hinnant
11243e519524SHoward Hinnanttemplate <class _Iter1, class _Iter2>
1125720ef472SMarshall Clowinline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
11263e519524SHoward Hinnantbool
11273e519524SHoward Hinnantoperator!=(const move_iterator<_Iter1>& __x, const move_iterator<_Iter2>& __y)
11283e519524SHoward Hinnant{
11293e519524SHoward Hinnant    return __x.base() != __y.base();
11303e519524SHoward Hinnant}
11313e519524SHoward Hinnant
11323e519524SHoward Hinnanttemplate <class _Iter1, class _Iter2>
1133720ef472SMarshall Clowinline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
11343e519524SHoward Hinnantbool
11353e519524SHoward Hinnantoperator>(const move_iterator<_Iter1>& __x, const move_iterator<_Iter2>& __y)
11363e519524SHoward Hinnant{
11373e519524SHoward Hinnant    return __x.base() > __y.base();
11383e519524SHoward Hinnant}
11393e519524SHoward Hinnant
11403e519524SHoward Hinnanttemplate <class _Iter1, class _Iter2>
1141720ef472SMarshall Clowinline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
11423e519524SHoward Hinnantbool
11433e519524SHoward Hinnantoperator>=(const move_iterator<_Iter1>& __x, const move_iterator<_Iter2>& __y)
11443e519524SHoward Hinnant{
11453e519524SHoward Hinnant    return __x.base() >= __y.base();
11463e519524SHoward Hinnant}
11473e519524SHoward Hinnant
11483e519524SHoward Hinnanttemplate <class _Iter1, class _Iter2>
1149720ef472SMarshall Clowinline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
11503e519524SHoward Hinnantbool
11513e519524SHoward Hinnantoperator<=(const move_iterator<_Iter1>& __x, const move_iterator<_Iter2>& __y)
11523e519524SHoward Hinnant{
11533e519524SHoward Hinnant    return __x.base() <= __y.base();
11543e519524SHoward Hinnant}
11553e519524SHoward Hinnant
11562ee83725SMarshall Clow#ifndef _LIBCPP_CXX03_LANG
1157947ce6b5SMarshall Clowtemplate <class _Iter1, class _Iter2>
1158720ef472SMarshall Clowinline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
1159947ce6b5SMarshall Clowauto
1160947ce6b5SMarshall Clowoperator-(const move_iterator<_Iter1>& __x, const move_iterator<_Iter2>& __y)
1161947ce6b5SMarshall Clow-> decltype(__x.base() - __y.base())
1162947ce6b5SMarshall Clow{
1163947ce6b5SMarshall Clow    return __x.base() - __y.base();
1164947ce6b5SMarshall Clow}
1165947ce6b5SMarshall Clow#else
11663e519524SHoward Hinnanttemplate <class _Iter1, class _Iter2>
11673e519524SHoward Hinnantinline _LIBCPP_INLINE_VISIBILITY
11683e519524SHoward Hinnanttypename move_iterator<_Iter1>::difference_type
11693e519524SHoward Hinnantoperator-(const move_iterator<_Iter1>& __x, const move_iterator<_Iter2>& __y)
11703e519524SHoward Hinnant{
11713e519524SHoward Hinnant    return __x.base() - __y.base();
11723e519524SHoward Hinnant}
1173947ce6b5SMarshall Clow#endif
11743e519524SHoward Hinnant
11753e519524SHoward Hinnanttemplate <class _Iter>
1176720ef472SMarshall Clowinline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
11773e519524SHoward Hinnantmove_iterator<_Iter>
11783e519524SHoward Hinnantoperator+(typename move_iterator<_Iter>::difference_type __n, const move_iterator<_Iter>& __x)
11793e519524SHoward Hinnant{
11803e519524SHoward Hinnant    return move_iterator<_Iter>(__x.base() + __n);
11813e519524SHoward Hinnant}
11823e519524SHoward Hinnant
11833e519524SHoward Hinnanttemplate <class _Iter>
1184720ef472SMarshall Clowinline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
11853e519524SHoward Hinnantmove_iterator<_Iter>
118654c83368SMarshall Clowmake_move_iterator(_Iter __i)
11873e519524SHoward Hinnant{
11883e519524SHoward Hinnant    return move_iterator<_Iter>(__i);
11893e519524SHoward Hinnant}
11903e519524SHoward Hinnant
11913e519524SHoward Hinnant// __wrap_iter
11923e519524SHoward Hinnant
11933e519524SHoward Hinnanttemplate <class _Iter> class __wrap_iter;
11943e519524SHoward Hinnant
11953e519524SHoward Hinnanttemplate <class _Iter1, class _Iter2>
11969cad5025SMarshall Clow_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG
11973e519524SHoward Hinnantbool
119861b302f9SEric Fiselieroperator==(const __wrap_iter<_Iter1>&, const __wrap_iter<_Iter2>&) _NOEXCEPT;
11993e519524SHoward Hinnant
12003e519524SHoward Hinnanttemplate <class _Iter1, class _Iter2>
12019cad5025SMarshall Clow_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG
12023e519524SHoward Hinnantbool
120361b302f9SEric Fiselieroperator<(const __wrap_iter<_Iter1>&, const __wrap_iter<_Iter2>&) _NOEXCEPT;
12043e519524SHoward Hinnant
12053e519524SHoward Hinnanttemplate <class _Iter1, class _Iter2>
12069cad5025SMarshall Clow_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG
12073e519524SHoward Hinnantbool
120861b302f9SEric Fiselieroperator!=(const __wrap_iter<_Iter1>&, const __wrap_iter<_Iter2>&) _NOEXCEPT;
12093e519524SHoward Hinnant
12103e519524SHoward Hinnanttemplate <class _Iter1, class _Iter2>
12119cad5025SMarshall Clow_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG
12123e519524SHoward Hinnantbool
121361b302f9SEric Fiselieroperator>(const __wrap_iter<_Iter1>&, const __wrap_iter<_Iter2>&) _NOEXCEPT;
12143e519524SHoward Hinnant
12153e519524SHoward Hinnanttemplate <class _Iter1, class _Iter2>
12169cad5025SMarshall Clow_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG
12173e519524SHoward Hinnantbool
121861b302f9SEric Fiselieroperator>=(const __wrap_iter<_Iter1>&, const __wrap_iter<_Iter2>&) _NOEXCEPT;
12193e519524SHoward Hinnant
12203e519524SHoward Hinnanttemplate <class _Iter1, class _Iter2>
12219cad5025SMarshall Clow_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG
12223e519524SHoward Hinnantbool
122361b302f9SEric Fiselieroperator<=(const __wrap_iter<_Iter1>&, const __wrap_iter<_Iter2>&) _NOEXCEPT;
12243e519524SHoward Hinnant
12252ee83725SMarshall Clow#ifndef _LIBCPP_CXX03_LANG
1226947ce6b5SMarshall Clowtemplate <class _Iter1, class _Iter2>
12279cad5025SMarshall Clow_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG
1228947ce6b5SMarshall Clowauto
122961b302f9SEric Fiselieroperator-(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter2>& __y) _NOEXCEPT
1230947ce6b5SMarshall Clow-> decltype(__x.base() - __y.base());
1231947ce6b5SMarshall Clow#else
12323e519524SHoward Hinnanttemplate <class _Iter1, class _Iter2>
1233aeb85680SHoward Hinnant_LIBCPP_INLINE_VISIBILITY
12343e519524SHoward Hinnanttypename __wrap_iter<_Iter1>::difference_type
123561b302f9SEric Fiselieroperator-(const __wrap_iter<_Iter1>&, const __wrap_iter<_Iter2>&) _NOEXCEPT;
1236947ce6b5SMarshall Clow#endif
12373e519524SHoward Hinnant
12383e519524SHoward Hinnanttemplate <class _Iter>
12399cad5025SMarshall Clow_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG
12403e519524SHoward Hinnant__wrap_iter<_Iter>
124161b302f9SEric Fiselieroperator+(typename __wrap_iter<_Iter>::difference_type, __wrap_iter<_Iter>) _NOEXCEPT;
12423e519524SHoward Hinnant
124313c90a57SLouis Dionnetemplate <class _Ip, class _Op> _Op _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 copy(_Ip, _Ip, _Op);
124413c90a57SLouis Dionnetemplate <class _B1, class _B2> _B2 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 copy_backward(_B1, _B1, _B2);
12453ed89b51Szoecarvertemplate <class _Ip, class _Op> _Op _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 move(_Ip, _Ip, _Op);
12463ed89b51Szoecarvertemplate <class _B1, class _B2> _B2 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 move_backward(_B1, _B1, _B2);
12473e519524SHoward Hinnant
12483e519524SHoward Hinnanttemplate <class _Iter>
12493e519524SHoward Hinnantclass __wrap_iter
12503e519524SHoward Hinnant{
12513e519524SHoward Hinnantpublic:
12523e519524SHoward Hinnant    typedef _Iter                                                      iterator_type;
12533e519524SHoward Hinnant    typedef typename iterator_traits<iterator_type>::value_type        value_type;
12543e519524SHoward Hinnant    typedef typename iterator_traits<iterator_type>::difference_type   difference_type;
12553e519524SHoward Hinnant    typedef typename iterator_traits<iterator_type>::pointer           pointer;
12563e519524SHoward Hinnant    typedef typename iterator_traits<iterator_type>::reference         reference;
1257d41c6d51SArthur O'Dwyer    typedef typename iterator_traits<iterator_type>::iterator_category iterator_category;
1258d41c6d51SArthur O'Dwyer#if _LIBCPP_STD_VER > 17
1259d41c6d51SArthur O'Dwyer    typedef _If<__is_cpp17_contiguous_iterator<_Iter>::value,
1260d41c6d51SArthur O'Dwyer                contiguous_iterator_tag, iterator_category>            iterator_concept;
1261d41c6d51SArthur O'Dwyer#endif
1262d41c6d51SArthur O'Dwyer
12633e519524SHoward Hinnantprivate:
12643e519524SHoward Hinnant    iterator_type __i;
12653e519524SHoward Hinnantpublic:
126661b302f9SEric Fiselier    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG __wrap_iter() _NOEXCEPT
126707186a7dSMarshall Clow#if _LIBCPP_STD_VER > 11
126807186a7dSMarshall Clow                : __i{}
126907186a7dSMarshall Clow#endif
1270c36bfc49SHoward Hinnant    {
127131e82037SLouis Dionne#if _LIBCPP_DEBUG_LEVEL == 2
1272c36bfc49SHoward Hinnant        __get_db()->__insert_i(this);
1273c36bfc49SHoward Hinnant#endif
1274c36bfc49SHoward Hinnant    }
12759cad5025SMarshall Clow    template <class _Up> _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG
12769cad5025SMarshall Clow        __wrap_iter(const __wrap_iter<_Up>& __u,
1277527a7fdfSBruce Mitchener            typename enable_if<is_convertible<_Up, iterator_type>::value>::type* = nullptr) _NOEXCEPT
1278f554add5SHoward Hinnant            : __i(__u.base())
1279f554add5SHoward Hinnant    {
128031e82037SLouis Dionne#if _LIBCPP_DEBUG_LEVEL == 2
1281f554add5SHoward Hinnant        __get_db()->__iterator_copy(this, &__u);
1282f554add5SHoward Hinnant#endif
1283f554add5SHoward Hinnant    }
128431e82037SLouis Dionne#if _LIBCPP_DEBUG_LEVEL == 2
12859cad5025SMarshall Clow    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG
1286f554add5SHoward Hinnant    __wrap_iter(const __wrap_iter& __x)
1287f554add5SHoward Hinnant        : __i(__x.base())
1288f554add5SHoward Hinnant    {
1289f554add5SHoward Hinnant        __get_db()->__iterator_copy(this, &__x);
1290f554add5SHoward Hinnant    }
12919cad5025SMarshall Clow    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG
1292f554add5SHoward Hinnant    __wrap_iter& operator=(const __wrap_iter& __x)
1293f554add5SHoward Hinnant    {
1294f554add5SHoward Hinnant        if (this != &__x)
1295f554add5SHoward Hinnant        {
1296f554add5SHoward Hinnant            __get_db()->__iterator_copy(this, &__x);
1297f554add5SHoward Hinnant            __i = __x.__i;
1298f554add5SHoward Hinnant        }
1299f554add5SHoward Hinnant        return *this;
1300f554add5SHoward Hinnant    }
13019cad5025SMarshall Clow    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG
1302f554add5SHoward Hinnant    ~__wrap_iter()
1303f554add5SHoward Hinnant    {
1304f554add5SHoward Hinnant        __get_db()->__erase_i(this);
1305f554add5SHoward Hinnant    }
1306f554add5SHoward Hinnant#endif
130761b302f9SEric Fiselier    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG reference operator*() const _NOEXCEPT
1308f554add5SHoward Hinnant    {
130931e82037SLouis Dionne#if _LIBCPP_DEBUG_LEVEL == 2
1310f554add5SHoward Hinnant        _LIBCPP_ASSERT(__get_const_db()->__dereferenceable(this),
1311f554add5SHoward Hinnant                       "Attempted to dereference a non-dereferenceable iterator");
1312cec9af9eSHoward Hinnant#endif
1313f554add5SHoward Hinnant        return *__i;
1314f554add5SHoward Hinnant    }
131561b302f9SEric Fiselier    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG pointer  operator->() const _NOEXCEPT
13163ec1f00bSHoward Hinnant    {
131731e82037SLouis Dionne#if _LIBCPP_DEBUG_LEVEL == 2
13183ec1f00bSHoward Hinnant        _LIBCPP_ASSERT(__get_const_db()->__dereferenceable(this),
13193ec1f00bSHoward Hinnant                       "Attempted to dereference a non-dereferenceable iterator");
13203ec1f00bSHoward Hinnant#endif
132105333fc8SMarshall Clow        return (pointer)_VSTD::addressof(*__i);
13223ec1f00bSHoward Hinnant    }
132361b302f9SEric Fiselier    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG __wrap_iter& operator++() _NOEXCEPT
1324f554add5SHoward Hinnant    {
132531e82037SLouis Dionne#if _LIBCPP_DEBUG_LEVEL == 2
1326f554add5SHoward Hinnant        _LIBCPP_ASSERT(__get_const_db()->__dereferenceable(this),
1327f554add5SHoward Hinnant                       "Attempted to increment non-incrementable iterator");
1328cec9af9eSHoward Hinnant#endif
1329f554add5SHoward Hinnant        ++__i;
1330f554add5SHoward Hinnant        return *this;
1331f554add5SHoward Hinnant    }
133261b302f9SEric Fiselier    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG __wrap_iter  operator++(int) _NOEXCEPT
1333f554add5SHoward Hinnant        {__wrap_iter __tmp(*this); ++(*this); return __tmp;}
13344ce0a916SMarshall Clow
133561b302f9SEric Fiselier    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG __wrap_iter& operator--() _NOEXCEPT
1336f554add5SHoward Hinnant    {
133731e82037SLouis Dionne#if _LIBCPP_DEBUG_LEVEL == 2
1338f554add5SHoward Hinnant        _LIBCPP_ASSERT(__get_const_db()->__decrementable(this),
1339f554add5SHoward Hinnant                       "Attempted to decrement non-decrementable iterator");
1340cec9af9eSHoward Hinnant#endif
1341f554add5SHoward Hinnant        --__i;
1342f554add5SHoward Hinnant        return *this;
1343f554add5SHoward Hinnant    }
134461b302f9SEric Fiselier    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG __wrap_iter  operator--(int) _NOEXCEPT
1345f554add5SHoward Hinnant        {__wrap_iter __tmp(*this); --(*this); return __tmp;}
134661b302f9SEric Fiselier    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG __wrap_iter  operator+ (difference_type __n) const _NOEXCEPT
1347f554add5SHoward Hinnant        {__wrap_iter __w(*this); __w += __n; return __w;}
134861b302f9SEric Fiselier    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG __wrap_iter& operator+=(difference_type __n) _NOEXCEPT
1349f554add5SHoward Hinnant    {
135031e82037SLouis Dionne#if _LIBCPP_DEBUG_LEVEL == 2
1351f554add5SHoward Hinnant        _LIBCPP_ASSERT(__get_const_db()->__addable(this, __n),
1352f554add5SHoward Hinnant                   "Attempted to add/subtract iterator outside of valid range");
1353cec9af9eSHoward Hinnant#endif
1354f554add5SHoward Hinnant        __i += __n;
1355f554add5SHoward Hinnant        return *this;
1356f554add5SHoward Hinnant    }
135761b302f9SEric Fiselier    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG __wrap_iter  operator- (difference_type __n) const _NOEXCEPT
1358f554add5SHoward Hinnant        {return *this + (-__n);}
135961b302f9SEric Fiselier    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG __wrap_iter& operator-=(difference_type __n) _NOEXCEPT
1360f554add5SHoward Hinnant        {*this += -__n; return *this;}
136161b302f9SEric Fiselier    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG reference    operator[](difference_type __n) const _NOEXCEPT
1362f554add5SHoward Hinnant    {
136331e82037SLouis Dionne#if _LIBCPP_DEBUG_LEVEL == 2
1364f554add5SHoward Hinnant        _LIBCPP_ASSERT(__get_const_db()->__subscriptable(this, __n),
1365f554add5SHoward Hinnant                   "Attempted to subscript iterator outside of valid range");
1366cec9af9eSHoward Hinnant#endif
1367f554add5SHoward Hinnant        return __i[__n];
1368f554add5SHoward Hinnant    }
13693e519524SHoward Hinnant
137061b302f9SEric Fiselier    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG iterator_type base() const _NOEXCEPT {return __i;}
13713e519524SHoward Hinnant
13723e519524SHoward Hinnantprivate:
137331e82037SLouis Dionne#if _LIBCPP_DEBUG_LEVEL == 2
13749cad5025SMarshall Clow    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG __wrap_iter(const void* __p, iterator_type __x) : __i(__x)
1375f554add5SHoward Hinnant    {
1376f554add5SHoward Hinnant        __get_db()->__insert_ic(this, __p);
1377f554add5SHoward Hinnant    }
1378fc88dbd2SHoward Hinnant#else
137961b302f9SEric Fiselier    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG __wrap_iter(iterator_type __x) _NOEXCEPT : __i(__x) {}
1380f554add5SHoward Hinnant#endif
13813e519524SHoward Hinnant
13823e519524SHoward Hinnant    template <class _Up> friend class __wrap_iter;
13833e519524SHoward Hinnant    template <class _CharT, class _Traits, class _Alloc> friend class basic_string;
1384e2f2d1edSEric Fiselier    template <class _Tp, class _Alloc> friend class _LIBCPP_TEMPLATE_VIS vector;
13857ad06a93SMarshall Clow    template <class _Tp, size_t> friend class _LIBCPP_TEMPLATE_VIS span;
13863e519524SHoward Hinnant
13873e519524SHoward Hinnant    template <class _Iter1, class _Iter2>
13889cad5025SMarshall Clow    _LIBCPP_CONSTEXPR_IF_NODEBUG friend
13893e519524SHoward Hinnant    bool
139061b302f9SEric Fiselier    operator==(const __wrap_iter<_Iter1>&, const __wrap_iter<_Iter2>&) _NOEXCEPT;
13913e519524SHoward Hinnant
13923e519524SHoward Hinnant    template <class _Iter1, class _Iter2>
13939cad5025SMarshall Clow    _LIBCPP_CONSTEXPR_IF_NODEBUG friend
13943e519524SHoward Hinnant    bool
139561b302f9SEric Fiselier    operator<(const __wrap_iter<_Iter1>&, const __wrap_iter<_Iter2>&) _NOEXCEPT;
13963e519524SHoward Hinnant
13973e519524SHoward Hinnant    template <class _Iter1, class _Iter2>
13989cad5025SMarshall Clow    _LIBCPP_CONSTEXPR_IF_NODEBUG friend
13993e519524SHoward Hinnant    bool
140061b302f9SEric Fiselier    operator!=(const __wrap_iter<_Iter1>&, const __wrap_iter<_Iter2>&) _NOEXCEPT;
14013e519524SHoward Hinnant
14023e519524SHoward Hinnant    template <class _Iter1, class _Iter2>
14039cad5025SMarshall Clow    _LIBCPP_CONSTEXPR_IF_NODEBUG friend
14043e519524SHoward Hinnant    bool
140561b302f9SEric Fiselier    operator>(const __wrap_iter<_Iter1>&, const __wrap_iter<_Iter2>&) _NOEXCEPT;
14063e519524SHoward Hinnant
14073e519524SHoward Hinnant    template <class _Iter1, class _Iter2>
14089cad5025SMarshall Clow    _LIBCPP_CONSTEXPR_IF_NODEBUG friend
14093e519524SHoward Hinnant    bool
141061b302f9SEric Fiselier    operator>=(const __wrap_iter<_Iter1>&, const __wrap_iter<_Iter2>&) _NOEXCEPT;
14113e519524SHoward Hinnant
14123e519524SHoward Hinnant    template <class _Iter1, class _Iter2>
14139cad5025SMarshall Clow    _LIBCPP_CONSTEXPR_IF_NODEBUG friend
14143e519524SHoward Hinnant    bool
141561b302f9SEric Fiselier    operator<=(const __wrap_iter<_Iter1>&, const __wrap_iter<_Iter2>&) _NOEXCEPT;
14163e519524SHoward Hinnant
14172ee83725SMarshall Clow#ifndef _LIBCPP_CXX03_LANG
1418947ce6b5SMarshall Clow    template <class _Iter1, class _Iter2>
14199cad5025SMarshall Clow    _LIBCPP_CONSTEXPR_IF_NODEBUG friend
1420947ce6b5SMarshall Clow    auto
142161b302f9SEric Fiselier    operator-(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter2>& __y) _NOEXCEPT
1422947ce6b5SMarshall Clow    -> decltype(__x.base() - __y.base());
1423947ce6b5SMarshall Clow#else
14243e519524SHoward Hinnant    template <class _Iter1, class _Iter2>
14259cad5025SMarshall Clow    _LIBCPP_CONSTEXPR_IF_NODEBUG friend
14263e519524SHoward Hinnant    typename __wrap_iter<_Iter1>::difference_type
142761b302f9SEric Fiselier    operator-(const __wrap_iter<_Iter1>&, const __wrap_iter<_Iter2>&) _NOEXCEPT;
1428947ce6b5SMarshall Clow#endif
14293e519524SHoward Hinnant
14303e519524SHoward Hinnant    template <class _Iter1>
14319cad5025SMarshall Clow    _LIBCPP_CONSTEXPR_IF_NODEBUG friend
14323e519524SHoward Hinnant    __wrap_iter<_Iter1>
143361b302f9SEric Fiselier    operator+(typename __wrap_iter<_Iter1>::difference_type, __wrap_iter<_Iter1>) _NOEXCEPT;
14343e519524SHoward Hinnant
143513c90a57SLouis Dionne    template <class _Ip, class _Op> friend _LIBCPP_CONSTEXPR_AFTER_CXX17 _Op copy(_Ip, _Ip, _Op);
143613c90a57SLouis Dionne    template <class _B1, class _B2> friend _LIBCPP_CONSTEXPR_AFTER_CXX17 _B2 copy_backward(_B1, _B1, _B2);
14373ed89b51Szoecarver    template <class _Ip, class _Op> friend _LIBCPP_CONSTEXPR_AFTER_CXX17 _Op move(_Ip, _Ip, _Op);
14383ed89b51Szoecarver    template <class _B1, class _B2> friend _LIBCPP_CONSTEXPR_AFTER_CXX17 _B2 move_backward(_B1, _B1, _B2);
14393e519524SHoward Hinnant};
14403e519524SHoward Hinnant
1441d41c6d51SArthur O'Dwyer#if _LIBCPP_STD_VER <= 17
1442d41c6d51SArthur O'Dwyertemplate <class _It>
1443d41c6d51SArthur O'Dwyerstruct __is_cpp17_contiguous_iterator<__wrap_iter<_It> > : __is_cpp17_contiguous_iterator<_It> {};
1444d41c6d51SArthur O'Dwyer#endif
1445d41c6d51SArthur O'Dwyer
1446d41c6d51SArthur O'Dwyertemplate <class _Iter>
1447d41c6d51SArthur O'Dwyer_LIBCPP_CONSTEXPR
1448d41c6d51SArthur O'Dwyer_EnableIf<__is_cpp17_contiguous_iterator<_Iter>::value, decltype(_VSTD::__to_address(declval<_Iter>()))>
1449d41c6d51SArthur O'Dwyer__to_address(__wrap_iter<_Iter> __w) _NOEXCEPT {
1450d41c6d51SArthur O'Dwyer    return _VSTD::__to_address(__w.base());
1451d41c6d51SArthur O'Dwyer}
1452d41c6d51SArthur O'Dwyer
14533e519524SHoward Hinnanttemplate <class _Iter1, class _Iter2>
14549cad5025SMarshall Clowinline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG
14553e519524SHoward Hinnantbool
145661b302f9SEric Fiselieroperator==(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter2>& __y) _NOEXCEPT
14573e519524SHoward Hinnant{
14583e519524SHoward Hinnant    return __x.base() == __y.base();
14593e519524SHoward Hinnant}
14603e519524SHoward Hinnant
14613e519524SHoward Hinnanttemplate <class _Iter1, class _Iter2>
14629cad5025SMarshall Clowinline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG
14633e519524SHoward Hinnantbool
146461b302f9SEric Fiselieroperator<(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter2>& __y) _NOEXCEPT
14653e519524SHoward Hinnant{
146631e82037SLouis Dionne#if _LIBCPP_DEBUG_LEVEL == 2
146742a3046eSHoward Hinnant    _LIBCPP_ASSERT(__get_const_db()->__less_than_comparable(&__x, &__y),
1468f554add5SHoward Hinnant                   "Attempted to compare incomparable iterators");
1469cec9af9eSHoward Hinnant#endif
14703e519524SHoward Hinnant    return __x.base() < __y.base();
14713e519524SHoward Hinnant}
14723e519524SHoward Hinnant
14733e519524SHoward Hinnanttemplate <class _Iter1, class _Iter2>
14749cad5025SMarshall Clowinline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG
14753e519524SHoward Hinnantbool
147661b302f9SEric Fiselieroperator!=(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter2>& __y) _NOEXCEPT
14773e519524SHoward Hinnant{
1478f554add5SHoward Hinnant    return !(__x == __y);
14793e519524SHoward Hinnant}
14803e519524SHoward Hinnant
14813e519524SHoward Hinnanttemplate <class _Iter1, class _Iter2>
14829cad5025SMarshall Clowinline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG
14833e519524SHoward Hinnantbool
148461b302f9SEric Fiselieroperator>(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter2>& __y) _NOEXCEPT
14853e519524SHoward Hinnant{
1486f554add5SHoward Hinnant    return __y < __x;
14873e519524SHoward Hinnant}
14883e519524SHoward Hinnant
14893e519524SHoward Hinnanttemplate <class _Iter1, class _Iter2>
14909cad5025SMarshall Clowinline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG
14913e519524SHoward Hinnantbool
149261b302f9SEric Fiselieroperator>=(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter2>& __y) _NOEXCEPT
14933e519524SHoward Hinnant{
1494f554add5SHoward Hinnant    return !(__x < __y);
14953e519524SHoward Hinnant}
14963e519524SHoward Hinnant
14973e519524SHoward Hinnanttemplate <class _Iter1, class _Iter2>
14989cad5025SMarshall Clowinline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG
14993e519524SHoward Hinnantbool
150061b302f9SEric Fiselieroperator<=(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter2>& __y) _NOEXCEPT
15013e519524SHoward Hinnant{
1502f554add5SHoward Hinnant    return !(__y < __x);
15033e519524SHoward Hinnant}
15043e519524SHoward Hinnant
15056e551ae1SHoward Hinnanttemplate <class _Iter1>
15069cad5025SMarshall Clowinline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG
15076e551ae1SHoward Hinnantbool
150861b302f9SEric Fiselieroperator!=(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter1>& __y) _NOEXCEPT
15096e551ae1SHoward Hinnant{
15106e551ae1SHoward Hinnant    return !(__x == __y);
15116e551ae1SHoward Hinnant}
15126e551ae1SHoward Hinnant
15136e551ae1SHoward Hinnanttemplate <class _Iter1>
15149cad5025SMarshall Clowinline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG
15156e551ae1SHoward Hinnantbool
151661b302f9SEric Fiselieroperator>(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter1>& __y) _NOEXCEPT
15176e551ae1SHoward Hinnant{
15186e551ae1SHoward Hinnant    return __y < __x;
15196e551ae1SHoward Hinnant}
15206e551ae1SHoward Hinnant
15216e551ae1SHoward Hinnanttemplate <class _Iter1>
15229cad5025SMarshall Clowinline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG
15236e551ae1SHoward Hinnantbool
152461b302f9SEric Fiselieroperator>=(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter1>& __y) _NOEXCEPT
15256e551ae1SHoward Hinnant{
15266e551ae1SHoward Hinnant    return !(__x < __y);
15276e551ae1SHoward Hinnant}
15286e551ae1SHoward Hinnant
15296e551ae1SHoward Hinnanttemplate <class _Iter1>
15309cad5025SMarshall Clowinline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG
15316e551ae1SHoward Hinnantbool
153261b302f9SEric Fiselieroperator<=(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter1>& __y) _NOEXCEPT
15336e551ae1SHoward Hinnant{
15346e551ae1SHoward Hinnant    return !(__y < __x);
15356e551ae1SHoward Hinnant}
15366e551ae1SHoward Hinnant
15372ee83725SMarshall Clow#ifndef _LIBCPP_CXX03_LANG
1538947ce6b5SMarshall Clowtemplate <class _Iter1, class _Iter2>
15399cad5025SMarshall Clowinline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG
1540947ce6b5SMarshall Clowauto
154161b302f9SEric Fiselieroperator-(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter2>& __y) _NOEXCEPT
1542947ce6b5SMarshall Clow-> decltype(__x.base() - __y.base())
1543947ce6b5SMarshall Clow{
154431e82037SLouis Dionne#if _LIBCPP_DEBUG_LEVEL == 2
1545947ce6b5SMarshall Clow    _LIBCPP_ASSERT(__get_const_db()->__less_than_comparable(&__x, &__y),
1546947ce6b5SMarshall Clow                   "Attempted to subtract incompatible iterators");
1547947ce6b5SMarshall Clow#endif
1548947ce6b5SMarshall Clow    return __x.base() - __y.base();
1549947ce6b5SMarshall Clow}
1550947ce6b5SMarshall Clow#else
15513e519524SHoward Hinnanttemplate <class _Iter1, class _Iter2>
15529cad5025SMarshall Clowinline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG
15533e519524SHoward Hinnanttypename __wrap_iter<_Iter1>::difference_type
155461b302f9SEric Fiselieroperator-(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter2>& __y) _NOEXCEPT
15553e519524SHoward Hinnant{
155631e82037SLouis Dionne#if _LIBCPP_DEBUG_LEVEL == 2
155742a3046eSHoward Hinnant    _LIBCPP_ASSERT(__get_const_db()->__less_than_comparable(&__x, &__y),
1558f554add5SHoward Hinnant                   "Attempted to subtract incompatible iterators");
1559cec9af9eSHoward Hinnant#endif
15603e519524SHoward Hinnant    return __x.base() - __y.base();
15613e519524SHoward Hinnant}
1562947ce6b5SMarshall Clow#endif
15633e519524SHoward Hinnant
15643e519524SHoward Hinnanttemplate <class _Iter>
15659cad5025SMarshall Clowinline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG
15663e519524SHoward Hinnant__wrap_iter<_Iter>
15673e519524SHoward Hinnantoperator+(typename __wrap_iter<_Iter>::difference_type __n,
156861b302f9SEric Fiselier          __wrap_iter<_Iter> __x) _NOEXCEPT
15693e519524SHoward Hinnant{
1570f554add5SHoward Hinnant    __x += __n;
1571f554add5SHoward Hinnant    return __x;
15723e519524SHoward Hinnant}
15733e519524SHoward Hinnant
157476b4afc0SMarshall Clowtemplate <class _Iter>
157576b4afc0SMarshall Clowstruct __libcpp_is_trivial_iterator
157676b4afc0SMarshall Clow    : public _LIBCPP_BOOL_CONSTANT(is_pointer<_Iter>::value) {};
157776b4afc0SMarshall Clow
157876b4afc0SMarshall Clowtemplate <class _Iter>
157976b4afc0SMarshall Clowstruct __libcpp_is_trivial_iterator<move_iterator<_Iter> >
158076b4afc0SMarshall Clow    : public _LIBCPP_BOOL_CONSTANT(__libcpp_is_trivial_iterator<_Iter>::value) {};
158176b4afc0SMarshall Clow
158276b4afc0SMarshall Clowtemplate <class _Iter>
158376b4afc0SMarshall Clowstruct __libcpp_is_trivial_iterator<reverse_iterator<_Iter> >
158476b4afc0SMarshall Clow    : public _LIBCPP_BOOL_CONSTANT(__libcpp_is_trivial_iterator<_Iter>::value) {};
158576b4afc0SMarshall Clow
158676b4afc0SMarshall Clowtemplate <class _Iter>
158776b4afc0SMarshall Clowstruct __libcpp_is_trivial_iterator<__wrap_iter<_Iter> >
158876b4afc0SMarshall Clow    : public _LIBCPP_BOOL_CONSTANT(__libcpp_is_trivial_iterator<_Iter>::value) {};
158976b4afc0SMarshall Clow
159076b4afc0SMarshall Clow
15913772a46aSMarshall Clowtemplate <class _Tp, size_t _Np>
15922ffa1705SMarshall Clow_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
15933772a46aSMarshall Clow_Tp*
15943772a46aSMarshall Clowbegin(_Tp (&__array)[_Np])
15953772a46aSMarshall Clow{
15963772a46aSMarshall Clow    return __array;
15973772a46aSMarshall Clow}
15983772a46aSMarshall Clow
15993772a46aSMarshall Clowtemplate <class _Tp, size_t _Np>
16002ffa1705SMarshall Clow_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
16013772a46aSMarshall Clow_Tp*
16023772a46aSMarshall Clowend(_Tp (&__array)[_Np])
16033772a46aSMarshall Clow{
16043772a46aSMarshall Clow    return __array + _Np;
16053772a46aSMarshall Clow}
16063772a46aSMarshall Clow
160754613ab4SEric Fiselier#if !defined(_LIBCPP_CXX03_LANG)
1608c66a611bSMarshall Clow
1609c003db1fSHoward Hinnanttemplate <class _Cp>
16102ffa1705SMarshall Clow_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
16113e519524SHoward Hinnantauto
1612c003db1fSHoward Hinnantbegin(_Cp& __c) -> decltype(__c.begin())
16133e519524SHoward Hinnant{
16143e519524SHoward Hinnant    return __c.begin();
16153e519524SHoward Hinnant}
16163e519524SHoward Hinnant
1617c003db1fSHoward Hinnanttemplate <class _Cp>
16182ffa1705SMarshall Clow_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
16193e519524SHoward Hinnantauto
1620c003db1fSHoward Hinnantbegin(const _Cp& __c) -> decltype(__c.begin())
16213e519524SHoward Hinnant{
16223e519524SHoward Hinnant    return __c.begin();
16233e519524SHoward Hinnant}
16243e519524SHoward Hinnant
1625c003db1fSHoward Hinnanttemplate <class _Cp>
16262ffa1705SMarshall Clow_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
16273e519524SHoward Hinnantauto
1628c003db1fSHoward Hinnantend(_Cp& __c) -> decltype(__c.end())
16293e519524SHoward Hinnant{
16303e519524SHoward Hinnant    return __c.end();
16313e519524SHoward Hinnant}
16323e519524SHoward Hinnant
1633c003db1fSHoward Hinnanttemplate <class _Cp>
16342ffa1705SMarshall Clow_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
16353e519524SHoward Hinnantauto
1636c003db1fSHoward Hinnantend(const _Cp& __c) -> decltype(__c.end())
16373e519524SHoward Hinnant{
16383e519524SHoward Hinnant    return __c.end();
16393e519524SHoward Hinnant}
16403e519524SHoward Hinnant
16411e548c72SMarshall Clow#if _LIBCPP_STD_VER > 11
16421e548c72SMarshall Clow
16433772a46aSMarshall Clowtemplate <class _Tp, size_t _Np>
16442ffa1705SMarshall Clow_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
16453772a46aSMarshall Clowreverse_iterator<_Tp*> rbegin(_Tp (&__array)[_Np])
16463772a46aSMarshall Clow{
16473772a46aSMarshall Clow    return reverse_iterator<_Tp*>(__array + _Np);
16483772a46aSMarshall Clow}
16493772a46aSMarshall Clow
16503772a46aSMarshall Clowtemplate <class _Tp, size_t _Np>
16512ffa1705SMarshall Clow_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
16523772a46aSMarshall Clowreverse_iterator<_Tp*> rend(_Tp (&__array)[_Np])
16533772a46aSMarshall Clow{
16543772a46aSMarshall Clow    return reverse_iterator<_Tp*>(__array);
16553772a46aSMarshall Clow}
16563772a46aSMarshall Clow
16573772a46aSMarshall Clowtemplate <class _Ep>
16582ffa1705SMarshall Clow_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
16593772a46aSMarshall Clowreverse_iterator<const _Ep*> rbegin(initializer_list<_Ep> __il)
16603772a46aSMarshall Clow{
16613772a46aSMarshall Clow    return reverse_iterator<const _Ep*>(__il.end());
16623772a46aSMarshall Clow}
16633772a46aSMarshall Clow
16643772a46aSMarshall Clowtemplate <class _Ep>
16652ffa1705SMarshall Clow_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
16663772a46aSMarshall Clowreverse_iterator<const _Ep*> rend(initializer_list<_Ep> __il)
16673772a46aSMarshall Clow{
16683772a46aSMarshall Clow    return reverse_iterator<const _Ep*>(__il.begin());
16693772a46aSMarshall Clow}
16703772a46aSMarshall Clow
16711e548c72SMarshall Clowtemplate <class _Cp>
16722ffa1705SMarshall Clow_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
16737725546aSMarshall Clowauto cbegin(const _Cp& __c) -> decltype(_VSTD::begin(__c))
16741e548c72SMarshall Clow{
16757725546aSMarshall Clow    return _VSTD::begin(__c);
16761e548c72SMarshall Clow}
16771e548c72SMarshall Clow
16781e548c72SMarshall Clowtemplate <class _Cp>
16792ffa1705SMarshall Clow_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
16807725546aSMarshall Clowauto cend(const _Cp& __c) -> decltype(_VSTD::end(__c))
16811e548c72SMarshall Clow{
16827725546aSMarshall Clow    return _VSTD::end(__c);
16831e548c72SMarshall Clow}
16841e548c72SMarshall Clow
16851e548c72SMarshall Clowtemplate <class _Cp>
16862ffa1705SMarshall Clow_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
16871e548c72SMarshall Clowauto rbegin(_Cp& __c) -> decltype(__c.rbegin())
16881e548c72SMarshall Clow{
16891e548c72SMarshall Clow    return __c.rbegin();
16901e548c72SMarshall Clow}
16911e548c72SMarshall Clow
16921e548c72SMarshall Clowtemplate <class _Cp>
16932ffa1705SMarshall Clow_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
16941e548c72SMarshall Clowauto rbegin(const _Cp& __c) -> decltype(__c.rbegin())
16951e548c72SMarshall Clow{
16961e548c72SMarshall Clow    return __c.rbegin();
16971e548c72SMarshall Clow}
16981e548c72SMarshall Clow
16991e548c72SMarshall Clowtemplate <class _Cp>
17002ffa1705SMarshall Clow_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
17011e548c72SMarshall Clowauto rend(_Cp& __c) -> decltype(__c.rend())
17021e548c72SMarshall Clow{
17031e548c72SMarshall Clow    return __c.rend();
17041e548c72SMarshall Clow}
17051e548c72SMarshall Clow
17061e548c72SMarshall Clowtemplate <class _Cp>
17072ffa1705SMarshall Clow_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
17081e548c72SMarshall Clowauto rend(const _Cp& __c) -> decltype(__c.rend())
17091e548c72SMarshall Clow{
17101e548c72SMarshall Clow    return __c.rend();
17111e548c72SMarshall Clow}
17121e548c72SMarshall Clow
17131e548c72SMarshall Clowtemplate <class _Cp>
17142ffa1705SMarshall Clow_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
17157725546aSMarshall Clowauto crbegin(const _Cp& __c) -> decltype(_VSTD::rbegin(__c))
17161e548c72SMarshall Clow{
17177725546aSMarshall Clow    return _VSTD::rbegin(__c);
17181e548c72SMarshall Clow}
17191e548c72SMarshall Clow
17201e548c72SMarshall Clowtemplate <class _Cp>
17212ffa1705SMarshall Clow_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
17227725546aSMarshall Clowauto crend(const _Cp& __c) -> decltype(_VSTD::rend(__c))
17231e548c72SMarshall Clow{
17247725546aSMarshall Clow    return _VSTD::rend(__c);
17251e548c72SMarshall Clow}
17261e548c72SMarshall Clow
17271e548c72SMarshall Clow#endif
17281e548c72SMarshall Clow
17291e548c72SMarshall Clow
173054613ab4SEric Fiselier#else  // defined(_LIBCPP_CXX03_LANG)
17313e519524SHoward Hinnant
1732c003db1fSHoward Hinnanttemplate <class _Cp>
17332ffa1705SMarshall Clow_LIBCPP_INLINE_VISIBILITY
1734c003db1fSHoward Hinnanttypename _Cp::iterator
1735c003db1fSHoward Hinnantbegin(_Cp& __c)
17363e519524SHoward Hinnant{
17373e519524SHoward Hinnant    return __c.begin();
17383e519524SHoward Hinnant}
17393e519524SHoward Hinnant
1740c003db1fSHoward Hinnanttemplate <class _Cp>
17412ffa1705SMarshall Clow_LIBCPP_INLINE_VISIBILITY
1742c003db1fSHoward Hinnanttypename _Cp::const_iterator
1743c003db1fSHoward Hinnantbegin(const _Cp& __c)
17443e519524SHoward Hinnant{
17453e519524SHoward Hinnant    return __c.begin();
17463e519524SHoward Hinnant}
17473e519524SHoward Hinnant
1748c003db1fSHoward Hinnanttemplate <class _Cp>
17492ffa1705SMarshall Clow_LIBCPP_INLINE_VISIBILITY
1750c003db1fSHoward Hinnanttypename _Cp::iterator
1751c003db1fSHoward Hinnantend(_Cp& __c)
17523e519524SHoward Hinnant{
17533e519524SHoward Hinnant    return __c.end();
17543e519524SHoward Hinnant}
17553e519524SHoward Hinnant
1756c003db1fSHoward Hinnanttemplate <class _Cp>
17572ffa1705SMarshall Clow_LIBCPP_INLINE_VISIBILITY
1758c003db1fSHoward Hinnanttypename _Cp::const_iterator
1759c003db1fSHoward Hinnantend(const _Cp& __c)
17603e519524SHoward Hinnant{
17613e519524SHoward Hinnant    return __c.end();
17623e519524SHoward Hinnant}
17633e519524SHoward Hinnant
176454613ab4SEric Fiselier#endif // !defined(_LIBCPP_CXX03_LANG)
17653e519524SHoward Hinnant
1766ad755104SMarshall Clow#if _LIBCPP_STD_VER > 14
1767d1dcda19SMarshall Clow
1768d1dcda19SMarshall Clow// #if _LIBCPP_STD_VER > 11
1769d1dcda19SMarshall Clow// template <>
1770d1dcda19SMarshall Clow// struct _LIBCPP_TEMPLATE_VIS plus<void>
1771d1dcda19SMarshall Clow// {
1772d1dcda19SMarshall Clow//     template <class _T1, class _T2>
1773d1dcda19SMarshall Clow//     _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
1774d1dcda19SMarshall Clow//     auto operator()(_T1&& __t, _T2&& __u) const
1775d1dcda19SMarshall Clow//     _NOEXCEPT_(noexcept(_VSTD::forward<_T1>(__t) + _VSTD::forward<_T2>(__u)))
1776d1dcda19SMarshall Clow//     -> decltype        (_VSTD::forward<_T1>(__t) + _VSTD::forward<_T2>(__u))
1777d1dcda19SMarshall Clow//         { return        _VSTD::forward<_T1>(__t) + _VSTD::forward<_T2>(__u); }
1778d1dcda19SMarshall Clow//     typedef void is_transparent;
1779d1dcda19SMarshall Clow// };
1780d1dcda19SMarshall Clow// #endif
1781d1dcda19SMarshall Clow
178288d21343SMarshall Clowtemplate <class _Cont>
17832ffa1705SMarshall Clow_LIBCPP_INLINE_VISIBILITY
1784d1dcda19SMarshall Clowconstexpr auto size(const _Cont& __c)
1785d1dcda19SMarshall Clow_NOEXCEPT_(noexcept(__c.size()))
1786d1dcda19SMarshall Clow-> decltype        (__c.size())
1787d1dcda19SMarshall Clow{ return            __c.size(); }
1788ad755104SMarshall Clow
178988d21343SMarshall Clowtemplate <class _Tp, size_t _Sz>
17902ffa1705SMarshall Clow_LIBCPP_INLINE_VISIBILITY
1791fd838227SEric Fiselierconstexpr size_t size(const _Tp (&)[_Sz]) noexcept { return _Sz; }
1792ad755104SMarshall Clow
17937d3986eaSMarshall Clow#if _LIBCPP_STD_VER > 17
17947d3986eaSMarshall Clowtemplate <class _Cont>
17952ffa1705SMarshall Clow_LIBCPP_INLINE_VISIBILITY
17967d3986eaSMarshall Clowconstexpr auto ssize(const _Cont& __c)
17977d3986eaSMarshall Clow_NOEXCEPT_(noexcept(static_cast<common_type_t<ptrdiff_t, make_signed_t<decltype(__c.size())>>>(__c.size())))
17987d3986eaSMarshall Clow->                              common_type_t<ptrdiff_t, make_signed_t<decltype(__c.size())>>
17997d3986eaSMarshall Clow{ return            static_cast<common_type_t<ptrdiff_t, make_signed_t<decltype(__c.size())>>>(__c.size()); }
18007d3986eaSMarshall Clow
18017d3986eaSMarshall Clowtemplate <class _Tp, ptrdiff_t _Sz>
18022ffa1705SMarshall Clow_LIBCPP_INLINE_VISIBILITY
18037d3986eaSMarshall Clowconstexpr ptrdiff_t ssize(const _Tp (&)[_Sz]) noexcept { return _Sz; }
18047d3986eaSMarshall Clow#endif
18057d3986eaSMarshall Clow
180688d21343SMarshall Clowtemplate <class _Cont>
18072ffa1705SMarshall Clow_LIBCPP_NODISCARD_AFTER_CXX17 _LIBCPP_INLINE_VISIBILITY
1808d1dcda19SMarshall Clowconstexpr auto empty(const _Cont& __c)
1809d1dcda19SMarshall Clow_NOEXCEPT_(noexcept(__c.empty()))
1810d1dcda19SMarshall Clow-> decltype        (__c.empty())
1811d1dcda19SMarshall Clow{ return            __c.empty(); }
1812ad755104SMarshall Clow
181388d21343SMarshall Clowtemplate <class _Tp, size_t _Sz>
18142ffa1705SMarshall Clow_LIBCPP_NODISCARD_AFTER_CXX17 _LIBCPP_INLINE_VISIBILITY
1815fd838227SEric Fiselierconstexpr bool empty(const _Tp (&)[_Sz]) noexcept { return false; }
1816ad755104SMarshall Clow
1817ad755104SMarshall Clowtemplate <class _Ep>
18182ffa1705SMarshall Clow_LIBCPP_NODISCARD_AFTER_CXX17 _LIBCPP_INLINE_VISIBILITY
1819ad755104SMarshall Clowconstexpr bool empty(initializer_list<_Ep> __il) noexcept { return __il.size() == 0; }
1820ad755104SMarshall Clow
182188d21343SMarshall Clowtemplate <class _Cont> constexpr
18222ffa1705SMarshall Clow_LIBCPP_INLINE_VISIBILITY
1823d1dcda19SMarshall Clowauto data(_Cont& __c)
1824d1dcda19SMarshall Clow_NOEXCEPT_(noexcept(__c.data()))
1825d1dcda19SMarshall Clow-> decltype        (__c.data())
1826d1dcda19SMarshall Clow{ return            __c.data(); }
1827ad755104SMarshall Clow
182888d21343SMarshall Clowtemplate <class _Cont> constexpr
18292ffa1705SMarshall Clow_LIBCPP_INLINE_VISIBILITY
1830d1dcda19SMarshall Clowauto data(const _Cont& __c)
1831d1dcda19SMarshall Clow_NOEXCEPT_(noexcept(__c.data()))
1832d1dcda19SMarshall Clow-> decltype        (__c.data())
1833d1dcda19SMarshall Clow{ return            __c.data(); }
1834ad755104SMarshall Clow
183588d21343SMarshall Clowtemplate <class _Tp, size_t _Sz>
18362ffa1705SMarshall Clow_LIBCPP_INLINE_VISIBILITY
183788d21343SMarshall Clowconstexpr _Tp* data(_Tp (&__array)[_Sz]) noexcept { return __array; }
1838ad755104SMarshall Clow
1839ad755104SMarshall Clowtemplate <class _Ep>
18402ffa1705SMarshall Clow_LIBCPP_INLINE_VISIBILITY
1841ad755104SMarshall Clowconstexpr const _Ep* data(initializer_list<_Ep> __il) noexcept { return __il.begin(); }
1842ad755104SMarshall Clow#endif
1843ad755104SMarshall Clow
18442ac6babcSArthur O'Dwyertemplate <class _Container, class _Predicate>
18452ac6babcSArthur O'Dwyertypename _Container::size_type
18462ac6babcSArthur O'Dwyer__libcpp_erase_if_container(_Container& __c, _Predicate& __pred) {
18472ac6babcSArthur O'Dwyer  typename _Container::size_type __old_size = __c.size();
18482ac6babcSArthur O'Dwyer
18492ac6babcSArthur O'Dwyer  const typename _Container::iterator __last = __c.end();
18502ac6babcSArthur O'Dwyer  for (typename _Container::iterator __iter = __c.begin(); __iter != __last;) {
18512ac6babcSArthur O'Dwyer    if (__pred(*__iter))
18522ac6babcSArthur O'Dwyer      __iter = __c.erase(__iter);
18532ac6babcSArthur O'Dwyer    else
18542ac6babcSArthur O'Dwyer      ++__iter;
18552ac6babcSArthur O'Dwyer  }
18562ac6babcSArthur O'Dwyer
18572ac6babcSArthur O'Dwyer  return __old_size - __c.size();
18582ac6babcSArthur O'Dwyer}
1859ad755104SMarshall Clow
18603e519524SHoward Hinnant_LIBCPP_END_NAMESPACE_STD
18613e519524SHoward Hinnant
18623e519524SHoward Hinnant#endif // _LIBCPP_ITERATOR
1863