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
4657ebf3d0SLouis Dionne// [iterator.concepts], iterator concepts
4757ebf3d0SLouis Dionne// [iterator.concept.readable], concept indirectly_readable
4857ebf3d0SLouis Dionnetemplate<class In>
4957ebf3d0SLouis Dionne  concept indirectly_readable = see below;                // since C++20
5057ebf3d0SLouis Dionne
5157ebf3d0SLouis Dionne// [iterator.concept.writable], concept indirectly_writable
5257ebf3d0SLouis Dionnetemplate<class Out, class T>
5357ebf3d0SLouis Dionne  concept indirectly_writable = see below;                // since C++20
5457ebf3d0SLouis Dionne
5518b03b00SMark de Wever// [iterator.concept.winc], concept weakly_incrementable
5622052860SChristopher Di Bellatemplate<class I>
5722052860SChristopher Di Bella  concept weakly_incrementable = see below;                // since C++20
5822052860SChristopher Di Bella
5922052860SChristopher Di Bella// [iterator.concept.inc], concept incrementable
6022052860SChristopher Di Bellatemplate<class I>
6122052860SChristopher Di Bella  concept incrementable = see below;                       // since C++20
6222052860SChristopher Di Bella
6318b03b00SMark de Wever// [iterator.concept.iterator], concept input_or_output_iterator
6438225d69SChristopher Di Bella  template<class I>
6538225d69SChristopher Di Bella    concept input_or_output_iterator = see below;          // since C++20
6638225d69SChristopher Di Bella
6718b03b00SMark de Wever// [iterator.concept.sentinel], concept sentinel_for
6838225d69SChristopher Di Bellatemplate<class S, class I>
6938225d69SChristopher Di Bella  concept sentinel_for = see below;                        // since C++20
7038225d69SChristopher Di Bella
71bdd68357Szoecarver// [iterator.concept.sizedsentinel], concept sized_sentinel_for
72bdd68357Szoecarvertemplate<class S, class I>
73bdd68357Szoecarver  inline constexpr bool disable_sized_sentinel_for = false;
74bdd68357Szoecarver
75bdd68357Szoecarvertemplate<class S, class I>
76bdd68357Szoecarver  concept sized_sentinel_for = see below;
77bdd68357Szoecarver
78c05d1eedSChristopher Di Bella// [iterator.concept.input], concept input_iterator
79c05d1eedSChristopher Di Bellatemplate<class I>
80c05d1eedSChristopher Di Bella  concept input_iterator = see below;                      // since C++20
81c05d1eedSChristopher Di Bella
82fa3e2626SChristopher Di Bella// [iterator.concept.forward], concept forward_iterator
83fa3e2626SChristopher Di Bellatemplate<class I>
84fa3e2626SChristopher Di Bella  concept forward_iterator = see below;                    // since C++20
85fa3e2626SChristopher Di Bella
869c5d86aaSChristopher Di Bella// [iterator.concept.bidir], concept bidirectional_iterator
879c5d86aaSChristopher Di Bellatemplate<class I>
889c5d86aaSChristopher Di Bella  concept bidirectional_iterator = see below;              // since C++20
899c5d86aaSChristopher Di Bella
90*6ffc41b0Szoecarver// [iterator.concept.random.access], concept random_access_iterator
91*6ffc41b0Szoecarvertemplate<class I>
92*6ffc41b0Szoecarver  concept random_access_iterator = see below;              // since C++20
93*6ffc41b0Szoecarver
943e519524SHoward Hinnanttemplate<class Category, class T, class Distance = ptrdiff_t,
953e519524SHoward Hinnant         class Pointer = T*, class Reference = T&>
963e519524SHoward Hinnantstruct iterator
973e519524SHoward Hinnant{
983e519524SHoward Hinnant    typedef T         value_type;
993e519524SHoward Hinnant    typedef Distance  difference_type;
1003e519524SHoward Hinnant    typedef Pointer   pointer;
1013e519524SHoward Hinnant    typedef Reference reference;
1023e519524SHoward Hinnant    typedef Category  iterator_category;
1033e519524SHoward Hinnant};
1043e519524SHoward Hinnant
1053e519524SHoward Hinnantstruct input_iterator_tag  {};
1063e519524SHoward Hinnantstruct output_iterator_tag {};
1073e519524SHoward Hinnantstruct forward_iterator_tag       : public input_iterator_tag         {};
1083e519524SHoward Hinnantstruct bidirectional_iterator_tag : public forward_iterator_tag       {};
1093e519524SHoward Hinnantstruct random_access_iterator_tag : public bidirectional_iterator_tag {};
1103e519524SHoward Hinnant
111f51ee632SMarshall Clow// 27.4.3, iterator operations
11212b01ab7SLouis Dionnetemplate <class InputIterator, class Distance>  // constexpr in C++17
11312b01ab7SLouis Dionne  constexpr void advance(InputIterator& i, Distance n);
1143e519524SHoward Hinnant
115f51ee632SMarshall Clowtemplate <class InputIterator>  // constexpr in C++17
116f51ee632SMarshall Clow  constexpr typename iterator_traits<InputIterator>::difference_type
1173e519524SHoward Hinnant    distance(InputIterator first, InputIterator last);
1183e519524SHoward Hinnant
119f51ee632SMarshall Clowtemplate <class InputIterator>  // constexpr in C++17
120f51ee632SMarshall Clow  constexpr InputIterator next(InputIterator x,
121f51ee632SMarshall Clowtypename iterator_traits<InputIterator>::difference_type n = 1);
122f51ee632SMarshall Clow
123f51ee632SMarshall Clowtemplate <class BidirectionalIterator>  // constexpr in C++17
124f51ee632SMarshall Clow  constexpr BidirectionalIterator prev(BidirectionalIterator x,
125f51ee632SMarshall Clow    typename iterator_traits<BidirectionalIterator>::difference_type n = 1);
126f51ee632SMarshall Clow
1273e519524SHoward Hinnanttemplate <class Iterator>
1283e519524SHoward Hinnantclass reverse_iterator
1293e519524SHoward Hinnant    : public iterator<typename iterator_traits<Iterator>::iterator_category,
1303e519524SHoward Hinnant                      typename iterator_traits<Iterator>::value_type,
1313e519524SHoward Hinnant                      typename iterator_traits<Iterator>::difference_type,
1323e519524SHoward Hinnant                      typename iterator_traits<Iterator>::pointer,
1333e519524SHoward Hinnant                      typename iterator_traits<Iterator>::reference>
1343e519524SHoward Hinnant{
1353e519524SHoward Hinnantprotected:
1363e519524SHoward Hinnant    Iterator current;
1373e519524SHoward Hinnantpublic:
1383e519524SHoward Hinnant    typedef Iterator                                            iterator_type;
1393e519524SHoward Hinnant    typedef typename iterator_traits<Iterator>::difference_type difference_type;
1403e519524SHoward Hinnant    typedef typename iterator_traits<Iterator>::reference       reference;
1413e519524SHoward Hinnant    typedef typename iterator_traits<Iterator>::pointer         pointer;
1423e519524SHoward Hinnant
1431b8f260eSMarshall Clow    constexpr reverse_iterator();
1441b8f260eSMarshall Clow    constexpr explicit reverse_iterator(Iterator x);
1451b8f260eSMarshall Clow    template <class U> constexpr reverse_iterator(const reverse_iterator<U>& u);
1461b8f260eSMarshall Clow    template <class U> constexpr reverse_iterator& operator=(const reverse_iterator<U>& u);
1471b8f260eSMarshall Clow    constexpr Iterator base() const;
1481b8f260eSMarshall Clow    constexpr reference operator*() const;
1491b8f260eSMarshall Clow    constexpr pointer   operator->() const;
1501b8f260eSMarshall Clow    constexpr reverse_iterator& operator++();
1511b8f260eSMarshall Clow    constexpr reverse_iterator  operator++(int);
1521b8f260eSMarshall Clow    constexpr reverse_iterator& operator--();
1531b8f260eSMarshall Clow    constexpr reverse_iterator  operator--(int);
1541b8f260eSMarshall Clow    constexpr reverse_iterator  operator+ (difference_type n) const;
1551b8f260eSMarshall Clow    constexpr reverse_iterator& operator+=(difference_type n);
1561b8f260eSMarshall Clow    constexpr reverse_iterator  operator- (difference_type n) const;
1571b8f260eSMarshall Clow    constexpr reverse_iterator& operator-=(difference_type n);
1581b8f260eSMarshall Clow    constexpr reference         operator[](difference_type n) const;
1593e519524SHoward Hinnant};
1603e519524SHoward Hinnant
1613e519524SHoward Hinnanttemplate <class Iterator1, class Iterator2>
1621b8f260eSMarshall Clowconstexpr bool                          // constexpr in C++17
1633e519524SHoward Hinnantoperator==(const reverse_iterator<Iterator1>& x, const reverse_iterator<Iterator2>& y);
1643e519524SHoward Hinnant
1653e519524SHoward Hinnanttemplate <class Iterator1, class Iterator2>
1661b8f260eSMarshall Clowconstexpr bool                          // constexpr in C++17
1673e519524SHoward Hinnantoperator<(const reverse_iterator<Iterator1>& x, const reverse_iterator<Iterator2>& y);
1683e519524SHoward Hinnant
1693e519524SHoward Hinnanttemplate <class Iterator1, class Iterator2>
1701b8f260eSMarshall Clowconstexpr bool                          // constexpr in C++17
1713e519524SHoward Hinnantoperator!=(const reverse_iterator<Iterator1>& x, const reverse_iterator<Iterator2>& y);
1723e519524SHoward Hinnant
1733e519524SHoward Hinnanttemplate <class Iterator1, class Iterator2>
1741b8f260eSMarshall Clowconstexpr bool                          // constexpr in C++17
1753e519524SHoward Hinnantoperator>(const reverse_iterator<Iterator1>& x, const reverse_iterator<Iterator2>& y);
1763e519524SHoward Hinnant
1773e519524SHoward Hinnanttemplate <class Iterator1, class Iterator2>
1781b8f260eSMarshall Clowconstexpr bool                          // constexpr in C++17
1793e519524SHoward Hinnantoperator>=(const reverse_iterator<Iterator1>& x, const reverse_iterator<Iterator2>& y);
1803e519524SHoward Hinnant
1813e519524SHoward Hinnanttemplate <class Iterator1, class Iterator2>
1821b8f260eSMarshall Clowconstexpr bool                          // constexpr in C++17
1833e519524SHoward Hinnantoperator<=(const reverse_iterator<Iterator1>& x, const reverse_iterator<Iterator2>& y);
1843e519524SHoward Hinnant
1853e519524SHoward Hinnanttemplate <class Iterator1, class Iterator2>
1861b8f260eSMarshall Clowconstexpr auto
187947ce6b5SMarshall Clowoperator-(const reverse_iterator<Iterator1>& x, const reverse_iterator<Iterator2>& y)
1881b8f260eSMarshall Clow-> decltype(__y.base() - __x.base());   // constexpr in C++17
1893e519524SHoward Hinnant
1903e519524SHoward Hinnanttemplate <class Iterator>
1911b8f260eSMarshall Clowconstexpr reverse_iterator<Iterator>
1921b8f260eSMarshall Clowoperator+(typename reverse_iterator<Iterator>::difference_type n,
1931b8f260eSMarshall Clow          const reverse_iterator<Iterator>& x);   // constexpr in C++17
1943e519524SHoward Hinnant
1951b8f260eSMarshall Clowtemplate <class Iterator>
1961b8f260eSMarshall Clowconstexpr reverse_iterator<Iterator> make_reverse_iterator(Iterator i); // C++14, constexpr in C++17
1976a640a18SMarshall Clow
1983e519524SHoward Hinnanttemplate <class Container>
1993e519524SHoward Hinnantclass back_insert_iterator
2003e519524SHoward Hinnant{
2013e519524SHoward Hinnantprotected:
2023e519524SHoward Hinnant    Container* container;
2033e519524SHoward Hinnantpublic:
2043e519524SHoward Hinnant    typedef Container                   container_type;
2053e519524SHoward Hinnant    typedef void                        value_type;
2063e519524SHoward Hinnant    typedef void                        difference_type;
2078892b4eeSEric Fiselier    typedef void                        reference;
2083e519524SHoward Hinnant    typedef void                        pointer;
2093e519524SHoward Hinnant
21006e2b737SArthur O'Dwyer    explicit back_insert_iterator(Container& x);  // constexpr in C++20
21106e2b737SArthur O'Dwyer    back_insert_iterator& operator=(const typename Container::value_type& value);  // constexpr in C++20
21206e2b737SArthur O'Dwyer    back_insert_iterator& operator*();  // constexpr in C++20
21306e2b737SArthur O'Dwyer    back_insert_iterator& operator++();  // constexpr in C++20
21406e2b737SArthur O'Dwyer    back_insert_iterator  operator++(int);  // constexpr in C++20
2153e519524SHoward Hinnant};
2163e519524SHoward Hinnant
21706e2b737SArthur O'Dwyertemplate <class Container> back_insert_iterator<Container> back_inserter(Container& x);  // constexpr in C++20
2183e519524SHoward Hinnant
2193e519524SHoward Hinnanttemplate <class Container>
2203e519524SHoward Hinnantclass front_insert_iterator
2213e519524SHoward Hinnant{
2223e519524SHoward Hinnantprotected:
2233e519524SHoward Hinnant    Container* container;
2243e519524SHoward Hinnantpublic:
2253e519524SHoward Hinnant    typedef Container                    container_type;
2263e519524SHoward Hinnant    typedef void                         value_type;
2273e519524SHoward Hinnant    typedef void                         difference_type;
2288892b4eeSEric Fiselier    typedef void                         reference;
2293e519524SHoward Hinnant    typedef void                         pointer;
2303e519524SHoward Hinnant
23106e2b737SArthur O'Dwyer    explicit front_insert_iterator(Container& x);  // constexpr in C++20
23206e2b737SArthur O'Dwyer    front_insert_iterator& operator=(const typename Container::value_type& value);  // constexpr in C++20
23306e2b737SArthur O'Dwyer    front_insert_iterator& operator*();  // constexpr in C++20
23406e2b737SArthur O'Dwyer    front_insert_iterator& operator++();  // constexpr in C++20
23506e2b737SArthur O'Dwyer    front_insert_iterator  operator++(int);  // constexpr in C++20
2363e519524SHoward Hinnant};
2373e519524SHoward Hinnant
23806e2b737SArthur O'Dwyertemplate <class Container> front_insert_iterator<Container> front_inserter(Container& x);  // constexpr in C++20
2393e519524SHoward Hinnant
2403e519524SHoward Hinnanttemplate <class Container>
2413e519524SHoward Hinnantclass insert_iterator
2423e519524SHoward Hinnant{
2433e519524SHoward Hinnantprotected:
2443e519524SHoward Hinnant    Container* container;
2453e519524SHoward Hinnant    typename Container::iterator iter;
2463e519524SHoward Hinnantpublic:
2473e519524SHoward Hinnant    typedef Container              container_type;
2483e519524SHoward Hinnant    typedef void                   value_type;
2493e519524SHoward Hinnant    typedef void                   difference_type;
2508892b4eeSEric Fiselier    typedef void                   reference;
2513e519524SHoward Hinnant    typedef void                   pointer;
2523e519524SHoward Hinnant
25306e2b737SArthur O'Dwyer    insert_iterator(Container& x, typename Container::iterator i);  // constexpr in C++20
25406e2b737SArthur O'Dwyer    insert_iterator& operator=(const typename Container::value_type& value);  // constexpr in C++20
25506e2b737SArthur O'Dwyer    insert_iterator& operator*();  // constexpr in C++20
25606e2b737SArthur O'Dwyer    insert_iterator& operator++();  // constexpr in C++20
25706e2b737SArthur O'Dwyer    insert_iterator& operator++(int);  // constexpr in C++20
2583e519524SHoward Hinnant};
2593e519524SHoward Hinnant
2603e519524SHoward Hinnanttemplate <class Container, class Iterator>
26106e2b737SArthur O'Dwyerinsert_iterator<Container> inserter(Container& x, Iterator i);  // constexpr in C++20
2623e519524SHoward Hinnant
263947ce6b5SMarshall Clowtemplate <class Iterator>
264947ce6b5SMarshall Clowclass move_iterator {
265947ce6b5SMarshall Clowpublic:
266947ce6b5SMarshall Clow    typedef Iterator                                              iterator_type;
267947ce6b5SMarshall Clow    typedef typename iterator_traits<Iterator>::difference_type   difference_type;
268947ce6b5SMarshall Clow    typedef Iterator                                              pointer;
269947ce6b5SMarshall Clow    typedef typename iterator_traits<Iterator>::value_type        value_type;
270947ce6b5SMarshall Clow    typedef typename iterator_traits<Iterator>::iterator_category iterator_category;
271947ce6b5SMarshall Clow    typedef value_type&&                                          reference;
272947ce6b5SMarshall Clow
273720ef472SMarshall Clow    constexpr move_iterator();  // all the constexprs are in C++17
274720ef472SMarshall Clow    constexpr explicit move_iterator(Iterator i);
275720ef472SMarshall Clow    template <class U>
276720ef472SMarshall Clow      constexpr move_iterator(const move_iterator<U>& u);
277720ef472SMarshall Clow    template <class U>
278720ef472SMarshall Clow      constexpr move_iterator& operator=(const move_iterator<U>& u);
279720ef472SMarshall Clow    constexpr iterator_type base() const;
280720ef472SMarshall Clow    constexpr reference operator*() const;
281720ef472SMarshall Clow    constexpr pointer operator->() const;
282720ef472SMarshall Clow    constexpr move_iterator& operator++();
283720ef472SMarshall Clow    constexpr move_iterator operator++(int);
284720ef472SMarshall Clow    constexpr move_iterator& operator--();
285720ef472SMarshall Clow    constexpr move_iterator operator--(int);
286720ef472SMarshall Clow    constexpr move_iterator operator+(difference_type n) const;
287720ef472SMarshall Clow    constexpr move_iterator& operator+=(difference_type n);
288720ef472SMarshall Clow    constexpr move_iterator operator-(difference_type n) const;
289720ef472SMarshall Clow    constexpr move_iterator& operator-=(difference_type n);
290720ef472SMarshall Clow    constexpr unspecified operator[](difference_type n) const;
291947ce6b5SMarshall Clowprivate:
292947ce6b5SMarshall Clow    Iterator current; // exposition only
293947ce6b5SMarshall Clow};
294947ce6b5SMarshall Clow
295947ce6b5SMarshall Clowtemplate <class Iterator1, class Iterator2>
296720ef472SMarshall Clowconstexpr bool   // constexpr in C++17
297947ce6b5SMarshall Clowoperator==(const move_iterator<Iterator1>& x, const move_iterator<Iterator2>& y);
298947ce6b5SMarshall Clow
299947ce6b5SMarshall Clowtemplate <class Iterator1, class Iterator2>
300720ef472SMarshall Clowconstexpr bool   // constexpr in C++17
301947ce6b5SMarshall Clowoperator!=(const move_iterator<Iterator1>& x, const move_iterator<Iterator2>& y);
302947ce6b5SMarshall Clow
303947ce6b5SMarshall Clowtemplate <class Iterator1, class Iterator2>
304720ef472SMarshall Clowconstexpr bool   // constexpr in C++17
305947ce6b5SMarshall Clowoperator<(const move_iterator<Iterator1>& x, const move_iterator<Iterator2>& y);
306947ce6b5SMarshall Clow
307947ce6b5SMarshall Clowtemplate <class Iterator1, class Iterator2>
308720ef472SMarshall Clowconstexpr bool   // constexpr in C++17
309947ce6b5SMarshall Clowoperator<=(const move_iterator<Iterator1>& x, const move_iterator<Iterator2>& y);
310947ce6b5SMarshall Clow
311947ce6b5SMarshall Clowtemplate <class Iterator1, class Iterator2>
312720ef472SMarshall Clowconstexpr bool   // constexpr in C++17
313947ce6b5SMarshall Clowoperator>(const move_iterator<Iterator1>& x, const move_iterator<Iterator2>& y);
314947ce6b5SMarshall Clow
315947ce6b5SMarshall Clowtemplate <class Iterator1, class Iterator2>
316720ef472SMarshall Clowconstexpr bool   // constexpr in C++17
317947ce6b5SMarshall Clowoperator>=(const move_iterator<Iterator1>& x, const move_iterator<Iterator2>& y);
318947ce6b5SMarshall Clow
319947ce6b5SMarshall Clowtemplate <class Iterator1, class Iterator2>
320720ef472SMarshall Clowconstexpr auto   // constexpr in C++17
321947ce6b5SMarshall Clowoperator-(const move_iterator<Iterator1>& x,
322947ce6b5SMarshall Clow          const move_iterator<Iterator2>& y) -> decltype(x.base() - y.base());
323947ce6b5SMarshall Clow
324947ce6b5SMarshall Clowtemplate <class Iterator>
325720ef472SMarshall Clowconstexpr move_iterator<Iterator> operator+(   // constexpr in C++17
326720ef472SMarshall Clow            typename move_iterator<Iterator>::difference_type n,
327947ce6b5SMarshall Clow            const move_iterator<Iterator>& x);
328947ce6b5SMarshall Clow
329720ef472SMarshall Clowtemplate <class Iterator>   // constexpr in C++17
330720ef472SMarshall Clowconstexpr  move_iterator<Iterator> make_move_iterator(const Iterator& i);
331947ce6b5SMarshall Clow
332947ce6b5SMarshall Clow
3333e519524SHoward Hinnanttemplate <class T, class charT = char, class traits = char_traits<charT>, class Distance = ptrdiff_t>
3343e519524SHoward Hinnantclass istream_iterator
3353e519524SHoward Hinnant    : public iterator<input_iterator_tag, T, Distance, const T*, const T&>
3363e519524SHoward Hinnant{
3373e519524SHoward Hinnantpublic:
3383e519524SHoward Hinnant    typedef charT char_type;
3393e519524SHoward Hinnant    typedef traits traits_type;
3403e519524SHoward Hinnant    typedef basic_istream<charT,traits> istream_type;
3413e519524SHoward Hinnant
34260d5e0e0SMarshall Clow    constexpr istream_iterator();
3433e519524SHoward Hinnant    istream_iterator(istream_type& s);
3443e519524SHoward Hinnant    istream_iterator(const istream_iterator& x);
3453e519524SHoward Hinnant    ~istream_iterator();
3463e519524SHoward Hinnant
3473e519524SHoward Hinnant    const T& operator*() const;
3483e519524SHoward Hinnant    const T* operator->() const;
3493e519524SHoward Hinnant    istream_iterator& operator++();
3503e519524SHoward Hinnant    istream_iterator  operator++(int);
3513e519524SHoward Hinnant};
3523e519524SHoward Hinnant
3533e519524SHoward Hinnanttemplate <class T, class charT, class traits, class Distance>
3543e519524SHoward Hinnantbool operator==(const istream_iterator<T,charT,traits,Distance>& x,
3553e519524SHoward Hinnant                const istream_iterator<T,charT,traits,Distance>& y);
3563e519524SHoward Hinnanttemplate <class T, class charT, class traits, class Distance>
3573e519524SHoward Hinnantbool operator!=(const istream_iterator<T,charT,traits,Distance>& x,
3583e519524SHoward Hinnant                const istream_iterator<T,charT,traits,Distance>& y);
3593e519524SHoward Hinnant
3603e519524SHoward Hinnanttemplate <class T, class charT = char, class traits = char_traits<charT> >
3613e519524SHoward Hinnantclass ostream_iterator
3623e519524SHoward Hinnant    : public iterator<output_iterator_tag, void, void, void ,void>
3633e519524SHoward Hinnant{
3643e519524SHoward Hinnantpublic:
3653e519524SHoward Hinnant    typedef charT char_type;
3663e519524SHoward Hinnant    typedef traits traits_type;
3673e519524SHoward Hinnant    typedef basic_ostream<charT,traits> ostream_type;
3683e519524SHoward Hinnant
3693e519524SHoward Hinnant    ostream_iterator(ostream_type& s);
3703e519524SHoward Hinnant    ostream_iterator(ostream_type& s, const charT* delimiter);
3713e519524SHoward Hinnant    ostream_iterator(const ostream_iterator& x);
3723e519524SHoward Hinnant    ~ostream_iterator();
3733e519524SHoward Hinnant    ostream_iterator& operator=(const T& value);
3743e519524SHoward Hinnant
3753e519524SHoward Hinnant    ostream_iterator& operator*();
3763e519524SHoward Hinnant    ostream_iterator& operator++();
3773e519524SHoward Hinnant    ostream_iterator& operator++(int);
3783e519524SHoward Hinnant};
3793e519524SHoward Hinnant
3803e519524SHoward Hinnanttemplate<class charT, class traits = char_traits<charT> >
3813e519524SHoward Hinnantclass istreambuf_iterator
3823e519524SHoward Hinnant    : public iterator<input_iterator_tag, charT,
3833e519524SHoward Hinnant                      typename traits::off_type, unspecified,
3843e519524SHoward Hinnant                      charT>
3853e519524SHoward Hinnant{
3863e519524SHoward Hinnantpublic:
3873e519524SHoward Hinnant    typedef charT                         char_type;
3883e519524SHoward Hinnant    typedef traits                        traits_type;
3893e519524SHoward Hinnant    typedef typename traits::int_type     int_type;
3903e519524SHoward Hinnant    typedef basic_streambuf<charT,traits> streambuf_type;
3913e519524SHoward Hinnant    typedef basic_istream<charT,traits>   istream_type;
3923e519524SHoward Hinnant
3938e882dcbSHoward Hinnant    istreambuf_iterator() noexcept;
3948e882dcbSHoward Hinnant    istreambuf_iterator(istream_type& s) noexcept;
3958e882dcbSHoward Hinnant    istreambuf_iterator(streambuf_type* s) noexcept;
3968e882dcbSHoward Hinnant    istreambuf_iterator(a-private-type) noexcept;
3973e519524SHoward Hinnant
3983e519524SHoward Hinnant    charT                operator*() const;
3993e519524SHoward Hinnant    pointer operator->() const;
4003e519524SHoward Hinnant    istreambuf_iterator& operator++();
4013e519524SHoward Hinnant    a-private-type       operator++(int);
4023e519524SHoward Hinnant
4033e519524SHoward Hinnant    bool equal(const istreambuf_iterator& b) const;
4043e519524SHoward Hinnant};
4053e519524SHoward Hinnant
4063e519524SHoward Hinnanttemplate <class charT, class traits>
4073e519524SHoward Hinnantbool operator==(const istreambuf_iterator<charT,traits>& a,
4083e519524SHoward Hinnant                const istreambuf_iterator<charT,traits>& b);
4093e519524SHoward Hinnanttemplate <class charT, class traits>
4103e519524SHoward Hinnantbool operator!=(const istreambuf_iterator<charT,traits>& a,
4113e519524SHoward Hinnant                const istreambuf_iterator<charT,traits>& b);
4123e519524SHoward Hinnant
4133e519524SHoward Hinnanttemplate <class charT, class traits = char_traits<charT> >
4143e519524SHoward Hinnantclass ostreambuf_iterator
4153e519524SHoward Hinnant    : public iterator<output_iterator_tag, void, void, void, void>
4163e519524SHoward Hinnant{
4173e519524SHoward Hinnantpublic:
4183e519524SHoward Hinnant    typedef charT                         char_type;
4193e519524SHoward Hinnant    typedef traits                        traits_type;
4203e519524SHoward Hinnant    typedef basic_streambuf<charT,traits> streambuf_type;
4213e519524SHoward Hinnant    typedef basic_ostream<charT,traits>   ostream_type;
4223e519524SHoward Hinnant
4238e882dcbSHoward Hinnant    ostreambuf_iterator(ostream_type& s) noexcept;
4248e882dcbSHoward Hinnant    ostreambuf_iterator(streambuf_type* s) noexcept;
4253e519524SHoward Hinnant    ostreambuf_iterator& operator=(charT c);
4263e519524SHoward Hinnant    ostreambuf_iterator& operator*();
4273e519524SHoward Hinnant    ostreambuf_iterator& operator++();
4283e519524SHoward Hinnant    ostreambuf_iterator& operator++(int);
4298e882dcbSHoward Hinnant    bool failed() const noexcept;
4303e519524SHoward Hinnant};
4313e519524SHoward Hinnant
432020b623aSMarshall Clowtemplate <class C> constexpr auto begin(C& c) -> decltype(c.begin());
433020b623aSMarshall Clowtemplate <class C> constexpr auto begin(const C& c) -> decltype(c.begin());
434020b623aSMarshall Clowtemplate <class C> constexpr auto end(C& c) -> decltype(c.end());
435020b623aSMarshall Clowtemplate <class C> constexpr auto end(const C& c) -> decltype(c.end());
436020b623aSMarshall Clowtemplate <class T, size_t N> constexpr T* begin(T (&array)[N]);
437020b623aSMarshall Clowtemplate <class T, size_t N> constexpr T* end(T (&array)[N]);
4383e519524SHoward Hinnant
439020b623aSMarshall Clowtemplate <class C> auto constexpr cbegin(const C& c) -> decltype(std::begin(c));        // C++14
440020b623aSMarshall Clowtemplate <class C> auto constexpr cend(const C& c) -> decltype(std::end(c));            // C++14
441020b623aSMarshall Clowtemplate <class C> auto constexpr rbegin(C& c) -> decltype(c.rbegin());                 // C++14
442020b623aSMarshall Clowtemplate <class C> auto constexpr rbegin(const C& c) -> decltype(c.rbegin());           // C++14
443020b623aSMarshall Clowtemplate <class C> auto constexpr rend(C& c) -> decltype(c.rend());                     // C++14
444020b623aSMarshall Clowtemplate <class C> constexpr auto rend(const C& c) -> decltype(c.rend());               // C++14
445020b623aSMarshall Clowtemplate <class E> reverse_iterator<const E*> constexpr rbegin(initializer_list<E> il); // C++14
446020b623aSMarshall Clowtemplate <class E> reverse_iterator<const E*> constexpr rend(initializer_list<E> il);   // C++14
447020b623aSMarshall Clowtemplate <class T, size_t N> reverse_iterator<T*> constexpr rbegin(T (&array)[N]);      // C++14
448020b623aSMarshall Clowtemplate <class T, size_t N> reverse_iterator<T*> constexpr rend(T (&array)[N]);        // C++14
449020b623aSMarshall Clowtemplate <class C> constexpr auto crbegin(const C& c) -> decltype(std::rbegin(c));      // C++14
450020b623aSMarshall Clowtemplate <class C> constexpr auto crend(const C& c) -> decltype(std::rend(c));          // C++14
4511e548c72SMarshall Clow
452ad755104SMarshall Clow// 24.8, container access:
453ad755104SMarshall Clowtemplate <class C> constexpr auto size(const C& c) -> decltype(c.size());         // C++17
454ad755104SMarshall Clowtemplate <class T, size_t N> constexpr size_t size(const T (&array)[N]) noexcept; // C++17
4557d3986eaSMarshall Clow
4567d3986eaSMarshall Clowtemplate <class C> constexpr auto ssize(const C& c)
4577d3986eaSMarshall Clow    -> common_type_t<ptrdiff_t, make_signed_t<decltype(c.size())>>;                    // C++20
4587d3986eaSMarshall Clowtemplate <class T, ptrdiff_t> constexpr ptrdiff_t ssize(const T (&array)[N]) noexcept; // C++20
4597d3986eaSMarshall Clow
460ad755104SMarshall Clowtemplate <class C> constexpr auto empty(const C& c) -> decltype(c.empty());       // C++17
461ad755104SMarshall Clowtemplate <class T, size_t N> constexpr bool empty(const T (&array)[N]) noexcept;  // C++17
462ad755104SMarshall Clowtemplate <class E> constexpr bool empty(initializer_list<E> il) noexcept;         // C++17
463ad755104SMarshall Clowtemplate <class C> constexpr auto data(C& c) -> decltype(c.data());               // C++17
464ad755104SMarshall Clowtemplate <class C> constexpr auto data(const C& c) -> decltype(c.data());         // C++17
465ad755104SMarshall Clowtemplate <class T, size_t N> constexpr T* data(T (&array)[N]) noexcept;           // C++17
466ad755104SMarshall Clowtemplate <class E> constexpr const E* data(initializer_list<E> il) noexcept;      // C++17
467ad755104SMarshall Clow
4683e519524SHoward Hinnant}  // std
4693e519524SHoward Hinnant
4703e519524SHoward Hinnant*/
4713e519524SHoward Hinnant
4723e519524SHoward Hinnant#include <__config>
4735f51fb34SArthur O'Dwyer#include <__debug>
474c204c130SMarshall Clow#include <__functional_base>
47557ebf3d0SLouis Dionne#include <__iterator/concepts.h>
476e0adf7e0Szoecarver#include <__iterator/incrementable_traits.h>
47797e383aaSLouis Dionne#include <__iterator/iter_move.h>
478120fa829Szoecarver#include <__iterator/iterator_traits.h>
479e0adf7e0Szoecarver#include <__iterator/readable_traits.h>
480f992cfbaSLouis Dionne#include <__memory/addressof.h>
481d41c6d51SArthur O'Dwyer#include <__memory/pointer_traits.h>
4825f51fb34SArthur O'Dwyer#include <compare>
4835f51fb34SArthur O'Dwyer#include <concepts> // Mandated by the Standard.
4845f51fb34SArthur O'Dwyer#include <cstddef>
4855f51fb34SArthur O'Dwyer#include <initializer_list>
4865f51fb34SArthur O'Dwyer#include <iosfwd> // for forward declarations of vector and string
4875f51fb34SArthur O'Dwyer#include <type_traits>
488f56972e2SMarshall Clow#include <version>
489b5c63a2eSHoward Hinnant
490073458b1SHoward Hinnant#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
4913e519524SHoward Hinnant#pragma GCC system_header
492073458b1SHoward Hinnant#endif
4933e519524SHoward Hinnant
4943e519524SHoward Hinnant_LIBCPP_BEGIN_NAMESPACE_STD
495fe31f11cSChristopher Di Bella
4963e519524SHoward Hinnanttemplate<class _Category, class _Tp, class _Distance = ptrdiff_t,
4973e519524SHoward Hinnant         class _Pointer = _Tp*, class _Reference = _Tp&>
498e2f2d1edSEric Fiselierstruct _LIBCPP_TEMPLATE_VIS iterator
4993e519524SHoward Hinnant{
5003e519524SHoward Hinnant    typedef _Tp        value_type;
5013e519524SHoward Hinnant    typedef _Distance  difference_type;
5023e519524SHoward Hinnant    typedef _Pointer   pointer;
5033e519524SHoward Hinnant    typedef _Reference reference;
5043e519524SHoward Hinnant    typedef _Category  iterator_category;
5053e519524SHoward Hinnant};
5063e519524SHoward Hinnant
5073e519524SHoward Hinnanttemplate <class _InputIter>
508f51ee632SMarshall Clowinline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
5093e519524SHoward Hinnantvoid __advance(_InputIter& __i,
5103e519524SHoward Hinnant             typename iterator_traits<_InputIter>::difference_type __n, input_iterator_tag)
5113e519524SHoward Hinnant{
5123e519524SHoward Hinnant    for (; __n > 0; --__n)
5133e519524SHoward Hinnant        ++__i;
5143e519524SHoward Hinnant}
5153e519524SHoward Hinnant
5163e519524SHoward Hinnanttemplate <class _BiDirIter>
517f51ee632SMarshall Clowinline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
5183e519524SHoward Hinnantvoid __advance(_BiDirIter& __i,
5193e519524SHoward Hinnant             typename iterator_traits<_BiDirIter>::difference_type __n, bidirectional_iterator_tag)
5203e519524SHoward Hinnant{
5213e519524SHoward Hinnant    if (__n >= 0)
5223e519524SHoward Hinnant        for (; __n > 0; --__n)
5233e519524SHoward Hinnant            ++__i;
5243e519524SHoward Hinnant    else
5253e519524SHoward Hinnant        for (; __n < 0; ++__n)
5263e519524SHoward Hinnant            --__i;
5273e519524SHoward Hinnant}
5283e519524SHoward Hinnant
5293e519524SHoward Hinnanttemplate <class _RandIter>
530f51ee632SMarshall Clowinline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
5313e519524SHoward Hinnantvoid __advance(_RandIter& __i,
5323e519524SHoward Hinnant             typename iterator_traits<_RandIter>::difference_type __n, random_access_iterator_tag)
5333e519524SHoward Hinnant{
5343e519524SHoward Hinnant   __i += __n;
5353e519524SHoward Hinnant}
5363e519524SHoward Hinnant
53712b01ab7SLouis Dionnetemplate <class _InputIter, class _Distance>
538f51ee632SMarshall Clowinline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
53912b01ab7SLouis Dionnevoid advance(_InputIter& __i, _Distance __orig_n)
5403e519524SHoward Hinnant{
54112b01ab7SLouis Dionne    _LIBCPP_ASSERT(__orig_n >= 0 || __is_cpp17_bidirectional_iterator<_InputIter>::value,
54212b01ab7SLouis Dionne                   "Attempt to advance(it, n) with negative n on a non-bidirectional iterator");
543c0428b3cSArthur O'Dwyer    typedef decltype(_VSTD::__convert_to_integral(__orig_n)) _IntegralSize;
54412b01ab7SLouis Dionne    _IntegralSize __n = __orig_n;
545c0428b3cSArthur O'Dwyer    _VSTD::__advance(__i, __n, typename iterator_traits<_InputIter>::iterator_category());
5463e519524SHoward Hinnant}
5473e519524SHoward Hinnant
5483e519524SHoward Hinnanttemplate <class _InputIter>
549f51ee632SMarshall Clowinline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
5503e519524SHoward Hinnanttypename iterator_traits<_InputIter>::difference_type
5513e519524SHoward Hinnant__distance(_InputIter __first, _InputIter __last, input_iterator_tag)
5523e519524SHoward Hinnant{
5533e519524SHoward Hinnant    typename iterator_traits<_InputIter>::difference_type __r(0);
5543e519524SHoward Hinnant    for (; __first != __last; ++__first)
5553e519524SHoward Hinnant        ++__r;
5563e519524SHoward Hinnant    return __r;
5573e519524SHoward Hinnant}
5583e519524SHoward Hinnant
5593e519524SHoward Hinnanttemplate <class _RandIter>
560f51ee632SMarshall Clowinline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
5613e519524SHoward Hinnanttypename iterator_traits<_RandIter>::difference_type
5623e519524SHoward Hinnant__distance(_RandIter __first, _RandIter __last, random_access_iterator_tag)
5633e519524SHoward Hinnant{
5643e519524SHoward Hinnant    return __last - __first;
5653e519524SHoward Hinnant}
5663e519524SHoward Hinnant
5673e519524SHoward Hinnanttemplate <class _InputIter>
568f51ee632SMarshall Clowinline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
5693e519524SHoward Hinnanttypename iterator_traits<_InputIter>::difference_type
5703e519524SHoward Hinnantdistance(_InputIter __first, _InputIter __last)
5713e519524SHoward Hinnant{
572c0428b3cSArthur O'Dwyer    return _VSTD::__distance(__first, __last, typename iterator_traits<_InputIter>::iterator_category());
5733e519524SHoward Hinnant}
5743e519524SHoward Hinnant
575e5f1288fSMarshall Clowtemplate <class _InputIter>
576f51ee632SMarshall Clowinline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
5773e2ef408SRachel Craiktypename enable_if
5783e2ef408SRachel Craik<
579f82dba01SEric Fiselier    __is_cpp17_input_iterator<_InputIter>::value,
580e5f1288fSMarshall Clow    _InputIter
5813e2ef408SRachel Craik>::type
582e5f1288fSMarshall Clownext(_InputIter __x,
5833e2ef408SRachel Craik     typename iterator_traits<_InputIter>::difference_type __n = 1)
5843e519524SHoward Hinnant{
585f82dba01SEric Fiselier    _LIBCPP_ASSERT(__n >= 0 || __is_cpp17_bidirectional_iterator<_InputIter>::value,
58612b01ab7SLouis Dionne                       "Attempt to next(it, n) with negative n on a non-bidirectional iterator");
587e1cd11d8SMarshall Clow
588ce48a113SHoward Hinnant    _VSTD::advance(__x, __n);
5893e519524SHoward Hinnant    return __x;
5903e519524SHoward Hinnant}
5913e519524SHoward Hinnant
592e1cd11d8SMarshall Clowtemplate <class _InputIter>
593f51ee632SMarshall Clowinline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
5943e2ef408SRachel Craiktypename enable_if
5953e2ef408SRachel Craik<
596f82dba01SEric Fiselier    __is_cpp17_input_iterator<_InputIter>::value,
597e1cd11d8SMarshall Clow    _InputIter
5983e2ef408SRachel Craik>::type
599e1cd11d8SMarshall Clowprev(_InputIter __x,
600e1cd11d8SMarshall Clow     typename iterator_traits<_InputIter>::difference_type __n = 1)
6013e519524SHoward Hinnant{
602f82dba01SEric Fiselier    _LIBCPP_ASSERT(__n <= 0 || __is_cpp17_bidirectional_iterator<_InputIter>::value,
60312b01ab7SLouis Dionne                       "Attempt to prev(it, n) with a positive n on a non-bidirectional iterator");
604ce48a113SHoward Hinnant    _VSTD::advance(__x, -__n);
6053e519524SHoward Hinnant    return __x;
6063e519524SHoward Hinnant}
6073e519524SHoward Hinnant
608e02ed1c2SEric Fiselier
609e02ed1c2SEric Fiseliertemplate <class _Tp, class = void>
610e02ed1c2SEric Fiselierstruct __is_stashing_iterator : false_type {};
611e02ed1c2SEric Fiselier
612e02ed1c2SEric Fiseliertemplate <class _Tp>
613e02ed1c2SEric Fiselierstruct __is_stashing_iterator<_Tp, typename __void_t<typename _Tp::__stashing_iterator_tag>::type>
614e02ed1c2SEric Fiselier  : true_type {};
615e02ed1c2SEric Fiselier
6163e519524SHoward Hinnanttemplate <class _Iter>
617e2f2d1edSEric Fiselierclass _LIBCPP_TEMPLATE_VIS reverse_iterator
6183e519524SHoward Hinnant    : public iterator<typename iterator_traits<_Iter>::iterator_category,
6193e519524SHoward Hinnant                      typename iterator_traits<_Iter>::value_type,
6203e519524SHoward Hinnant                      typename iterator_traits<_Iter>::difference_type,
6213e519524SHoward Hinnant                      typename iterator_traits<_Iter>::pointer,
6223e519524SHoward Hinnant                      typename iterator_traits<_Iter>::reference>
6233e519524SHoward Hinnant{
6243b83496dSMarshall Clowprivate:
6251b8f260eSMarshall Clow    /*mutable*/ _Iter __t;  // no longer used as of LWG #2360, not removed due to ABI break
626e02ed1c2SEric Fiselier
627e02ed1c2SEric Fiselier    static_assert(!__is_stashing_iterator<_Iter>::value,
628e02ed1c2SEric Fiselier      "The specified iterator type cannot be used with reverse_iterator; "
629e02ed1c2SEric Fiselier      "Using stashing iterators with reverse_iterator causes undefined behavior");
630e02ed1c2SEric Fiselier
631b2d74f29SMarshall Clowprotected:
632b2d74f29SMarshall Clow    _Iter current;
6333e519524SHoward Hinnantpublic:
6343e519524SHoward Hinnant    typedef _Iter                                            iterator_type;
6353e519524SHoward Hinnant    typedef typename iterator_traits<_Iter>::difference_type difference_type;
6363e519524SHoward Hinnant    typedef typename iterator_traits<_Iter>::reference       reference;
6373e519524SHoward Hinnant    typedef typename iterator_traits<_Iter>::pointer         pointer;
638d41c6d51SArthur O'Dwyer    typedef _If<__is_cpp17_random_access_iterator<_Iter>::value,
639d41c6d51SArthur O'Dwyer        random_access_iterator_tag,
640d41c6d51SArthur O'Dwyer        typename iterator_traits<_Iter>::iterator_category>  iterator_category;
641d41c6d51SArthur O'Dwyer#if _LIBCPP_STD_VER > 17
642d41c6d51SArthur O'Dwyer    typedef _If<__is_cpp17_random_access_iterator<_Iter>::value,
643d41c6d51SArthur O'Dwyer        random_access_iterator_tag,
644d41c6d51SArthur O'Dwyer        bidirectional_iterator_tag>                          iterator_concept;
645d41c6d51SArthur O'Dwyer#endif
6463e519524SHoward Hinnant
6471b8f260eSMarshall Clow    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
6481b8f260eSMarshall Clow    reverse_iterator() : __t(), current() {}
6491b8f260eSMarshall Clow    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
6501b8f260eSMarshall Clow    explicit reverse_iterator(_Iter __x) : __t(__x), current(__x) {}
6511b8f260eSMarshall Clow    template <class _Up>
6521b8f260eSMarshall Clow        _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
6531b8f260eSMarshall Clow        reverse_iterator(const reverse_iterator<_Up>& __u) : __t(__u.base()), current(__u.base()) {}
6541b8f260eSMarshall Clow    template <class _Up>
6551b8f260eSMarshall Clow        _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
6561b8f260eSMarshall Clow        reverse_iterator& operator=(const reverse_iterator<_Up>& __u)
6571b8f260eSMarshall Clow            { __t = current = __u.base(); return *this; }
6581b8f260eSMarshall Clow    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
6591b8f260eSMarshall Clow    _Iter base() const {return current;}
6601b8f260eSMarshall Clow    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
6611b8f260eSMarshall Clow    reference operator*() const {_Iter __tmp = current; return *--__tmp;}
6621b8f260eSMarshall Clow    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
6631b8f260eSMarshall Clow    pointer  operator->() const {return _VSTD::addressof(operator*());}
6641b8f260eSMarshall Clow    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
6651b8f260eSMarshall Clow    reverse_iterator& operator++() {--current; return *this;}
6661b8f260eSMarshall Clow    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
6671b8f260eSMarshall Clow    reverse_iterator  operator++(int) {reverse_iterator __tmp(*this); --current; return __tmp;}
6681b8f260eSMarshall Clow    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
6691b8f260eSMarshall Clow    reverse_iterator& operator--() {++current; return *this;}
6701b8f260eSMarshall Clow    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
6711b8f260eSMarshall Clow    reverse_iterator  operator--(int) {reverse_iterator __tmp(*this); ++current; return __tmp;}
6721b8f260eSMarshall Clow    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
6731b8f260eSMarshall Clow    reverse_iterator  operator+ (difference_type __n) const {return reverse_iterator(current - __n);}
6741b8f260eSMarshall Clow    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
6751b8f260eSMarshall Clow    reverse_iterator& operator+=(difference_type __n) {current -= __n; return *this;}
6761b8f260eSMarshall Clow    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
6771b8f260eSMarshall Clow    reverse_iterator  operator- (difference_type __n) const {return reverse_iterator(current + __n);}
6781b8f260eSMarshall Clow    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
6791b8f260eSMarshall Clow    reverse_iterator& operator-=(difference_type __n) {current += __n; return *this;}
6801b8f260eSMarshall Clow    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
6811b8f260eSMarshall Clow    reference         operator[](difference_type __n) const {return *(*this + __n);}
6823e519524SHoward Hinnant};
6833e519524SHoward Hinnant
6843e519524SHoward Hinnanttemplate <class _Iter1, class _Iter2>
6851b8f260eSMarshall Clowinline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
6863e519524SHoward Hinnantbool
6873e519524SHoward Hinnantoperator==(const reverse_iterator<_Iter1>& __x, const reverse_iterator<_Iter2>& __y)
6883e519524SHoward Hinnant{
6893e519524SHoward Hinnant    return __x.base() == __y.base();
6903e519524SHoward Hinnant}
6913e519524SHoward Hinnant
6923e519524SHoward Hinnanttemplate <class _Iter1, class _Iter2>
6931b8f260eSMarshall Clowinline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
6943e519524SHoward Hinnantbool
6953e519524SHoward Hinnantoperator<(const reverse_iterator<_Iter1>& __x, const reverse_iterator<_Iter2>& __y)
6963e519524SHoward Hinnant{
6973e519524SHoward Hinnant    return __x.base() > __y.base();
6983e519524SHoward Hinnant}
6993e519524SHoward Hinnant
7003e519524SHoward Hinnanttemplate <class _Iter1, class _Iter2>
7011b8f260eSMarshall Clowinline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
7023e519524SHoward Hinnantbool
7033e519524SHoward Hinnantoperator!=(const reverse_iterator<_Iter1>& __x, const reverse_iterator<_Iter2>& __y)
7043e519524SHoward Hinnant{
7053e519524SHoward Hinnant    return __x.base() != __y.base();
7063e519524SHoward Hinnant}
7073e519524SHoward Hinnant
7083e519524SHoward Hinnanttemplate <class _Iter1, class _Iter2>
7091b8f260eSMarshall Clowinline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
7103e519524SHoward Hinnantbool
7113e519524SHoward Hinnantoperator>(const reverse_iterator<_Iter1>& __x, const reverse_iterator<_Iter2>& __y)
7123e519524SHoward Hinnant{
7133e519524SHoward Hinnant    return __x.base() < __y.base();
7143e519524SHoward Hinnant}
7153e519524SHoward Hinnant
7163e519524SHoward Hinnanttemplate <class _Iter1, class _Iter2>
7171b8f260eSMarshall Clowinline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
7183e519524SHoward Hinnantbool
7193e519524SHoward Hinnantoperator>=(const reverse_iterator<_Iter1>& __x, const reverse_iterator<_Iter2>& __y)
7203e519524SHoward Hinnant{
7213e519524SHoward Hinnant    return __x.base() <= __y.base();
7223e519524SHoward Hinnant}
7233e519524SHoward Hinnant
7243e519524SHoward Hinnanttemplate <class _Iter1, class _Iter2>
7251b8f260eSMarshall Clowinline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
7263e519524SHoward Hinnantbool
7273e519524SHoward Hinnantoperator<=(const reverse_iterator<_Iter1>& __x, const reverse_iterator<_Iter2>& __y)
7283e519524SHoward Hinnant{
7293e519524SHoward Hinnant    return __x.base() >= __y.base();
7303e519524SHoward Hinnant}
7313e519524SHoward Hinnant
7322ee83725SMarshall Clow#ifndef _LIBCPP_CXX03_LANG
733947ce6b5SMarshall Clowtemplate <class _Iter1, class _Iter2>
7341b8f260eSMarshall Clowinline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
735947ce6b5SMarshall Clowauto
736947ce6b5SMarshall Clowoperator-(const reverse_iterator<_Iter1>& __x, const reverse_iterator<_Iter2>& __y)
737947ce6b5SMarshall Clow-> decltype(__y.base() - __x.base())
738947ce6b5SMarshall Clow{
739947ce6b5SMarshall Clow    return __y.base() - __x.base();
740947ce6b5SMarshall Clow}
741947ce6b5SMarshall Clow#else
7423e519524SHoward Hinnanttemplate <class _Iter1, class _Iter2>
7433e519524SHoward Hinnantinline _LIBCPP_INLINE_VISIBILITY
7443e519524SHoward Hinnanttypename reverse_iterator<_Iter1>::difference_type
7453e519524SHoward Hinnantoperator-(const reverse_iterator<_Iter1>& __x, const reverse_iterator<_Iter2>& __y)
7463e519524SHoward Hinnant{
7473e519524SHoward Hinnant    return __y.base() - __x.base();
7483e519524SHoward Hinnant}
749947ce6b5SMarshall Clow#endif
7503e519524SHoward Hinnant
7513e519524SHoward Hinnanttemplate <class _Iter>
7521b8f260eSMarshall Clowinline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
7533e519524SHoward Hinnantreverse_iterator<_Iter>
7543e519524SHoward Hinnantoperator+(typename reverse_iterator<_Iter>::difference_type __n, const reverse_iterator<_Iter>& __x)
7553e519524SHoward Hinnant{
7563e519524SHoward Hinnant    return reverse_iterator<_Iter>(__x.base() - __n);
7573e519524SHoward Hinnant}
7583e519524SHoward Hinnant
7596a640a18SMarshall Clow#if _LIBCPP_STD_VER > 11
7606a640a18SMarshall Clowtemplate <class _Iter>
7611b8f260eSMarshall Clowinline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
7626a640a18SMarshall Clowreverse_iterator<_Iter> make_reverse_iterator(_Iter __i)
7636a640a18SMarshall Clow{
7646a640a18SMarshall Clow    return reverse_iterator<_Iter>(__i);
7656a640a18SMarshall Clow}
7666a640a18SMarshall Clow#endif
7676a640a18SMarshall Clow
7683e519524SHoward Hinnanttemplate <class _Container>
769e2f2d1edSEric Fiselierclass _LIBCPP_TEMPLATE_VIS back_insert_iterator
7703e519524SHoward Hinnant    : public iterator<output_iterator_tag,
7713e519524SHoward Hinnant                      void,
7723e519524SHoward Hinnant                      void,
7733e519524SHoward Hinnant                      void,
7748892b4eeSEric Fiselier                      void>
7753e519524SHoward Hinnant{
7763e519524SHoward Hinnantprotected:
7773e519524SHoward Hinnant    _Container* container;
7783e519524SHoward Hinnantpublic:
7793e519524SHoward Hinnant    typedef _Container container_type;
7803e519524SHoward Hinnant
78106e2b737SArthur O'Dwyer    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 explicit back_insert_iterator(_Container& __x) : container(_VSTD::addressof(__x)) {}
78206e2b737SArthur O'Dwyer    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 back_insert_iterator& operator=(const typename _Container::value_type& __value_)
783e4383379SHoward Hinnant        {container->push_back(__value_); return *this;}
784046492b9SEric Fiselier#ifndef _LIBCPP_CXX03_LANG
78506e2b737SArthur O'Dwyer    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 back_insert_iterator& operator=(typename _Container::value_type&& __value_)
786e4383379SHoward Hinnant        {container->push_back(_VSTD::move(__value_)); return *this;}
787046492b9SEric Fiselier#endif // _LIBCPP_CXX03_LANG
78806e2b737SArthur O'Dwyer    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 back_insert_iterator& operator*()     {return *this;}
78906e2b737SArthur O'Dwyer    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 back_insert_iterator& operator++()    {return *this;}
79006e2b737SArthur O'Dwyer    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 back_insert_iterator  operator++(int) {return *this;}
7913e519524SHoward Hinnant};
7923e519524SHoward Hinnant
7933e519524SHoward Hinnanttemplate <class _Container>
79406e2b737SArthur O'Dwyerinline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
7953e519524SHoward Hinnantback_insert_iterator<_Container>
7963e519524SHoward Hinnantback_inserter(_Container& __x)
7973e519524SHoward Hinnant{
7983e519524SHoward Hinnant    return back_insert_iterator<_Container>(__x);
7993e519524SHoward Hinnant}
8003e519524SHoward Hinnant
8013e519524SHoward Hinnanttemplate <class _Container>
802e2f2d1edSEric Fiselierclass _LIBCPP_TEMPLATE_VIS front_insert_iterator
8033e519524SHoward Hinnant    : public iterator<output_iterator_tag,
8043e519524SHoward Hinnant                      void,
8053e519524SHoward Hinnant                      void,
8063e519524SHoward Hinnant                      void,
8078892b4eeSEric Fiselier                      void>
8083e519524SHoward Hinnant{
8093e519524SHoward Hinnantprotected:
8103e519524SHoward Hinnant    _Container* container;
8113e519524SHoward Hinnantpublic:
8123e519524SHoward Hinnant    typedef _Container container_type;
8133e519524SHoward Hinnant
81406e2b737SArthur O'Dwyer    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 explicit front_insert_iterator(_Container& __x) : container(_VSTD::addressof(__x)) {}
81506e2b737SArthur O'Dwyer    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 front_insert_iterator& operator=(const typename _Container::value_type& __value_)
816e4383379SHoward Hinnant        {container->push_front(__value_); return *this;}
817046492b9SEric Fiselier#ifndef _LIBCPP_CXX03_LANG
81806e2b737SArthur O'Dwyer    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 front_insert_iterator& operator=(typename _Container::value_type&& __value_)
819e4383379SHoward Hinnant        {container->push_front(_VSTD::move(__value_)); return *this;}
820046492b9SEric Fiselier#endif // _LIBCPP_CXX03_LANG
82106e2b737SArthur O'Dwyer    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 front_insert_iterator& operator*()     {return *this;}
82206e2b737SArthur O'Dwyer    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 front_insert_iterator& operator++()    {return *this;}
82306e2b737SArthur O'Dwyer    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 front_insert_iterator  operator++(int) {return *this;}
8243e519524SHoward Hinnant};
8253e519524SHoward Hinnant
8263e519524SHoward Hinnanttemplate <class _Container>
82706e2b737SArthur O'Dwyerinline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
8283e519524SHoward Hinnantfront_insert_iterator<_Container>
8293e519524SHoward Hinnantfront_inserter(_Container& __x)
8303e519524SHoward Hinnant{
8313e519524SHoward Hinnant    return front_insert_iterator<_Container>(__x);
8323e519524SHoward Hinnant}
8333e519524SHoward Hinnant
8343e519524SHoward Hinnanttemplate <class _Container>
835e2f2d1edSEric Fiselierclass _LIBCPP_TEMPLATE_VIS insert_iterator
8363e519524SHoward Hinnant    : public iterator<output_iterator_tag,
8373e519524SHoward Hinnant                      void,
8383e519524SHoward Hinnant                      void,
8393e519524SHoward Hinnant                      void,
8408892b4eeSEric Fiselier                      void>
8413e519524SHoward Hinnant{
8423e519524SHoward Hinnantprotected:
8433e519524SHoward Hinnant    _Container* container;
8443e519524SHoward Hinnant    typename _Container::iterator iter;
8453e519524SHoward Hinnantpublic:
8463e519524SHoward Hinnant    typedef _Container container_type;
8473e519524SHoward Hinnant
84806e2b737SArthur O'Dwyer    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 insert_iterator(_Container& __x, typename _Container::iterator __i)
849f519be34SMarshall Clow        : container(_VSTD::addressof(__x)), iter(__i) {}
85006e2b737SArthur O'Dwyer    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 insert_iterator& operator=(const typename _Container::value_type& __value_)
851e4383379SHoward Hinnant        {iter = container->insert(iter, __value_); ++iter; return *this;}
852046492b9SEric Fiselier#ifndef _LIBCPP_CXX03_LANG
85306e2b737SArthur O'Dwyer    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 insert_iterator& operator=(typename _Container::value_type&& __value_)
854e4383379SHoward Hinnant        {iter = container->insert(iter, _VSTD::move(__value_)); ++iter; return *this;}
855046492b9SEric Fiselier#endif // _LIBCPP_CXX03_LANG
85606e2b737SArthur O'Dwyer    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 insert_iterator& operator*()        {return *this;}
85706e2b737SArthur O'Dwyer    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 insert_iterator& operator++()       {return *this;}
85806e2b737SArthur O'Dwyer    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 insert_iterator& operator++(int)    {return *this;}
8593e519524SHoward Hinnant};
8603e519524SHoward Hinnant
8613e519524SHoward Hinnanttemplate <class _Container>
86206e2b737SArthur O'Dwyerinline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
8633e519524SHoward Hinnantinsert_iterator<_Container>
8643e519524SHoward Hinnantinserter(_Container& __x, typename _Container::iterator __i)
8653e519524SHoward Hinnant{
8663e519524SHoward Hinnant    return insert_iterator<_Container>(__x, __i);
8673e519524SHoward Hinnant}
8683e519524SHoward Hinnant
8693e519524SHoward Hinnanttemplate <class _Tp, class _CharT = char,
8703e519524SHoward Hinnant          class _Traits = char_traits<_CharT>, class _Distance = ptrdiff_t>
871e2f2d1edSEric Fiselierclass _LIBCPP_TEMPLATE_VIS istream_iterator
8723e519524SHoward Hinnant    : public iterator<input_iterator_tag, _Tp, _Distance, const _Tp*, const _Tp&>
8733e519524SHoward Hinnant{
8743e519524SHoward Hinnantpublic:
8753e519524SHoward Hinnant    typedef _CharT char_type;
8763e519524SHoward Hinnant    typedef _Traits traits_type;
8773e519524SHoward Hinnant    typedef basic_istream<_CharT,_Traits> istream_type;
8783e519524SHoward Hinnantprivate:
8793e519524SHoward Hinnant    istream_type* __in_stream_;
8803e519524SHoward Hinnant    _Tp __value_;
8813e519524SHoward Hinnantpublic:
882527a7fdfSBruce Mitchener    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR istream_iterator() : __in_stream_(nullptr), __value_() {}
883bc6a7df0SMarshall Clow    _LIBCPP_INLINE_VISIBILITY istream_iterator(istream_type& __s) : __in_stream_(_VSTD::addressof(__s))
8843e519524SHoward Hinnant        {
8853e519524SHoward Hinnant            if (!(*__in_stream_ >> __value_))
886527a7fdfSBruce Mitchener                __in_stream_ = nullptr;
8873e519524SHoward Hinnant        }
8883e519524SHoward Hinnant
8893e519524SHoward Hinnant    _LIBCPP_INLINE_VISIBILITY const _Tp& operator*() const {return __value_;}
890bc6a7df0SMarshall Clow    _LIBCPP_INLINE_VISIBILITY const _Tp* operator->() const {return _VSTD::addressof((operator*()));}
8913e519524SHoward Hinnant    _LIBCPP_INLINE_VISIBILITY istream_iterator& operator++()
8923e519524SHoward Hinnant        {
8933e519524SHoward Hinnant            if (!(*__in_stream_ >> __value_))
894527a7fdfSBruce Mitchener                __in_stream_ = nullptr;
8953e519524SHoward Hinnant            return *this;
8963e519524SHoward Hinnant        }
8973e519524SHoward Hinnant    _LIBCPP_INLINE_VISIBILITY istream_iterator  operator++(int)
8983e519524SHoward Hinnant        {istream_iterator __t(*this); ++(*this); return __t;}
8993e519524SHoward Hinnant
9006f56d3eeSRoger Ferrer Ibanez    template <class _Up, class _CharU, class _TraitsU, class _DistanceU>
9013e519524SHoward Hinnant    friend _LIBCPP_INLINE_VISIBILITY
9026f56d3eeSRoger Ferrer Ibanez    bool
9036f56d3eeSRoger Ferrer Ibanez    operator==(const istream_iterator<_Up, _CharU, _TraitsU, _DistanceU>& __x,
9046f56d3eeSRoger Ferrer Ibanez               const istream_iterator<_Up, _CharU, _TraitsU, _DistanceU>& __y);
9053e519524SHoward Hinnant
9066f56d3eeSRoger Ferrer Ibanez    template <class _Up, class _CharU, class _TraitsU, class _DistanceU>
9073e519524SHoward Hinnant    friend _LIBCPP_INLINE_VISIBILITY
9086f56d3eeSRoger Ferrer Ibanez    bool
9096f56d3eeSRoger Ferrer Ibanez    operator==(const istream_iterator<_Up, _CharU, _TraitsU, _DistanceU>& __x,
9106f56d3eeSRoger Ferrer Ibanez               const istream_iterator<_Up, _CharU, _TraitsU, _DistanceU>& __y);
9113e519524SHoward Hinnant};
9123e519524SHoward Hinnant
9136f56d3eeSRoger Ferrer Ibaneztemplate <class _Tp, class _CharT, class _Traits, class _Distance>
9146f56d3eeSRoger Ferrer Ibanezinline _LIBCPP_INLINE_VISIBILITY
9156f56d3eeSRoger Ferrer Ibanezbool
9166f56d3eeSRoger Ferrer Ibanezoperator==(const istream_iterator<_Tp, _CharT, _Traits, _Distance>& __x,
9176f56d3eeSRoger Ferrer Ibanez           const istream_iterator<_Tp, _CharT, _Traits, _Distance>& __y)
9186f56d3eeSRoger Ferrer Ibanez{
9196f56d3eeSRoger Ferrer Ibanez    return __x.__in_stream_ == __y.__in_stream_;
9206f56d3eeSRoger Ferrer Ibanez}
9216f56d3eeSRoger Ferrer Ibanez
9226f56d3eeSRoger Ferrer Ibaneztemplate <class _Tp, class _CharT, class _Traits, class _Distance>
9236f56d3eeSRoger Ferrer Ibanezinline _LIBCPP_INLINE_VISIBILITY
9246f56d3eeSRoger Ferrer Ibanezbool
9256f56d3eeSRoger Ferrer Ibanezoperator!=(const istream_iterator<_Tp, _CharT, _Traits, _Distance>& __x,
9266f56d3eeSRoger Ferrer Ibanez           const istream_iterator<_Tp, _CharT, _Traits, _Distance>& __y)
9276f56d3eeSRoger Ferrer Ibanez{
9286f56d3eeSRoger Ferrer Ibanez    return !(__x == __y);
9296f56d3eeSRoger Ferrer Ibanez}
9306f56d3eeSRoger Ferrer Ibanez
9313e519524SHoward Hinnanttemplate <class _Tp, class _CharT = char, class _Traits = char_traits<_CharT> >
932e2f2d1edSEric Fiselierclass _LIBCPP_TEMPLATE_VIS ostream_iterator
9333e519524SHoward Hinnant    : public iterator<output_iterator_tag, void, void, void, void>
9343e519524SHoward Hinnant{
9353e519524SHoward Hinnantpublic:
93671a16e40SLouis Dionne    typedef output_iterator_tag             iterator_category;
93771a16e40SLouis Dionne    typedef void                            value_type;
93871a16e40SLouis Dionne#if _LIBCPP_STD_VER > 17
93971a16e40SLouis Dionne    typedef std::ptrdiff_t                  difference_type;
94071a16e40SLouis Dionne#else
94171a16e40SLouis Dionne    typedef void                            difference_type;
94271a16e40SLouis Dionne#endif
94371a16e40SLouis Dionne    typedef void                            pointer;
94471a16e40SLouis Dionne    typedef void                            reference;
9453e519524SHoward Hinnant    typedef _CharT                          char_type;
9463e519524SHoward Hinnant    typedef _Traits                         traits_type;
9473e519524SHoward Hinnant    typedef basic_ostream<_CharT, _Traits>  ostream_type;
94871a16e40SLouis Dionne
9493e519524SHoward Hinnantprivate:
9503e519524SHoward Hinnant    ostream_type* __out_stream_;
9513e519524SHoward Hinnant    const char_type* __delim_;
9523e519524SHoward Hinnantpublic:
953853042cfSMarshall Clow    _LIBCPP_INLINE_VISIBILITY ostream_iterator(ostream_type& __s) _NOEXCEPT
954527a7fdfSBruce Mitchener        : __out_stream_(_VSTD::addressof(__s)), __delim_(nullptr) {}
955853042cfSMarshall Clow    _LIBCPP_INLINE_VISIBILITY ostream_iterator(ostream_type& __s, const _CharT* __delimiter) _NOEXCEPT
956bc6a7df0SMarshall Clow        : __out_stream_(_VSTD::addressof(__s)), __delim_(__delimiter) {}
957e4383379SHoward Hinnant    _LIBCPP_INLINE_VISIBILITY ostream_iterator& operator=(const _Tp& __value_)
9583e519524SHoward Hinnant        {
959e4383379SHoward Hinnant            *__out_stream_ << __value_;
9603e519524SHoward Hinnant            if (__delim_)
9613e519524SHoward Hinnant                *__out_stream_ << __delim_;
9623e519524SHoward Hinnant            return *this;
9633e519524SHoward Hinnant        }
9643e519524SHoward Hinnant
9653e519524SHoward Hinnant    _LIBCPP_INLINE_VISIBILITY ostream_iterator& operator*()     {return *this;}
9663e519524SHoward Hinnant    _LIBCPP_INLINE_VISIBILITY ostream_iterator& operator++()    {return *this;}
9673e519524SHoward Hinnant    _LIBCPP_INLINE_VISIBILITY ostream_iterator& operator++(int) {return *this;}
9683e519524SHoward Hinnant};
9693e519524SHoward Hinnant
9703e519524SHoward Hinnanttemplate<class _CharT, class _Traits>
971e2f2d1edSEric Fiselierclass _LIBCPP_TEMPLATE_VIS istreambuf_iterator
9723e519524SHoward Hinnant    : public iterator<input_iterator_tag, _CharT,
9733e519524SHoward Hinnant                      typename _Traits::off_type, _CharT*,
9743e519524SHoward Hinnant                      _CharT>
9753e519524SHoward Hinnant{
9763e519524SHoward Hinnantpublic:
9773e519524SHoward Hinnant    typedef _CharT                          char_type;
9783e519524SHoward Hinnant    typedef _Traits                         traits_type;
9793e519524SHoward Hinnant    typedef typename _Traits::int_type      int_type;
9803e519524SHoward Hinnant    typedef basic_streambuf<_CharT,_Traits> streambuf_type;
9813e519524SHoward Hinnant    typedef basic_istream<_CharT,_Traits>   istream_type;
9823e519524SHoward Hinnantprivate:
983dfdf5085SHoward Hinnant    mutable streambuf_type* __sbuf_;
9843e519524SHoward Hinnant
9853e519524SHoward Hinnant    class __proxy
9863e519524SHoward Hinnant    {
9873e519524SHoward Hinnant        char_type __keep_;
9883e519524SHoward Hinnant        streambuf_type* __sbuf_;
9893e519524SHoward Hinnant        _LIBCPP_INLINE_VISIBILITY __proxy(char_type __c, streambuf_type* __s)
9903e519524SHoward Hinnant            : __keep_(__c), __sbuf_(__s) {}
9913e519524SHoward Hinnant        friend class istreambuf_iterator;
9923e519524SHoward Hinnant    public:
9933e519524SHoward Hinnant        _LIBCPP_INLINE_VISIBILITY char_type operator*() const {return __keep_;}
9943e519524SHoward Hinnant    };
9953e519524SHoward Hinnant
996848a5374SHoward Hinnant    _LIBCPP_INLINE_VISIBILITY
997dfdf5085SHoward Hinnant    bool __test_for_eof() const
9983e519524SHoward Hinnant    {
9993e519524SHoward Hinnant        if (__sbuf_ && traits_type::eq_int_type(__sbuf_->sgetc(), traits_type::eof()))
1000527a7fdfSBruce Mitchener            __sbuf_ = nullptr;
1001527a7fdfSBruce Mitchener        return __sbuf_ == nullptr;
10023e519524SHoward Hinnant    }
10033e519524SHoward Hinnantpublic:
1004527a7fdfSBruce Mitchener    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR istreambuf_iterator() _NOEXCEPT : __sbuf_(nullptr) {}
10058e882dcbSHoward Hinnant    _LIBCPP_INLINE_VISIBILITY istreambuf_iterator(istream_type& __s) _NOEXCEPT
1006a96d7458SHoward Hinnant        : __sbuf_(__s.rdbuf()) {}
10078e882dcbSHoward Hinnant    _LIBCPP_INLINE_VISIBILITY istreambuf_iterator(streambuf_type* __s) _NOEXCEPT
1008a96d7458SHoward Hinnant        : __sbuf_(__s) {}
10098e882dcbSHoward Hinnant    _LIBCPP_INLINE_VISIBILITY istreambuf_iterator(const __proxy& __p) _NOEXCEPT
10103e519524SHoward Hinnant        : __sbuf_(__p.__sbuf_) {}
10113e519524SHoward Hinnant
1012c206366fSHoward Hinnant    _LIBCPP_INLINE_VISIBILITY char_type  operator*() const
1013c206366fSHoward Hinnant        {return static_cast<char_type>(__sbuf_->sgetc());}
10143e519524SHoward Hinnant    _LIBCPP_INLINE_VISIBILITY istreambuf_iterator& operator++()
10153e519524SHoward Hinnant        {
1016dfdf5085SHoward Hinnant            __sbuf_->sbumpc();
10173e519524SHoward Hinnant            return *this;
10183e519524SHoward Hinnant        }
10193e519524SHoward Hinnant    _LIBCPP_INLINE_VISIBILITY __proxy              operator++(int)
10203e519524SHoward Hinnant        {
1021dfdf5085SHoward Hinnant            return __proxy(__sbuf_->sbumpc(), __sbuf_);
10223e519524SHoward Hinnant        }
10233e519524SHoward Hinnant
10243e519524SHoward Hinnant    _LIBCPP_INLINE_VISIBILITY bool equal(const istreambuf_iterator& __b) const
1025dfdf5085SHoward Hinnant        {return __test_for_eof() == __b.__test_for_eof();}
10263e519524SHoward Hinnant};
10273e519524SHoward Hinnant
10283e519524SHoward Hinnanttemplate <class _CharT, class _Traits>
10293e519524SHoward Hinnantinline _LIBCPP_INLINE_VISIBILITY
10303e519524SHoward Hinnantbool operator==(const istreambuf_iterator<_CharT,_Traits>& __a,
10313e519524SHoward Hinnant                const istreambuf_iterator<_CharT,_Traits>& __b)
10323e519524SHoward Hinnant                {return __a.equal(__b);}
10333e519524SHoward Hinnant
10343e519524SHoward Hinnanttemplate <class _CharT, class _Traits>
10353e519524SHoward Hinnantinline _LIBCPP_INLINE_VISIBILITY
10363e519524SHoward Hinnantbool operator!=(const istreambuf_iterator<_CharT,_Traits>& __a,
10373e519524SHoward Hinnant                const istreambuf_iterator<_CharT,_Traits>& __b)
10383e519524SHoward Hinnant                {return !__a.equal(__b);}
10393e519524SHoward Hinnant
10403e519524SHoward Hinnanttemplate <class _CharT, class _Traits>
1041e2f2d1edSEric Fiselierclass _LIBCPP_TEMPLATE_VIS ostreambuf_iterator
10423e519524SHoward Hinnant    : public iterator<output_iterator_tag, void, void, void, void>
10433e519524SHoward Hinnant{
10443e519524SHoward Hinnantpublic:
104571a16e40SLouis Dionne    typedef output_iterator_tag                 iterator_category;
104671a16e40SLouis Dionne    typedef void                                value_type;
104771a16e40SLouis Dionne#if _LIBCPP_STD_VER > 17
104871a16e40SLouis Dionne    typedef std::ptrdiff_t                      difference_type;
104971a16e40SLouis Dionne#else
105071a16e40SLouis Dionne    typedef void                                difference_type;
105171a16e40SLouis Dionne#endif
105271a16e40SLouis Dionne    typedef void                                pointer;
105371a16e40SLouis Dionne    typedef void                                reference;
10543e519524SHoward Hinnant    typedef _CharT                              char_type;
10553e519524SHoward Hinnant    typedef _Traits                             traits_type;
10563e519524SHoward Hinnant    typedef basic_streambuf<_CharT, _Traits>    streambuf_type;
10573e519524SHoward Hinnant    typedef basic_ostream<_CharT, _Traits>      ostream_type;
105871a16e40SLouis Dionne
10593e519524SHoward Hinnantprivate:
10603e519524SHoward Hinnant    streambuf_type* __sbuf_;
10613e519524SHoward Hinnantpublic:
10628e882dcbSHoward Hinnant    _LIBCPP_INLINE_VISIBILITY ostreambuf_iterator(ostream_type& __s) _NOEXCEPT
10633e519524SHoward Hinnant        : __sbuf_(__s.rdbuf()) {}
10648e882dcbSHoward Hinnant    _LIBCPP_INLINE_VISIBILITY ostreambuf_iterator(streambuf_type* __s) _NOEXCEPT
10653e519524SHoward Hinnant        : __sbuf_(__s) {}
10663e519524SHoward Hinnant    _LIBCPP_INLINE_VISIBILITY ostreambuf_iterator& operator=(_CharT __c)
10673e519524SHoward Hinnant        {
10683e519524SHoward Hinnant            if (__sbuf_ && traits_type::eq_int_type(__sbuf_->sputc(__c), traits_type::eof()))
1069527a7fdfSBruce Mitchener                __sbuf_ = nullptr;
10703e519524SHoward Hinnant            return *this;
10713e519524SHoward Hinnant        }
10723e519524SHoward Hinnant    _LIBCPP_INLINE_VISIBILITY ostreambuf_iterator& operator*()     {return *this;}
10733e519524SHoward Hinnant    _LIBCPP_INLINE_VISIBILITY ostreambuf_iterator& operator++()    {return *this;}
10743e519524SHoward Hinnant    _LIBCPP_INLINE_VISIBILITY ostreambuf_iterator& operator++(int) {return *this;}
1075527a7fdfSBruce Mitchener    _LIBCPP_INLINE_VISIBILITY bool failed() const _NOEXCEPT {return __sbuf_ == nullptr;}
107692b5940fSHoward Hinnant
107792b5940fSHoward Hinnant    template <class _Ch, class _Tr>
107892b5940fSHoward Hinnant    friend
107992b5940fSHoward Hinnant    _LIBCPP_HIDDEN
108092b5940fSHoward Hinnant    ostreambuf_iterator<_Ch, _Tr>
108192b5940fSHoward Hinnant    __pad_and_output(ostreambuf_iterator<_Ch, _Tr> __s,
108292b5940fSHoward Hinnant                     const _Ch* __ob, const _Ch* __op, const _Ch* __oe,
108392b5940fSHoward Hinnant                     ios_base& __iob, _Ch __fl);
10843e519524SHoward Hinnant};
10853e519524SHoward Hinnant
10863e519524SHoward Hinnanttemplate <class _Iter>
1087e2f2d1edSEric Fiselierclass _LIBCPP_TEMPLATE_VIS move_iterator
10883e519524SHoward Hinnant{
10893e519524SHoward Hinnantprivate:
10903e519524SHoward Hinnant    _Iter __i;
10913e519524SHoward Hinnantpublic:
10923e519524SHoward Hinnant    typedef _Iter                                            iterator_type;
10933e519524SHoward Hinnant    typedef typename iterator_traits<iterator_type>::value_type value_type;
10943e519524SHoward Hinnant    typedef typename iterator_traits<iterator_type>::difference_type difference_type;
109505333fc8SMarshall Clow    typedef iterator_type pointer;
1096d41c6d51SArthur O'Dwyer    typedef _If<__is_cpp17_random_access_iterator<_Iter>::value,
1097d41c6d51SArthur O'Dwyer        random_access_iterator_tag,
1098d41c6d51SArthur O'Dwyer        typename iterator_traits<_Iter>::iterator_category>  iterator_category;
1099d41c6d51SArthur O'Dwyer#if _LIBCPP_STD_VER > 17
1100d41c6d51SArthur O'Dwyer    typedef input_iterator_tag                               iterator_concept;
1101d41c6d51SArthur O'Dwyer#endif
1102d41c6d51SArthur O'Dwyer
1103046492b9SEric Fiselier#ifndef _LIBCPP_CXX03_LANG
1104906c5085SEric Fiselier    typedef typename iterator_traits<iterator_type>::reference __reference;
1105906c5085SEric Fiselier    typedef typename conditional<
1106906c5085SEric Fiselier            is_reference<__reference>::value,
1107906c5085SEric Fiselier            typename remove_reference<__reference>::type&&,
1108906c5085SEric Fiselier            __reference
1109906c5085SEric Fiselier        >::type reference;
11103e519524SHoward Hinnant#else
11113e519524SHoward Hinnant    typedef typename iterator_traits<iterator_type>::reference reference;
11123e519524SHoward Hinnant#endif
11133e519524SHoward Hinnant
1114720ef472SMarshall Clow    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
1115720ef472SMarshall Clow    move_iterator() : __i() {}
1116720ef472SMarshall Clow    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
1117720ef472SMarshall Clow    explicit move_iterator(_Iter __x) : __i(__x) {}
1118720ef472SMarshall Clow    template <class _Up>
1119720ef472SMarshall Clow      _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
1120720ef472SMarshall Clow      move_iterator(const move_iterator<_Up>& __u) : __i(__u.base()) {}
1121720ef472SMarshall Clow    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 _Iter base() const {return __i;}
1122720ef472SMarshall Clow    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
1123720ef472SMarshall Clow    reference operator*() const { return static_cast<reference>(*__i); }
1124720ef472SMarshall Clow    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
1125720ef472SMarshall Clow    pointer  operator->() const { return __i;}
1126720ef472SMarshall Clow    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
1127720ef472SMarshall Clow    move_iterator& operator++() {++__i; return *this;}
1128720ef472SMarshall Clow    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
1129720ef472SMarshall Clow    move_iterator  operator++(int) {move_iterator __tmp(*this); ++__i; return __tmp;}
1130720ef472SMarshall Clow    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
1131720ef472SMarshall Clow    move_iterator& operator--() {--__i; return *this;}
1132720ef472SMarshall Clow    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
1133720ef472SMarshall Clow    move_iterator  operator--(int) {move_iterator __tmp(*this); --__i; return __tmp;}
1134720ef472SMarshall Clow    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
1135720ef472SMarshall Clow    move_iterator  operator+ (difference_type __n) const {return move_iterator(__i + __n);}
1136720ef472SMarshall Clow    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
1137720ef472SMarshall Clow    move_iterator& operator+=(difference_type __n) {__i += __n; return *this;}
1138720ef472SMarshall Clow    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
1139720ef472SMarshall Clow    move_iterator  operator- (difference_type __n) const {return move_iterator(__i - __n);}
1140720ef472SMarshall Clow    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
1141720ef472SMarshall Clow    move_iterator& operator-=(difference_type __n) {__i -= __n; return *this;}
1142720ef472SMarshall Clow    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
1143720ef472SMarshall Clow    reference operator[](difference_type __n) const { return static_cast<reference>(__i[__n]); }
11443e519524SHoward Hinnant};
11453e519524SHoward Hinnant
11463e519524SHoward Hinnanttemplate <class _Iter1, class _Iter2>
1147720ef472SMarshall Clowinline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
11483e519524SHoward Hinnantbool
11493e519524SHoward Hinnantoperator==(const move_iterator<_Iter1>& __x, const move_iterator<_Iter2>& __y)
11503e519524SHoward Hinnant{
11513e519524SHoward Hinnant    return __x.base() == __y.base();
11523e519524SHoward Hinnant}
11533e519524SHoward Hinnant
11543e519524SHoward Hinnanttemplate <class _Iter1, class _Iter2>
1155720ef472SMarshall Clowinline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
11563e519524SHoward Hinnantbool
11573e519524SHoward Hinnantoperator<(const move_iterator<_Iter1>& __x, const move_iterator<_Iter2>& __y)
11583e519524SHoward Hinnant{
11593e519524SHoward Hinnant    return __x.base() < __y.base();
11603e519524SHoward Hinnant}
11613e519524SHoward Hinnant
11623e519524SHoward Hinnanttemplate <class _Iter1, class _Iter2>
1163720ef472SMarshall Clowinline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
11643e519524SHoward Hinnantbool
11653e519524SHoward Hinnantoperator!=(const move_iterator<_Iter1>& __x, const move_iterator<_Iter2>& __y)
11663e519524SHoward Hinnant{
11673e519524SHoward Hinnant    return __x.base() != __y.base();
11683e519524SHoward Hinnant}
11693e519524SHoward Hinnant
11703e519524SHoward Hinnanttemplate <class _Iter1, class _Iter2>
1171720ef472SMarshall Clowinline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
11723e519524SHoward Hinnantbool
11733e519524SHoward Hinnantoperator>(const move_iterator<_Iter1>& __x, const move_iterator<_Iter2>& __y)
11743e519524SHoward Hinnant{
11753e519524SHoward Hinnant    return __x.base() > __y.base();
11763e519524SHoward Hinnant}
11773e519524SHoward Hinnant
11783e519524SHoward Hinnanttemplate <class _Iter1, class _Iter2>
1179720ef472SMarshall Clowinline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
11803e519524SHoward Hinnantbool
11813e519524SHoward Hinnantoperator>=(const move_iterator<_Iter1>& __x, const move_iterator<_Iter2>& __y)
11823e519524SHoward Hinnant{
11833e519524SHoward Hinnant    return __x.base() >= __y.base();
11843e519524SHoward Hinnant}
11853e519524SHoward Hinnant
11863e519524SHoward Hinnanttemplate <class _Iter1, class _Iter2>
1187720ef472SMarshall Clowinline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
11883e519524SHoward Hinnantbool
11893e519524SHoward Hinnantoperator<=(const move_iterator<_Iter1>& __x, const move_iterator<_Iter2>& __y)
11903e519524SHoward Hinnant{
11913e519524SHoward Hinnant    return __x.base() <= __y.base();
11923e519524SHoward Hinnant}
11933e519524SHoward Hinnant
11942ee83725SMarshall Clow#ifndef _LIBCPP_CXX03_LANG
1195947ce6b5SMarshall Clowtemplate <class _Iter1, class _Iter2>
1196720ef472SMarshall Clowinline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
1197947ce6b5SMarshall Clowauto
1198947ce6b5SMarshall Clowoperator-(const move_iterator<_Iter1>& __x, const move_iterator<_Iter2>& __y)
1199947ce6b5SMarshall Clow-> decltype(__x.base() - __y.base())
1200947ce6b5SMarshall Clow{
1201947ce6b5SMarshall Clow    return __x.base() - __y.base();
1202947ce6b5SMarshall Clow}
1203947ce6b5SMarshall Clow#else
12043e519524SHoward Hinnanttemplate <class _Iter1, class _Iter2>
12053e519524SHoward Hinnantinline _LIBCPP_INLINE_VISIBILITY
12063e519524SHoward Hinnanttypename move_iterator<_Iter1>::difference_type
12073e519524SHoward Hinnantoperator-(const move_iterator<_Iter1>& __x, const move_iterator<_Iter2>& __y)
12083e519524SHoward Hinnant{
12093e519524SHoward Hinnant    return __x.base() - __y.base();
12103e519524SHoward Hinnant}
1211947ce6b5SMarshall Clow#endif
12123e519524SHoward Hinnant
12133e519524SHoward Hinnanttemplate <class _Iter>
1214720ef472SMarshall Clowinline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
12153e519524SHoward Hinnantmove_iterator<_Iter>
12163e519524SHoward Hinnantoperator+(typename move_iterator<_Iter>::difference_type __n, const move_iterator<_Iter>& __x)
12173e519524SHoward Hinnant{
12183e519524SHoward Hinnant    return move_iterator<_Iter>(__x.base() + __n);
12193e519524SHoward Hinnant}
12203e519524SHoward Hinnant
12213e519524SHoward Hinnanttemplate <class _Iter>
1222720ef472SMarshall Clowinline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
12233e519524SHoward Hinnantmove_iterator<_Iter>
122454c83368SMarshall Clowmake_move_iterator(_Iter __i)
12253e519524SHoward Hinnant{
12263e519524SHoward Hinnant    return move_iterator<_Iter>(__i);
12273e519524SHoward Hinnant}
12283e519524SHoward Hinnant
12293e519524SHoward Hinnant// __wrap_iter
12303e519524SHoward Hinnant
12313e519524SHoward Hinnanttemplate <class _Iter> class __wrap_iter;
12323e519524SHoward Hinnant
12333e519524SHoward Hinnanttemplate <class _Iter1, class _Iter2>
12349cad5025SMarshall Clow_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG
12353e519524SHoward Hinnantbool
123661b302f9SEric Fiselieroperator==(const __wrap_iter<_Iter1>&, const __wrap_iter<_Iter2>&) _NOEXCEPT;
12373e519524SHoward Hinnant
12383e519524SHoward Hinnanttemplate <class _Iter1, class _Iter2>
12399cad5025SMarshall Clow_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG
12403e519524SHoward Hinnantbool
124161b302f9SEric Fiselieroperator<(const __wrap_iter<_Iter1>&, const __wrap_iter<_Iter2>&) _NOEXCEPT;
12423e519524SHoward Hinnant
12433e519524SHoward Hinnanttemplate <class _Iter1, class _Iter2>
12449cad5025SMarshall Clow_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG
12453e519524SHoward Hinnantbool
124661b302f9SEric Fiselieroperator!=(const __wrap_iter<_Iter1>&, const __wrap_iter<_Iter2>&) _NOEXCEPT;
12473e519524SHoward Hinnant
12483e519524SHoward Hinnanttemplate <class _Iter1, class _Iter2>
12499cad5025SMarshall Clow_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG
12503e519524SHoward Hinnantbool
125161b302f9SEric Fiselieroperator>(const __wrap_iter<_Iter1>&, const __wrap_iter<_Iter2>&) _NOEXCEPT;
12523e519524SHoward Hinnant
12533e519524SHoward Hinnanttemplate <class _Iter1, class _Iter2>
12549cad5025SMarshall Clow_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG
12553e519524SHoward Hinnantbool
125661b302f9SEric Fiselieroperator>=(const __wrap_iter<_Iter1>&, const __wrap_iter<_Iter2>&) _NOEXCEPT;
12573e519524SHoward Hinnant
12583e519524SHoward Hinnanttemplate <class _Iter1, class _Iter2>
12599cad5025SMarshall Clow_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG
12603e519524SHoward Hinnantbool
126161b302f9SEric Fiselieroperator<=(const __wrap_iter<_Iter1>&, const __wrap_iter<_Iter2>&) _NOEXCEPT;
12623e519524SHoward Hinnant
12632ee83725SMarshall Clow#ifndef _LIBCPP_CXX03_LANG
1264947ce6b5SMarshall Clowtemplate <class _Iter1, class _Iter2>
12659cad5025SMarshall Clow_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG
1266947ce6b5SMarshall Clowauto
126761b302f9SEric Fiselieroperator-(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter2>& __y) _NOEXCEPT
1268947ce6b5SMarshall Clow-> decltype(__x.base() - __y.base());
1269947ce6b5SMarshall Clow#else
12703e519524SHoward Hinnanttemplate <class _Iter1, class _Iter2>
1271aeb85680SHoward Hinnant_LIBCPP_INLINE_VISIBILITY
12723e519524SHoward Hinnanttypename __wrap_iter<_Iter1>::difference_type
127361b302f9SEric Fiselieroperator-(const __wrap_iter<_Iter1>&, const __wrap_iter<_Iter2>&) _NOEXCEPT;
1274947ce6b5SMarshall Clow#endif
12753e519524SHoward Hinnant
12763e519524SHoward Hinnanttemplate <class _Iter>
12779cad5025SMarshall Clow_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG
12783e519524SHoward Hinnant__wrap_iter<_Iter>
127961b302f9SEric Fiselieroperator+(typename __wrap_iter<_Iter>::difference_type, __wrap_iter<_Iter>) _NOEXCEPT;
12803e519524SHoward Hinnant
128113c90a57SLouis Dionnetemplate <class _Ip, class _Op> _Op _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 copy(_Ip, _Ip, _Op);
128213c90a57SLouis Dionnetemplate <class _B1, class _B2> _B2 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 copy_backward(_B1, _B1, _B2);
12833ed89b51Szoecarvertemplate <class _Ip, class _Op> _Op _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 move(_Ip, _Ip, _Op);
12843ed89b51Szoecarvertemplate <class _B1, class _B2> _B2 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 move_backward(_B1, _B1, _B2);
12853e519524SHoward Hinnant
12863e519524SHoward Hinnanttemplate <class _Iter>
12873e519524SHoward Hinnantclass __wrap_iter
12883e519524SHoward Hinnant{
12893e519524SHoward Hinnantpublic:
12903e519524SHoward Hinnant    typedef _Iter                                                      iterator_type;
12913e519524SHoward Hinnant    typedef typename iterator_traits<iterator_type>::value_type        value_type;
12923e519524SHoward Hinnant    typedef typename iterator_traits<iterator_type>::difference_type   difference_type;
12933e519524SHoward Hinnant    typedef typename iterator_traits<iterator_type>::pointer           pointer;
12943e519524SHoward Hinnant    typedef typename iterator_traits<iterator_type>::reference         reference;
1295d41c6d51SArthur O'Dwyer    typedef typename iterator_traits<iterator_type>::iterator_category iterator_category;
1296d41c6d51SArthur O'Dwyer#if _LIBCPP_STD_VER > 17
1297d41c6d51SArthur O'Dwyer    typedef _If<__is_cpp17_contiguous_iterator<_Iter>::value,
1298d41c6d51SArthur O'Dwyer                contiguous_iterator_tag, iterator_category>            iterator_concept;
1299d41c6d51SArthur O'Dwyer#endif
1300d41c6d51SArthur O'Dwyer
13013e519524SHoward Hinnantprivate:
13023e519524SHoward Hinnant    iterator_type __i;
13033e519524SHoward Hinnantpublic:
130461b302f9SEric Fiselier    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG __wrap_iter() _NOEXCEPT
130507186a7dSMarshall Clow#if _LIBCPP_STD_VER > 11
130607186a7dSMarshall Clow                : __i{}
130707186a7dSMarshall Clow#endif
1308c36bfc49SHoward Hinnant    {
130931e82037SLouis Dionne#if _LIBCPP_DEBUG_LEVEL == 2
1310c36bfc49SHoward Hinnant        __get_db()->__insert_i(this);
1311c36bfc49SHoward Hinnant#endif
1312c36bfc49SHoward Hinnant    }
13139cad5025SMarshall Clow    template <class _Up> _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG
13149cad5025SMarshall Clow        __wrap_iter(const __wrap_iter<_Up>& __u,
1315527a7fdfSBruce Mitchener            typename enable_if<is_convertible<_Up, iterator_type>::value>::type* = nullptr) _NOEXCEPT
1316f554add5SHoward Hinnant            : __i(__u.base())
1317f554add5SHoward Hinnant    {
131831e82037SLouis Dionne#if _LIBCPP_DEBUG_LEVEL == 2
1319f554add5SHoward Hinnant        __get_db()->__iterator_copy(this, &__u);
1320f554add5SHoward Hinnant#endif
1321f554add5SHoward Hinnant    }
132231e82037SLouis Dionne#if _LIBCPP_DEBUG_LEVEL == 2
13239cad5025SMarshall Clow    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG
1324f554add5SHoward Hinnant    __wrap_iter(const __wrap_iter& __x)
1325f554add5SHoward Hinnant        : __i(__x.base())
1326f554add5SHoward Hinnant    {
1327f554add5SHoward Hinnant        __get_db()->__iterator_copy(this, &__x);
1328f554add5SHoward Hinnant    }
13299cad5025SMarshall Clow    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG
1330f554add5SHoward Hinnant    __wrap_iter& operator=(const __wrap_iter& __x)
1331f554add5SHoward Hinnant    {
1332f554add5SHoward Hinnant        if (this != &__x)
1333f554add5SHoward Hinnant        {
1334f554add5SHoward Hinnant            __get_db()->__iterator_copy(this, &__x);
1335f554add5SHoward Hinnant            __i = __x.__i;
1336f554add5SHoward Hinnant        }
1337f554add5SHoward Hinnant        return *this;
1338f554add5SHoward Hinnant    }
13399cad5025SMarshall Clow    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG
1340f554add5SHoward Hinnant    ~__wrap_iter()
1341f554add5SHoward Hinnant    {
1342f554add5SHoward Hinnant        __get_db()->__erase_i(this);
1343f554add5SHoward Hinnant    }
1344f554add5SHoward Hinnant#endif
134561b302f9SEric Fiselier    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG reference operator*() const _NOEXCEPT
1346f554add5SHoward Hinnant    {
134731e82037SLouis Dionne#if _LIBCPP_DEBUG_LEVEL == 2
1348f554add5SHoward Hinnant        _LIBCPP_ASSERT(__get_const_db()->__dereferenceable(this),
1349f554add5SHoward Hinnant                       "Attempted to dereference a non-dereferenceable iterator");
1350cec9af9eSHoward Hinnant#endif
1351f554add5SHoward Hinnant        return *__i;
1352f554add5SHoward Hinnant    }
135361b302f9SEric Fiselier    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG pointer  operator->() const _NOEXCEPT
13543ec1f00bSHoward Hinnant    {
135531e82037SLouis Dionne#if _LIBCPP_DEBUG_LEVEL == 2
13563ec1f00bSHoward Hinnant        _LIBCPP_ASSERT(__get_const_db()->__dereferenceable(this),
13573ec1f00bSHoward Hinnant                       "Attempted to dereference a non-dereferenceable iterator");
13583ec1f00bSHoward Hinnant#endif
1359347f69c5SLouis Dionne        return (pointer)_VSTD::addressof(*__i);
13603ec1f00bSHoward Hinnant    }
136161b302f9SEric Fiselier    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG __wrap_iter& operator++() _NOEXCEPT
1362f554add5SHoward Hinnant    {
136331e82037SLouis Dionne#if _LIBCPP_DEBUG_LEVEL == 2
1364f554add5SHoward Hinnant        _LIBCPP_ASSERT(__get_const_db()->__dereferenceable(this),
1365f554add5SHoward Hinnant                       "Attempted to increment non-incrementable iterator");
1366cec9af9eSHoward Hinnant#endif
1367f554add5SHoward Hinnant        ++__i;
1368f554add5SHoward Hinnant        return *this;
1369f554add5SHoward Hinnant    }
137061b302f9SEric Fiselier    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG __wrap_iter  operator++(int) _NOEXCEPT
1371f554add5SHoward Hinnant        {__wrap_iter __tmp(*this); ++(*this); return __tmp;}
13724ce0a916SMarshall Clow
137361b302f9SEric Fiselier    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG __wrap_iter& operator--() _NOEXCEPT
1374f554add5SHoward Hinnant    {
137531e82037SLouis Dionne#if _LIBCPP_DEBUG_LEVEL == 2
1376f554add5SHoward Hinnant        _LIBCPP_ASSERT(__get_const_db()->__decrementable(this),
1377f554add5SHoward Hinnant                       "Attempted to decrement non-decrementable iterator");
1378cec9af9eSHoward Hinnant#endif
1379f554add5SHoward Hinnant        --__i;
1380f554add5SHoward Hinnant        return *this;
1381f554add5SHoward Hinnant    }
138261b302f9SEric Fiselier    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG __wrap_iter  operator--(int) _NOEXCEPT
1383f554add5SHoward Hinnant        {__wrap_iter __tmp(*this); --(*this); return __tmp;}
138461b302f9SEric Fiselier    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG __wrap_iter  operator+ (difference_type __n) const _NOEXCEPT
1385f554add5SHoward Hinnant        {__wrap_iter __w(*this); __w += __n; return __w;}
138661b302f9SEric Fiselier    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG __wrap_iter& operator+=(difference_type __n) _NOEXCEPT
1387f554add5SHoward Hinnant    {
138831e82037SLouis Dionne#if _LIBCPP_DEBUG_LEVEL == 2
1389f554add5SHoward Hinnant        _LIBCPP_ASSERT(__get_const_db()->__addable(this, __n),
1390f554add5SHoward Hinnant                   "Attempted to add/subtract iterator outside of valid range");
1391cec9af9eSHoward Hinnant#endif
1392f554add5SHoward Hinnant        __i += __n;
1393f554add5SHoward Hinnant        return *this;
1394f554add5SHoward Hinnant    }
139561b302f9SEric Fiselier    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG __wrap_iter  operator- (difference_type __n) const _NOEXCEPT
1396f554add5SHoward Hinnant        {return *this + (-__n);}
139761b302f9SEric Fiselier    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG __wrap_iter& operator-=(difference_type __n) _NOEXCEPT
1398f554add5SHoward Hinnant        {*this += -__n; return *this;}
139961b302f9SEric Fiselier    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG reference    operator[](difference_type __n) const _NOEXCEPT
1400f554add5SHoward Hinnant    {
140131e82037SLouis Dionne#if _LIBCPP_DEBUG_LEVEL == 2
1402f554add5SHoward Hinnant        _LIBCPP_ASSERT(__get_const_db()->__subscriptable(this, __n),
1403f554add5SHoward Hinnant                   "Attempted to subscript iterator outside of valid range");
1404cec9af9eSHoward Hinnant#endif
1405f554add5SHoward Hinnant        return __i[__n];
1406f554add5SHoward Hinnant    }
14073e519524SHoward Hinnant
140861b302f9SEric Fiselier    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG iterator_type base() const _NOEXCEPT {return __i;}
14093e519524SHoward Hinnant
14103e519524SHoward Hinnantprivate:
141131e82037SLouis Dionne#if _LIBCPP_DEBUG_LEVEL == 2
14129cad5025SMarshall Clow    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG __wrap_iter(const void* __p, iterator_type __x) : __i(__x)
1413f554add5SHoward Hinnant    {
1414f554add5SHoward Hinnant        __get_db()->__insert_ic(this, __p);
1415f554add5SHoward Hinnant    }
1416fc88dbd2SHoward Hinnant#else
141761b302f9SEric Fiselier    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG __wrap_iter(iterator_type __x) _NOEXCEPT : __i(__x) {}
1418f554add5SHoward Hinnant#endif
14193e519524SHoward Hinnant
14203e519524SHoward Hinnant    template <class _Up> friend class __wrap_iter;
14213e519524SHoward Hinnant    template <class _CharT, class _Traits, class _Alloc> friend class basic_string;
1422e2f2d1edSEric Fiselier    template <class _Tp, class _Alloc> friend class _LIBCPP_TEMPLATE_VIS vector;
14237ad06a93SMarshall Clow    template <class _Tp, size_t> friend class _LIBCPP_TEMPLATE_VIS span;
14243e519524SHoward Hinnant
14253e519524SHoward Hinnant    template <class _Iter1, class _Iter2>
14269cad5025SMarshall Clow    _LIBCPP_CONSTEXPR_IF_NODEBUG friend
14273e519524SHoward Hinnant    bool
142861b302f9SEric Fiselier    operator==(const __wrap_iter<_Iter1>&, const __wrap_iter<_Iter2>&) _NOEXCEPT;
14293e519524SHoward Hinnant
14303e519524SHoward Hinnant    template <class _Iter1, class _Iter2>
14319cad5025SMarshall Clow    _LIBCPP_CONSTEXPR_IF_NODEBUG friend
14323e519524SHoward Hinnant    bool
143361b302f9SEric Fiselier    operator<(const __wrap_iter<_Iter1>&, const __wrap_iter<_Iter2>&) _NOEXCEPT;
14343e519524SHoward Hinnant
14353e519524SHoward Hinnant    template <class _Iter1, class _Iter2>
14369cad5025SMarshall Clow    _LIBCPP_CONSTEXPR_IF_NODEBUG friend
14373e519524SHoward Hinnant    bool
143861b302f9SEric Fiselier    operator!=(const __wrap_iter<_Iter1>&, const __wrap_iter<_Iter2>&) _NOEXCEPT;
14393e519524SHoward Hinnant
14403e519524SHoward Hinnant    template <class _Iter1, class _Iter2>
14419cad5025SMarshall Clow    _LIBCPP_CONSTEXPR_IF_NODEBUG friend
14423e519524SHoward Hinnant    bool
144361b302f9SEric Fiselier    operator>(const __wrap_iter<_Iter1>&, const __wrap_iter<_Iter2>&) _NOEXCEPT;
14443e519524SHoward Hinnant
14453e519524SHoward Hinnant    template <class _Iter1, class _Iter2>
14469cad5025SMarshall Clow    _LIBCPP_CONSTEXPR_IF_NODEBUG friend
14473e519524SHoward Hinnant    bool
144861b302f9SEric Fiselier    operator>=(const __wrap_iter<_Iter1>&, const __wrap_iter<_Iter2>&) _NOEXCEPT;
14493e519524SHoward Hinnant
14503e519524SHoward Hinnant    template <class _Iter1, class _Iter2>
14519cad5025SMarshall Clow    _LIBCPP_CONSTEXPR_IF_NODEBUG friend
14523e519524SHoward Hinnant    bool
145361b302f9SEric Fiselier    operator<=(const __wrap_iter<_Iter1>&, const __wrap_iter<_Iter2>&) _NOEXCEPT;
14543e519524SHoward Hinnant
14552ee83725SMarshall Clow#ifndef _LIBCPP_CXX03_LANG
1456947ce6b5SMarshall Clow    template <class _Iter1, class _Iter2>
14579cad5025SMarshall Clow    _LIBCPP_CONSTEXPR_IF_NODEBUG friend
1458947ce6b5SMarshall Clow    auto
145961b302f9SEric Fiselier    operator-(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter2>& __y) _NOEXCEPT
1460947ce6b5SMarshall Clow    -> decltype(__x.base() - __y.base());
1461947ce6b5SMarshall Clow#else
14623e519524SHoward Hinnant    template <class _Iter1, class _Iter2>
14639cad5025SMarshall Clow    _LIBCPP_CONSTEXPR_IF_NODEBUG friend
14643e519524SHoward Hinnant    typename __wrap_iter<_Iter1>::difference_type
146561b302f9SEric Fiselier    operator-(const __wrap_iter<_Iter1>&, const __wrap_iter<_Iter2>&) _NOEXCEPT;
1466947ce6b5SMarshall Clow#endif
14673e519524SHoward Hinnant
14683e519524SHoward Hinnant    template <class _Iter1>
14699cad5025SMarshall Clow    _LIBCPP_CONSTEXPR_IF_NODEBUG friend
14703e519524SHoward Hinnant    __wrap_iter<_Iter1>
147161b302f9SEric Fiselier    operator+(typename __wrap_iter<_Iter1>::difference_type, __wrap_iter<_Iter1>) _NOEXCEPT;
14723e519524SHoward Hinnant};
14733e519524SHoward Hinnant
1474d41c6d51SArthur O'Dwyer#if _LIBCPP_STD_VER <= 17
1475d41c6d51SArthur O'Dwyertemplate <class _It>
1476d41c6d51SArthur O'Dwyerstruct __is_cpp17_contiguous_iterator<__wrap_iter<_It> > : __is_cpp17_contiguous_iterator<_It> {};
1477d41c6d51SArthur O'Dwyer#endif
1478d41c6d51SArthur O'Dwyer
1479d41c6d51SArthur O'Dwyertemplate <class _Iter>
1480d41c6d51SArthur O'Dwyer_LIBCPP_CONSTEXPR
1481d41c6d51SArthur O'Dwyer_EnableIf<__is_cpp17_contiguous_iterator<_Iter>::value, decltype(_VSTD::__to_address(declval<_Iter>()))>
1482d41c6d51SArthur O'Dwyer__to_address(__wrap_iter<_Iter> __w) _NOEXCEPT {
1483d41c6d51SArthur O'Dwyer    return _VSTD::__to_address(__w.base());
1484d41c6d51SArthur O'Dwyer}
1485d41c6d51SArthur O'Dwyer
14863e519524SHoward Hinnanttemplate <class _Iter1, class _Iter2>
14879cad5025SMarshall Clowinline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG
14883e519524SHoward Hinnantbool
148961b302f9SEric Fiselieroperator==(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter2>& __y) _NOEXCEPT
14903e519524SHoward Hinnant{
14913e519524SHoward Hinnant    return __x.base() == __y.base();
14923e519524SHoward Hinnant}
14933e519524SHoward Hinnant
14943e519524SHoward Hinnanttemplate <class _Iter1, class _Iter2>
14959cad5025SMarshall Clowinline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG
14963e519524SHoward Hinnantbool
149761b302f9SEric Fiselieroperator<(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter2>& __y) _NOEXCEPT
14983e519524SHoward Hinnant{
149931e82037SLouis Dionne#if _LIBCPP_DEBUG_LEVEL == 2
150042a3046eSHoward Hinnant    _LIBCPP_ASSERT(__get_const_db()->__less_than_comparable(&__x, &__y),
1501f554add5SHoward Hinnant                   "Attempted to compare incomparable iterators");
1502cec9af9eSHoward Hinnant#endif
15033e519524SHoward Hinnant    return __x.base() < __y.base();
15043e519524SHoward Hinnant}
15053e519524SHoward Hinnant
15063e519524SHoward Hinnanttemplate <class _Iter1, class _Iter2>
15079cad5025SMarshall Clowinline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG
15083e519524SHoward Hinnantbool
150961b302f9SEric Fiselieroperator!=(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter2>& __y) _NOEXCEPT
15103e519524SHoward Hinnant{
1511f554add5SHoward Hinnant    return !(__x == __y);
15123e519524SHoward Hinnant}
15133e519524SHoward Hinnant
15143e519524SHoward Hinnanttemplate <class _Iter1, class _Iter2>
15159cad5025SMarshall Clowinline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG
15163e519524SHoward Hinnantbool
151761b302f9SEric Fiselieroperator>(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter2>& __y) _NOEXCEPT
15183e519524SHoward Hinnant{
1519f554add5SHoward Hinnant    return __y < __x;
15203e519524SHoward Hinnant}
15213e519524SHoward Hinnant
15223e519524SHoward Hinnanttemplate <class _Iter1, class _Iter2>
15239cad5025SMarshall Clowinline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG
15243e519524SHoward Hinnantbool
152561b302f9SEric Fiselieroperator>=(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter2>& __y) _NOEXCEPT
15263e519524SHoward Hinnant{
1527f554add5SHoward Hinnant    return !(__x < __y);
15283e519524SHoward Hinnant}
15293e519524SHoward Hinnant
15303e519524SHoward Hinnanttemplate <class _Iter1, class _Iter2>
15319cad5025SMarshall Clowinline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG
15323e519524SHoward Hinnantbool
153361b302f9SEric Fiselieroperator<=(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter2>& __y) _NOEXCEPT
15343e519524SHoward Hinnant{
1535f554add5SHoward Hinnant    return !(__y < __x);
15363e519524SHoward Hinnant}
15373e519524SHoward Hinnant
15386e551ae1SHoward Hinnanttemplate <class _Iter1>
15399cad5025SMarshall Clowinline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG
15406e551ae1SHoward Hinnantbool
154161b302f9SEric Fiselieroperator!=(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter1>& __y) _NOEXCEPT
15426e551ae1SHoward Hinnant{
15436e551ae1SHoward Hinnant    return !(__x == __y);
15446e551ae1SHoward Hinnant}
15456e551ae1SHoward Hinnant
15466e551ae1SHoward Hinnanttemplate <class _Iter1>
15479cad5025SMarshall Clowinline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG
15486e551ae1SHoward Hinnantbool
154961b302f9SEric Fiselieroperator>(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter1>& __y) _NOEXCEPT
15506e551ae1SHoward Hinnant{
15516e551ae1SHoward Hinnant    return __y < __x;
15526e551ae1SHoward Hinnant}
15536e551ae1SHoward Hinnant
15546e551ae1SHoward Hinnanttemplate <class _Iter1>
15559cad5025SMarshall Clowinline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG
15566e551ae1SHoward Hinnantbool
155761b302f9SEric Fiselieroperator>=(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter1>& __y) _NOEXCEPT
15586e551ae1SHoward Hinnant{
15596e551ae1SHoward Hinnant    return !(__x < __y);
15606e551ae1SHoward Hinnant}
15616e551ae1SHoward Hinnant
15626e551ae1SHoward Hinnanttemplate <class _Iter1>
15639cad5025SMarshall Clowinline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG
15646e551ae1SHoward Hinnantbool
156561b302f9SEric Fiselieroperator<=(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter1>& __y) _NOEXCEPT
15666e551ae1SHoward Hinnant{
15676e551ae1SHoward Hinnant    return !(__y < __x);
15686e551ae1SHoward Hinnant}
15696e551ae1SHoward Hinnant
15702ee83725SMarshall Clow#ifndef _LIBCPP_CXX03_LANG
1571947ce6b5SMarshall Clowtemplate <class _Iter1, class _Iter2>
15729cad5025SMarshall Clowinline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG
1573947ce6b5SMarshall Clowauto
157461b302f9SEric Fiselieroperator-(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter2>& __y) _NOEXCEPT
1575947ce6b5SMarshall Clow-> decltype(__x.base() - __y.base())
1576947ce6b5SMarshall Clow{
157731e82037SLouis Dionne#if _LIBCPP_DEBUG_LEVEL == 2
1578947ce6b5SMarshall Clow    _LIBCPP_ASSERT(__get_const_db()->__less_than_comparable(&__x, &__y),
1579947ce6b5SMarshall Clow                   "Attempted to subtract incompatible iterators");
1580947ce6b5SMarshall Clow#endif
1581947ce6b5SMarshall Clow    return __x.base() - __y.base();
1582947ce6b5SMarshall Clow}
1583947ce6b5SMarshall Clow#else
15843e519524SHoward Hinnanttemplate <class _Iter1, class _Iter2>
15859cad5025SMarshall Clowinline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG
15863e519524SHoward Hinnanttypename __wrap_iter<_Iter1>::difference_type
158761b302f9SEric Fiselieroperator-(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter2>& __y) _NOEXCEPT
15883e519524SHoward Hinnant{
158931e82037SLouis Dionne#if _LIBCPP_DEBUG_LEVEL == 2
159042a3046eSHoward Hinnant    _LIBCPP_ASSERT(__get_const_db()->__less_than_comparable(&__x, &__y),
1591f554add5SHoward Hinnant                   "Attempted to subtract incompatible iterators");
1592cec9af9eSHoward Hinnant#endif
15933e519524SHoward Hinnant    return __x.base() - __y.base();
15943e519524SHoward Hinnant}
1595947ce6b5SMarshall Clow#endif
15963e519524SHoward Hinnant
15973e519524SHoward Hinnanttemplate <class _Iter>
15989cad5025SMarshall Clowinline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG
15993e519524SHoward Hinnant__wrap_iter<_Iter>
16003e519524SHoward Hinnantoperator+(typename __wrap_iter<_Iter>::difference_type __n,
160161b302f9SEric Fiselier          __wrap_iter<_Iter> __x) _NOEXCEPT
16023e519524SHoward Hinnant{
1603f554add5SHoward Hinnant    __x += __n;
1604f554add5SHoward Hinnant    return __x;
16053e519524SHoward Hinnant}
16063e519524SHoward Hinnant
16073772a46aSMarshall Clowtemplate <class _Tp, size_t _Np>
16082ffa1705SMarshall Clow_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
16093772a46aSMarshall Clow_Tp*
16103772a46aSMarshall Clowbegin(_Tp (&__array)[_Np])
16113772a46aSMarshall Clow{
16123772a46aSMarshall Clow    return __array;
16133772a46aSMarshall Clow}
16143772a46aSMarshall Clow
16153772a46aSMarshall Clowtemplate <class _Tp, size_t _Np>
16162ffa1705SMarshall Clow_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
16173772a46aSMarshall Clow_Tp*
16183772a46aSMarshall Clowend(_Tp (&__array)[_Np])
16193772a46aSMarshall Clow{
16203772a46aSMarshall Clow    return __array + _Np;
16213772a46aSMarshall Clow}
16223772a46aSMarshall Clow
162354613ab4SEric Fiselier#if !defined(_LIBCPP_CXX03_LANG)
1624c66a611bSMarshall Clow
1625c003db1fSHoward Hinnanttemplate <class _Cp>
16262ffa1705SMarshall Clow_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
16273e519524SHoward Hinnantauto
1628c003db1fSHoward Hinnantbegin(_Cp& __c) -> decltype(__c.begin())
16293e519524SHoward Hinnant{
16303e519524SHoward Hinnant    return __c.begin();
16313e519524SHoward Hinnant}
16323e519524SHoward Hinnant
1633c003db1fSHoward Hinnanttemplate <class _Cp>
16342ffa1705SMarshall Clow_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
16353e519524SHoward Hinnantauto
1636c003db1fSHoward Hinnantbegin(const _Cp& __c) -> decltype(__c.begin())
16373e519524SHoward Hinnant{
16383e519524SHoward Hinnant    return __c.begin();
16393e519524SHoward Hinnant}
16403e519524SHoward Hinnant
1641c003db1fSHoward Hinnanttemplate <class _Cp>
16422ffa1705SMarshall Clow_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
16433e519524SHoward Hinnantauto
1644c003db1fSHoward Hinnantend(_Cp& __c) -> decltype(__c.end())
16453e519524SHoward Hinnant{
16463e519524SHoward Hinnant    return __c.end();
16473e519524SHoward Hinnant}
16483e519524SHoward Hinnant
1649c003db1fSHoward Hinnanttemplate <class _Cp>
16502ffa1705SMarshall Clow_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
16513e519524SHoward Hinnantauto
1652c003db1fSHoward Hinnantend(const _Cp& __c) -> decltype(__c.end())
16533e519524SHoward Hinnant{
16543e519524SHoward Hinnant    return __c.end();
16553e519524SHoward Hinnant}
16563e519524SHoward Hinnant
16571e548c72SMarshall Clow#if _LIBCPP_STD_VER > 11
16581e548c72SMarshall Clow
16593772a46aSMarshall Clowtemplate <class _Tp, size_t _Np>
16602ffa1705SMarshall Clow_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
16613772a46aSMarshall Clowreverse_iterator<_Tp*> rbegin(_Tp (&__array)[_Np])
16623772a46aSMarshall Clow{
16633772a46aSMarshall Clow    return reverse_iterator<_Tp*>(__array + _Np);
16643772a46aSMarshall Clow}
16653772a46aSMarshall Clow
16663772a46aSMarshall Clowtemplate <class _Tp, size_t _Np>
16672ffa1705SMarshall Clow_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
16683772a46aSMarshall Clowreverse_iterator<_Tp*> rend(_Tp (&__array)[_Np])
16693772a46aSMarshall Clow{
16703772a46aSMarshall Clow    return reverse_iterator<_Tp*>(__array);
16713772a46aSMarshall Clow}
16723772a46aSMarshall Clow
16733772a46aSMarshall Clowtemplate <class _Ep>
16742ffa1705SMarshall Clow_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
16753772a46aSMarshall Clowreverse_iterator<const _Ep*> rbegin(initializer_list<_Ep> __il)
16763772a46aSMarshall Clow{
16773772a46aSMarshall Clow    return reverse_iterator<const _Ep*>(__il.end());
16783772a46aSMarshall Clow}
16793772a46aSMarshall Clow
16803772a46aSMarshall Clowtemplate <class _Ep>
16812ffa1705SMarshall Clow_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
16823772a46aSMarshall Clowreverse_iterator<const _Ep*> rend(initializer_list<_Ep> __il)
16833772a46aSMarshall Clow{
16843772a46aSMarshall Clow    return reverse_iterator<const _Ep*>(__il.begin());
16853772a46aSMarshall Clow}
16863772a46aSMarshall Clow
16871e548c72SMarshall Clowtemplate <class _Cp>
16882ffa1705SMarshall Clow_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
16897725546aSMarshall Clowauto cbegin(const _Cp& __c) -> decltype(_VSTD::begin(__c))
16901e548c72SMarshall Clow{
16917725546aSMarshall Clow    return _VSTD::begin(__c);
16921e548c72SMarshall Clow}
16931e548c72SMarshall Clow
16941e548c72SMarshall Clowtemplate <class _Cp>
16952ffa1705SMarshall Clow_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
16967725546aSMarshall Clowauto cend(const _Cp& __c) -> decltype(_VSTD::end(__c))
16971e548c72SMarshall Clow{
16987725546aSMarshall Clow    return _VSTD::end(__c);
16991e548c72SMarshall Clow}
17001e548c72SMarshall Clow
17011e548c72SMarshall Clowtemplate <class _Cp>
17022ffa1705SMarshall Clow_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
17031e548c72SMarshall Clowauto rbegin(_Cp& __c) -> decltype(__c.rbegin())
17041e548c72SMarshall Clow{
17051e548c72SMarshall Clow    return __c.rbegin();
17061e548c72SMarshall Clow}
17071e548c72SMarshall Clow
17081e548c72SMarshall Clowtemplate <class _Cp>
17092ffa1705SMarshall Clow_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
17101e548c72SMarshall Clowauto rbegin(const _Cp& __c) -> decltype(__c.rbegin())
17111e548c72SMarshall Clow{
17121e548c72SMarshall Clow    return __c.rbegin();
17131e548c72SMarshall Clow}
17141e548c72SMarshall Clow
17151e548c72SMarshall Clowtemplate <class _Cp>
17162ffa1705SMarshall Clow_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
17171e548c72SMarshall Clowauto rend(_Cp& __c) -> decltype(__c.rend())
17181e548c72SMarshall Clow{
17191e548c72SMarshall Clow    return __c.rend();
17201e548c72SMarshall Clow}
17211e548c72SMarshall Clow
17221e548c72SMarshall Clowtemplate <class _Cp>
17232ffa1705SMarshall Clow_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
17241e548c72SMarshall Clowauto rend(const _Cp& __c) -> decltype(__c.rend())
17251e548c72SMarshall Clow{
17261e548c72SMarshall Clow    return __c.rend();
17271e548c72SMarshall Clow}
17281e548c72SMarshall Clow
17291e548c72SMarshall Clowtemplate <class _Cp>
17302ffa1705SMarshall Clow_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
17317725546aSMarshall Clowauto crbegin(const _Cp& __c) -> decltype(_VSTD::rbegin(__c))
17321e548c72SMarshall Clow{
17337725546aSMarshall Clow    return _VSTD::rbegin(__c);
17341e548c72SMarshall Clow}
17351e548c72SMarshall Clow
17361e548c72SMarshall Clowtemplate <class _Cp>
17372ffa1705SMarshall Clow_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
17387725546aSMarshall Clowauto crend(const _Cp& __c) -> decltype(_VSTD::rend(__c))
17391e548c72SMarshall Clow{
17407725546aSMarshall Clow    return _VSTD::rend(__c);
17411e548c72SMarshall Clow}
17421e548c72SMarshall Clow
17431e548c72SMarshall Clow#endif
17441e548c72SMarshall Clow
17451e548c72SMarshall Clow
174654613ab4SEric Fiselier#else  // defined(_LIBCPP_CXX03_LANG)
17473e519524SHoward Hinnant
1748c003db1fSHoward Hinnanttemplate <class _Cp>
17492ffa1705SMarshall Clow_LIBCPP_INLINE_VISIBILITY
1750c003db1fSHoward Hinnanttypename _Cp::iterator
1751c003db1fSHoward Hinnantbegin(_Cp& __c)
17523e519524SHoward Hinnant{
17533e519524SHoward Hinnant    return __c.begin();
17543e519524SHoward Hinnant}
17553e519524SHoward Hinnant
1756c003db1fSHoward Hinnanttemplate <class _Cp>
17572ffa1705SMarshall Clow_LIBCPP_INLINE_VISIBILITY
1758c003db1fSHoward Hinnanttypename _Cp::const_iterator
1759c003db1fSHoward Hinnantbegin(const _Cp& __c)
17603e519524SHoward Hinnant{
17613e519524SHoward Hinnant    return __c.begin();
17623e519524SHoward Hinnant}
17633e519524SHoward Hinnant
1764c003db1fSHoward Hinnanttemplate <class _Cp>
17652ffa1705SMarshall Clow_LIBCPP_INLINE_VISIBILITY
1766c003db1fSHoward Hinnanttypename _Cp::iterator
1767c003db1fSHoward Hinnantend(_Cp& __c)
17683e519524SHoward Hinnant{
17693e519524SHoward Hinnant    return __c.end();
17703e519524SHoward Hinnant}
17713e519524SHoward Hinnant
1772c003db1fSHoward Hinnanttemplate <class _Cp>
17732ffa1705SMarshall Clow_LIBCPP_INLINE_VISIBILITY
1774c003db1fSHoward Hinnanttypename _Cp::const_iterator
1775c003db1fSHoward Hinnantend(const _Cp& __c)
17763e519524SHoward Hinnant{
17773e519524SHoward Hinnant    return __c.end();
17783e519524SHoward Hinnant}
17793e519524SHoward Hinnant
178054613ab4SEric Fiselier#endif // !defined(_LIBCPP_CXX03_LANG)
17813e519524SHoward Hinnant
1782ad755104SMarshall Clow#if _LIBCPP_STD_VER > 14
1783d1dcda19SMarshall Clow
1784d1dcda19SMarshall Clow// #if _LIBCPP_STD_VER > 11
1785d1dcda19SMarshall Clow// template <>
1786d1dcda19SMarshall Clow// struct _LIBCPP_TEMPLATE_VIS plus<void>
1787d1dcda19SMarshall Clow// {
1788d1dcda19SMarshall Clow//     template <class _T1, class _T2>
1789d1dcda19SMarshall Clow//     _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
1790d1dcda19SMarshall Clow//     auto operator()(_T1&& __t, _T2&& __u) const
1791d1dcda19SMarshall Clow//     _NOEXCEPT_(noexcept(_VSTD::forward<_T1>(__t) + _VSTD::forward<_T2>(__u)))
1792d1dcda19SMarshall Clow//     -> decltype        (_VSTD::forward<_T1>(__t) + _VSTD::forward<_T2>(__u))
1793d1dcda19SMarshall Clow//         { return        _VSTD::forward<_T1>(__t) + _VSTD::forward<_T2>(__u); }
1794d1dcda19SMarshall Clow//     typedef void is_transparent;
1795d1dcda19SMarshall Clow// };
1796d1dcda19SMarshall Clow// #endif
1797d1dcda19SMarshall Clow
179888d21343SMarshall Clowtemplate <class _Cont>
17992ffa1705SMarshall Clow_LIBCPP_INLINE_VISIBILITY
1800d1dcda19SMarshall Clowconstexpr auto size(const _Cont& __c)
1801d1dcda19SMarshall Clow_NOEXCEPT_(noexcept(__c.size()))
1802d1dcda19SMarshall Clow-> decltype        (__c.size())
1803d1dcda19SMarshall Clow{ return            __c.size(); }
1804ad755104SMarshall Clow
180588d21343SMarshall Clowtemplate <class _Tp, size_t _Sz>
18062ffa1705SMarshall Clow_LIBCPP_INLINE_VISIBILITY
1807fd838227SEric Fiselierconstexpr size_t size(const _Tp (&)[_Sz]) noexcept { return _Sz; }
1808ad755104SMarshall Clow
18097d3986eaSMarshall Clow#if _LIBCPP_STD_VER > 17
18107d3986eaSMarshall Clowtemplate <class _Cont>
18112ffa1705SMarshall Clow_LIBCPP_INLINE_VISIBILITY
18127d3986eaSMarshall Clowconstexpr auto ssize(const _Cont& __c)
18137d3986eaSMarshall Clow_NOEXCEPT_(noexcept(static_cast<common_type_t<ptrdiff_t, make_signed_t<decltype(__c.size())>>>(__c.size())))
18147d3986eaSMarshall Clow->                              common_type_t<ptrdiff_t, make_signed_t<decltype(__c.size())>>
18157d3986eaSMarshall Clow{ return            static_cast<common_type_t<ptrdiff_t, make_signed_t<decltype(__c.size())>>>(__c.size()); }
18167d3986eaSMarshall Clow
18177d3986eaSMarshall Clowtemplate <class _Tp, ptrdiff_t _Sz>
18182ffa1705SMarshall Clow_LIBCPP_INLINE_VISIBILITY
18197d3986eaSMarshall Clowconstexpr ptrdiff_t ssize(const _Tp (&)[_Sz]) noexcept { return _Sz; }
18207d3986eaSMarshall Clow#endif
18217d3986eaSMarshall Clow
182288d21343SMarshall Clowtemplate <class _Cont>
18232ffa1705SMarshall Clow_LIBCPP_NODISCARD_AFTER_CXX17 _LIBCPP_INLINE_VISIBILITY
1824d1dcda19SMarshall Clowconstexpr auto empty(const _Cont& __c)
1825d1dcda19SMarshall Clow_NOEXCEPT_(noexcept(__c.empty()))
1826d1dcda19SMarshall Clow-> decltype        (__c.empty())
1827d1dcda19SMarshall Clow{ return            __c.empty(); }
1828ad755104SMarshall Clow
182988d21343SMarshall Clowtemplate <class _Tp, size_t _Sz>
18302ffa1705SMarshall Clow_LIBCPP_NODISCARD_AFTER_CXX17 _LIBCPP_INLINE_VISIBILITY
1831fd838227SEric Fiselierconstexpr bool empty(const _Tp (&)[_Sz]) noexcept { return false; }
1832ad755104SMarshall Clow
1833ad755104SMarshall Clowtemplate <class _Ep>
18342ffa1705SMarshall Clow_LIBCPP_NODISCARD_AFTER_CXX17 _LIBCPP_INLINE_VISIBILITY
1835ad755104SMarshall Clowconstexpr bool empty(initializer_list<_Ep> __il) noexcept { return __il.size() == 0; }
1836ad755104SMarshall Clow
183788d21343SMarshall Clowtemplate <class _Cont> constexpr
18382ffa1705SMarshall Clow_LIBCPP_INLINE_VISIBILITY
1839d1dcda19SMarshall Clowauto data(_Cont& __c)
1840d1dcda19SMarshall Clow_NOEXCEPT_(noexcept(__c.data()))
1841d1dcda19SMarshall Clow-> decltype        (__c.data())
1842d1dcda19SMarshall Clow{ return            __c.data(); }
1843ad755104SMarshall Clow
184488d21343SMarshall Clowtemplate <class _Cont> constexpr
18452ffa1705SMarshall Clow_LIBCPP_INLINE_VISIBILITY
1846d1dcda19SMarshall Clowauto data(const _Cont& __c)
1847d1dcda19SMarshall Clow_NOEXCEPT_(noexcept(__c.data()))
1848d1dcda19SMarshall Clow-> decltype        (__c.data())
1849d1dcda19SMarshall Clow{ return            __c.data(); }
1850ad755104SMarshall Clow
185188d21343SMarshall Clowtemplate <class _Tp, size_t _Sz>
18522ffa1705SMarshall Clow_LIBCPP_INLINE_VISIBILITY
185388d21343SMarshall Clowconstexpr _Tp* data(_Tp (&__array)[_Sz]) noexcept { return __array; }
1854ad755104SMarshall Clow
1855ad755104SMarshall Clowtemplate <class _Ep>
18562ffa1705SMarshall Clow_LIBCPP_INLINE_VISIBILITY
1857ad755104SMarshall Clowconstexpr const _Ep* data(initializer_list<_Ep> __il) noexcept { return __il.begin(); }
1858ad755104SMarshall Clow#endif
1859ad755104SMarshall Clow
18602ac6babcSArthur O'Dwyertemplate <class _Container, class _Predicate>
18612ac6babcSArthur O'Dwyertypename _Container::size_type
18622ac6babcSArthur O'Dwyer__libcpp_erase_if_container(_Container& __c, _Predicate& __pred) {
18632ac6babcSArthur O'Dwyer  typename _Container::size_type __old_size = __c.size();
18642ac6babcSArthur O'Dwyer
18652ac6babcSArthur O'Dwyer  const typename _Container::iterator __last = __c.end();
18662ac6babcSArthur O'Dwyer  for (typename _Container::iterator __iter = __c.begin(); __iter != __last;) {
18672ac6babcSArthur O'Dwyer    if (__pred(*__iter))
18682ac6babcSArthur O'Dwyer      __iter = __c.erase(__iter);
18692ac6babcSArthur O'Dwyer    else
18702ac6babcSArthur O'Dwyer      ++__iter;
18712ac6babcSArthur O'Dwyer  }
18722ac6babcSArthur O'Dwyer
18732ac6babcSArthur O'Dwyer  return __old_size - __c.size();
18742ac6babcSArthur O'Dwyer}
1875ad755104SMarshall Clow
18763e519524SHoward Hinnant_LIBCPP_END_NAMESPACE_STD
18773e519524SHoward Hinnant
18783e519524SHoward Hinnant#endif // _LIBCPP_ITERATOR
1879