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
51*58b29a4eSLouis Dionnetemplate<indirectly_readable T>
52*58b29a4eSLouis Dionne  using iter_common_reference_t =
53*58b29a4eSLouis Dionne    common_reference_t<iter_reference_t<T>, iter_value_t<T>&>;  // since C++20
54*58b29a4eSLouis Dionne
5557ebf3d0SLouis Dionne// [iterator.concept.writable], concept indirectly_writable
5657ebf3d0SLouis Dionnetemplate<class Out, class T>
5757ebf3d0SLouis Dionne  concept indirectly_writable = see below;                // since C++20
5857ebf3d0SLouis Dionne
5918b03b00SMark de Wever// [iterator.concept.winc], concept weakly_incrementable
6022052860SChristopher Di Bellatemplate<class I>
6122052860SChristopher Di Bella  concept weakly_incrementable = see below;                // since C++20
6222052860SChristopher Di Bella
6322052860SChristopher Di Bella// [iterator.concept.inc], concept incrementable
6422052860SChristopher Di Bellatemplate<class I>
6522052860SChristopher Di Bella  concept incrementable = see below;                       // since C++20
6622052860SChristopher Di Bella
6718b03b00SMark de Wever// [iterator.concept.iterator], concept input_or_output_iterator
6838225d69SChristopher Di Bella  template<class I>
6938225d69SChristopher Di Bella    concept input_or_output_iterator = see below;          // since C++20
7038225d69SChristopher Di Bella
7118b03b00SMark de Wever// [iterator.concept.sentinel], concept sentinel_for
7238225d69SChristopher Di Bellatemplate<class S, class I>
7338225d69SChristopher Di Bella  concept sentinel_for = see below;                        // since C++20
7438225d69SChristopher Di Bella
75bdd68357Szoecarver// [iterator.concept.sizedsentinel], concept sized_sentinel_for
76bdd68357Szoecarvertemplate<class S, class I>
77bdd68357Szoecarver  inline constexpr bool disable_sized_sentinel_for = false;
78bdd68357Szoecarver
79bdd68357Szoecarvertemplate<class S, class I>
80bdd68357Szoecarver  concept sized_sentinel_for = see below;
81bdd68357Szoecarver
82c05d1eedSChristopher Di Bella// [iterator.concept.input], concept input_iterator
83c05d1eedSChristopher Di Bellatemplate<class I>
84c05d1eedSChristopher Di Bella  concept input_iterator = see below;                      // since C++20
85c05d1eedSChristopher Di Bella
86fa3e2626SChristopher Di Bella// [iterator.concept.forward], concept forward_iterator
87fa3e2626SChristopher Di Bellatemplate<class I>
88fa3e2626SChristopher Di Bella  concept forward_iterator = see below;                    // since C++20
89fa3e2626SChristopher Di Bella
909c5d86aaSChristopher Di Bella// [iterator.concept.bidir], concept bidirectional_iterator
919c5d86aaSChristopher Di Bellatemplate<class I>
929c5d86aaSChristopher Di Bella  concept bidirectional_iterator = see below;              // since C++20
939c5d86aaSChristopher Di Bella
946ffc41b0Szoecarver// [iterator.concept.random.access], concept random_access_iterator
956ffc41b0Szoecarvertemplate<class I>
966ffc41b0Szoecarver  concept random_access_iterator = see below;              // since C++20
976ffc41b0Szoecarver
98*58b29a4eSLouis Dionne// [indirectcallable]
99*58b29a4eSLouis Dionne// [indirectcallable.indirectinvocable]
100*58b29a4eSLouis Dionnetemplate<class F, class I>
101*58b29a4eSLouis Dionne  concept indirectly_unary_invocable = see below;          // since C++20
102*58b29a4eSLouis Dionne
103*58b29a4eSLouis Dionnetemplate<class F, class I>
104*58b29a4eSLouis Dionne  concept indirectly_regular_unary_invocable = see below;  // since C++20
105*58b29a4eSLouis Dionne
106*58b29a4eSLouis Dionnetemplate<class F, class I>
107*58b29a4eSLouis Dionne  concept indirect_unary_predicate = see below;            // since C++20
108*58b29a4eSLouis Dionne
109*58b29a4eSLouis Dionnetemplate<class F, class I1, class I2>
110*58b29a4eSLouis Dionne  concept indirect_binary_predicate = see below;           // since C++20
111*58b29a4eSLouis Dionne
112*58b29a4eSLouis Dionnetemplate<class F, class I1, class I2 = I1>
113*58b29a4eSLouis Dionne  concept indirect_equivalence_relation = see below;       // since C++20
114*58b29a4eSLouis Dionne
115*58b29a4eSLouis Dionnetemplate<class F, class I1, class I2 = I1>
116*58b29a4eSLouis Dionne  concept indirect_strict_weak_order = see below;          // since C++20
117*58b29a4eSLouis Dionne
118*58b29a4eSLouis Dionnetemplate<class F, class... Is>
119*58b29a4eSLouis Dionne  using indirect_result_t = see below;                     // since C++20
120*58b29a4eSLouis Dionne
121*58b29a4eSLouis Dionne// [projected], projected
122*58b29a4eSLouis Dionnetemplate<indirectly_readable I, indirectly_regular_unary_invocable<I> Proj>
123*58b29a4eSLouis Dionne  struct projected;                                        // since C++20
124*58b29a4eSLouis Dionne
125*58b29a4eSLouis Dionnetemplate<weakly_incrementable I, indirectly_regular_unary_invocable<I> Proj>
126*58b29a4eSLouis Dionne  struct incrementable_traits<projected<I, Proj>>;         // since C++20
127*58b29a4eSLouis Dionne
1283e519524SHoward Hinnanttemplate<class Category, class T, class Distance = ptrdiff_t,
1293e519524SHoward Hinnant         class Pointer = T*, class Reference = T&>
1301055cb91SLouis Dionnestruct iterator                                            // deprecated in C++17
1313e519524SHoward Hinnant{
1323e519524SHoward Hinnant    typedef T         value_type;
1333e519524SHoward Hinnant    typedef Distance  difference_type;
1343e519524SHoward Hinnant    typedef Pointer   pointer;
1353e519524SHoward Hinnant    typedef Reference reference;
1363e519524SHoward Hinnant    typedef Category  iterator_category;
1373e519524SHoward Hinnant};
1383e519524SHoward Hinnant
1393e519524SHoward Hinnantstruct input_iterator_tag  {};
1403e519524SHoward Hinnantstruct output_iterator_tag {};
1413e519524SHoward Hinnantstruct forward_iterator_tag       : public input_iterator_tag         {};
1423e519524SHoward Hinnantstruct bidirectional_iterator_tag : public forward_iterator_tag       {};
1433e519524SHoward Hinnantstruct random_access_iterator_tag : public bidirectional_iterator_tag {};
1443e519524SHoward Hinnant
145f51ee632SMarshall Clow// 27.4.3, iterator operations
14612b01ab7SLouis Dionnetemplate <class InputIterator, class Distance>  // constexpr in C++17
14712b01ab7SLouis Dionne  constexpr void advance(InputIterator& i, Distance n);
1483e519524SHoward Hinnant
149f51ee632SMarshall Clowtemplate <class InputIterator>  // constexpr in C++17
150f51ee632SMarshall Clow  constexpr typename iterator_traits<InputIterator>::difference_type
1513e519524SHoward Hinnant    distance(InputIterator first, InputIterator last);
1523e519524SHoward Hinnant
153f51ee632SMarshall Clowtemplate <class InputIterator>  // constexpr in C++17
154f51ee632SMarshall Clow  constexpr InputIterator next(InputIterator x,
155f51ee632SMarshall Clowtypename iterator_traits<InputIterator>::difference_type n = 1);
156f51ee632SMarshall Clow
157f51ee632SMarshall Clowtemplate <class BidirectionalIterator>  // constexpr in C++17
158f51ee632SMarshall Clow  constexpr BidirectionalIterator prev(BidirectionalIterator x,
159f51ee632SMarshall Clow    typename iterator_traits<BidirectionalIterator>::difference_type n = 1);
160f51ee632SMarshall Clow
16136d0fdf9SChristopher Di Bella// [range.iter.ops], range iterator operations
16236d0fdf9SChristopher Di Bellanamespace ranges {
16336d0fdf9SChristopher Di Bella  // [range.iter.op.advance], ranges::advance
16436d0fdf9SChristopher Di Bella  template<input_or_output_iterator I>
16536d0fdf9SChristopher Di Bella    constexpr void advance(I& i, iter_difference_t<I> n);                          // since C++20
16636d0fdf9SChristopher Di Bella  template<input_or_output_iterator I, sentinel_for<I> S>
16736d0fdf9SChristopher Di Bella    constexpr void advance(I& i, S bound);                                         // since C++20
16836d0fdf9SChristopher Di Bella  template<input_or_output_iterator I, sentinel_for<I> S>
16936d0fdf9SChristopher Di Bella    constexpr iter_difference_t<I> advance(I& i, iter_difference_t<I> n, S bound); // since C++20
17036d0fdf9SChristopher Di Bella}
17136d0fdf9SChristopher Di Bella
1723e519524SHoward Hinnanttemplate <class Iterator>
1733e519524SHoward Hinnantclass reverse_iterator
1741055cb91SLouis Dionne    : public iterator<typename iterator_traits<Iterator>::iterator_category, // until C++17
1753e519524SHoward Hinnant                      typename iterator_traits<Iterator>::value_type,
1763e519524SHoward Hinnant                      typename iterator_traits<Iterator>::difference_type,
1773e519524SHoward Hinnant                      typename iterator_traits<Iterator>::pointer,
1783e519524SHoward Hinnant                      typename iterator_traits<Iterator>::reference>
1793e519524SHoward Hinnant{
1803e519524SHoward Hinnantprotected:
1813e519524SHoward Hinnant    Iterator current;
1823e519524SHoward Hinnantpublic:
1833e519524SHoward Hinnant    typedef Iterator                                            iterator_type;
1843e519524SHoward Hinnant    typedef typename iterator_traits<Iterator>::difference_type difference_type;
1853e519524SHoward Hinnant    typedef typename iterator_traits<Iterator>::reference       reference;
1863e519524SHoward Hinnant    typedef typename iterator_traits<Iterator>::pointer         pointer;
1873e519524SHoward Hinnant
1881b8f260eSMarshall Clow    constexpr reverse_iterator();
1891b8f260eSMarshall Clow    constexpr explicit reverse_iterator(Iterator x);
1901b8f260eSMarshall Clow    template <class U> constexpr reverse_iterator(const reverse_iterator<U>& u);
1911b8f260eSMarshall Clow    template <class U> constexpr reverse_iterator& operator=(const reverse_iterator<U>& u);
1921b8f260eSMarshall Clow    constexpr Iterator base() const;
1931b8f260eSMarshall Clow    constexpr reference operator*() const;
1941b8f260eSMarshall Clow    constexpr pointer   operator->() const;
1951b8f260eSMarshall Clow    constexpr reverse_iterator& operator++();
1961b8f260eSMarshall Clow    constexpr reverse_iterator  operator++(int);
1971b8f260eSMarshall Clow    constexpr reverse_iterator& operator--();
1981b8f260eSMarshall Clow    constexpr reverse_iterator  operator--(int);
1991b8f260eSMarshall Clow    constexpr reverse_iterator  operator+ (difference_type n) const;
2001b8f260eSMarshall Clow    constexpr reverse_iterator& operator+=(difference_type n);
2011b8f260eSMarshall Clow    constexpr reverse_iterator  operator- (difference_type n) const;
2021b8f260eSMarshall Clow    constexpr reverse_iterator& operator-=(difference_type n);
2031b8f260eSMarshall Clow    constexpr reference         operator[](difference_type n) const;
2043e519524SHoward Hinnant};
2053e519524SHoward Hinnant
2063e519524SHoward Hinnanttemplate <class Iterator1, class Iterator2>
2071b8f260eSMarshall Clowconstexpr bool                          // constexpr in C++17
2083e519524SHoward Hinnantoperator==(const reverse_iterator<Iterator1>& x, const reverse_iterator<Iterator2>& y);
2093e519524SHoward Hinnant
2103e519524SHoward Hinnanttemplate <class Iterator1, class Iterator2>
2111b8f260eSMarshall Clowconstexpr bool                          // constexpr in C++17
2123e519524SHoward Hinnantoperator<(const reverse_iterator<Iterator1>& x, const reverse_iterator<Iterator2>& y);
2133e519524SHoward Hinnant
2143e519524SHoward Hinnanttemplate <class Iterator1, class Iterator2>
2151b8f260eSMarshall Clowconstexpr bool                          // constexpr in C++17
2163e519524SHoward Hinnantoperator!=(const reverse_iterator<Iterator1>& x, const reverse_iterator<Iterator2>& y);
2173e519524SHoward Hinnant
2183e519524SHoward Hinnanttemplate <class Iterator1, class Iterator2>
2191b8f260eSMarshall Clowconstexpr bool                          // constexpr in C++17
2203e519524SHoward Hinnantoperator>(const reverse_iterator<Iterator1>& x, const reverse_iterator<Iterator2>& y);
2213e519524SHoward Hinnant
2223e519524SHoward Hinnanttemplate <class Iterator1, class Iterator2>
2231b8f260eSMarshall Clowconstexpr bool                          // constexpr in C++17
2243e519524SHoward Hinnantoperator>=(const reverse_iterator<Iterator1>& x, const reverse_iterator<Iterator2>& y);
2253e519524SHoward Hinnant
2263e519524SHoward Hinnanttemplate <class Iterator1, class Iterator2>
2271b8f260eSMarshall Clowconstexpr bool                          // constexpr in C++17
2283e519524SHoward Hinnantoperator<=(const reverse_iterator<Iterator1>& x, const reverse_iterator<Iterator2>& y);
2293e519524SHoward Hinnant
2303e519524SHoward Hinnanttemplate <class Iterator1, class Iterator2>
2311b8f260eSMarshall Clowconstexpr auto
232947ce6b5SMarshall Clowoperator-(const reverse_iterator<Iterator1>& x, const reverse_iterator<Iterator2>& y)
2331b8f260eSMarshall Clow-> decltype(__y.base() - __x.base());   // constexpr in C++17
2343e519524SHoward Hinnant
2353e519524SHoward Hinnanttemplate <class Iterator>
2361b8f260eSMarshall Clowconstexpr reverse_iterator<Iterator>
2371b8f260eSMarshall Clowoperator+(typename reverse_iterator<Iterator>::difference_type n,
2381b8f260eSMarshall Clow          const reverse_iterator<Iterator>& x);   // constexpr in C++17
2393e519524SHoward Hinnant
2401b8f260eSMarshall Clowtemplate <class Iterator>
2411b8f260eSMarshall Clowconstexpr reverse_iterator<Iterator> make_reverse_iterator(Iterator i); // C++14, constexpr in C++17
2426a640a18SMarshall Clow
2433e519524SHoward Hinnanttemplate <class Container>
2443e519524SHoward Hinnantclass back_insert_iterator
2453e519524SHoward Hinnant{
2463e519524SHoward Hinnantprotected:
2473e519524SHoward Hinnant    Container* container;
2483e519524SHoward Hinnantpublic:
2493e519524SHoward Hinnant    typedef Container                   container_type;
2503e519524SHoward Hinnant    typedef void                        value_type;
2513e519524SHoward Hinnant    typedef void                        difference_type;
2528892b4eeSEric Fiselier    typedef void                        reference;
2533e519524SHoward Hinnant    typedef void                        pointer;
2543e519524SHoward Hinnant
25506e2b737SArthur O'Dwyer    explicit back_insert_iterator(Container& x);  // constexpr in C++20
25606e2b737SArthur O'Dwyer    back_insert_iterator& operator=(const typename Container::value_type& value);  // constexpr in C++20
25706e2b737SArthur O'Dwyer    back_insert_iterator& operator*();  // constexpr in C++20
25806e2b737SArthur O'Dwyer    back_insert_iterator& operator++();  // constexpr in C++20
25906e2b737SArthur O'Dwyer    back_insert_iterator  operator++(int);  // constexpr in C++20
2603e519524SHoward Hinnant};
2613e519524SHoward Hinnant
26206e2b737SArthur O'Dwyertemplate <class Container> back_insert_iterator<Container> back_inserter(Container& x);  // constexpr in C++20
2633e519524SHoward Hinnant
2643e519524SHoward Hinnanttemplate <class Container>
2653e519524SHoward Hinnantclass front_insert_iterator
2663e519524SHoward Hinnant{
2673e519524SHoward Hinnantprotected:
2683e519524SHoward Hinnant    Container* container;
2693e519524SHoward Hinnantpublic:
2703e519524SHoward Hinnant    typedef Container                    container_type;
2713e519524SHoward Hinnant    typedef void                         value_type;
2723e519524SHoward Hinnant    typedef void                         difference_type;
2738892b4eeSEric Fiselier    typedef void                         reference;
2743e519524SHoward Hinnant    typedef void                         pointer;
2753e519524SHoward Hinnant
27606e2b737SArthur O'Dwyer    explicit front_insert_iterator(Container& x);  // constexpr in C++20
27706e2b737SArthur O'Dwyer    front_insert_iterator& operator=(const typename Container::value_type& value);  // constexpr in C++20
27806e2b737SArthur O'Dwyer    front_insert_iterator& operator*();  // constexpr in C++20
27906e2b737SArthur O'Dwyer    front_insert_iterator& operator++();  // constexpr in C++20
28006e2b737SArthur O'Dwyer    front_insert_iterator  operator++(int);  // constexpr in C++20
2813e519524SHoward Hinnant};
2823e519524SHoward Hinnant
28306e2b737SArthur O'Dwyertemplate <class Container> front_insert_iterator<Container> front_inserter(Container& x);  // constexpr in C++20
2843e519524SHoward Hinnant
2853e519524SHoward Hinnanttemplate <class Container>
2863e519524SHoward Hinnantclass insert_iterator
2873e519524SHoward Hinnant{
2883e519524SHoward Hinnantprotected:
2893e519524SHoward Hinnant    Container* container;
2903e519524SHoward Hinnant    typename Container::iterator iter;
2913e519524SHoward Hinnantpublic:
2923e519524SHoward Hinnant    typedef Container              container_type;
2933e519524SHoward Hinnant    typedef void                   value_type;
2943e519524SHoward Hinnant    typedef void                   difference_type;
2958892b4eeSEric Fiselier    typedef void                   reference;
2963e519524SHoward Hinnant    typedef void                   pointer;
2973e519524SHoward Hinnant
29806e2b737SArthur O'Dwyer    insert_iterator(Container& x, typename Container::iterator i);  // constexpr in C++20
29906e2b737SArthur O'Dwyer    insert_iterator& operator=(const typename Container::value_type& value);  // constexpr in C++20
30006e2b737SArthur O'Dwyer    insert_iterator& operator*();  // constexpr in C++20
30106e2b737SArthur O'Dwyer    insert_iterator& operator++();  // constexpr in C++20
30206e2b737SArthur O'Dwyer    insert_iterator& operator++(int);  // constexpr in C++20
3033e519524SHoward Hinnant};
3043e519524SHoward Hinnant
3053e519524SHoward Hinnanttemplate <class Container, class Iterator>
30606e2b737SArthur O'Dwyerinsert_iterator<Container> inserter(Container& x, Iterator i);  // constexpr in C++20
3073e519524SHoward Hinnant
308947ce6b5SMarshall Clowtemplate <class Iterator>
309947ce6b5SMarshall Clowclass move_iterator {
310947ce6b5SMarshall Clowpublic:
311947ce6b5SMarshall Clow    typedef Iterator                                              iterator_type;
312947ce6b5SMarshall Clow    typedef typename iterator_traits<Iterator>::difference_type   difference_type;
313947ce6b5SMarshall Clow    typedef Iterator                                              pointer;
314947ce6b5SMarshall Clow    typedef typename iterator_traits<Iterator>::value_type        value_type;
315947ce6b5SMarshall Clow    typedef typename iterator_traits<Iterator>::iterator_category iterator_category;
316947ce6b5SMarshall Clow    typedef value_type&&                                          reference;
317947ce6b5SMarshall Clow
318720ef472SMarshall Clow    constexpr move_iterator();  // all the constexprs are in C++17
319720ef472SMarshall Clow    constexpr explicit move_iterator(Iterator i);
320720ef472SMarshall Clow    template <class U>
321720ef472SMarshall Clow      constexpr move_iterator(const move_iterator<U>& u);
322720ef472SMarshall Clow    template <class U>
323720ef472SMarshall Clow      constexpr move_iterator& operator=(const move_iterator<U>& u);
324720ef472SMarshall Clow    constexpr iterator_type base() const;
325720ef472SMarshall Clow    constexpr reference operator*() const;
326720ef472SMarshall Clow    constexpr pointer operator->() const;
327720ef472SMarshall Clow    constexpr move_iterator& operator++();
328720ef472SMarshall Clow    constexpr move_iterator operator++(int);
329720ef472SMarshall Clow    constexpr move_iterator& operator--();
330720ef472SMarshall Clow    constexpr move_iterator operator--(int);
331720ef472SMarshall Clow    constexpr move_iterator operator+(difference_type n) const;
332720ef472SMarshall Clow    constexpr move_iterator& operator+=(difference_type n);
333720ef472SMarshall Clow    constexpr move_iterator operator-(difference_type n) const;
334720ef472SMarshall Clow    constexpr move_iterator& operator-=(difference_type n);
335720ef472SMarshall Clow    constexpr unspecified operator[](difference_type n) const;
336947ce6b5SMarshall Clowprivate:
337947ce6b5SMarshall Clow    Iterator current; // exposition only
338947ce6b5SMarshall Clow};
339947ce6b5SMarshall Clow
340947ce6b5SMarshall Clowtemplate <class Iterator1, class Iterator2>
341720ef472SMarshall Clowconstexpr bool   // constexpr in C++17
342947ce6b5SMarshall Clowoperator==(const move_iterator<Iterator1>& x, const move_iterator<Iterator2>& y);
343947ce6b5SMarshall Clow
344947ce6b5SMarshall Clowtemplate <class Iterator1, class Iterator2>
345720ef472SMarshall Clowconstexpr bool   // constexpr in C++17
346947ce6b5SMarshall Clowoperator!=(const move_iterator<Iterator1>& x, const move_iterator<Iterator2>& y);
347947ce6b5SMarshall Clow
348947ce6b5SMarshall Clowtemplate <class Iterator1, class Iterator2>
349720ef472SMarshall Clowconstexpr bool   // constexpr in C++17
350947ce6b5SMarshall Clowoperator<(const move_iterator<Iterator1>& x, const move_iterator<Iterator2>& y);
351947ce6b5SMarshall Clow
352947ce6b5SMarshall Clowtemplate <class Iterator1, class Iterator2>
353720ef472SMarshall Clowconstexpr bool   // constexpr in C++17
354947ce6b5SMarshall Clowoperator<=(const move_iterator<Iterator1>& x, const move_iterator<Iterator2>& y);
355947ce6b5SMarshall Clow
356947ce6b5SMarshall Clowtemplate <class Iterator1, class Iterator2>
357720ef472SMarshall Clowconstexpr bool   // constexpr in C++17
358947ce6b5SMarshall Clowoperator>(const move_iterator<Iterator1>& x, const move_iterator<Iterator2>& y);
359947ce6b5SMarshall Clow
360947ce6b5SMarshall Clowtemplate <class Iterator1, class Iterator2>
361720ef472SMarshall Clowconstexpr bool   // constexpr in C++17
362947ce6b5SMarshall Clowoperator>=(const move_iterator<Iterator1>& x, const move_iterator<Iterator2>& y);
363947ce6b5SMarshall Clow
364947ce6b5SMarshall Clowtemplate <class Iterator1, class Iterator2>
365720ef472SMarshall Clowconstexpr auto   // constexpr in C++17
366947ce6b5SMarshall Clowoperator-(const move_iterator<Iterator1>& x,
367947ce6b5SMarshall Clow          const move_iterator<Iterator2>& y) -> decltype(x.base() - y.base());
368947ce6b5SMarshall Clow
369947ce6b5SMarshall Clowtemplate <class Iterator>
370720ef472SMarshall Clowconstexpr move_iterator<Iterator> operator+(   // constexpr in C++17
371720ef472SMarshall Clow            typename move_iterator<Iterator>::difference_type n,
372947ce6b5SMarshall Clow            const move_iterator<Iterator>& x);
373947ce6b5SMarshall Clow
374720ef472SMarshall Clowtemplate <class Iterator>   // constexpr in C++17
375720ef472SMarshall Clowconstexpr  move_iterator<Iterator> make_move_iterator(const Iterator& i);
376947ce6b5SMarshall Clow
377947ce6b5SMarshall Clow
3783e519524SHoward Hinnanttemplate <class T, class charT = char, class traits = char_traits<charT>, class Distance = ptrdiff_t>
3793e519524SHoward Hinnantclass istream_iterator
3801055cb91SLouis Dionne    : public iterator<input_iterator_tag, T, Distance, const T*, const T&> // until C++17
3813e519524SHoward Hinnant{
3823e519524SHoward Hinnantpublic:
3833e519524SHoward Hinnant    typedef charT char_type;
3843e519524SHoward Hinnant    typedef traits traits_type;
3853e519524SHoward Hinnant    typedef basic_istream<charT,traits> istream_type;
3863e519524SHoward Hinnant
38760d5e0e0SMarshall Clow    constexpr istream_iterator();
3883e519524SHoward Hinnant    istream_iterator(istream_type& s);
3893e519524SHoward Hinnant    istream_iterator(const istream_iterator& x);
3903e519524SHoward Hinnant    ~istream_iterator();
3913e519524SHoward Hinnant
3923e519524SHoward Hinnant    const T& operator*() const;
3933e519524SHoward Hinnant    const T* operator->() const;
3943e519524SHoward Hinnant    istream_iterator& operator++();
3953e519524SHoward Hinnant    istream_iterator  operator++(int);
3963e519524SHoward Hinnant};
3973e519524SHoward Hinnant
3983e519524SHoward Hinnanttemplate <class T, class charT, class traits, class Distance>
3993e519524SHoward Hinnantbool operator==(const istream_iterator<T,charT,traits,Distance>& x,
4003e519524SHoward Hinnant                const istream_iterator<T,charT,traits,Distance>& y);
4013e519524SHoward Hinnanttemplate <class T, class charT, class traits, class Distance>
4023e519524SHoward Hinnantbool operator!=(const istream_iterator<T,charT,traits,Distance>& x,
4033e519524SHoward Hinnant                const istream_iterator<T,charT,traits,Distance>& y);
4043e519524SHoward Hinnant
4053e519524SHoward Hinnanttemplate <class T, class charT = char, class traits = char_traits<charT> >
4063e519524SHoward Hinnantclass ostream_iterator
4071055cb91SLouis Dionne    : public iterator<output_iterator_tag, void, void, void ,void> // until C++17
4083e519524SHoward Hinnant{
4093e519524SHoward Hinnantpublic:
4103e519524SHoward Hinnant    typedef charT char_type;
4113e519524SHoward Hinnant    typedef traits traits_type;
4123e519524SHoward Hinnant    typedef basic_ostream<charT,traits> ostream_type;
4133e519524SHoward Hinnant
4143e519524SHoward Hinnant    ostream_iterator(ostream_type& s);
4153e519524SHoward Hinnant    ostream_iterator(ostream_type& s, const charT* delimiter);
4163e519524SHoward Hinnant    ostream_iterator(const ostream_iterator& x);
4173e519524SHoward Hinnant    ~ostream_iterator();
4183e519524SHoward Hinnant    ostream_iterator& operator=(const T& value);
4193e519524SHoward Hinnant
4203e519524SHoward Hinnant    ostream_iterator& operator*();
4213e519524SHoward Hinnant    ostream_iterator& operator++();
4223e519524SHoward Hinnant    ostream_iterator& operator++(int);
4233e519524SHoward Hinnant};
4243e519524SHoward Hinnant
4253e519524SHoward Hinnanttemplate<class charT, class traits = char_traits<charT> >
4263e519524SHoward Hinnantclass istreambuf_iterator
4271055cb91SLouis Dionne    : public iterator<input_iterator_tag, charT,                // until C++17
4283e519524SHoward Hinnant                      typename traits::off_type, unspecified,
4293e519524SHoward Hinnant                      charT>
4303e519524SHoward Hinnant{
4313e519524SHoward Hinnantpublic:
4323e519524SHoward Hinnant    typedef charT                         char_type;
4333e519524SHoward Hinnant    typedef traits                        traits_type;
4343e519524SHoward Hinnant    typedef typename traits::int_type     int_type;
4353e519524SHoward Hinnant    typedef basic_streambuf<charT,traits> streambuf_type;
4363e519524SHoward Hinnant    typedef basic_istream<charT,traits>   istream_type;
4373e519524SHoward Hinnant
4388e882dcbSHoward Hinnant    istreambuf_iterator() noexcept;
4398e882dcbSHoward Hinnant    istreambuf_iterator(istream_type& s) noexcept;
4408e882dcbSHoward Hinnant    istreambuf_iterator(streambuf_type* s) noexcept;
4418e882dcbSHoward Hinnant    istreambuf_iterator(a-private-type) noexcept;
4423e519524SHoward Hinnant
4433e519524SHoward Hinnant    charT                operator*() const;
4443e519524SHoward Hinnant    pointer operator->() const;
4453e519524SHoward Hinnant    istreambuf_iterator& operator++();
4463e519524SHoward Hinnant    a-private-type       operator++(int);
4473e519524SHoward Hinnant
4483e519524SHoward Hinnant    bool equal(const istreambuf_iterator& b) const;
4493e519524SHoward Hinnant};
4503e519524SHoward Hinnant
4513e519524SHoward Hinnanttemplate <class charT, class traits>
4523e519524SHoward Hinnantbool operator==(const istreambuf_iterator<charT,traits>& a,
4533e519524SHoward Hinnant                const istreambuf_iterator<charT,traits>& b);
4543e519524SHoward Hinnanttemplate <class charT, class traits>
4553e519524SHoward Hinnantbool operator!=(const istreambuf_iterator<charT,traits>& a,
4563e519524SHoward Hinnant                const istreambuf_iterator<charT,traits>& b);
4573e519524SHoward Hinnant
4583e519524SHoward Hinnanttemplate <class charT, class traits = char_traits<charT> >
4593e519524SHoward Hinnantclass ostreambuf_iterator
4601055cb91SLouis Dionne    : public iterator<output_iterator_tag, void, void, void, void> // until C++17
4613e519524SHoward Hinnant{
4623e519524SHoward Hinnantpublic:
4633e519524SHoward Hinnant    typedef charT                         char_type;
4643e519524SHoward Hinnant    typedef traits                        traits_type;
4653e519524SHoward Hinnant    typedef basic_streambuf<charT,traits> streambuf_type;
4663e519524SHoward Hinnant    typedef basic_ostream<charT,traits>   ostream_type;
4673e519524SHoward Hinnant
4688e882dcbSHoward Hinnant    ostreambuf_iterator(ostream_type& s) noexcept;
4698e882dcbSHoward Hinnant    ostreambuf_iterator(streambuf_type* s) noexcept;
4703e519524SHoward Hinnant    ostreambuf_iterator& operator=(charT c);
4713e519524SHoward Hinnant    ostreambuf_iterator& operator*();
4723e519524SHoward Hinnant    ostreambuf_iterator& operator++();
4733e519524SHoward Hinnant    ostreambuf_iterator& operator++(int);
4748e882dcbSHoward Hinnant    bool failed() const noexcept;
4753e519524SHoward Hinnant};
4763e519524SHoward Hinnant
477020b623aSMarshall Clowtemplate <class C> constexpr auto begin(C& c) -> decltype(c.begin());
478020b623aSMarshall Clowtemplate <class C> constexpr auto begin(const C& c) -> decltype(c.begin());
479020b623aSMarshall Clowtemplate <class C> constexpr auto end(C& c) -> decltype(c.end());
480020b623aSMarshall Clowtemplate <class C> constexpr auto end(const C& c) -> decltype(c.end());
481020b623aSMarshall Clowtemplate <class T, size_t N> constexpr T* begin(T (&array)[N]);
482020b623aSMarshall Clowtemplate <class T, size_t N> constexpr T* end(T (&array)[N]);
4833e519524SHoward Hinnant
484020b623aSMarshall Clowtemplate <class C> auto constexpr cbegin(const C& c) -> decltype(std::begin(c));        // C++14
485020b623aSMarshall Clowtemplate <class C> auto constexpr cend(const C& c) -> decltype(std::end(c));            // C++14
486020b623aSMarshall Clowtemplate <class C> auto constexpr rbegin(C& c) -> decltype(c.rbegin());                 // C++14
487020b623aSMarshall Clowtemplate <class C> auto constexpr rbegin(const C& c) -> decltype(c.rbegin());           // C++14
488020b623aSMarshall Clowtemplate <class C> auto constexpr rend(C& c) -> decltype(c.rend());                     // C++14
489020b623aSMarshall Clowtemplate <class C> constexpr auto rend(const C& c) -> decltype(c.rend());               // C++14
490020b623aSMarshall Clowtemplate <class E> reverse_iterator<const E*> constexpr rbegin(initializer_list<E> il); // C++14
491020b623aSMarshall Clowtemplate <class E> reverse_iterator<const E*> constexpr rend(initializer_list<E> il);   // C++14
492020b623aSMarshall Clowtemplate <class T, size_t N> reverse_iterator<T*> constexpr rbegin(T (&array)[N]);      // C++14
493020b623aSMarshall Clowtemplate <class T, size_t N> reverse_iterator<T*> constexpr rend(T (&array)[N]);        // C++14
494020b623aSMarshall Clowtemplate <class C> constexpr auto crbegin(const C& c) -> decltype(std::rbegin(c));      // C++14
495020b623aSMarshall Clowtemplate <class C> constexpr auto crend(const C& c) -> decltype(std::rend(c));          // C++14
4961e548c72SMarshall Clow
497ad755104SMarshall Clow// 24.8, container access:
498ad755104SMarshall Clowtemplate <class C> constexpr auto size(const C& c) -> decltype(c.size());         // C++17
499ad755104SMarshall Clowtemplate <class T, size_t N> constexpr size_t size(const T (&array)[N]) noexcept; // C++17
5007d3986eaSMarshall Clow
5017d3986eaSMarshall Clowtemplate <class C> constexpr auto ssize(const C& c)
5027d3986eaSMarshall Clow    -> common_type_t<ptrdiff_t, make_signed_t<decltype(c.size())>>;                    // C++20
5037d3986eaSMarshall Clowtemplate <class T, ptrdiff_t> constexpr ptrdiff_t ssize(const T (&array)[N]) noexcept; // C++20
5047d3986eaSMarshall Clow
505ad755104SMarshall Clowtemplate <class C> constexpr auto empty(const C& c) -> decltype(c.empty());       // C++17
506ad755104SMarshall Clowtemplate <class T, size_t N> constexpr bool empty(const T (&array)[N]) noexcept;  // C++17
507ad755104SMarshall Clowtemplate <class E> constexpr bool empty(initializer_list<E> il) noexcept;         // C++17
508ad755104SMarshall Clowtemplate <class C> constexpr auto data(C& c) -> decltype(c.data());               // C++17
509ad755104SMarshall Clowtemplate <class C> constexpr auto data(const C& c) -> decltype(c.data());         // C++17
510ad755104SMarshall Clowtemplate <class T, size_t N> constexpr T* data(T (&array)[N]) noexcept;           // C++17
511ad755104SMarshall Clowtemplate <class E> constexpr const E* data(initializer_list<E> il) noexcept;      // C++17
512ad755104SMarshall Clow
5133e519524SHoward Hinnant}  // std
5143e519524SHoward Hinnant
5153e519524SHoward Hinnant*/
5163e519524SHoward Hinnant
5173e519524SHoward Hinnant#include <__config>
5185f51fb34SArthur O'Dwyer#include <__debug>
519c204c130SMarshall Clow#include <__functional_base>
52036d0fdf9SChristopher Di Bella#include <__iterator/advance.h>
52157ebf3d0SLouis Dionne#include <__iterator/concepts.h>
522e0adf7e0Szoecarver#include <__iterator/incrementable_traits.h>
523*58b29a4eSLouis Dionne#include <__iterator/indirect_concepts.h>
52497e383aaSLouis Dionne#include <__iterator/iter_move.h>
525120fa829Szoecarver#include <__iterator/iterator_traits.h>
526857fa7b7SChristopher Di Bella#include <__iterator/next.h>
5270dc7fd1bSChristopher Di Bella#include <__iterator/prev.h>
528*58b29a4eSLouis Dionne#include <__iterator/projected.h>
529e0adf7e0Szoecarver#include <__iterator/readable_traits.h>
530f992cfbaSLouis Dionne#include <__memory/addressof.h>
531d41c6d51SArthur O'Dwyer#include <__memory/pointer_traits.h>
5325f51fb34SArthur O'Dwyer#include <compare>
5335f51fb34SArthur O'Dwyer#include <concepts> // Mandated by the Standard.
5345f51fb34SArthur O'Dwyer#include <cstddef>
5355f51fb34SArthur O'Dwyer#include <initializer_list>
5365f51fb34SArthur O'Dwyer#include <iosfwd> // for forward declarations of vector and string
5375f51fb34SArthur O'Dwyer#include <type_traits>
538f56972e2SMarshall Clow#include <version>
539b5c63a2eSHoward Hinnant
540073458b1SHoward Hinnant#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
5413e519524SHoward Hinnant#pragma GCC system_header
542073458b1SHoward Hinnant#endif
5433e519524SHoward Hinnant
5443e519524SHoward Hinnant_LIBCPP_BEGIN_NAMESPACE_STD
545fe31f11cSChristopher Di Bella
5463e519524SHoward Hinnanttemplate<class _Category, class _Tp, class _Distance = ptrdiff_t,
5473e519524SHoward Hinnant         class _Pointer = _Tp*, class _Reference = _Tp&>
5481055cb91SLouis Dionnestruct _LIBCPP_TEMPLATE_VIS _LIBCPP_DEPRECATED_IN_CXX17 iterator
5493e519524SHoward Hinnant{
5503e519524SHoward Hinnant    typedef _Tp        value_type;
5513e519524SHoward Hinnant    typedef _Distance  difference_type;
5523e519524SHoward Hinnant    typedef _Pointer   pointer;
5533e519524SHoward Hinnant    typedef _Reference reference;
5543e519524SHoward Hinnant    typedef _Category  iterator_category;
5553e519524SHoward Hinnant};
5563e519524SHoward Hinnant
5573e519524SHoward Hinnanttemplate <class _InputIter>
558f51ee632SMarshall Clowinline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
5593e519524SHoward Hinnantvoid __advance(_InputIter& __i,
5603e519524SHoward Hinnant             typename iterator_traits<_InputIter>::difference_type __n, input_iterator_tag)
5613e519524SHoward Hinnant{
5623e519524SHoward Hinnant    for (; __n > 0; --__n)
5633e519524SHoward Hinnant        ++__i;
5643e519524SHoward Hinnant}
5653e519524SHoward Hinnant
5663e519524SHoward Hinnanttemplate <class _BiDirIter>
567f51ee632SMarshall Clowinline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
5683e519524SHoward Hinnantvoid __advance(_BiDirIter& __i,
5693e519524SHoward Hinnant             typename iterator_traits<_BiDirIter>::difference_type __n, bidirectional_iterator_tag)
5703e519524SHoward Hinnant{
5713e519524SHoward Hinnant    if (__n >= 0)
5723e519524SHoward Hinnant        for (; __n > 0; --__n)
5733e519524SHoward Hinnant            ++__i;
5743e519524SHoward Hinnant    else
5753e519524SHoward Hinnant        for (; __n < 0; ++__n)
5763e519524SHoward Hinnant            --__i;
5773e519524SHoward Hinnant}
5783e519524SHoward Hinnant
5793e519524SHoward Hinnanttemplate <class _RandIter>
580f51ee632SMarshall Clowinline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
5813e519524SHoward Hinnantvoid __advance(_RandIter& __i,
5823e519524SHoward Hinnant             typename iterator_traits<_RandIter>::difference_type __n, random_access_iterator_tag)
5833e519524SHoward Hinnant{
5843e519524SHoward Hinnant   __i += __n;
5853e519524SHoward Hinnant}
5863e519524SHoward Hinnant
58736d0fdf9SChristopher Di Bellatemplate <class _InputIter, class _Distance,
58836d0fdf9SChristopher Di Bella          class = typename enable_if<is_integral<decltype(_VSTD::__convert_to_integral(declval<_Distance>()))>::value>::type>
589f51ee632SMarshall Clowinline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
59012b01ab7SLouis Dionnevoid advance(_InputIter& __i, _Distance __orig_n)
5913e519524SHoward Hinnant{
592c0428b3cSArthur O'Dwyer    typedef decltype(_VSTD::__convert_to_integral(__orig_n)) _IntegralSize;
59312b01ab7SLouis Dionne    _IntegralSize __n = __orig_n;
5949571b8f2SArthur O'Dwyer    _LIBCPP_ASSERT(__n >= 0 || __is_cpp17_bidirectional_iterator<_InputIter>::value,
5959571b8f2SArthur O'Dwyer                   "Attempt to advance(it, n) with negative n on a non-bidirectional iterator");
596c0428b3cSArthur O'Dwyer    _VSTD::__advance(__i, __n, typename iterator_traits<_InputIter>::iterator_category());
5973e519524SHoward Hinnant}
5983e519524SHoward Hinnant
5993e519524SHoward Hinnanttemplate <class _InputIter>
600f51ee632SMarshall Clowinline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
6013e519524SHoward Hinnanttypename iterator_traits<_InputIter>::difference_type
6023e519524SHoward Hinnant__distance(_InputIter __first, _InputIter __last, input_iterator_tag)
6033e519524SHoward Hinnant{
6043e519524SHoward Hinnant    typename iterator_traits<_InputIter>::difference_type __r(0);
6053e519524SHoward Hinnant    for (; __first != __last; ++__first)
6063e519524SHoward Hinnant        ++__r;
6073e519524SHoward Hinnant    return __r;
6083e519524SHoward Hinnant}
6093e519524SHoward Hinnant
6103e519524SHoward Hinnanttemplate <class _RandIter>
611f51ee632SMarshall Clowinline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
6123e519524SHoward Hinnanttypename iterator_traits<_RandIter>::difference_type
6133e519524SHoward Hinnant__distance(_RandIter __first, _RandIter __last, random_access_iterator_tag)
6143e519524SHoward Hinnant{
6153e519524SHoward Hinnant    return __last - __first;
6163e519524SHoward Hinnant}
6173e519524SHoward Hinnant
6183e519524SHoward Hinnanttemplate <class _InputIter>
619f51ee632SMarshall Clowinline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
6203e519524SHoward Hinnanttypename iterator_traits<_InputIter>::difference_type
6213e519524SHoward Hinnantdistance(_InputIter __first, _InputIter __last)
6223e519524SHoward Hinnant{
623c0428b3cSArthur O'Dwyer    return _VSTD::__distance(__first, __last, typename iterator_traits<_InputIter>::iterator_category());
6243e519524SHoward Hinnant}
6253e519524SHoward Hinnant
626e5f1288fSMarshall Clowtemplate <class _InputIter>
627f51ee632SMarshall Clowinline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
6283e2ef408SRachel Craiktypename enable_if
6293e2ef408SRachel Craik<
630f82dba01SEric Fiselier    __is_cpp17_input_iterator<_InputIter>::value,
631e5f1288fSMarshall Clow    _InputIter
6323e2ef408SRachel Craik>::type
633e5f1288fSMarshall Clownext(_InputIter __x,
6343e2ef408SRachel Craik     typename iterator_traits<_InputIter>::difference_type __n = 1)
6353e519524SHoward Hinnant{
636f82dba01SEric Fiselier    _LIBCPP_ASSERT(__n >= 0 || __is_cpp17_bidirectional_iterator<_InputIter>::value,
63712b01ab7SLouis Dionne                       "Attempt to next(it, n) with negative n on a non-bidirectional iterator");
638e1cd11d8SMarshall Clow
639ce48a113SHoward Hinnant    _VSTD::advance(__x, __n);
6403e519524SHoward Hinnant    return __x;
6413e519524SHoward Hinnant}
6423e519524SHoward Hinnant
643e1cd11d8SMarshall Clowtemplate <class _InputIter>
644f51ee632SMarshall Clowinline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
6453e2ef408SRachel Craiktypename enable_if
6463e2ef408SRachel Craik<
647f82dba01SEric Fiselier    __is_cpp17_input_iterator<_InputIter>::value,
648e1cd11d8SMarshall Clow    _InputIter
6493e2ef408SRachel Craik>::type
650e1cd11d8SMarshall Clowprev(_InputIter __x,
651e1cd11d8SMarshall Clow     typename iterator_traits<_InputIter>::difference_type __n = 1)
6523e519524SHoward Hinnant{
653f82dba01SEric Fiselier    _LIBCPP_ASSERT(__n <= 0 || __is_cpp17_bidirectional_iterator<_InputIter>::value,
65412b01ab7SLouis Dionne                       "Attempt to prev(it, n) with a positive n on a non-bidirectional iterator");
655ce48a113SHoward Hinnant    _VSTD::advance(__x, -__n);
6563e519524SHoward Hinnant    return __x;
6573e519524SHoward Hinnant}
6583e519524SHoward Hinnant
659e02ed1c2SEric Fiselier
660e02ed1c2SEric Fiseliertemplate <class _Tp, class = void>
661e02ed1c2SEric Fiselierstruct __is_stashing_iterator : false_type {};
662e02ed1c2SEric Fiselier
663e02ed1c2SEric Fiseliertemplate <class _Tp>
664e02ed1c2SEric Fiselierstruct __is_stashing_iterator<_Tp, typename __void_t<typename _Tp::__stashing_iterator_tag>::type>
665e02ed1c2SEric Fiselier  : true_type {};
666e02ed1c2SEric Fiselier
6671055cb91SLouis Dionne_LIBCPP_SUPPRESS_DEPRECATED_PUSH
6683e519524SHoward Hinnanttemplate <class _Iter>
669e2f2d1edSEric Fiselierclass _LIBCPP_TEMPLATE_VIS reverse_iterator
6701055cb91SLouis Dionne#if _LIBCPP_STD_VER <= 14 || !defined(_LIBCPP_ABI_NO_ITERATOR_BASES)
6713e519524SHoward Hinnant    : public iterator<typename iterator_traits<_Iter>::iterator_category,
6723e519524SHoward Hinnant                      typename iterator_traits<_Iter>::value_type,
6733e519524SHoward Hinnant                      typename iterator_traits<_Iter>::difference_type,
6743e519524SHoward Hinnant                      typename iterator_traits<_Iter>::pointer,
6753e519524SHoward Hinnant                      typename iterator_traits<_Iter>::reference>
6761055cb91SLouis Dionne#endif
6773e519524SHoward Hinnant{
6781055cb91SLouis Dionne_LIBCPP_SUPPRESS_DEPRECATED_POP
6793b83496dSMarshall Clowprivate:
6801055cb91SLouis Dionne#ifndef _LIBCPP_ABI_NO_ITERATOR_BASES
6811055cb91SLouis Dionne    _Iter __t; // no longer used as of LWG #2360, not removed due to ABI break
6821055cb91SLouis Dionne#endif
683e02ed1c2SEric Fiselier
684e02ed1c2SEric Fiselier    static_assert(!__is_stashing_iterator<_Iter>::value,
685e02ed1c2SEric Fiselier      "The specified iterator type cannot be used with reverse_iterator; "
686e02ed1c2SEric Fiselier      "Using stashing iterators with reverse_iterator causes undefined behavior");
687e02ed1c2SEric Fiselier
688b2d74f29SMarshall Clowprotected:
689b2d74f29SMarshall Clow    _Iter current;
6903e519524SHoward Hinnantpublic:
6913e519524SHoward Hinnant    typedef _Iter                                            iterator_type;
6923e519524SHoward Hinnant    typedef typename iterator_traits<_Iter>::difference_type difference_type;
6933e519524SHoward Hinnant    typedef typename iterator_traits<_Iter>::reference       reference;
6943e519524SHoward Hinnant    typedef typename iterator_traits<_Iter>::pointer         pointer;
695d41c6d51SArthur O'Dwyer    typedef _If<__is_cpp17_random_access_iterator<_Iter>::value,
696d41c6d51SArthur O'Dwyer        random_access_iterator_tag,
697d41c6d51SArthur O'Dwyer        typename iterator_traits<_Iter>::iterator_category>  iterator_category;
6981055cb91SLouis Dionne    typedef typename iterator_traits<_Iter>::value_type      value_type;
6991055cb91SLouis Dionne
700d41c6d51SArthur O'Dwyer#if _LIBCPP_STD_VER > 17
701d41c6d51SArthur O'Dwyer    typedef _If<__is_cpp17_random_access_iterator<_Iter>::value,
702d41c6d51SArthur O'Dwyer        random_access_iterator_tag,
703d41c6d51SArthur O'Dwyer        bidirectional_iterator_tag>                          iterator_concept;
704d41c6d51SArthur O'Dwyer#endif
7053e519524SHoward Hinnant
7061055cb91SLouis Dionne#ifndef _LIBCPP_ABI_NO_ITERATOR_BASES
7071b8f260eSMarshall Clow    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
7081b8f260eSMarshall Clow    reverse_iterator() : __t(), current() {}
7091b8f260eSMarshall Clow    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
7101b8f260eSMarshall Clow    explicit reverse_iterator(_Iter __x) : __t(__x), current(__x) {}
7111b8f260eSMarshall Clow    template <class _Up>
7121b8f260eSMarshall Clow        _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
7131b8f260eSMarshall Clow        reverse_iterator(const reverse_iterator<_Up>& __u) : __t(__u.base()), current(__u.base()) {}
7141b8f260eSMarshall Clow    template <class _Up>
7151b8f260eSMarshall Clow        _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
7161b8f260eSMarshall Clow        reverse_iterator& operator=(const reverse_iterator<_Up>& __u)
7171b8f260eSMarshall Clow            { __t = current = __u.base(); return *this; }
7181055cb91SLouis Dionne#else
7191055cb91SLouis Dionne    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
7201055cb91SLouis Dionne    reverse_iterator() : current() {}
7211055cb91SLouis Dionne    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
7221055cb91SLouis Dionne    explicit reverse_iterator(_Iter __x) : current(__x) {}
7231055cb91SLouis Dionne    template <class _Up>
7241055cb91SLouis Dionne        _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
7251055cb91SLouis Dionne        reverse_iterator(const reverse_iterator<_Up>& __u) : current(__u.base()) {}
7261055cb91SLouis Dionne    template <class _Up>
7271055cb91SLouis Dionne        _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
7281055cb91SLouis Dionne        reverse_iterator& operator=(const reverse_iterator<_Up>& __u)
7291055cb91SLouis Dionne            { current = __u.base(); return *this; }
7301055cb91SLouis Dionne#endif
7311b8f260eSMarshall Clow    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
7321b8f260eSMarshall Clow    _Iter base() const {return current;}
7331b8f260eSMarshall Clow    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
7341b8f260eSMarshall Clow    reference operator*() const {_Iter __tmp = current; return *--__tmp;}
7351b8f260eSMarshall Clow    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
7361b8f260eSMarshall Clow    pointer  operator->() const {return _VSTD::addressof(operator*());}
7371b8f260eSMarshall Clow    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
7381b8f260eSMarshall Clow    reverse_iterator& operator++() {--current; return *this;}
7391b8f260eSMarshall Clow    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
7401b8f260eSMarshall Clow    reverse_iterator  operator++(int) {reverse_iterator __tmp(*this); --current; return __tmp;}
7411b8f260eSMarshall Clow    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
7421b8f260eSMarshall Clow    reverse_iterator& operator--() {++current; return *this;}
7431b8f260eSMarshall Clow    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
7441b8f260eSMarshall Clow    reverse_iterator  operator--(int) {reverse_iterator __tmp(*this); ++current; return __tmp;}
7451b8f260eSMarshall Clow    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
7461b8f260eSMarshall Clow    reverse_iterator  operator+ (difference_type __n) const {return reverse_iterator(current - __n);}
7471b8f260eSMarshall Clow    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
7481b8f260eSMarshall Clow    reverse_iterator& operator+=(difference_type __n) {current -= __n; return *this;}
7491b8f260eSMarshall Clow    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
7501b8f260eSMarshall Clow    reverse_iterator  operator- (difference_type __n) const {return reverse_iterator(current + __n);}
7511b8f260eSMarshall Clow    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
7521b8f260eSMarshall Clow    reverse_iterator& operator-=(difference_type __n) {current += __n; return *this;}
7531b8f260eSMarshall Clow    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
7541b8f260eSMarshall Clow    reference         operator[](difference_type __n) const {return *(*this + __n);}
7553e519524SHoward Hinnant};
7563e519524SHoward Hinnant
7573e519524SHoward Hinnanttemplate <class _Iter1, class _Iter2>
7581b8f260eSMarshall Clowinline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
7593e519524SHoward Hinnantbool
7603e519524SHoward Hinnantoperator==(const reverse_iterator<_Iter1>& __x, const reverse_iterator<_Iter2>& __y)
7613e519524SHoward Hinnant{
7623e519524SHoward Hinnant    return __x.base() == __y.base();
7633e519524SHoward Hinnant}
7643e519524SHoward Hinnant
7653e519524SHoward Hinnanttemplate <class _Iter1, class _Iter2>
7661b8f260eSMarshall Clowinline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
7673e519524SHoward Hinnantbool
7683e519524SHoward Hinnantoperator<(const reverse_iterator<_Iter1>& __x, const reverse_iterator<_Iter2>& __y)
7693e519524SHoward Hinnant{
7703e519524SHoward Hinnant    return __x.base() > __y.base();
7713e519524SHoward Hinnant}
7723e519524SHoward Hinnant
7733e519524SHoward Hinnanttemplate <class _Iter1, class _Iter2>
7741b8f260eSMarshall Clowinline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
7753e519524SHoward Hinnantbool
7763e519524SHoward Hinnantoperator!=(const reverse_iterator<_Iter1>& __x, const reverse_iterator<_Iter2>& __y)
7773e519524SHoward Hinnant{
7783e519524SHoward Hinnant    return __x.base() != __y.base();
7793e519524SHoward Hinnant}
7803e519524SHoward Hinnant
7813e519524SHoward Hinnanttemplate <class _Iter1, class _Iter2>
7821b8f260eSMarshall Clowinline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
7833e519524SHoward Hinnantbool
7843e519524SHoward Hinnantoperator>(const reverse_iterator<_Iter1>& __x, const reverse_iterator<_Iter2>& __y)
7853e519524SHoward Hinnant{
7863e519524SHoward Hinnant    return __x.base() < __y.base();
7873e519524SHoward Hinnant}
7883e519524SHoward Hinnant
7893e519524SHoward Hinnanttemplate <class _Iter1, class _Iter2>
7901b8f260eSMarshall Clowinline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
7913e519524SHoward Hinnantbool
7923e519524SHoward Hinnantoperator>=(const reverse_iterator<_Iter1>& __x, const reverse_iterator<_Iter2>& __y)
7933e519524SHoward Hinnant{
7943e519524SHoward Hinnant    return __x.base() <= __y.base();
7953e519524SHoward Hinnant}
7963e519524SHoward Hinnant
7973e519524SHoward Hinnanttemplate <class _Iter1, class _Iter2>
7981b8f260eSMarshall Clowinline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
7993e519524SHoward Hinnantbool
8003e519524SHoward Hinnantoperator<=(const reverse_iterator<_Iter1>& __x, const reverse_iterator<_Iter2>& __y)
8013e519524SHoward Hinnant{
8023e519524SHoward Hinnant    return __x.base() >= __y.base();
8033e519524SHoward Hinnant}
8043e519524SHoward Hinnant
8052ee83725SMarshall Clow#ifndef _LIBCPP_CXX03_LANG
806947ce6b5SMarshall Clowtemplate <class _Iter1, class _Iter2>
8071b8f260eSMarshall Clowinline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
808947ce6b5SMarshall Clowauto
809947ce6b5SMarshall Clowoperator-(const reverse_iterator<_Iter1>& __x, const reverse_iterator<_Iter2>& __y)
810947ce6b5SMarshall Clow-> decltype(__y.base() - __x.base())
811947ce6b5SMarshall Clow{
812947ce6b5SMarshall Clow    return __y.base() - __x.base();
813947ce6b5SMarshall Clow}
814947ce6b5SMarshall Clow#else
8153e519524SHoward Hinnanttemplate <class _Iter1, class _Iter2>
8163e519524SHoward Hinnantinline _LIBCPP_INLINE_VISIBILITY
8173e519524SHoward Hinnanttypename reverse_iterator<_Iter1>::difference_type
8183e519524SHoward Hinnantoperator-(const reverse_iterator<_Iter1>& __x, const reverse_iterator<_Iter2>& __y)
8193e519524SHoward Hinnant{
8203e519524SHoward Hinnant    return __y.base() - __x.base();
8213e519524SHoward Hinnant}
822947ce6b5SMarshall Clow#endif
8233e519524SHoward Hinnant
8243e519524SHoward Hinnanttemplate <class _Iter>
8251b8f260eSMarshall Clowinline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
8263e519524SHoward Hinnantreverse_iterator<_Iter>
8273e519524SHoward Hinnantoperator+(typename reverse_iterator<_Iter>::difference_type __n, const reverse_iterator<_Iter>& __x)
8283e519524SHoward Hinnant{
8293e519524SHoward Hinnant    return reverse_iterator<_Iter>(__x.base() - __n);
8303e519524SHoward Hinnant}
8313e519524SHoward Hinnant
8326a640a18SMarshall Clow#if _LIBCPP_STD_VER > 11
8336a640a18SMarshall Clowtemplate <class _Iter>
8341b8f260eSMarshall Clowinline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
8356a640a18SMarshall Clowreverse_iterator<_Iter> make_reverse_iterator(_Iter __i)
8366a640a18SMarshall Clow{
8376a640a18SMarshall Clow    return reverse_iterator<_Iter>(__i);
8386a640a18SMarshall Clow}
8396a640a18SMarshall Clow#endif
8406a640a18SMarshall Clow
8411055cb91SLouis Dionne_LIBCPP_SUPPRESS_DEPRECATED_PUSH
8423e519524SHoward Hinnanttemplate <class _Container>
843e2f2d1edSEric Fiselierclass _LIBCPP_TEMPLATE_VIS back_insert_iterator
8441055cb91SLouis Dionne#if _LIBCPP_STD_VER <= 14 || !defined(_LIBCPP_ABI_NO_ITERATOR_BASES)
8451055cb91SLouis Dionne    : public iterator<output_iterator_tag, void, void, void, void>
8461055cb91SLouis Dionne#endif
8473e519524SHoward Hinnant{
8481055cb91SLouis Dionne_LIBCPP_SUPPRESS_DEPRECATED_POP
8493e519524SHoward Hinnantprotected:
8503e519524SHoward Hinnant    _Container* container;
8513e519524SHoward Hinnantpublic:
8521055cb91SLouis Dionne    typedef output_iterator_tag iterator_category;
8531055cb91SLouis Dionne    typedef void value_type;
8541055cb91SLouis Dionne    typedef void difference_type;
8551055cb91SLouis Dionne    typedef void pointer;
8561055cb91SLouis Dionne    typedef void reference;
8573e519524SHoward Hinnant    typedef _Container container_type;
8583e519524SHoward Hinnant
85906e2b737SArthur O'Dwyer    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 explicit back_insert_iterator(_Container& __x) : container(_VSTD::addressof(__x)) {}
86006e2b737SArthur O'Dwyer    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 back_insert_iterator& operator=(const typename _Container::value_type& __value_)
861e4383379SHoward Hinnant        {container->push_back(__value_); return *this;}
862046492b9SEric Fiselier#ifndef _LIBCPP_CXX03_LANG
86306e2b737SArthur O'Dwyer    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 back_insert_iterator& operator=(typename _Container::value_type&& __value_)
864e4383379SHoward Hinnant        {container->push_back(_VSTD::move(__value_)); return *this;}
865046492b9SEric Fiselier#endif // _LIBCPP_CXX03_LANG
86606e2b737SArthur O'Dwyer    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 back_insert_iterator& operator*()     {return *this;}
86706e2b737SArthur O'Dwyer    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 back_insert_iterator& operator++()    {return *this;}
86806e2b737SArthur O'Dwyer    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 back_insert_iterator  operator++(int) {return *this;}
8693e519524SHoward Hinnant};
8703e519524SHoward Hinnant
8713e519524SHoward Hinnanttemplate <class _Container>
87206e2b737SArthur O'Dwyerinline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
8733e519524SHoward Hinnantback_insert_iterator<_Container>
8743e519524SHoward Hinnantback_inserter(_Container& __x)
8753e519524SHoward Hinnant{
8763e519524SHoward Hinnant    return back_insert_iterator<_Container>(__x);
8773e519524SHoward Hinnant}
8783e519524SHoward Hinnant
8791055cb91SLouis Dionne_LIBCPP_SUPPRESS_DEPRECATED_PUSH
8803e519524SHoward Hinnanttemplate <class _Container>
881e2f2d1edSEric Fiselierclass _LIBCPP_TEMPLATE_VIS front_insert_iterator
8821055cb91SLouis Dionne#if _LIBCPP_STD_VER <= 14 || !defined(_LIBCPP_ABI_NO_ITERATOR_BASES)
8831055cb91SLouis Dionne    : public iterator<output_iterator_tag, void, void, void, void>
8841055cb91SLouis Dionne#endif
8853e519524SHoward Hinnant{
8861055cb91SLouis Dionne_LIBCPP_SUPPRESS_DEPRECATED_POP
8873e519524SHoward Hinnantprotected:
8883e519524SHoward Hinnant    _Container* container;
8893e519524SHoward Hinnantpublic:
8901055cb91SLouis Dionne    typedef output_iterator_tag iterator_category;
8911055cb91SLouis Dionne    typedef void value_type;
8921055cb91SLouis Dionne    typedef void difference_type;
8931055cb91SLouis Dionne    typedef void pointer;
8941055cb91SLouis Dionne    typedef void reference;
8953e519524SHoward Hinnant    typedef _Container container_type;
8963e519524SHoward Hinnant
89706e2b737SArthur O'Dwyer    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 explicit front_insert_iterator(_Container& __x) : container(_VSTD::addressof(__x)) {}
89806e2b737SArthur O'Dwyer    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 front_insert_iterator& operator=(const typename _Container::value_type& __value_)
899e4383379SHoward Hinnant        {container->push_front(__value_); return *this;}
900046492b9SEric Fiselier#ifndef _LIBCPP_CXX03_LANG
90106e2b737SArthur O'Dwyer    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 front_insert_iterator& operator=(typename _Container::value_type&& __value_)
902e4383379SHoward Hinnant        {container->push_front(_VSTD::move(__value_)); return *this;}
903046492b9SEric Fiselier#endif // _LIBCPP_CXX03_LANG
90406e2b737SArthur O'Dwyer    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 front_insert_iterator& operator*()     {return *this;}
90506e2b737SArthur O'Dwyer    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 front_insert_iterator& operator++()    {return *this;}
90606e2b737SArthur O'Dwyer    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 front_insert_iterator  operator++(int) {return *this;}
9073e519524SHoward Hinnant};
9083e519524SHoward Hinnant
9093e519524SHoward Hinnanttemplate <class _Container>
91006e2b737SArthur O'Dwyerinline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
9113e519524SHoward Hinnantfront_insert_iterator<_Container>
9123e519524SHoward Hinnantfront_inserter(_Container& __x)
9133e519524SHoward Hinnant{
9143e519524SHoward Hinnant    return front_insert_iterator<_Container>(__x);
9153e519524SHoward Hinnant}
9163e519524SHoward Hinnant
9171055cb91SLouis Dionne_LIBCPP_SUPPRESS_DEPRECATED_PUSH
9183e519524SHoward Hinnanttemplate <class _Container>
919e2f2d1edSEric Fiselierclass _LIBCPP_TEMPLATE_VIS insert_iterator
9201055cb91SLouis Dionne#if _LIBCPP_STD_VER <= 14 || !defined(_LIBCPP_ABI_NO_ITERATOR_BASES)
9211055cb91SLouis Dionne    : public iterator<output_iterator_tag, void, void, void, void>
9221055cb91SLouis Dionne#endif
9233e519524SHoward Hinnant{
9241055cb91SLouis Dionne_LIBCPP_SUPPRESS_DEPRECATED_POP
9253e519524SHoward Hinnantprotected:
9263e519524SHoward Hinnant    _Container* container;
9273e519524SHoward Hinnant    typename _Container::iterator iter;
9283e519524SHoward Hinnantpublic:
9291055cb91SLouis Dionne    typedef output_iterator_tag iterator_category;
9301055cb91SLouis Dionne    typedef void value_type;
9311055cb91SLouis Dionne    typedef void difference_type;
9321055cb91SLouis Dionne    typedef void pointer;
9331055cb91SLouis Dionne    typedef void reference;
9343e519524SHoward Hinnant    typedef _Container container_type;
9353e519524SHoward Hinnant
93606e2b737SArthur O'Dwyer    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 insert_iterator(_Container& __x, typename _Container::iterator __i)
937f519be34SMarshall Clow        : container(_VSTD::addressof(__x)), iter(__i) {}
93806e2b737SArthur O'Dwyer    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 insert_iterator& operator=(const typename _Container::value_type& __value_)
939e4383379SHoward Hinnant        {iter = container->insert(iter, __value_); ++iter; return *this;}
940046492b9SEric Fiselier#ifndef _LIBCPP_CXX03_LANG
94106e2b737SArthur O'Dwyer    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 insert_iterator& operator=(typename _Container::value_type&& __value_)
942e4383379SHoward Hinnant        {iter = container->insert(iter, _VSTD::move(__value_)); ++iter; return *this;}
943046492b9SEric Fiselier#endif // _LIBCPP_CXX03_LANG
94406e2b737SArthur O'Dwyer    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 insert_iterator& operator*()        {return *this;}
94506e2b737SArthur O'Dwyer    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 insert_iterator& operator++()       {return *this;}
94606e2b737SArthur O'Dwyer    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 insert_iterator& operator++(int)    {return *this;}
9473e519524SHoward Hinnant};
9483e519524SHoward Hinnant
9493e519524SHoward Hinnanttemplate <class _Container>
95006e2b737SArthur O'Dwyerinline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
9513e519524SHoward Hinnantinsert_iterator<_Container>
9523e519524SHoward Hinnantinserter(_Container& __x, typename _Container::iterator __i)
9533e519524SHoward Hinnant{
9543e519524SHoward Hinnant    return insert_iterator<_Container>(__x, __i);
9553e519524SHoward Hinnant}
9563e519524SHoward Hinnant
9571055cb91SLouis Dionne_LIBCPP_SUPPRESS_DEPRECATED_PUSH
9583e519524SHoward Hinnanttemplate <class _Tp, class _CharT = char,
9593e519524SHoward Hinnant          class _Traits = char_traits<_CharT>, class _Distance = ptrdiff_t>
960e2f2d1edSEric Fiselierclass _LIBCPP_TEMPLATE_VIS istream_iterator
9611055cb91SLouis Dionne#if _LIBCPP_STD_VER <= 14 || !defined(_LIBCPP_ABI_NO_ITERATOR_BASES)
9623e519524SHoward Hinnant    : public iterator<input_iterator_tag, _Tp, _Distance, const _Tp*, const _Tp&>
9631055cb91SLouis Dionne#endif
9643e519524SHoward Hinnant{
9651055cb91SLouis Dionne_LIBCPP_SUPPRESS_DEPRECATED_POP
9663e519524SHoward Hinnantpublic:
9671055cb91SLouis Dionne    typedef input_iterator_tag iterator_category;
9681055cb91SLouis Dionne    typedef _Tp value_type;
9691055cb91SLouis Dionne    typedef _Distance difference_type;
9701055cb91SLouis Dionne    typedef const _Tp* pointer;
9711055cb91SLouis Dionne    typedef const _Tp& reference;
9723e519524SHoward Hinnant    typedef _CharT char_type;
9733e519524SHoward Hinnant    typedef _Traits traits_type;
9743e519524SHoward Hinnant    typedef basic_istream<_CharT,_Traits> istream_type;
9753e519524SHoward Hinnantprivate:
9763e519524SHoward Hinnant    istream_type* __in_stream_;
9773e519524SHoward Hinnant    _Tp __value_;
9783e519524SHoward Hinnantpublic:
979527a7fdfSBruce Mitchener    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR istream_iterator() : __in_stream_(nullptr), __value_() {}
980bc6a7df0SMarshall Clow    _LIBCPP_INLINE_VISIBILITY istream_iterator(istream_type& __s) : __in_stream_(_VSTD::addressof(__s))
9813e519524SHoward Hinnant        {
9823e519524SHoward Hinnant            if (!(*__in_stream_ >> __value_))
983527a7fdfSBruce Mitchener                __in_stream_ = nullptr;
9843e519524SHoward Hinnant        }
9853e519524SHoward Hinnant
9863e519524SHoward Hinnant    _LIBCPP_INLINE_VISIBILITY const _Tp& operator*() const {return __value_;}
987bc6a7df0SMarshall Clow    _LIBCPP_INLINE_VISIBILITY const _Tp* operator->() const {return _VSTD::addressof((operator*()));}
9883e519524SHoward Hinnant    _LIBCPP_INLINE_VISIBILITY istream_iterator& operator++()
9893e519524SHoward Hinnant        {
9903e519524SHoward Hinnant            if (!(*__in_stream_ >> __value_))
991527a7fdfSBruce Mitchener                __in_stream_ = nullptr;
9923e519524SHoward Hinnant            return *this;
9933e519524SHoward Hinnant        }
9943e519524SHoward Hinnant    _LIBCPP_INLINE_VISIBILITY istream_iterator  operator++(int)
9953e519524SHoward Hinnant        {istream_iterator __t(*this); ++(*this); return __t;}
9963e519524SHoward Hinnant
9976f56d3eeSRoger Ferrer Ibanez    template <class _Up, class _CharU, class _TraitsU, class _DistanceU>
9983e519524SHoward Hinnant    friend _LIBCPP_INLINE_VISIBILITY
9996f56d3eeSRoger Ferrer Ibanez    bool
10006f56d3eeSRoger Ferrer Ibanez    operator==(const istream_iterator<_Up, _CharU, _TraitsU, _DistanceU>& __x,
10016f56d3eeSRoger Ferrer Ibanez               const istream_iterator<_Up, _CharU, _TraitsU, _DistanceU>& __y);
10023e519524SHoward Hinnant
10036f56d3eeSRoger Ferrer Ibanez    template <class _Up, class _CharU, class _TraitsU, class _DistanceU>
10043e519524SHoward Hinnant    friend _LIBCPP_INLINE_VISIBILITY
10056f56d3eeSRoger Ferrer Ibanez    bool
10066f56d3eeSRoger Ferrer Ibanez    operator==(const istream_iterator<_Up, _CharU, _TraitsU, _DistanceU>& __x,
10076f56d3eeSRoger Ferrer Ibanez               const istream_iterator<_Up, _CharU, _TraitsU, _DistanceU>& __y);
10083e519524SHoward Hinnant};
10093e519524SHoward Hinnant
10106f56d3eeSRoger Ferrer Ibaneztemplate <class _Tp, class _CharT, class _Traits, class _Distance>
10116f56d3eeSRoger Ferrer Ibanezinline _LIBCPP_INLINE_VISIBILITY
10126f56d3eeSRoger Ferrer Ibanezbool
10136f56d3eeSRoger Ferrer Ibanezoperator==(const istream_iterator<_Tp, _CharT, _Traits, _Distance>& __x,
10146f56d3eeSRoger Ferrer Ibanez           const istream_iterator<_Tp, _CharT, _Traits, _Distance>& __y)
10156f56d3eeSRoger Ferrer Ibanez{
10166f56d3eeSRoger Ferrer Ibanez    return __x.__in_stream_ == __y.__in_stream_;
10176f56d3eeSRoger Ferrer Ibanez}
10186f56d3eeSRoger Ferrer Ibanez
10196f56d3eeSRoger Ferrer Ibaneztemplate <class _Tp, class _CharT, class _Traits, class _Distance>
10206f56d3eeSRoger Ferrer Ibanezinline _LIBCPP_INLINE_VISIBILITY
10216f56d3eeSRoger Ferrer Ibanezbool
10226f56d3eeSRoger Ferrer Ibanezoperator!=(const istream_iterator<_Tp, _CharT, _Traits, _Distance>& __x,
10236f56d3eeSRoger Ferrer Ibanez           const istream_iterator<_Tp, _CharT, _Traits, _Distance>& __y)
10246f56d3eeSRoger Ferrer Ibanez{
10256f56d3eeSRoger Ferrer Ibanez    return !(__x == __y);
10266f56d3eeSRoger Ferrer Ibanez}
10276f56d3eeSRoger Ferrer Ibanez
10281055cb91SLouis Dionne_LIBCPP_SUPPRESS_DEPRECATED_PUSH
10293e519524SHoward Hinnanttemplate <class _Tp, class _CharT = char, class _Traits = char_traits<_CharT> >
1030e2f2d1edSEric Fiselierclass _LIBCPP_TEMPLATE_VIS ostream_iterator
10311055cb91SLouis Dionne#if _LIBCPP_STD_VER <= 14 || !defined(_LIBCPP_ABI_NO_ITERATOR_BASES)
10323e519524SHoward Hinnant    : public iterator<output_iterator_tag, void, void, void, void>
10331055cb91SLouis Dionne#endif
10343e519524SHoward Hinnant{
10351055cb91SLouis Dionne_LIBCPP_SUPPRESS_DEPRECATED_POP
10363e519524SHoward Hinnantpublic:
103771a16e40SLouis Dionne    typedef output_iterator_tag             iterator_category;
103871a16e40SLouis Dionne    typedef void                            value_type;
103971a16e40SLouis Dionne#if _LIBCPP_STD_VER > 17
104071a16e40SLouis Dionne    typedef std::ptrdiff_t                  difference_type;
104171a16e40SLouis Dionne#else
104271a16e40SLouis Dionne    typedef void                            difference_type;
104371a16e40SLouis Dionne#endif
104471a16e40SLouis Dionne    typedef void                            pointer;
104571a16e40SLouis Dionne    typedef void                            reference;
10463e519524SHoward Hinnant    typedef _CharT                          char_type;
10473e519524SHoward Hinnant    typedef _Traits                         traits_type;
10483e519524SHoward Hinnant    typedef basic_ostream<_CharT, _Traits>  ostream_type;
104971a16e40SLouis Dionne
10503e519524SHoward Hinnantprivate:
10513e519524SHoward Hinnant    ostream_type* __out_stream_;
10523e519524SHoward Hinnant    const char_type* __delim_;
10533e519524SHoward Hinnantpublic:
1054853042cfSMarshall Clow    _LIBCPP_INLINE_VISIBILITY ostream_iterator(ostream_type& __s) _NOEXCEPT
1055527a7fdfSBruce Mitchener        : __out_stream_(_VSTD::addressof(__s)), __delim_(nullptr) {}
1056853042cfSMarshall Clow    _LIBCPP_INLINE_VISIBILITY ostream_iterator(ostream_type& __s, const _CharT* __delimiter) _NOEXCEPT
1057bc6a7df0SMarshall Clow        : __out_stream_(_VSTD::addressof(__s)), __delim_(__delimiter) {}
1058e4383379SHoward Hinnant    _LIBCPP_INLINE_VISIBILITY ostream_iterator& operator=(const _Tp& __value_)
10593e519524SHoward Hinnant        {
1060e4383379SHoward Hinnant            *__out_stream_ << __value_;
10613e519524SHoward Hinnant            if (__delim_)
10623e519524SHoward Hinnant                *__out_stream_ << __delim_;
10633e519524SHoward Hinnant            return *this;
10643e519524SHoward Hinnant        }
10653e519524SHoward Hinnant
10663e519524SHoward Hinnant    _LIBCPP_INLINE_VISIBILITY ostream_iterator& operator*()     {return *this;}
10673e519524SHoward Hinnant    _LIBCPP_INLINE_VISIBILITY ostream_iterator& operator++()    {return *this;}
10683e519524SHoward Hinnant    _LIBCPP_INLINE_VISIBILITY ostream_iterator& operator++(int) {return *this;}
10693e519524SHoward Hinnant};
10703e519524SHoward Hinnant
10711055cb91SLouis Dionne_LIBCPP_SUPPRESS_DEPRECATED_PUSH
10723e519524SHoward Hinnanttemplate<class _CharT, class _Traits>
1073e2f2d1edSEric Fiselierclass _LIBCPP_TEMPLATE_VIS istreambuf_iterator
10741055cb91SLouis Dionne#if _LIBCPP_STD_VER <= 14 || !defined(_LIBCPP_ABI_NO_ITERATOR_BASES)
10753e519524SHoward Hinnant    : public iterator<input_iterator_tag, _CharT,
10763e519524SHoward Hinnant                      typename _Traits::off_type, _CharT*,
10773e519524SHoward Hinnant                      _CharT>
10781055cb91SLouis Dionne#endif
10793e519524SHoward Hinnant{
10801055cb91SLouis Dionne_LIBCPP_SUPPRESS_DEPRECATED_POP
10813e519524SHoward Hinnantpublic:
10821055cb91SLouis Dionne    typedef input_iterator_tag              iterator_category;
10831055cb91SLouis Dionne    typedef _CharT                          value_type;
10841055cb91SLouis Dionne    typedef typename _Traits::off_type      difference_type;
10851055cb91SLouis Dionne    typedef _CharT*                         pointer;
10861055cb91SLouis Dionne    typedef _CharT                          reference;
10873e519524SHoward Hinnant    typedef _CharT                          char_type;
10883e519524SHoward Hinnant    typedef _Traits                         traits_type;
10893e519524SHoward Hinnant    typedef typename _Traits::int_type      int_type;
10903e519524SHoward Hinnant    typedef basic_streambuf<_CharT,_Traits> streambuf_type;
10913e519524SHoward Hinnant    typedef basic_istream<_CharT,_Traits>   istream_type;
10923e519524SHoward Hinnantprivate:
1093dfdf5085SHoward Hinnant    mutable streambuf_type* __sbuf_;
10943e519524SHoward Hinnant
10953e519524SHoward Hinnant    class __proxy
10963e519524SHoward Hinnant    {
10973e519524SHoward Hinnant        char_type __keep_;
10983e519524SHoward Hinnant        streambuf_type* __sbuf_;
10993e519524SHoward Hinnant        _LIBCPP_INLINE_VISIBILITY __proxy(char_type __c, streambuf_type* __s)
11003e519524SHoward Hinnant            : __keep_(__c), __sbuf_(__s) {}
11013e519524SHoward Hinnant        friend class istreambuf_iterator;
11023e519524SHoward Hinnant    public:
11033e519524SHoward Hinnant        _LIBCPP_INLINE_VISIBILITY char_type operator*() const {return __keep_;}
11043e519524SHoward Hinnant    };
11053e519524SHoward Hinnant
1106848a5374SHoward Hinnant    _LIBCPP_INLINE_VISIBILITY
1107dfdf5085SHoward Hinnant    bool __test_for_eof() const
11083e519524SHoward Hinnant    {
11093e519524SHoward Hinnant        if (__sbuf_ && traits_type::eq_int_type(__sbuf_->sgetc(), traits_type::eof()))
1110527a7fdfSBruce Mitchener            __sbuf_ = nullptr;
1111527a7fdfSBruce Mitchener        return __sbuf_ == nullptr;
11123e519524SHoward Hinnant    }
11133e519524SHoward Hinnantpublic:
1114527a7fdfSBruce Mitchener    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR istreambuf_iterator() _NOEXCEPT : __sbuf_(nullptr) {}
11158e882dcbSHoward Hinnant    _LIBCPP_INLINE_VISIBILITY istreambuf_iterator(istream_type& __s) _NOEXCEPT
1116a96d7458SHoward Hinnant        : __sbuf_(__s.rdbuf()) {}
11178e882dcbSHoward Hinnant    _LIBCPP_INLINE_VISIBILITY istreambuf_iterator(streambuf_type* __s) _NOEXCEPT
1118a96d7458SHoward Hinnant        : __sbuf_(__s) {}
11198e882dcbSHoward Hinnant    _LIBCPP_INLINE_VISIBILITY istreambuf_iterator(const __proxy& __p) _NOEXCEPT
11203e519524SHoward Hinnant        : __sbuf_(__p.__sbuf_) {}
11213e519524SHoward Hinnant
1122c206366fSHoward Hinnant    _LIBCPP_INLINE_VISIBILITY char_type  operator*() const
1123c206366fSHoward Hinnant        {return static_cast<char_type>(__sbuf_->sgetc());}
11243e519524SHoward Hinnant    _LIBCPP_INLINE_VISIBILITY istreambuf_iterator& operator++()
11253e519524SHoward Hinnant        {
1126dfdf5085SHoward Hinnant            __sbuf_->sbumpc();
11273e519524SHoward Hinnant            return *this;
11283e519524SHoward Hinnant        }
11293e519524SHoward Hinnant    _LIBCPP_INLINE_VISIBILITY __proxy              operator++(int)
11303e519524SHoward Hinnant        {
1131dfdf5085SHoward Hinnant            return __proxy(__sbuf_->sbumpc(), __sbuf_);
11323e519524SHoward Hinnant        }
11333e519524SHoward Hinnant
11343e519524SHoward Hinnant    _LIBCPP_INLINE_VISIBILITY bool equal(const istreambuf_iterator& __b) const
1135dfdf5085SHoward Hinnant        {return __test_for_eof() == __b.__test_for_eof();}
11363e519524SHoward Hinnant};
11373e519524SHoward Hinnant
11383e519524SHoward Hinnanttemplate <class _CharT, class _Traits>
11393e519524SHoward Hinnantinline _LIBCPP_INLINE_VISIBILITY
11403e519524SHoward Hinnantbool operator==(const istreambuf_iterator<_CharT,_Traits>& __a,
11413e519524SHoward Hinnant                const istreambuf_iterator<_CharT,_Traits>& __b)
11423e519524SHoward Hinnant                {return __a.equal(__b);}
11433e519524SHoward Hinnant
11443e519524SHoward Hinnanttemplate <class _CharT, class _Traits>
11453e519524SHoward Hinnantinline _LIBCPP_INLINE_VISIBILITY
11463e519524SHoward Hinnantbool operator!=(const istreambuf_iterator<_CharT,_Traits>& __a,
11473e519524SHoward Hinnant                const istreambuf_iterator<_CharT,_Traits>& __b)
11483e519524SHoward Hinnant                {return !__a.equal(__b);}
11493e519524SHoward Hinnant
11501055cb91SLouis Dionne_LIBCPP_SUPPRESS_DEPRECATED_PUSH
11513e519524SHoward Hinnanttemplate <class _CharT, class _Traits>
1152e2f2d1edSEric Fiselierclass _LIBCPP_TEMPLATE_VIS ostreambuf_iterator
11531055cb91SLouis Dionne#if _LIBCPP_STD_VER <= 14 || !defined(_LIBCPP_ABI_NO_ITERATOR_BASES)
11543e519524SHoward Hinnant    : public iterator<output_iterator_tag, void, void, void, void>
11551055cb91SLouis Dionne#endif
11563e519524SHoward Hinnant{
11571055cb91SLouis Dionne_LIBCPP_SUPPRESS_DEPRECATED_POP
11583e519524SHoward Hinnantpublic:
115971a16e40SLouis Dionne    typedef output_iterator_tag                 iterator_category;
116071a16e40SLouis Dionne    typedef void                                value_type;
116171a16e40SLouis Dionne#if _LIBCPP_STD_VER > 17
116271a16e40SLouis Dionne    typedef std::ptrdiff_t                      difference_type;
116371a16e40SLouis Dionne#else
116471a16e40SLouis Dionne    typedef void                                difference_type;
116571a16e40SLouis Dionne#endif
116671a16e40SLouis Dionne    typedef void                                pointer;
116771a16e40SLouis Dionne    typedef void                                reference;
11683e519524SHoward Hinnant    typedef _CharT                              char_type;
11693e519524SHoward Hinnant    typedef _Traits                             traits_type;
11703e519524SHoward Hinnant    typedef basic_streambuf<_CharT, _Traits>    streambuf_type;
11713e519524SHoward Hinnant    typedef basic_ostream<_CharT, _Traits>      ostream_type;
117271a16e40SLouis Dionne
11733e519524SHoward Hinnantprivate:
11743e519524SHoward Hinnant    streambuf_type* __sbuf_;
11753e519524SHoward Hinnantpublic:
11768e882dcbSHoward Hinnant    _LIBCPP_INLINE_VISIBILITY ostreambuf_iterator(ostream_type& __s) _NOEXCEPT
11773e519524SHoward Hinnant        : __sbuf_(__s.rdbuf()) {}
11788e882dcbSHoward Hinnant    _LIBCPP_INLINE_VISIBILITY ostreambuf_iterator(streambuf_type* __s) _NOEXCEPT
11793e519524SHoward Hinnant        : __sbuf_(__s) {}
11803e519524SHoward Hinnant    _LIBCPP_INLINE_VISIBILITY ostreambuf_iterator& operator=(_CharT __c)
11813e519524SHoward Hinnant        {
11823e519524SHoward Hinnant            if (__sbuf_ && traits_type::eq_int_type(__sbuf_->sputc(__c), traits_type::eof()))
1183527a7fdfSBruce Mitchener                __sbuf_ = nullptr;
11843e519524SHoward Hinnant            return *this;
11853e519524SHoward Hinnant        }
11863e519524SHoward Hinnant    _LIBCPP_INLINE_VISIBILITY ostreambuf_iterator& operator*()     {return *this;}
11873e519524SHoward Hinnant    _LIBCPP_INLINE_VISIBILITY ostreambuf_iterator& operator++()    {return *this;}
11883e519524SHoward Hinnant    _LIBCPP_INLINE_VISIBILITY ostreambuf_iterator& operator++(int) {return *this;}
1189527a7fdfSBruce Mitchener    _LIBCPP_INLINE_VISIBILITY bool failed() const _NOEXCEPT {return __sbuf_ == nullptr;}
119092b5940fSHoward Hinnant
119192b5940fSHoward Hinnant    template <class _Ch, class _Tr>
119292b5940fSHoward Hinnant    friend
119392b5940fSHoward Hinnant    _LIBCPP_HIDDEN
119492b5940fSHoward Hinnant    ostreambuf_iterator<_Ch, _Tr>
119592b5940fSHoward Hinnant    __pad_and_output(ostreambuf_iterator<_Ch, _Tr> __s,
119692b5940fSHoward Hinnant                     const _Ch* __ob, const _Ch* __op, const _Ch* __oe,
119792b5940fSHoward Hinnant                     ios_base& __iob, _Ch __fl);
11983e519524SHoward Hinnant};
11993e519524SHoward Hinnant
12003e519524SHoward Hinnanttemplate <class _Iter>
1201e2f2d1edSEric Fiselierclass _LIBCPP_TEMPLATE_VIS move_iterator
12023e519524SHoward Hinnant{
12033e519524SHoward Hinnantprivate:
12043e519524SHoward Hinnant    _Iter __i;
12053e519524SHoward Hinnantpublic:
12063e519524SHoward Hinnant    typedef _Iter                                            iterator_type;
12073e519524SHoward Hinnant    typedef typename iterator_traits<iterator_type>::value_type value_type;
12083e519524SHoward Hinnant    typedef typename iterator_traits<iterator_type>::difference_type difference_type;
120905333fc8SMarshall Clow    typedef iterator_type pointer;
1210d41c6d51SArthur O'Dwyer    typedef _If<__is_cpp17_random_access_iterator<_Iter>::value,
1211d41c6d51SArthur O'Dwyer        random_access_iterator_tag,
1212d41c6d51SArthur O'Dwyer        typename iterator_traits<_Iter>::iterator_category>  iterator_category;
1213d41c6d51SArthur O'Dwyer#if _LIBCPP_STD_VER > 17
1214d41c6d51SArthur O'Dwyer    typedef input_iterator_tag                               iterator_concept;
1215d41c6d51SArthur O'Dwyer#endif
1216d41c6d51SArthur O'Dwyer
1217046492b9SEric Fiselier#ifndef _LIBCPP_CXX03_LANG
1218906c5085SEric Fiselier    typedef typename iterator_traits<iterator_type>::reference __reference;
1219906c5085SEric Fiselier    typedef typename conditional<
1220906c5085SEric Fiselier            is_reference<__reference>::value,
1221906c5085SEric Fiselier            typename remove_reference<__reference>::type&&,
1222906c5085SEric Fiselier            __reference
1223906c5085SEric Fiselier        >::type reference;
12243e519524SHoward Hinnant#else
12253e519524SHoward Hinnant    typedef typename iterator_traits<iterator_type>::reference reference;
12263e519524SHoward Hinnant#endif
12273e519524SHoward Hinnant
1228720ef472SMarshall Clow    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
1229720ef472SMarshall Clow    move_iterator() : __i() {}
1230720ef472SMarshall Clow    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
1231720ef472SMarshall Clow    explicit move_iterator(_Iter __x) : __i(__x) {}
1232720ef472SMarshall Clow    template <class _Up>
1233720ef472SMarshall Clow      _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
1234720ef472SMarshall Clow      move_iterator(const move_iterator<_Up>& __u) : __i(__u.base()) {}
1235720ef472SMarshall Clow    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 _Iter base() const {return __i;}
1236720ef472SMarshall Clow    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
1237720ef472SMarshall Clow    reference operator*() const { return static_cast<reference>(*__i); }
1238720ef472SMarshall Clow    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
1239720ef472SMarshall Clow    pointer  operator->() const { return __i;}
1240720ef472SMarshall Clow    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
1241720ef472SMarshall Clow    move_iterator& operator++() {++__i; return *this;}
1242720ef472SMarshall Clow    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
1243720ef472SMarshall Clow    move_iterator  operator++(int) {move_iterator __tmp(*this); ++__i; return __tmp;}
1244720ef472SMarshall Clow    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
1245720ef472SMarshall Clow    move_iterator& operator--() {--__i; return *this;}
1246720ef472SMarshall Clow    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
1247720ef472SMarshall Clow    move_iterator  operator--(int) {move_iterator __tmp(*this); --__i; return __tmp;}
1248720ef472SMarshall Clow    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
1249720ef472SMarshall Clow    move_iterator  operator+ (difference_type __n) const {return move_iterator(__i + __n);}
1250720ef472SMarshall Clow    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
1251720ef472SMarshall Clow    move_iterator& operator+=(difference_type __n) {__i += __n; return *this;}
1252720ef472SMarshall Clow    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
1253720ef472SMarshall Clow    move_iterator  operator- (difference_type __n) const {return move_iterator(__i - __n);}
1254720ef472SMarshall Clow    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
1255720ef472SMarshall Clow    move_iterator& operator-=(difference_type __n) {__i -= __n; return *this;}
1256720ef472SMarshall Clow    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
1257720ef472SMarshall Clow    reference operator[](difference_type __n) const { return static_cast<reference>(__i[__n]); }
12583e519524SHoward Hinnant};
12593e519524SHoward Hinnant
12603e519524SHoward Hinnanttemplate <class _Iter1, class _Iter2>
1261720ef472SMarshall Clowinline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
12623e519524SHoward Hinnantbool
12633e519524SHoward Hinnantoperator==(const move_iterator<_Iter1>& __x, const move_iterator<_Iter2>& __y)
12643e519524SHoward Hinnant{
12653e519524SHoward Hinnant    return __x.base() == __y.base();
12663e519524SHoward Hinnant}
12673e519524SHoward Hinnant
12683e519524SHoward Hinnanttemplate <class _Iter1, class _Iter2>
1269720ef472SMarshall Clowinline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
12703e519524SHoward Hinnantbool
12713e519524SHoward Hinnantoperator<(const move_iterator<_Iter1>& __x, const move_iterator<_Iter2>& __y)
12723e519524SHoward Hinnant{
12733e519524SHoward Hinnant    return __x.base() < __y.base();
12743e519524SHoward Hinnant}
12753e519524SHoward Hinnant
12763e519524SHoward Hinnanttemplate <class _Iter1, class _Iter2>
1277720ef472SMarshall Clowinline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
12783e519524SHoward Hinnantbool
12793e519524SHoward Hinnantoperator!=(const move_iterator<_Iter1>& __x, const move_iterator<_Iter2>& __y)
12803e519524SHoward Hinnant{
12813e519524SHoward Hinnant    return __x.base() != __y.base();
12823e519524SHoward Hinnant}
12833e519524SHoward Hinnant
12843e519524SHoward Hinnanttemplate <class _Iter1, class _Iter2>
1285720ef472SMarshall Clowinline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
12863e519524SHoward Hinnantbool
12873e519524SHoward Hinnantoperator>(const move_iterator<_Iter1>& __x, const move_iterator<_Iter2>& __y)
12883e519524SHoward Hinnant{
12893e519524SHoward Hinnant    return __x.base() > __y.base();
12903e519524SHoward Hinnant}
12913e519524SHoward Hinnant
12923e519524SHoward Hinnanttemplate <class _Iter1, class _Iter2>
1293720ef472SMarshall Clowinline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
12943e519524SHoward Hinnantbool
12953e519524SHoward Hinnantoperator>=(const move_iterator<_Iter1>& __x, const move_iterator<_Iter2>& __y)
12963e519524SHoward Hinnant{
12973e519524SHoward Hinnant    return __x.base() >= __y.base();
12983e519524SHoward Hinnant}
12993e519524SHoward Hinnant
13003e519524SHoward Hinnanttemplate <class _Iter1, class _Iter2>
1301720ef472SMarshall Clowinline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
13023e519524SHoward Hinnantbool
13033e519524SHoward Hinnantoperator<=(const move_iterator<_Iter1>& __x, const move_iterator<_Iter2>& __y)
13043e519524SHoward Hinnant{
13053e519524SHoward Hinnant    return __x.base() <= __y.base();
13063e519524SHoward Hinnant}
13073e519524SHoward Hinnant
13082ee83725SMarshall Clow#ifndef _LIBCPP_CXX03_LANG
1309947ce6b5SMarshall Clowtemplate <class _Iter1, class _Iter2>
1310720ef472SMarshall Clowinline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
1311947ce6b5SMarshall Clowauto
1312947ce6b5SMarshall Clowoperator-(const move_iterator<_Iter1>& __x, const move_iterator<_Iter2>& __y)
1313947ce6b5SMarshall Clow-> decltype(__x.base() - __y.base())
1314947ce6b5SMarshall Clow{
1315947ce6b5SMarshall Clow    return __x.base() - __y.base();
1316947ce6b5SMarshall Clow}
1317947ce6b5SMarshall Clow#else
13183e519524SHoward Hinnanttemplate <class _Iter1, class _Iter2>
13193e519524SHoward Hinnantinline _LIBCPP_INLINE_VISIBILITY
13203e519524SHoward Hinnanttypename move_iterator<_Iter1>::difference_type
13213e519524SHoward Hinnantoperator-(const move_iterator<_Iter1>& __x, const move_iterator<_Iter2>& __y)
13223e519524SHoward Hinnant{
13233e519524SHoward Hinnant    return __x.base() - __y.base();
13243e519524SHoward Hinnant}
1325947ce6b5SMarshall Clow#endif
13263e519524SHoward Hinnant
13273e519524SHoward Hinnanttemplate <class _Iter>
1328720ef472SMarshall Clowinline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
13293e519524SHoward Hinnantmove_iterator<_Iter>
13303e519524SHoward Hinnantoperator+(typename move_iterator<_Iter>::difference_type __n, const move_iterator<_Iter>& __x)
13313e519524SHoward Hinnant{
13323e519524SHoward Hinnant    return move_iterator<_Iter>(__x.base() + __n);
13333e519524SHoward Hinnant}
13343e519524SHoward Hinnant
13353e519524SHoward Hinnanttemplate <class _Iter>
1336720ef472SMarshall Clowinline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
13373e519524SHoward Hinnantmove_iterator<_Iter>
133854c83368SMarshall Clowmake_move_iterator(_Iter __i)
13393e519524SHoward Hinnant{
13403e519524SHoward Hinnant    return move_iterator<_Iter>(__i);
13413e519524SHoward Hinnant}
13423e519524SHoward Hinnant
13433e519524SHoward Hinnant// __wrap_iter
13443e519524SHoward Hinnant
13453e519524SHoward Hinnanttemplate <class _Iter> class __wrap_iter;
13463e519524SHoward Hinnant
13473e519524SHoward Hinnanttemplate <class _Iter1, class _Iter2>
13489cad5025SMarshall Clow_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG
13493e519524SHoward Hinnantbool
135061b302f9SEric Fiselieroperator==(const __wrap_iter<_Iter1>&, const __wrap_iter<_Iter2>&) _NOEXCEPT;
13513e519524SHoward Hinnant
13523e519524SHoward Hinnanttemplate <class _Iter1, class _Iter2>
13539cad5025SMarshall Clow_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG
13543e519524SHoward Hinnantbool
135561b302f9SEric Fiselieroperator<(const __wrap_iter<_Iter1>&, const __wrap_iter<_Iter2>&) _NOEXCEPT;
13563e519524SHoward Hinnant
13573e519524SHoward Hinnanttemplate <class _Iter1, class _Iter2>
13589cad5025SMarshall Clow_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG
13593e519524SHoward Hinnantbool
136061b302f9SEric Fiselieroperator!=(const __wrap_iter<_Iter1>&, const __wrap_iter<_Iter2>&) _NOEXCEPT;
13613e519524SHoward Hinnant
13623e519524SHoward Hinnanttemplate <class _Iter1, class _Iter2>
13639cad5025SMarshall Clow_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG
13643e519524SHoward Hinnantbool
136561b302f9SEric Fiselieroperator>(const __wrap_iter<_Iter1>&, const __wrap_iter<_Iter2>&) _NOEXCEPT;
13663e519524SHoward Hinnant
13673e519524SHoward Hinnanttemplate <class _Iter1, class _Iter2>
13689cad5025SMarshall Clow_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG
13693e519524SHoward Hinnantbool
137061b302f9SEric Fiselieroperator>=(const __wrap_iter<_Iter1>&, const __wrap_iter<_Iter2>&) _NOEXCEPT;
13713e519524SHoward Hinnant
13723e519524SHoward Hinnanttemplate <class _Iter1, class _Iter2>
13739cad5025SMarshall Clow_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG
13743e519524SHoward Hinnantbool
137561b302f9SEric Fiselieroperator<=(const __wrap_iter<_Iter1>&, const __wrap_iter<_Iter2>&) _NOEXCEPT;
13763e519524SHoward Hinnant
13772ee83725SMarshall Clow#ifndef _LIBCPP_CXX03_LANG
1378947ce6b5SMarshall Clowtemplate <class _Iter1, class _Iter2>
13799cad5025SMarshall Clow_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG
1380947ce6b5SMarshall Clowauto
138161b302f9SEric Fiselieroperator-(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter2>& __y) _NOEXCEPT
1382947ce6b5SMarshall Clow-> decltype(__x.base() - __y.base());
1383947ce6b5SMarshall Clow#else
13843e519524SHoward Hinnanttemplate <class _Iter1, class _Iter2>
1385aeb85680SHoward Hinnant_LIBCPP_INLINE_VISIBILITY
13863e519524SHoward Hinnanttypename __wrap_iter<_Iter1>::difference_type
138761b302f9SEric Fiselieroperator-(const __wrap_iter<_Iter1>&, const __wrap_iter<_Iter2>&) _NOEXCEPT;
1388947ce6b5SMarshall Clow#endif
13893e519524SHoward Hinnant
13903e519524SHoward Hinnanttemplate <class _Iter>
13919cad5025SMarshall Clow_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG
13923e519524SHoward Hinnant__wrap_iter<_Iter>
139361b302f9SEric Fiselieroperator+(typename __wrap_iter<_Iter>::difference_type, __wrap_iter<_Iter>) _NOEXCEPT;
13943e519524SHoward Hinnant
139513c90a57SLouis Dionnetemplate <class _Ip, class _Op> _Op _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 copy(_Ip, _Ip, _Op);
139613c90a57SLouis Dionnetemplate <class _B1, class _B2> _B2 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 copy_backward(_B1, _B1, _B2);
13973ed89b51Szoecarvertemplate <class _Ip, class _Op> _Op _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 move(_Ip, _Ip, _Op);
13983ed89b51Szoecarvertemplate <class _B1, class _B2> _B2 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 move_backward(_B1, _B1, _B2);
13993e519524SHoward Hinnant
14003e519524SHoward Hinnanttemplate <class _Iter>
14013e519524SHoward Hinnantclass __wrap_iter
14023e519524SHoward Hinnant{
14033e519524SHoward Hinnantpublic:
14043e519524SHoward Hinnant    typedef _Iter                                                      iterator_type;
14053e519524SHoward Hinnant    typedef typename iterator_traits<iterator_type>::value_type        value_type;
14063e519524SHoward Hinnant    typedef typename iterator_traits<iterator_type>::difference_type   difference_type;
14073e519524SHoward Hinnant    typedef typename iterator_traits<iterator_type>::pointer           pointer;
14083e519524SHoward Hinnant    typedef typename iterator_traits<iterator_type>::reference         reference;
1409d41c6d51SArthur O'Dwyer    typedef typename iterator_traits<iterator_type>::iterator_category iterator_category;
1410d41c6d51SArthur O'Dwyer#if _LIBCPP_STD_VER > 17
1411fc924887SArthur O'Dwyer    typedef contiguous_iterator_tag                                    iterator_concept;
1412d41c6d51SArthur O'Dwyer#endif
1413d41c6d51SArthur O'Dwyer
14143e519524SHoward Hinnantprivate:
14153e519524SHoward Hinnant    iterator_type __i;
14163e519524SHoward Hinnantpublic:
141761b302f9SEric Fiselier    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG __wrap_iter() _NOEXCEPT
141807186a7dSMarshall Clow#if _LIBCPP_STD_VER > 11
141907186a7dSMarshall Clow                : __i{}
142007186a7dSMarshall Clow#endif
1421c36bfc49SHoward Hinnant    {
142231e82037SLouis Dionne#if _LIBCPP_DEBUG_LEVEL == 2
1423c36bfc49SHoward Hinnant        __get_db()->__insert_i(this);
1424c36bfc49SHoward Hinnant#endif
1425c36bfc49SHoward Hinnant    }
14269cad5025SMarshall Clow    template <class _Up> _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG
14279cad5025SMarshall Clow        __wrap_iter(const __wrap_iter<_Up>& __u,
1428527a7fdfSBruce Mitchener            typename enable_if<is_convertible<_Up, iterator_type>::value>::type* = nullptr) _NOEXCEPT
1429f554add5SHoward Hinnant            : __i(__u.base())
1430f554add5SHoward Hinnant    {
143131e82037SLouis Dionne#if _LIBCPP_DEBUG_LEVEL == 2
1432f554add5SHoward Hinnant        __get_db()->__iterator_copy(this, &__u);
1433f554add5SHoward Hinnant#endif
1434f554add5SHoward Hinnant    }
143531e82037SLouis Dionne#if _LIBCPP_DEBUG_LEVEL == 2
14369cad5025SMarshall Clow    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG
1437f554add5SHoward Hinnant    __wrap_iter(const __wrap_iter& __x)
1438f554add5SHoward Hinnant        : __i(__x.base())
1439f554add5SHoward Hinnant    {
1440f554add5SHoward Hinnant        __get_db()->__iterator_copy(this, &__x);
1441f554add5SHoward Hinnant    }
14429cad5025SMarshall Clow    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG
1443f554add5SHoward Hinnant    __wrap_iter& operator=(const __wrap_iter& __x)
1444f554add5SHoward Hinnant    {
1445f554add5SHoward Hinnant        if (this != &__x)
1446f554add5SHoward Hinnant        {
1447f554add5SHoward Hinnant            __get_db()->__iterator_copy(this, &__x);
1448f554add5SHoward Hinnant            __i = __x.__i;
1449f554add5SHoward Hinnant        }
1450f554add5SHoward Hinnant        return *this;
1451f554add5SHoward Hinnant    }
14529cad5025SMarshall Clow    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG
1453f554add5SHoward Hinnant    ~__wrap_iter()
1454f554add5SHoward Hinnant    {
1455f554add5SHoward Hinnant        __get_db()->__erase_i(this);
1456f554add5SHoward Hinnant    }
1457f554add5SHoward Hinnant#endif
145861b302f9SEric Fiselier    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG reference operator*() const _NOEXCEPT
1459f554add5SHoward Hinnant    {
146031e82037SLouis Dionne#if _LIBCPP_DEBUG_LEVEL == 2
1461f554add5SHoward Hinnant        _LIBCPP_ASSERT(__get_const_db()->__dereferenceable(this),
1462f554add5SHoward Hinnant                       "Attempted to dereference a non-dereferenceable iterator");
1463cec9af9eSHoward Hinnant#endif
1464f554add5SHoward Hinnant        return *__i;
1465f554add5SHoward Hinnant    }
146661b302f9SEric Fiselier    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG pointer  operator->() const _NOEXCEPT
14673ec1f00bSHoward Hinnant    {
146831e82037SLouis Dionne#if _LIBCPP_DEBUG_LEVEL == 2
14693ec1f00bSHoward Hinnant        _LIBCPP_ASSERT(__get_const_db()->__dereferenceable(this),
14703ec1f00bSHoward Hinnant                       "Attempted to dereference a non-dereferenceable iterator");
14713ec1f00bSHoward Hinnant#endif
1472fe0e86e6SLouis Dionne        return _VSTD::__to_address(__i);
14733ec1f00bSHoward Hinnant    }
147461b302f9SEric Fiselier    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG __wrap_iter& operator++() _NOEXCEPT
1475f554add5SHoward Hinnant    {
147631e82037SLouis Dionne#if _LIBCPP_DEBUG_LEVEL == 2
1477f554add5SHoward Hinnant        _LIBCPP_ASSERT(__get_const_db()->__dereferenceable(this),
147896100f15SKristina Bessonova                       "Attempted to increment a non-incrementable iterator");
1479cec9af9eSHoward Hinnant#endif
1480f554add5SHoward Hinnant        ++__i;
1481f554add5SHoward Hinnant        return *this;
1482f554add5SHoward Hinnant    }
148361b302f9SEric Fiselier    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG __wrap_iter  operator++(int) _NOEXCEPT
1484f554add5SHoward Hinnant        {__wrap_iter __tmp(*this); ++(*this); return __tmp;}
14854ce0a916SMarshall Clow
148661b302f9SEric Fiselier    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG __wrap_iter& operator--() _NOEXCEPT
1487f554add5SHoward Hinnant    {
148831e82037SLouis Dionne#if _LIBCPP_DEBUG_LEVEL == 2
1489f554add5SHoward Hinnant        _LIBCPP_ASSERT(__get_const_db()->__decrementable(this),
149096100f15SKristina Bessonova                       "Attempted to decrement a non-decrementable iterator");
1491cec9af9eSHoward Hinnant#endif
1492f554add5SHoward Hinnant        --__i;
1493f554add5SHoward Hinnant        return *this;
1494f554add5SHoward Hinnant    }
149561b302f9SEric Fiselier    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG __wrap_iter  operator--(int) _NOEXCEPT
1496f554add5SHoward Hinnant        {__wrap_iter __tmp(*this); --(*this); return __tmp;}
149761b302f9SEric Fiselier    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG __wrap_iter  operator+ (difference_type __n) const _NOEXCEPT
1498f554add5SHoward Hinnant        {__wrap_iter __w(*this); __w += __n; return __w;}
149961b302f9SEric Fiselier    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG __wrap_iter& operator+=(difference_type __n) _NOEXCEPT
1500f554add5SHoward Hinnant    {
150131e82037SLouis Dionne#if _LIBCPP_DEBUG_LEVEL == 2
1502f554add5SHoward Hinnant        _LIBCPP_ASSERT(__get_const_db()->__addable(this, __n),
150396100f15SKristina Bessonova                   "Attempted to add/subtract an iterator outside its valid range");
1504cec9af9eSHoward Hinnant#endif
1505f554add5SHoward Hinnant        __i += __n;
1506f554add5SHoward Hinnant        return *this;
1507f554add5SHoward Hinnant    }
150861b302f9SEric Fiselier    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG __wrap_iter  operator- (difference_type __n) const _NOEXCEPT
1509f554add5SHoward Hinnant        {return *this + (-__n);}
151061b302f9SEric Fiselier    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG __wrap_iter& operator-=(difference_type __n) _NOEXCEPT
1511f554add5SHoward Hinnant        {*this += -__n; return *this;}
151261b302f9SEric Fiselier    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG reference    operator[](difference_type __n) const _NOEXCEPT
1513f554add5SHoward Hinnant    {
151431e82037SLouis Dionne#if _LIBCPP_DEBUG_LEVEL == 2
1515f554add5SHoward Hinnant        _LIBCPP_ASSERT(__get_const_db()->__subscriptable(this, __n),
151696100f15SKristina Bessonova                   "Attempted to subscript an iterator outside its valid range");
1517cec9af9eSHoward Hinnant#endif
1518f554add5SHoward Hinnant        return __i[__n];
1519f554add5SHoward Hinnant    }
15203e519524SHoward Hinnant
152161b302f9SEric Fiselier    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG iterator_type base() const _NOEXCEPT {return __i;}
15223e519524SHoward Hinnant
15233e519524SHoward Hinnantprivate:
152431e82037SLouis Dionne#if _LIBCPP_DEBUG_LEVEL == 2
15259cad5025SMarshall Clow    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG __wrap_iter(const void* __p, iterator_type __x) : __i(__x)
1526f554add5SHoward Hinnant    {
1527f554add5SHoward Hinnant        __get_db()->__insert_ic(this, __p);
1528f554add5SHoward Hinnant    }
1529fc88dbd2SHoward Hinnant#else
153061b302f9SEric Fiselier    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG __wrap_iter(iterator_type __x) _NOEXCEPT : __i(__x) {}
1531f554add5SHoward Hinnant#endif
15323e519524SHoward Hinnant
15333e519524SHoward Hinnant    template <class _Up> friend class __wrap_iter;
15343e519524SHoward Hinnant    template <class _CharT, class _Traits, class _Alloc> friend class basic_string;
1535e2f2d1edSEric Fiselier    template <class _Tp, class _Alloc> friend class _LIBCPP_TEMPLATE_VIS vector;
15367ad06a93SMarshall Clow    template <class _Tp, size_t> friend class _LIBCPP_TEMPLATE_VIS span;
15373e519524SHoward Hinnant
15383e519524SHoward Hinnant    template <class _Iter1, class _Iter2>
15399cad5025SMarshall Clow    _LIBCPP_CONSTEXPR_IF_NODEBUG friend
15403e519524SHoward Hinnant    bool
154161b302f9SEric Fiselier    operator==(const __wrap_iter<_Iter1>&, const __wrap_iter<_Iter2>&) _NOEXCEPT;
15423e519524SHoward Hinnant
15433e519524SHoward Hinnant    template <class _Iter1, class _Iter2>
15449cad5025SMarshall Clow    _LIBCPP_CONSTEXPR_IF_NODEBUG friend
15453e519524SHoward Hinnant    bool
154661b302f9SEric Fiselier    operator<(const __wrap_iter<_Iter1>&, const __wrap_iter<_Iter2>&) _NOEXCEPT;
15473e519524SHoward Hinnant
15483e519524SHoward Hinnant    template <class _Iter1, class _Iter2>
15499cad5025SMarshall Clow    _LIBCPP_CONSTEXPR_IF_NODEBUG friend
15503e519524SHoward Hinnant    bool
155161b302f9SEric Fiselier    operator!=(const __wrap_iter<_Iter1>&, const __wrap_iter<_Iter2>&) _NOEXCEPT;
15523e519524SHoward Hinnant
15533e519524SHoward Hinnant    template <class _Iter1, class _Iter2>
15549cad5025SMarshall Clow    _LIBCPP_CONSTEXPR_IF_NODEBUG friend
15553e519524SHoward Hinnant    bool
155661b302f9SEric Fiselier    operator>(const __wrap_iter<_Iter1>&, const __wrap_iter<_Iter2>&) _NOEXCEPT;
15573e519524SHoward Hinnant
15583e519524SHoward Hinnant    template <class _Iter1, class _Iter2>
15599cad5025SMarshall Clow    _LIBCPP_CONSTEXPR_IF_NODEBUG friend
15603e519524SHoward Hinnant    bool
156161b302f9SEric Fiselier    operator>=(const __wrap_iter<_Iter1>&, const __wrap_iter<_Iter2>&) _NOEXCEPT;
15623e519524SHoward Hinnant
15633e519524SHoward Hinnant    template <class _Iter1, class _Iter2>
15649cad5025SMarshall Clow    _LIBCPP_CONSTEXPR_IF_NODEBUG friend
15653e519524SHoward Hinnant    bool
156661b302f9SEric Fiselier    operator<=(const __wrap_iter<_Iter1>&, const __wrap_iter<_Iter2>&) _NOEXCEPT;
15673e519524SHoward Hinnant
15682ee83725SMarshall Clow#ifndef _LIBCPP_CXX03_LANG
1569947ce6b5SMarshall Clow    template <class _Iter1, class _Iter2>
15709cad5025SMarshall Clow    _LIBCPP_CONSTEXPR_IF_NODEBUG friend
1571947ce6b5SMarshall Clow    auto
157261b302f9SEric Fiselier    operator-(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter2>& __y) _NOEXCEPT
1573947ce6b5SMarshall Clow    -> decltype(__x.base() - __y.base());
1574947ce6b5SMarshall Clow#else
15753e519524SHoward Hinnant    template <class _Iter1, class _Iter2>
15769cad5025SMarshall Clow    _LIBCPP_CONSTEXPR_IF_NODEBUG friend
15773e519524SHoward Hinnant    typename __wrap_iter<_Iter1>::difference_type
157861b302f9SEric Fiselier    operator-(const __wrap_iter<_Iter1>&, const __wrap_iter<_Iter2>&) _NOEXCEPT;
1579947ce6b5SMarshall Clow#endif
15803e519524SHoward Hinnant
15813e519524SHoward Hinnant    template <class _Iter1>
15829cad5025SMarshall Clow    _LIBCPP_CONSTEXPR_IF_NODEBUG friend
15833e519524SHoward Hinnant    __wrap_iter<_Iter1>
158461b302f9SEric Fiselier    operator+(typename __wrap_iter<_Iter1>::difference_type, __wrap_iter<_Iter1>) _NOEXCEPT;
15853e519524SHoward Hinnant};
15863e519524SHoward Hinnant
1587d41c6d51SArthur O'Dwyer#if _LIBCPP_STD_VER <= 17
1588d41c6d51SArthur O'Dwyertemplate <class _It>
1589fc924887SArthur O'Dwyerstruct __is_cpp17_contiguous_iterator<__wrap_iter<_It> > : true_type {};
1590d41c6d51SArthur O'Dwyer#endif
1591d41c6d51SArthur O'Dwyer
1592d41c6d51SArthur O'Dwyertemplate <class _Iter>
1593d41c6d51SArthur O'Dwyer_LIBCPP_CONSTEXPR
1594fc924887SArthur O'Dwyerdecltype(_VSTD::__to_address(declval<_Iter>()))
1595d41c6d51SArthur O'Dwyer__to_address(__wrap_iter<_Iter> __w) _NOEXCEPT {
1596d41c6d51SArthur O'Dwyer    return _VSTD::__to_address(__w.base());
1597d41c6d51SArthur O'Dwyer}
1598d41c6d51SArthur O'Dwyer
15993e519524SHoward Hinnanttemplate <class _Iter1, class _Iter2>
16009cad5025SMarshall Clowinline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG
16013e519524SHoward Hinnantbool
160261b302f9SEric Fiselieroperator==(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter2>& __y) _NOEXCEPT
16033e519524SHoward Hinnant{
16043e519524SHoward Hinnant    return __x.base() == __y.base();
16053e519524SHoward Hinnant}
16063e519524SHoward Hinnant
16073e519524SHoward Hinnanttemplate <class _Iter1, class _Iter2>
16089cad5025SMarshall Clowinline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG
16093e519524SHoward Hinnantbool
161061b302f9SEric Fiselieroperator<(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter2>& __y) _NOEXCEPT
16113e519524SHoward Hinnant{
161231e82037SLouis Dionne#if _LIBCPP_DEBUG_LEVEL == 2
161342a3046eSHoward Hinnant    _LIBCPP_ASSERT(__get_const_db()->__less_than_comparable(&__x, &__y),
1614f554add5SHoward Hinnant                   "Attempted to compare incomparable iterators");
1615cec9af9eSHoward Hinnant#endif
16163e519524SHoward Hinnant    return __x.base() < __y.base();
16173e519524SHoward Hinnant}
16183e519524SHoward Hinnant
16193e519524SHoward Hinnanttemplate <class _Iter1, class _Iter2>
16209cad5025SMarshall Clowinline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG
16213e519524SHoward Hinnantbool
162261b302f9SEric Fiselieroperator!=(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter2>& __y) _NOEXCEPT
16233e519524SHoward Hinnant{
1624f554add5SHoward Hinnant    return !(__x == __y);
16253e519524SHoward Hinnant}
16263e519524SHoward Hinnant
16273e519524SHoward Hinnanttemplate <class _Iter1, class _Iter2>
16289cad5025SMarshall Clowinline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG
16293e519524SHoward Hinnantbool
163061b302f9SEric Fiselieroperator>(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter2>& __y) _NOEXCEPT
16313e519524SHoward Hinnant{
1632f554add5SHoward Hinnant    return __y < __x;
16333e519524SHoward Hinnant}
16343e519524SHoward Hinnant
16353e519524SHoward Hinnanttemplate <class _Iter1, class _Iter2>
16369cad5025SMarshall Clowinline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG
16373e519524SHoward Hinnantbool
163861b302f9SEric Fiselieroperator>=(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter2>& __y) _NOEXCEPT
16393e519524SHoward Hinnant{
1640f554add5SHoward Hinnant    return !(__x < __y);
16413e519524SHoward Hinnant}
16423e519524SHoward Hinnant
16433e519524SHoward Hinnanttemplate <class _Iter1, class _Iter2>
16449cad5025SMarshall Clowinline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG
16453e519524SHoward Hinnantbool
164661b302f9SEric Fiselieroperator<=(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter2>& __y) _NOEXCEPT
16473e519524SHoward Hinnant{
1648f554add5SHoward Hinnant    return !(__y < __x);
16493e519524SHoward Hinnant}
16503e519524SHoward Hinnant
16516e551ae1SHoward Hinnanttemplate <class _Iter1>
16529cad5025SMarshall Clowinline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG
16536e551ae1SHoward Hinnantbool
165461b302f9SEric Fiselieroperator!=(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter1>& __y) _NOEXCEPT
16556e551ae1SHoward Hinnant{
16566e551ae1SHoward Hinnant    return !(__x == __y);
16576e551ae1SHoward Hinnant}
16586e551ae1SHoward Hinnant
16596e551ae1SHoward Hinnanttemplate <class _Iter1>
16609cad5025SMarshall Clowinline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG
16616e551ae1SHoward Hinnantbool
166261b302f9SEric Fiselieroperator>(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter1>& __y) _NOEXCEPT
16636e551ae1SHoward Hinnant{
16646e551ae1SHoward Hinnant    return __y < __x;
16656e551ae1SHoward Hinnant}
16666e551ae1SHoward Hinnant
16676e551ae1SHoward Hinnanttemplate <class _Iter1>
16689cad5025SMarshall Clowinline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG
16696e551ae1SHoward Hinnantbool
167061b302f9SEric Fiselieroperator>=(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter1>& __y) _NOEXCEPT
16716e551ae1SHoward Hinnant{
16726e551ae1SHoward Hinnant    return !(__x < __y);
16736e551ae1SHoward Hinnant}
16746e551ae1SHoward Hinnant
16756e551ae1SHoward Hinnanttemplate <class _Iter1>
16769cad5025SMarshall Clowinline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG
16776e551ae1SHoward Hinnantbool
167861b302f9SEric Fiselieroperator<=(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter1>& __y) _NOEXCEPT
16796e551ae1SHoward Hinnant{
16806e551ae1SHoward Hinnant    return !(__y < __x);
16816e551ae1SHoward Hinnant}
16826e551ae1SHoward Hinnant
16832ee83725SMarshall Clow#ifndef _LIBCPP_CXX03_LANG
1684947ce6b5SMarshall Clowtemplate <class _Iter1, class _Iter2>
16859cad5025SMarshall Clowinline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG
1686947ce6b5SMarshall Clowauto
168761b302f9SEric Fiselieroperator-(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter2>& __y) _NOEXCEPT
1688947ce6b5SMarshall Clow-> decltype(__x.base() - __y.base())
1689947ce6b5SMarshall Clow{
169031e82037SLouis Dionne#if _LIBCPP_DEBUG_LEVEL == 2
1691947ce6b5SMarshall Clow    _LIBCPP_ASSERT(__get_const_db()->__less_than_comparable(&__x, &__y),
1692947ce6b5SMarshall Clow                   "Attempted to subtract incompatible iterators");
1693947ce6b5SMarshall Clow#endif
1694947ce6b5SMarshall Clow    return __x.base() - __y.base();
1695947ce6b5SMarshall Clow}
1696947ce6b5SMarshall Clow#else
16973e519524SHoward Hinnanttemplate <class _Iter1, class _Iter2>
16989cad5025SMarshall Clowinline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG
16993e519524SHoward Hinnanttypename __wrap_iter<_Iter1>::difference_type
170061b302f9SEric Fiselieroperator-(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter2>& __y) _NOEXCEPT
17013e519524SHoward Hinnant{
170231e82037SLouis Dionne#if _LIBCPP_DEBUG_LEVEL == 2
170342a3046eSHoward Hinnant    _LIBCPP_ASSERT(__get_const_db()->__less_than_comparable(&__x, &__y),
1704f554add5SHoward Hinnant                   "Attempted to subtract incompatible iterators");
1705cec9af9eSHoward Hinnant#endif
17063e519524SHoward Hinnant    return __x.base() - __y.base();
17073e519524SHoward Hinnant}
1708947ce6b5SMarshall Clow#endif
17093e519524SHoward Hinnant
17103e519524SHoward Hinnanttemplate <class _Iter>
17119cad5025SMarshall Clowinline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG
17123e519524SHoward Hinnant__wrap_iter<_Iter>
17133e519524SHoward Hinnantoperator+(typename __wrap_iter<_Iter>::difference_type __n,
171461b302f9SEric Fiselier          __wrap_iter<_Iter> __x) _NOEXCEPT
17153e519524SHoward Hinnant{
1716f554add5SHoward Hinnant    __x += __n;
1717f554add5SHoward Hinnant    return __x;
17183e519524SHoward Hinnant}
17193e519524SHoward Hinnant
17203772a46aSMarshall Clowtemplate <class _Tp, size_t _Np>
17212ffa1705SMarshall Clow_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
17223772a46aSMarshall Clow_Tp*
17233772a46aSMarshall Clowbegin(_Tp (&__array)[_Np])
17243772a46aSMarshall Clow{
17253772a46aSMarshall Clow    return __array;
17263772a46aSMarshall Clow}
17273772a46aSMarshall Clow
17283772a46aSMarshall Clowtemplate <class _Tp, size_t _Np>
17292ffa1705SMarshall Clow_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
17303772a46aSMarshall Clow_Tp*
17313772a46aSMarshall Clowend(_Tp (&__array)[_Np])
17323772a46aSMarshall Clow{
17333772a46aSMarshall Clow    return __array + _Np;
17343772a46aSMarshall Clow}
17353772a46aSMarshall Clow
173654613ab4SEric Fiselier#if !defined(_LIBCPP_CXX03_LANG)
1737c66a611bSMarshall Clow
1738c003db1fSHoward Hinnanttemplate <class _Cp>
17392ffa1705SMarshall Clow_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
17403e519524SHoward Hinnantauto
1741c003db1fSHoward Hinnantbegin(_Cp& __c) -> decltype(__c.begin())
17423e519524SHoward Hinnant{
17433e519524SHoward Hinnant    return __c.begin();
17443e519524SHoward Hinnant}
17453e519524SHoward Hinnant
1746c003db1fSHoward Hinnanttemplate <class _Cp>
17472ffa1705SMarshall Clow_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
17483e519524SHoward Hinnantauto
1749c003db1fSHoward Hinnantbegin(const _Cp& __c) -> decltype(__c.begin())
17503e519524SHoward Hinnant{
17513e519524SHoward Hinnant    return __c.begin();
17523e519524SHoward Hinnant}
17533e519524SHoward Hinnant
1754c003db1fSHoward Hinnanttemplate <class _Cp>
17552ffa1705SMarshall Clow_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
17563e519524SHoward Hinnantauto
1757c003db1fSHoward Hinnantend(_Cp& __c) -> decltype(__c.end())
17583e519524SHoward Hinnant{
17593e519524SHoward Hinnant    return __c.end();
17603e519524SHoward Hinnant}
17613e519524SHoward Hinnant
1762c003db1fSHoward Hinnanttemplate <class _Cp>
17632ffa1705SMarshall Clow_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
17643e519524SHoward Hinnantauto
1765c003db1fSHoward Hinnantend(const _Cp& __c) -> decltype(__c.end())
17663e519524SHoward Hinnant{
17673e519524SHoward Hinnant    return __c.end();
17683e519524SHoward Hinnant}
17693e519524SHoward Hinnant
17701e548c72SMarshall Clow#if _LIBCPP_STD_VER > 11
17711e548c72SMarshall Clow
17723772a46aSMarshall Clowtemplate <class _Tp, size_t _Np>
17732ffa1705SMarshall Clow_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
17743772a46aSMarshall Clowreverse_iterator<_Tp*> rbegin(_Tp (&__array)[_Np])
17753772a46aSMarshall Clow{
17763772a46aSMarshall Clow    return reverse_iterator<_Tp*>(__array + _Np);
17773772a46aSMarshall Clow}
17783772a46aSMarshall Clow
17793772a46aSMarshall Clowtemplate <class _Tp, size_t _Np>
17802ffa1705SMarshall Clow_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
17813772a46aSMarshall Clowreverse_iterator<_Tp*> rend(_Tp (&__array)[_Np])
17823772a46aSMarshall Clow{
17833772a46aSMarshall Clow    return reverse_iterator<_Tp*>(__array);
17843772a46aSMarshall Clow}
17853772a46aSMarshall Clow
17863772a46aSMarshall Clowtemplate <class _Ep>
17872ffa1705SMarshall Clow_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
17883772a46aSMarshall Clowreverse_iterator<const _Ep*> rbegin(initializer_list<_Ep> __il)
17893772a46aSMarshall Clow{
17903772a46aSMarshall Clow    return reverse_iterator<const _Ep*>(__il.end());
17913772a46aSMarshall Clow}
17923772a46aSMarshall Clow
17933772a46aSMarshall Clowtemplate <class _Ep>
17942ffa1705SMarshall Clow_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
17953772a46aSMarshall Clowreverse_iterator<const _Ep*> rend(initializer_list<_Ep> __il)
17963772a46aSMarshall Clow{
17973772a46aSMarshall Clow    return reverse_iterator<const _Ep*>(__il.begin());
17983772a46aSMarshall Clow}
17993772a46aSMarshall Clow
18001e548c72SMarshall Clowtemplate <class _Cp>
18012ffa1705SMarshall Clow_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
18027725546aSMarshall Clowauto cbegin(const _Cp& __c) -> decltype(_VSTD::begin(__c))
18031e548c72SMarshall Clow{
18047725546aSMarshall Clow    return _VSTD::begin(__c);
18051e548c72SMarshall Clow}
18061e548c72SMarshall Clow
18071e548c72SMarshall Clowtemplate <class _Cp>
18082ffa1705SMarshall Clow_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
18097725546aSMarshall Clowauto cend(const _Cp& __c) -> decltype(_VSTD::end(__c))
18101e548c72SMarshall Clow{
18117725546aSMarshall Clow    return _VSTD::end(__c);
18121e548c72SMarshall Clow}
18131e548c72SMarshall Clow
18141e548c72SMarshall Clowtemplate <class _Cp>
18152ffa1705SMarshall Clow_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
18161e548c72SMarshall Clowauto rbegin(_Cp& __c) -> decltype(__c.rbegin())
18171e548c72SMarshall Clow{
18181e548c72SMarshall Clow    return __c.rbegin();
18191e548c72SMarshall Clow}
18201e548c72SMarshall Clow
18211e548c72SMarshall Clowtemplate <class _Cp>
18222ffa1705SMarshall Clow_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
18231e548c72SMarshall Clowauto rbegin(const _Cp& __c) -> decltype(__c.rbegin())
18241e548c72SMarshall Clow{
18251e548c72SMarshall Clow    return __c.rbegin();
18261e548c72SMarshall Clow}
18271e548c72SMarshall Clow
18281e548c72SMarshall Clowtemplate <class _Cp>
18292ffa1705SMarshall Clow_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
18301e548c72SMarshall Clowauto rend(_Cp& __c) -> decltype(__c.rend())
18311e548c72SMarshall Clow{
18321e548c72SMarshall Clow    return __c.rend();
18331e548c72SMarshall Clow}
18341e548c72SMarshall Clow
18351e548c72SMarshall Clowtemplate <class _Cp>
18362ffa1705SMarshall Clow_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
18371e548c72SMarshall Clowauto rend(const _Cp& __c) -> decltype(__c.rend())
18381e548c72SMarshall Clow{
18391e548c72SMarshall Clow    return __c.rend();
18401e548c72SMarshall Clow}
18411e548c72SMarshall Clow
18421e548c72SMarshall Clowtemplate <class _Cp>
18432ffa1705SMarshall Clow_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
18447725546aSMarshall Clowauto crbegin(const _Cp& __c) -> decltype(_VSTD::rbegin(__c))
18451e548c72SMarshall Clow{
18467725546aSMarshall Clow    return _VSTD::rbegin(__c);
18471e548c72SMarshall Clow}
18481e548c72SMarshall Clow
18491e548c72SMarshall Clowtemplate <class _Cp>
18502ffa1705SMarshall Clow_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
18517725546aSMarshall Clowauto crend(const _Cp& __c) -> decltype(_VSTD::rend(__c))
18521e548c72SMarshall Clow{
18537725546aSMarshall Clow    return _VSTD::rend(__c);
18541e548c72SMarshall Clow}
18551e548c72SMarshall Clow
18561e548c72SMarshall Clow#endif
18571e548c72SMarshall Clow
18581e548c72SMarshall Clow
185954613ab4SEric Fiselier#else  // defined(_LIBCPP_CXX03_LANG)
18603e519524SHoward Hinnant
1861c003db1fSHoward Hinnanttemplate <class _Cp>
18622ffa1705SMarshall Clow_LIBCPP_INLINE_VISIBILITY
1863c003db1fSHoward Hinnanttypename _Cp::iterator
1864c003db1fSHoward Hinnantbegin(_Cp& __c)
18653e519524SHoward Hinnant{
18663e519524SHoward Hinnant    return __c.begin();
18673e519524SHoward Hinnant}
18683e519524SHoward Hinnant
1869c003db1fSHoward Hinnanttemplate <class _Cp>
18702ffa1705SMarshall Clow_LIBCPP_INLINE_VISIBILITY
1871c003db1fSHoward Hinnanttypename _Cp::const_iterator
1872c003db1fSHoward Hinnantbegin(const _Cp& __c)
18733e519524SHoward Hinnant{
18743e519524SHoward Hinnant    return __c.begin();
18753e519524SHoward Hinnant}
18763e519524SHoward Hinnant
1877c003db1fSHoward Hinnanttemplate <class _Cp>
18782ffa1705SMarshall Clow_LIBCPP_INLINE_VISIBILITY
1879c003db1fSHoward Hinnanttypename _Cp::iterator
1880c003db1fSHoward Hinnantend(_Cp& __c)
18813e519524SHoward Hinnant{
18823e519524SHoward Hinnant    return __c.end();
18833e519524SHoward Hinnant}
18843e519524SHoward Hinnant
1885c003db1fSHoward Hinnanttemplate <class _Cp>
18862ffa1705SMarshall Clow_LIBCPP_INLINE_VISIBILITY
1887c003db1fSHoward Hinnanttypename _Cp::const_iterator
1888c003db1fSHoward Hinnantend(const _Cp& __c)
18893e519524SHoward Hinnant{
18903e519524SHoward Hinnant    return __c.end();
18913e519524SHoward Hinnant}
18923e519524SHoward Hinnant
189354613ab4SEric Fiselier#endif // !defined(_LIBCPP_CXX03_LANG)
18943e519524SHoward Hinnant
1895ad755104SMarshall Clow#if _LIBCPP_STD_VER > 14
1896d1dcda19SMarshall Clow
1897d1dcda19SMarshall Clow// #if _LIBCPP_STD_VER > 11
1898d1dcda19SMarshall Clow// template <>
1899d1dcda19SMarshall Clow// struct _LIBCPP_TEMPLATE_VIS plus<void>
1900d1dcda19SMarshall Clow// {
1901d1dcda19SMarshall Clow//     template <class _T1, class _T2>
1902d1dcda19SMarshall Clow//     _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
1903d1dcda19SMarshall Clow//     auto operator()(_T1&& __t, _T2&& __u) const
1904d1dcda19SMarshall Clow//     _NOEXCEPT_(noexcept(_VSTD::forward<_T1>(__t) + _VSTD::forward<_T2>(__u)))
1905d1dcda19SMarshall Clow//     -> decltype        (_VSTD::forward<_T1>(__t) + _VSTD::forward<_T2>(__u))
1906d1dcda19SMarshall Clow//         { return        _VSTD::forward<_T1>(__t) + _VSTD::forward<_T2>(__u); }
1907d1dcda19SMarshall Clow//     typedef void is_transparent;
1908d1dcda19SMarshall Clow// };
1909d1dcda19SMarshall Clow// #endif
1910d1dcda19SMarshall Clow
191188d21343SMarshall Clowtemplate <class _Cont>
19122ffa1705SMarshall Clow_LIBCPP_INLINE_VISIBILITY
1913d1dcda19SMarshall Clowconstexpr auto size(const _Cont& __c)
1914d1dcda19SMarshall Clow_NOEXCEPT_(noexcept(__c.size()))
1915d1dcda19SMarshall Clow-> decltype        (__c.size())
1916d1dcda19SMarshall Clow{ return            __c.size(); }
1917ad755104SMarshall Clow
191888d21343SMarshall Clowtemplate <class _Tp, size_t _Sz>
19192ffa1705SMarshall Clow_LIBCPP_INLINE_VISIBILITY
1920fd838227SEric Fiselierconstexpr size_t size(const _Tp (&)[_Sz]) noexcept { return _Sz; }
1921ad755104SMarshall Clow
19227d3986eaSMarshall Clow#if _LIBCPP_STD_VER > 17
19237d3986eaSMarshall Clowtemplate <class _Cont>
19242ffa1705SMarshall Clow_LIBCPP_INLINE_VISIBILITY
19257d3986eaSMarshall Clowconstexpr auto ssize(const _Cont& __c)
19267d3986eaSMarshall Clow_NOEXCEPT_(noexcept(static_cast<common_type_t<ptrdiff_t, make_signed_t<decltype(__c.size())>>>(__c.size())))
19277d3986eaSMarshall Clow->                              common_type_t<ptrdiff_t, make_signed_t<decltype(__c.size())>>
19287d3986eaSMarshall Clow{ return            static_cast<common_type_t<ptrdiff_t, make_signed_t<decltype(__c.size())>>>(__c.size()); }
19297d3986eaSMarshall Clow
19307d3986eaSMarshall Clowtemplate <class _Tp, ptrdiff_t _Sz>
19312ffa1705SMarshall Clow_LIBCPP_INLINE_VISIBILITY
19327d3986eaSMarshall Clowconstexpr ptrdiff_t ssize(const _Tp (&)[_Sz]) noexcept { return _Sz; }
19337d3986eaSMarshall Clow#endif
19347d3986eaSMarshall Clow
193588d21343SMarshall Clowtemplate <class _Cont>
19362ffa1705SMarshall Clow_LIBCPP_NODISCARD_AFTER_CXX17 _LIBCPP_INLINE_VISIBILITY
1937d1dcda19SMarshall Clowconstexpr auto empty(const _Cont& __c)
1938d1dcda19SMarshall Clow_NOEXCEPT_(noexcept(__c.empty()))
1939d1dcda19SMarshall Clow-> decltype        (__c.empty())
1940d1dcda19SMarshall Clow{ return            __c.empty(); }
1941ad755104SMarshall Clow
194288d21343SMarshall Clowtemplate <class _Tp, size_t _Sz>
19432ffa1705SMarshall Clow_LIBCPP_NODISCARD_AFTER_CXX17 _LIBCPP_INLINE_VISIBILITY
1944fd838227SEric Fiselierconstexpr bool empty(const _Tp (&)[_Sz]) noexcept { return false; }
1945ad755104SMarshall Clow
1946ad755104SMarshall Clowtemplate <class _Ep>
19472ffa1705SMarshall Clow_LIBCPP_NODISCARD_AFTER_CXX17 _LIBCPP_INLINE_VISIBILITY
1948ad755104SMarshall Clowconstexpr bool empty(initializer_list<_Ep> __il) noexcept { return __il.size() == 0; }
1949ad755104SMarshall Clow
195088d21343SMarshall Clowtemplate <class _Cont> constexpr
19512ffa1705SMarshall Clow_LIBCPP_INLINE_VISIBILITY
1952d1dcda19SMarshall Clowauto data(_Cont& __c)
1953d1dcda19SMarshall Clow_NOEXCEPT_(noexcept(__c.data()))
1954d1dcda19SMarshall Clow-> decltype        (__c.data())
1955d1dcda19SMarshall Clow{ return            __c.data(); }
1956ad755104SMarshall Clow
195788d21343SMarshall Clowtemplate <class _Cont> constexpr
19582ffa1705SMarshall Clow_LIBCPP_INLINE_VISIBILITY
1959d1dcda19SMarshall Clowauto data(const _Cont& __c)
1960d1dcda19SMarshall Clow_NOEXCEPT_(noexcept(__c.data()))
1961d1dcda19SMarshall Clow-> decltype        (__c.data())
1962d1dcda19SMarshall Clow{ return            __c.data(); }
1963ad755104SMarshall Clow
196488d21343SMarshall Clowtemplate <class _Tp, size_t _Sz>
19652ffa1705SMarshall Clow_LIBCPP_INLINE_VISIBILITY
196688d21343SMarshall Clowconstexpr _Tp* data(_Tp (&__array)[_Sz]) noexcept { return __array; }
1967ad755104SMarshall Clow
1968ad755104SMarshall Clowtemplate <class _Ep>
19692ffa1705SMarshall Clow_LIBCPP_INLINE_VISIBILITY
1970ad755104SMarshall Clowconstexpr const _Ep* data(initializer_list<_Ep> __il) noexcept { return __il.begin(); }
1971ad755104SMarshall Clow#endif
1972ad755104SMarshall Clow
19732ac6babcSArthur O'Dwyertemplate <class _Container, class _Predicate>
19742ac6babcSArthur O'Dwyertypename _Container::size_type
19752ac6babcSArthur O'Dwyer__libcpp_erase_if_container(_Container& __c, _Predicate& __pred) {
19762ac6babcSArthur O'Dwyer  typename _Container::size_type __old_size = __c.size();
19772ac6babcSArthur O'Dwyer
19782ac6babcSArthur O'Dwyer  const typename _Container::iterator __last = __c.end();
19792ac6babcSArthur O'Dwyer  for (typename _Container::iterator __iter = __c.begin(); __iter != __last;) {
19802ac6babcSArthur O'Dwyer    if (__pred(*__iter))
19812ac6babcSArthur O'Dwyer      __iter = __c.erase(__iter);
19822ac6babcSArthur O'Dwyer    else
19832ac6babcSArthur O'Dwyer      ++__iter;
19842ac6babcSArthur O'Dwyer  }
19852ac6babcSArthur O'Dwyer
19862ac6babcSArthur O'Dwyer  return __old_size - __c.size();
19872ac6babcSArthur O'Dwyer}
1988ad755104SMarshall Clow
19893e519524SHoward Hinnant_LIBCPP_END_NAMESPACE_STD
19903e519524SHoward Hinnant
19913e519524SHoward Hinnant#endif // _LIBCPP_ITERATOR
1992