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
5158b29a4eSLouis Dionnetemplate<indirectly_readable T>
5258b29a4eSLouis Dionne  using iter_common_reference_t =
5358b29a4eSLouis Dionne    common_reference_t<iter_reference_t<T>, iter_value_t<T>&>;  // since C++20
5458b29a4eSLouis 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
9858b29a4eSLouis Dionne// [indirectcallable]
9958b29a4eSLouis Dionne// [indirectcallable.indirectinvocable]
10058b29a4eSLouis Dionnetemplate<class F, class I>
10158b29a4eSLouis Dionne  concept indirectly_unary_invocable = see below;          // since C++20
10258b29a4eSLouis Dionne
10358b29a4eSLouis Dionnetemplate<class F, class I>
10458b29a4eSLouis Dionne  concept indirectly_regular_unary_invocable = see below;  // since C++20
10558b29a4eSLouis Dionne
10658b29a4eSLouis Dionnetemplate<class F, class I>
10758b29a4eSLouis Dionne  concept indirect_unary_predicate = see below;            // since C++20
10858b29a4eSLouis Dionne
10958b29a4eSLouis Dionnetemplate<class F, class I1, class I2>
11058b29a4eSLouis Dionne  concept indirect_binary_predicate = see below;           // since C++20
11158b29a4eSLouis Dionne
11258b29a4eSLouis Dionnetemplate<class F, class I1, class I2 = I1>
11358b29a4eSLouis Dionne  concept indirect_equivalence_relation = see below;       // since C++20
11458b29a4eSLouis Dionne
11558b29a4eSLouis Dionnetemplate<class F, class I1, class I2 = I1>
11658b29a4eSLouis Dionne  concept indirect_strict_weak_order = see below;          // since C++20
11758b29a4eSLouis Dionne
11858b29a4eSLouis Dionnetemplate<class F, class... Is>
11958b29a4eSLouis Dionne  using indirect_result_t = see below;                     // since C++20
12058b29a4eSLouis Dionne
12158b29a4eSLouis Dionne// [projected], projected
12258b29a4eSLouis Dionnetemplate<indirectly_readable I, indirectly_regular_unary_invocable<I> Proj>
12358b29a4eSLouis Dionne  struct projected;                                        // since C++20
12458b29a4eSLouis Dionne
12558b29a4eSLouis Dionnetemplate<weakly_incrementable I, indirectly_regular_unary_invocable<I> Proj>
12658b29a4eSLouis Dionne  struct incrementable_traits<projected<I, Proj>>;         // since C++20
12758b29a4eSLouis 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
245*41bdf64dSLouis Dionne    : public iterator<output_iterator_tag, void, void, void, void> // until C++17
2463e519524SHoward Hinnant{
2473e519524SHoward Hinnantprotected:
2483e519524SHoward Hinnant    Container* container;
2493e519524SHoward Hinnantpublic:
2503e519524SHoward Hinnant    typedef Container                   container_type;
2513e519524SHoward Hinnant    typedef void                        value_type;
252*41bdf64dSLouis Dionne    typedef void                        difference_type; // until C++20
253*41bdf64dSLouis Dionne    typedef ptrdiff_t                   difference_type; // since C++20
2548892b4eeSEric Fiselier    typedef void                        reference;
2553e519524SHoward Hinnant    typedef void                        pointer;
2563e519524SHoward Hinnant
257*41bdf64dSLouis Dionne    constexpr back_insert_iterator() noexcept = default; // since C++20
25806e2b737SArthur O'Dwyer    explicit back_insert_iterator(Container& x);  // constexpr in C++20
25906e2b737SArthur O'Dwyer    back_insert_iterator& operator=(const typename Container::value_type& value);  // constexpr in C++20
26006e2b737SArthur O'Dwyer    back_insert_iterator& operator*();  // constexpr in C++20
26106e2b737SArthur O'Dwyer    back_insert_iterator& operator++();  // constexpr in C++20
26206e2b737SArthur O'Dwyer    back_insert_iterator  operator++(int);  // constexpr in C++20
2633e519524SHoward Hinnant};
2643e519524SHoward Hinnant
26506e2b737SArthur O'Dwyertemplate <class Container> back_insert_iterator<Container> back_inserter(Container& x);  // constexpr in C++20
2663e519524SHoward Hinnant
2673e519524SHoward Hinnanttemplate <class Container>
2683e519524SHoward Hinnantclass front_insert_iterator
269*41bdf64dSLouis Dionne    : public iterator<output_iterator_tag, void, void, void, void> // until C++17
2703e519524SHoward Hinnant{
2713e519524SHoward Hinnantprotected:
2723e519524SHoward Hinnant    Container* container;
2733e519524SHoward Hinnantpublic:
2743e519524SHoward Hinnant    typedef Container                    container_type;
2753e519524SHoward Hinnant    typedef void                         value_type;
276*41bdf64dSLouis Dionne    typedef void                         difference_type; // until C++20
277*41bdf64dSLouis Dionne    typedef ptrdiff_t                    difference_type; // since C++20
2788892b4eeSEric Fiselier    typedef void                         reference;
2793e519524SHoward Hinnant    typedef void                         pointer;
2803e519524SHoward Hinnant
281*41bdf64dSLouis Dionne    constexpr front_insert_iterator() noexcept = default; // since C++20
28206e2b737SArthur O'Dwyer    explicit front_insert_iterator(Container& x);  // constexpr in C++20
28306e2b737SArthur O'Dwyer    front_insert_iterator& operator=(const typename Container::value_type& value);  // constexpr in C++20
28406e2b737SArthur O'Dwyer    front_insert_iterator& operator*();  // constexpr in C++20
28506e2b737SArthur O'Dwyer    front_insert_iterator& operator++();  // constexpr in C++20
28606e2b737SArthur O'Dwyer    front_insert_iterator  operator++(int);  // constexpr in C++20
2873e519524SHoward Hinnant};
2883e519524SHoward Hinnant
28906e2b737SArthur O'Dwyertemplate <class Container> front_insert_iterator<Container> front_inserter(Container& x);  // constexpr in C++20
2903e519524SHoward Hinnant
2913e519524SHoward Hinnanttemplate <class Container>
2923e519524SHoward Hinnantclass insert_iterator
293*41bdf64dSLouis Dionne    : public iterator<output_iterator_tag, void, void, void, void> // until C++17
2943e519524SHoward Hinnant{
2953e519524SHoward Hinnantprotected:
2963e519524SHoward Hinnant    Container* container;
2973e519524SHoward Hinnant    typename Container::iterator iter;
2983e519524SHoward Hinnantpublic:
2993e519524SHoward Hinnant    typedef Container              container_type;
3003e519524SHoward Hinnant    typedef void                   value_type;
301*41bdf64dSLouis Dionne    typedef void                   difference_type; // until C++20
302*41bdf64dSLouis Dionne    typedef ptrdiff_t              difference_type; // since C++20
3038892b4eeSEric Fiselier    typedef void                   reference;
3043e519524SHoward Hinnant    typedef void                   pointer;
3053e519524SHoward Hinnant
306*41bdf64dSLouis Dionne    insert_iterator() = default; // since C++20
30706e2b737SArthur O'Dwyer    insert_iterator(Container& x, typename Container::iterator i);  // constexpr in C++20
30806e2b737SArthur O'Dwyer    insert_iterator& operator=(const typename Container::value_type& value);  // constexpr in C++20
30906e2b737SArthur O'Dwyer    insert_iterator& operator*();  // constexpr in C++20
31006e2b737SArthur O'Dwyer    insert_iterator& operator++();  // constexpr in C++20
31106e2b737SArthur O'Dwyer    insert_iterator& operator++(int);  // constexpr in C++20
3123e519524SHoward Hinnant};
3133e519524SHoward Hinnant
3143e519524SHoward Hinnanttemplate <class Container, class Iterator>
31506e2b737SArthur O'Dwyerinsert_iterator<Container> inserter(Container& x, Iterator i);  // constexpr in C++20
3163e519524SHoward Hinnant
317947ce6b5SMarshall Clowtemplate <class Iterator>
318947ce6b5SMarshall Clowclass move_iterator {
319947ce6b5SMarshall Clowpublic:
320947ce6b5SMarshall Clow    typedef Iterator                                              iterator_type;
321947ce6b5SMarshall Clow    typedef typename iterator_traits<Iterator>::difference_type   difference_type;
322947ce6b5SMarshall Clow    typedef Iterator                                              pointer;
323947ce6b5SMarshall Clow    typedef typename iterator_traits<Iterator>::value_type        value_type;
324947ce6b5SMarshall Clow    typedef typename iterator_traits<Iterator>::iterator_category iterator_category;
325947ce6b5SMarshall Clow    typedef value_type&&                                          reference;
326947ce6b5SMarshall Clow
327720ef472SMarshall Clow    constexpr move_iterator();  // all the constexprs are in C++17
328720ef472SMarshall Clow    constexpr explicit move_iterator(Iterator i);
329720ef472SMarshall Clow    template <class U>
330720ef472SMarshall Clow      constexpr move_iterator(const move_iterator<U>& u);
331720ef472SMarshall Clow    template <class U>
332720ef472SMarshall Clow      constexpr move_iterator& operator=(const move_iterator<U>& u);
333720ef472SMarshall Clow    constexpr iterator_type base() const;
334720ef472SMarshall Clow    constexpr reference operator*() const;
335720ef472SMarshall Clow    constexpr pointer operator->() const;
336720ef472SMarshall Clow    constexpr move_iterator& operator++();
337720ef472SMarshall Clow    constexpr move_iterator operator++(int);
338720ef472SMarshall Clow    constexpr move_iterator& operator--();
339720ef472SMarshall Clow    constexpr move_iterator operator--(int);
340720ef472SMarshall Clow    constexpr move_iterator operator+(difference_type n) const;
341720ef472SMarshall Clow    constexpr move_iterator& operator+=(difference_type n);
342720ef472SMarshall Clow    constexpr move_iterator operator-(difference_type n) const;
343720ef472SMarshall Clow    constexpr move_iterator& operator-=(difference_type n);
344720ef472SMarshall Clow    constexpr unspecified operator[](difference_type n) const;
345947ce6b5SMarshall Clowprivate:
346947ce6b5SMarshall Clow    Iterator current; // exposition only
347947ce6b5SMarshall Clow};
348947ce6b5SMarshall Clow
349947ce6b5SMarshall Clowtemplate <class Iterator1, class Iterator2>
350720ef472SMarshall Clowconstexpr bool   // constexpr in C++17
351947ce6b5SMarshall Clowoperator==(const move_iterator<Iterator1>& x, const move_iterator<Iterator2>& y);
352947ce6b5SMarshall Clow
353947ce6b5SMarshall Clowtemplate <class Iterator1, class Iterator2>
354720ef472SMarshall Clowconstexpr bool   // constexpr in C++17
355947ce6b5SMarshall Clowoperator!=(const move_iterator<Iterator1>& x, const move_iterator<Iterator2>& y);
356947ce6b5SMarshall Clow
357947ce6b5SMarshall Clowtemplate <class Iterator1, class Iterator2>
358720ef472SMarshall Clowconstexpr bool   // constexpr in C++17
359947ce6b5SMarshall Clowoperator<(const move_iterator<Iterator1>& x, const move_iterator<Iterator2>& y);
360947ce6b5SMarshall Clow
361947ce6b5SMarshall Clowtemplate <class Iterator1, class Iterator2>
362720ef472SMarshall Clowconstexpr bool   // constexpr in C++17
363947ce6b5SMarshall Clowoperator<=(const move_iterator<Iterator1>& x, const move_iterator<Iterator2>& y);
364947ce6b5SMarshall Clow
365947ce6b5SMarshall Clowtemplate <class Iterator1, class Iterator2>
366720ef472SMarshall Clowconstexpr bool   // constexpr in C++17
367947ce6b5SMarshall Clowoperator>(const move_iterator<Iterator1>& x, const move_iterator<Iterator2>& y);
368947ce6b5SMarshall Clow
369947ce6b5SMarshall Clowtemplate <class Iterator1, class Iterator2>
370720ef472SMarshall Clowconstexpr bool   // constexpr in C++17
371947ce6b5SMarshall Clowoperator>=(const move_iterator<Iterator1>& x, const move_iterator<Iterator2>& y);
372947ce6b5SMarshall Clow
373947ce6b5SMarshall Clowtemplate <class Iterator1, class Iterator2>
374720ef472SMarshall Clowconstexpr auto   // constexpr in C++17
375947ce6b5SMarshall Clowoperator-(const move_iterator<Iterator1>& x,
376947ce6b5SMarshall Clow          const move_iterator<Iterator2>& y) -> decltype(x.base() - y.base());
377947ce6b5SMarshall Clow
378947ce6b5SMarshall Clowtemplate <class Iterator>
379720ef472SMarshall Clowconstexpr move_iterator<Iterator> operator+(   // constexpr in C++17
380720ef472SMarshall Clow            typename move_iterator<Iterator>::difference_type n,
381947ce6b5SMarshall Clow            const move_iterator<Iterator>& x);
382947ce6b5SMarshall Clow
383720ef472SMarshall Clowtemplate <class Iterator>   // constexpr in C++17
384720ef472SMarshall Clowconstexpr  move_iterator<Iterator> make_move_iterator(const Iterator& i);
385947ce6b5SMarshall Clow
386947ce6b5SMarshall Clow
3873e519524SHoward Hinnanttemplate <class T, class charT = char, class traits = char_traits<charT>, class Distance = ptrdiff_t>
3883e519524SHoward Hinnantclass istream_iterator
3891055cb91SLouis Dionne    : public iterator<input_iterator_tag, T, Distance, const T*, const T&> // until C++17
3903e519524SHoward Hinnant{
3913e519524SHoward Hinnantpublic:
392*41bdf64dSLouis Dionne    typedef input_iterator_tag           iterator_category;
393*41bdf64dSLouis Dionne    typedef T                            value_type;
394*41bdf64dSLouis Dionne    typedef Distance                     difference_type;
395*41bdf64dSLouis Dionne    typedef const T*                     pointer;
396*41bdf64dSLouis Dionne    typedef const T&                     reference;
397*41bdf64dSLouis Dionne
3983e519524SHoward Hinnant    typedef charT                        char_type;
3993e519524SHoward Hinnant    typedef traits                       traits_type;
4003e519524SHoward Hinnant    typedef basic_istream<charT, traits> istream_type;
4013e519524SHoward Hinnant
40260d5e0e0SMarshall Clow    constexpr istream_iterator();
4033e519524SHoward Hinnant    istream_iterator(istream_type& s);
4043e519524SHoward Hinnant    istream_iterator(const istream_iterator& x);
4053e519524SHoward Hinnant    ~istream_iterator();
4063e519524SHoward Hinnant
4073e519524SHoward Hinnant    const T& operator*() const;
4083e519524SHoward Hinnant    const T* operator->() const;
4093e519524SHoward Hinnant    istream_iterator& operator++();
4103e519524SHoward Hinnant    istream_iterator  operator++(int);
4113e519524SHoward Hinnant};
4123e519524SHoward Hinnant
4133e519524SHoward Hinnanttemplate <class T, class charT, class traits, class Distance>
4143e519524SHoward Hinnantbool operator==(const istream_iterator<T,charT,traits,Distance>& x,
4153e519524SHoward Hinnant                const istream_iterator<T,charT,traits,Distance>& y);
4163e519524SHoward Hinnanttemplate <class T, class charT, class traits, class Distance>
4173e519524SHoward Hinnantbool operator!=(const istream_iterator<T,charT,traits,Distance>& x,
4183e519524SHoward Hinnant                const istream_iterator<T,charT,traits,Distance>& y);
4193e519524SHoward Hinnant
4203e519524SHoward Hinnanttemplate <class T, class charT = char, class traits = char_traits<charT> >
4213e519524SHoward Hinnantclass ostream_iterator
4221055cb91SLouis Dionne    : public iterator<output_iterator_tag, void, void, void, void> // until C++17
4233e519524SHoward Hinnant{
4243e519524SHoward Hinnantpublic:
425*41bdf64dSLouis Dionne    typedef output_iterator_tag         iterator_category;
426*41bdf64dSLouis Dionne    typedef void                        value_type;
427*41bdf64dSLouis Dionne    typedef void                        difference_type; // until C++20
428*41bdf64dSLouis Dionne    typedef ptrdiff_t                   difference_type; // since C++20
429*41bdf64dSLouis Dionne    typedef void                        pointer;
430*41bdf64dSLouis Dionne    typedef void                        reference;
431*41bdf64dSLouis Dionne
4323e519524SHoward Hinnant    typedef charT char_type;
4333e519524SHoward Hinnant    typedef traits traits_type;
4343e519524SHoward Hinnant    typedef basic_ostream<charT,traits> ostream_type;
4353e519524SHoward Hinnant
436*41bdf64dSLouis Dionne    constexpr ostream_iterator() noexcept = default; // since C++20
4373e519524SHoward Hinnant    ostream_iterator(ostream_type& s);
4383e519524SHoward Hinnant    ostream_iterator(ostream_type& s, const charT* delimiter);
4393e519524SHoward Hinnant    ostream_iterator(const ostream_iterator& x);
4403e519524SHoward Hinnant    ~ostream_iterator();
4413e519524SHoward Hinnant    ostream_iterator& operator=(const T& value);
4423e519524SHoward Hinnant
4433e519524SHoward Hinnant    ostream_iterator& operator*();
4443e519524SHoward Hinnant    ostream_iterator& operator++();
4453e519524SHoward Hinnant    ostream_iterator& operator++(int);
4463e519524SHoward Hinnant};
4473e519524SHoward Hinnant
4483e519524SHoward Hinnanttemplate<class charT, class traits = char_traits<charT> >
4493e519524SHoward Hinnantclass istreambuf_iterator
450*41bdf64dSLouis Dionne    : public iterator<input_iterator_tag, charT, traits::off_type, unspecified, charT> // until C++17
4513e519524SHoward Hinnant{
4523e519524SHoward Hinnantpublic:
453*41bdf64dSLouis Dionne    typedef input_iterator_tag              iterator_category;
454*41bdf64dSLouis Dionne    typedef charT                           value_type;
455*41bdf64dSLouis Dionne    typedef traits::off_type                difference_type;
456*41bdf64dSLouis Dionne    typedef unspecified                     pointer;
457*41bdf64dSLouis Dionne    typedef charT                           reference;
458*41bdf64dSLouis Dionne
4593e519524SHoward Hinnant    typedef charT                           char_type;
4603e519524SHoward Hinnant    typedef traits                          traits_type;
461*41bdf64dSLouis Dionne    typedef traits::int_type                int_type;
4623e519524SHoward Hinnant    typedef basic_streambuf<charT, traits>  streambuf_type;
4633e519524SHoward Hinnant    typedef basic_istream<charT, traits>    istream_type;
4643e519524SHoward Hinnant
4658e882dcbSHoward Hinnant    istreambuf_iterator() noexcept;
4668e882dcbSHoward Hinnant    istreambuf_iterator(istream_type& s) noexcept;
4678e882dcbSHoward Hinnant    istreambuf_iterator(streambuf_type* s) noexcept;
4688e882dcbSHoward Hinnant    istreambuf_iterator(a-private-type) noexcept;
4693e519524SHoward Hinnant
4703e519524SHoward Hinnant    charT                operator*() const;
4713e519524SHoward Hinnant    pointer operator->() const;
4723e519524SHoward Hinnant    istreambuf_iterator& operator++();
4733e519524SHoward Hinnant    a-private-type       operator++(int);
4743e519524SHoward Hinnant
4753e519524SHoward Hinnant    bool equal(const istreambuf_iterator& b) const;
4763e519524SHoward Hinnant};
4773e519524SHoward Hinnant
4783e519524SHoward Hinnanttemplate <class charT, class traits>
4793e519524SHoward Hinnantbool operator==(const istreambuf_iterator<charT,traits>& a,
4803e519524SHoward Hinnant                const istreambuf_iterator<charT,traits>& b);
4813e519524SHoward Hinnanttemplate <class charT, class traits>
4823e519524SHoward Hinnantbool operator!=(const istreambuf_iterator<charT,traits>& a,
4833e519524SHoward Hinnant                const istreambuf_iterator<charT,traits>& b);
4843e519524SHoward Hinnant
4853e519524SHoward Hinnanttemplate <class charT, class traits = char_traits<charT> >
4863e519524SHoward Hinnantclass ostreambuf_iterator
4871055cb91SLouis Dionne    : public iterator<output_iterator_tag, void, void, void, void> // until C++17
4883e519524SHoward Hinnant{
4893e519524SHoward Hinnantpublic:
490*41bdf64dSLouis Dionne    typedef output_iterator_tag            iterator_category;
491*41bdf64dSLouis Dionne    typedef void                           value_type;
492*41bdf64dSLouis Dionne    typedef void                           difference_type; // until C++20
493*41bdf64dSLouis Dionne    typedef ptrdiff_t                      difference_type; // since C++20
494*41bdf64dSLouis Dionne    typedef void                           pointer;
495*41bdf64dSLouis Dionne    typedef void                           reference;
496*41bdf64dSLouis Dionne
4973e519524SHoward Hinnant    typedef charT                          char_type;
4983e519524SHoward Hinnant    typedef traits                         traits_type;
4993e519524SHoward Hinnant    typedef basic_streambuf<charT, traits> streambuf_type;
5003e519524SHoward Hinnant    typedef basic_ostream<charT, traits>   ostream_type;
5013e519524SHoward Hinnant
502*41bdf64dSLouis Dionne    constexpr ostreambuf_iterator() noexcept = default; // since C++20
5038e882dcbSHoward Hinnant    ostreambuf_iterator(ostream_type& s) noexcept;
5048e882dcbSHoward Hinnant    ostreambuf_iterator(streambuf_type* s) noexcept;
5053e519524SHoward Hinnant    ostreambuf_iterator& operator=(charT c);
5063e519524SHoward Hinnant    ostreambuf_iterator& operator*();
5073e519524SHoward Hinnant    ostreambuf_iterator& operator++();
5083e519524SHoward Hinnant    ostreambuf_iterator& operator++(int);
5098e882dcbSHoward Hinnant    bool failed() const noexcept;
5103e519524SHoward Hinnant};
5113e519524SHoward Hinnant
512020b623aSMarshall Clowtemplate <class C> constexpr auto begin(C& c) -> decltype(c.begin());
513020b623aSMarshall Clowtemplate <class C> constexpr auto begin(const C& c) -> decltype(c.begin());
514020b623aSMarshall Clowtemplate <class C> constexpr auto end(C& c) -> decltype(c.end());
515020b623aSMarshall Clowtemplate <class C> constexpr auto end(const C& c) -> decltype(c.end());
516020b623aSMarshall Clowtemplate <class T, size_t N> constexpr T* begin(T (&array)[N]);
517020b623aSMarshall Clowtemplate <class T, size_t N> constexpr T* end(T (&array)[N]);
5183e519524SHoward Hinnant
519020b623aSMarshall Clowtemplate <class C> auto constexpr cbegin(const C& c) -> decltype(std::begin(c));        // C++14
520020b623aSMarshall Clowtemplate <class C> auto constexpr cend(const C& c) -> decltype(std::end(c));            // C++14
521020b623aSMarshall Clowtemplate <class C> auto constexpr rbegin(C& c) -> decltype(c.rbegin());                 // C++14
522020b623aSMarshall Clowtemplate <class C> auto constexpr rbegin(const C& c) -> decltype(c.rbegin());           // C++14
523020b623aSMarshall Clowtemplate <class C> auto constexpr rend(C& c) -> decltype(c.rend());                     // C++14
524020b623aSMarshall Clowtemplate <class C> constexpr auto rend(const C& c) -> decltype(c.rend());               // C++14
525020b623aSMarshall Clowtemplate <class E> reverse_iterator<const E*> constexpr rbegin(initializer_list<E> il); // C++14
526020b623aSMarshall Clowtemplate <class E> reverse_iterator<const E*> constexpr rend(initializer_list<E> il);   // C++14
527020b623aSMarshall Clowtemplate <class T, size_t N> reverse_iterator<T*> constexpr rbegin(T (&array)[N]);      // C++14
528020b623aSMarshall Clowtemplate <class T, size_t N> reverse_iterator<T*> constexpr rend(T (&array)[N]);        // C++14
529020b623aSMarshall Clowtemplate <class C> constexpr auto crbegin(const C& c) -> decltype(std::rbegin(c));      // C++14
530020b623aSMarshall Clowtemplate <class C> constexpr auto crend(const C& c) -> decltype(std::rend(c));          // C++14
5311e548c72SMarshall Clow
532ad755104SMarshall Clow// 24.8, container access:
533ad755104SMarshall Clowtemplate <class C> constexpr auto size(const C& c) -> decltype(c.size());         // C++17
534ad755104SMarshall Clowtemplate <class T, size_t N> constexpr size_t size(const T (&array)[N]) noexcept; // C++17
5357d3986eaSMarshall Clow
5367d3986eaSMarshall Clowtemplate <class C> constexpr auto ssize(const C& c)
5377d3986eaSMarshall Clow    -> common_type_t<ptrdiff_t, make_signed_t<decltype(c.size())>>;                    // C++20
5387d3986eaSMarshall Clowtemplate <class T, ptrdiff_t> constexpr ptrdiff_t ssize(const T (&array)[N]) noexcept; // C++20
5397d3986eaSMarshall Clow
540ad755104SMarshall Clowtemplate <class C> constexpr auto empty(const C& c) -> decltype(c.empty());       // C++17
541ad755104SMarshall Clowtemplate <class T, size_t N> constexpr bool empty(const T (&array)[N]) noexcept;  // C++17
542ad755104SMarshall Clowtemplate <class E> constexpr bool empty(initializer_list<E> il) noexcept;         // C++17
543ad755104SMarshall Clowtemplate <class C> constexpr auto data(C& c) -> decltype(c.data());               // C++17
544ad755104SMarshall Clowtemplate <class C> constexpr auto data(const C& c) -> decltype(c.data());         // C++17
545ad755104SMarshall Clowtemplate <class T, size_t N> constexpr T* data(T (&array)[N]) noexcept;           // C++17
546ad755104SMarshall Clowtemplate <class E> constexpr const E* data(initializer_list<E> il) noexcept;      // C++17
547ad755104SMarshall Clow
5483e519524SHoward Hinnant}  // std
5493e519524SHoward Hinnant
5503e519524SHoward Hinnant*/
5513e519524SHoward Hinnant
5523e519524SHoward Hinnant#include <__config>
5535f51fb34SArthur O'Dwyer#include <__debug>
554c204c130SMarshall Clow#include <__functional_base>
55536d0fdf9SChristopher Di Bella#include <__iterator/advance.h>
55657ebf3d0SLouis Dionne#include <__iterator/concepts.h>
557e0adf7e0Szoecarver#include <__iterator/incrementable_traits.h>
55858b29a4eSLouis Dionne#include <__iterator/indirect_concepts.h>
55997e383aaSLouis Dionne#include <__iterator/iter_move.h>
560120fa829Szoecarver#include <__iterator/iterator_traits.h>
561857fa7b7SChristopher Di Bella#include <__iterator/next.h>
5620dc7fd1bSChristopher Di Bella#include <__iterator/prev.h>
56358b29a4eSLouis Dionne#include <__iterator/projected.h>
564e0adf7e0Szoecarver#include <__iterator/readable_traits.h>
565f992cfbaSLouis Dionne#include <__memory/addressof.h>
566d41c6d51SArthur O'Dwyer#include <__memory/pointer_traits.h>
5675f51fb34SArthur O'Dwyer#include <compare>
5685f51fb34SArthur O'Dwyer#include <concepts> // Mandated by the Standard.
5695f51fb34SArthur O'Dwyer#include <cstddef>
5705f51fb34SArthur O'Dwyer#include <initializer_list>
5715f51fb34SArthur O'Dwyer#include <iosfwd> // for forward declarations of vector and string
5725f51fb34SArthur O'Dwyer#include <type_traits>
573f56972e2SMarshall Clow#include <version>
574b5c63a2eSHoward Hinnant
575073458b1SHoward Hinnant#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
5763e519524SHoward Hinnant#pragma GCC system_header
577073458b1SHoward Hinnant#endif
5783e519524SHoward Hinnant
5793e519524SHoward Hinnant_LIBCPP_BEGIN_NAMESPACE_STD
580fe31f11cSChristopher Di Bella
5813e519524SHoward Hinnanttemplate<class _Category, class _Tp, class _Distance = ptrdiff_t,
5823e519524SHoward Hinnant         class _Pointer = _Tp*, class _Reference = _Tp&>
5831055cb91SLouis Dionnestruct _LIBCPP_TEMPLATE_VIS _LIBCPP_DEPRECATED_IN_CXX17 iterator
5843e519524SHoward Hinnant{
5853e519524SHoward Hinnant    typedef _Tp        value_type;
5863e519524SHoward Hinnant    typedef _Distance  difference_type;
5873e519524SHoward Hinnant    typedef _Pointer   pointer;
5883e519524SHoward Hinnant    typedef _Reference reference;
5893e519524SHoward Hinnant    typedef _Category  iterator_category;
5903e519524SHoward Hinnant};
5913e519524SHoward Hinnant
5923e519524SHoward Hinnanttemplate <class _InputIter>
593f51ee632SMarshall Clowinline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
5943e519524SHoward Hinnantvoid __advance(_InputIter& __i,
5953e519524SHoward Hinnant             typename iterator_traits<_InputIter>::difference_type __n, input_iterator_tag)
5963e519524SHoward Hinnant{
5973e519524SHoward Hinnant    for (; __n > 0; --__n)
5983e519524SHoward Hinnant        ++__i;
5993e519524SHoward Hinnant}
6003e519524SHoward Hinnant
6013e519524SHoward Hinnanttemplate <class _BiDirIter>
602f51ee632SMarshall Clowinline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
6033e519524SHoward Hinnantvoid __advance(_BiDirIter& __i,
6043e519524SHoward Hinnant             typename iterator_traits<_BiDirIter>::difference_type __n, bidirectional_iterator_tag)
6053e519524SHoward Hinnant{
6063e519524SHoward Hinnant    if (__n >= 0)
6073e519524SHoward Hinnant        for (; __n > 0; --__n)
6083e519524SHoward Hinnant            ++__i;
6093e519524SHoward Hinnant    else
6103e519524SHoward Hinnant        for (; __n < 0; ++__n)
6113e519524SHoward Hinnant            --__i;
6123e519524SHoward Hinnant}
6133e519524SHoward Hinnant
6143e519524SHoward Hinnanttemplate <class _RandIter>
615f51ee632SMarshall Clowinline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
6163e519524SHoward Hinnantvoid __advance(_RandIter& __i,
6173e519524SHoward Hinnant             typename iterator_traits<_RandIter>::difference_type __n, random_access_iterator_tag)
6183e519524SHoward Hinnant{
6193e519524SHoward Hinnant   __i += __n;
6203e519524SHoward Hinnant}
6213e519524SHoward Hinnant
62236d0fdf9SChristopher Di Bellatemplate <class _InputIter, class _Distance,
62336d0fdf9SChristopher Di Bella          class = typename enable_if<is_integral<decltype(_VSTD::__convert_to_integral(declval<_Distance>()))>::value>::type>
624f51ee632SMarshall Clowinline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
62512b01ab7SLouis Dionnevoid advance(_InputIter& __i, _Distance __orig_n)
6263e519524SHoward Hinnant{
627c0428b3cSArthur O'Dwyer    typedef decltype(_VSTD::__convert_to_integral(__orig_n)) _IntegralSize;
62812b01ab7SLouis Dionne    _IntegralSize __n = __orig_n;
6299571b8f2SArthur O'Dwyer    _LIBCPP_ASSERT(__n >= 0 || __is_cpp17_bidirectional_iterator<_InputIter>::value,
6309571b8f2SArthur O'Dwyer                   "Attempt to advance(it, n) with negative n on a non-bidirectional iterator");
631c0428b3cSArthur O'Dwyer    _VSTD::__advance(__i, __n, typename iterator_traits<_InputIter>::iterator_category());
6323e519524SHoward Hinnant}
6333e519524SHoward Hinnant
6343e519524SHoward Hinnanttemplate <class _InputIter>
635f51ee632SMarshall Clowinline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
6363e519524SHoward Hinnanttypename iterator_traits<_InputIter>::difference_type
6373e519524SHoward Hinnant__distance(_InputIter __first, _InputIter __last, input_iterator_tag)
6383e519524SHoward Hinnant{
6393e519524SHoward Hinnant    typename iterator_traits<_InputIter>::difference_type __r(0);
6403e519524SHoward Hinnant    for (; __first != __last; ++__first)
6413e519524SHoward Hinnant        ++__r;
6423e519524SHoward Hinnant    return __r;
6433e519524SHoward Hinnant}
6443e519524SHoward Hinnant
6453e519524SHoward Hinnanttemplate <class _RandIter>
646f51ee632SMarshall Clowinline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
6473e519524SHoward Hinnanttypename iterator_traits<_RandIter>::difference_type
6483e519524SHoward Hinnant__distance(_RandIter __first, _RandIter __last, random_access_iterator_tag)
6493e519524SHoward Hinnant{
6503e519524SHoward Hinnant    return __last - __first;
6513e519524SHoward Hinnant}
6523e519524SHoward Hinnant
6533e519524SHoward Hinnanttemplate <class _InputIter>
654f51ee632SMarshall Clowinline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
6553e519524SHoward Hinnanttypename iterator_traits<_InputIter>::difference_type
6563e519524SHoward Hinnantdistance(_InputIter __first, _InputIter __last)
6573e519524SHoward Hinnant{
658c0428b3cSArthur O'Dwyer    return _VSTD::__distance(__first, __last, typename iterator_traits<_InputIter>::iterator_category());
6593e519524SHoward Hinnant}
6603e519524SHoward Hinnant
661e5f1288fSMarshall Clowtemplate <class _InputIter>
662f51ee632SMarshall Clowinline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
6633e2ef408SRachel Craiktypename enable_if
6643e2ef408SRachel Craik<
665f82dba01SEric Fiselier    __is_cpp17_input_iterator<_InputIter>::value,
666e5f1288fSMarshall Clow    _InputIter
6673e2ef408SRachel Craik>::type
668e5f1288fSMarshall Clownext(_InputIter __x,
6693e2ef408SRachel Craik     typename iterator_traits<_InputIter>::difference_type __n = 1)
6703e519524SHoward Hinnant{
671f82dba01SEric Fiselier    _LIBCPP_ASSERT(__n >= 0 || __is_cpp17_bidirectional_iterator<_InputIter>::value,
67212b01ab7SLouis Dionne                       "Attempt to next(it, n) with negative n on a non-bidirectional iterator");
673e1cd11d8SMarshall Clow
674ce48a113SHoward Hinnant    _VSTD::advance(__x, __n);
6753e519524SHoward Hinnant    return __x;
6763e519524SHoward Hinnant}
6773e519524SHoward Hinnant
678e1cd11d8SMarshall Clowtemplate <class _InputIter>
679f51ee632SMarshall Clowinline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
6803e2ef408SRachel Craiktypename enable_if
6813e2ef408SRachel Craik<
682f82dba01SEric Fiselier    __is_cpp17_input_iterator<_InputIter>::value,
683e1cd11d8SMarshall Clow    _InputIter
6843e2ef408SRachel Craik>::type
685e1cd11d8SMarshall Clowprev(_InputIter __x,
686e1cd11d8SMarshall Clow     typename iterator_traits<_InputIter>::difference_type __n = 1)
6873e519524SHoward Hinnant{
688f82dba01SEric Fiselier    _LIBCPP_ASSERT(__n <= 0 || __is_cpp17_bidirectional_iterator<_InputIter>::value,
68912b01ab7SLouis Dionne                       "Attempt to prev(it, n) with a positive n on a non-bidirectional iterator");
690ce48a113SHoward Hinnant    _VSTD::advance(__x, -__n);
6913e519524SHoward Hinnant    return __x;
6923e519524SHoward Hinnant}
6933e519524SHoward Hinnant
694e02ed1c2SEric Fiselier
695e02ed1c2SEric Fiseliertemplate <class _Tp, class = void>
696e02ed1c2SEric Fiselierstruct __is_stashing_iterator : false_type {};
697e02ed1c2SEric Fiselier
698e02ed1c2SEric Fiseliertemplate <class _Tp>
699e02ed1c2SEric Fiselierstruct __is_stashing_iterator<_Tp, typename __void_t<typename _Tp::__stashing_iterator_tag>::type>
700e02ed1c2SEric Fiselier  : true_type {};
701e02ed1c2SEric Fiselier
7021055cb91SLouis Dionne_LIBCPP_SUPPRESS_DEPRECATED_PUSH
7033e519524SHoward Hinnanttemplate <class _Iter>
704e2f2d1edSEric Fiselierclass _LIBCPP_TEMPLATE_VIS reverse_iterator
7051055cb91SLouis Dionne#if _LIBCPP_STD_VER <= 14 || !defined(_LIBCPP_ABI_NO_ITERATOR_BASES)
7063e519524SHoward Hinnant    : public iterator<typename iterator_traits<_Iter>::iterator_category,
7073e519524SHoward Hinnant                      typename iterator_traits<_Iter>::value_type,
7083e519524SHoward Hinnant                      typename iterator_traits<_Iter>::difference_type,
7093e519524SHoward Hinnant                      typename iterator_traits<_Iter>::pointer,
7103e519524SHoward Hinnant                      typename iterator_traits<_Iter>::reference>
7111055cb91SLouis Dionne#endif
7123e519524SHoward Hinnant{
7131055cb91SLouis Dionne_LIBCPP_SUPPRESS_DEPRECATED_POP
7143b83496dSMarshall Clowprivate:
7151055cb91SLouis Dionne#ifndef _LIBCPP_ABI_NO_ITERATOR_BASES
7161055cb91SLouis Dionne    _Iter __t; // no longer used as of LWG #2360, not removed due to ABI break
7171055cb91SLouis Dionne#endif
718e02ed1c2SEric Fiselier
719e02ed1c2SEric Fiselier    static_assert(!__is_stashing_iterator<_Iter>::value,
720e02ed1c2SEric Fiselier      "The specified iterator type cannot be used with reverse_iterator; "
721e02ed1c2SEric Fiselier      "Using stashing iterators with reverse_iterator causes undefined behavior");
722e02ed1c2SEric Fiselier
723b2d74f29SMarshall Clowprotected:
724b2d74f29SMarshall Clow    _Iter current;
7253e519524SHoward Hinnantpublic:
7263e519524SHoward Hinnant    typedef _Iter                                            iterator_type;
7273e519524SHoward Hinnant    typedef typename iterator_traits<_Iter>::difference_type difference_type;
7283e519524SHoward Hinnant    typedef typename iterator_traits<_Iter>::reference       reference;
7293e519524SHoward Hinnant    typedef typename iterator_traits<_Iter>::pointer         pointer;
730d41c6d51SArthur O'Dwyer    typedef _If<__is_cpp17_random_access_iterator<_Iter>::value,
731d41c6d51SArthur O'Dwyer        random_access_iterator_tag,
732d41c6d51SArthur O'Dwyer        typename iterator_traits<_Iter>::iterator_category>  iterator_category;
7331055cb91SLouis Dionne    typedef typename iterator_traits<_Iter>::value_type      value_type;
7341055cb91SLouis Dionne
735d41c6d51SArthur O'Dwyer#if _LIBCPP_STD_VER > 17
736d41c6d51SArthur O'Dwyer    typedef _If<__is_cpp17_random_access_iterator<_Iter>::value,
737d41c6d51SArthur O'Dwyer        random_access_iterator_tag,
738d41c6d51SArthur O'Dwyer        bidirectional_iterator_tag>                          iterator_concept;
739d41c6d51SArthur O'Dwyer#endif
7403e519524SHoward Hinnant
7411055cb91SLouis Dionne#ifndef _LIBCPP_ABI_NO_ITERATOR_BASES
7421b8f260eSMarshall Clow    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
7431b8f260eSMarshall Clow    reverse_iterator() : __t(), current() {}
7441b8f260eSMarshall Clow    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
7451b8f260eSMarshall Clow    explicit reverse_iterator(_Iter __x) : __t(__x), current(__x) {}
7461b8f260eSMarshall Clow    template <class _Up>
7471b8f260eSMarshall Clow        _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
7481b8f260eSMarshall Clow        reverse_iterator(const reverse_iterator<_Up>& __u) : __t(__u.base()), current(__u.base()) {}
7491b8f260eSMarshall Clow    template <class _Up>
7501b8f260eSMarshall Clow        _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
7511b8f260eSMarshall Clow        reverse_iterator& operator=(const reverse_iterator<_Up>& __u)
7521b8f260eSMarshall Clow            { __t = current = __u.base(); return *this; }
7531055cb91SLouis Dionne#else
7541055cb91SLouis Dionne    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
7551055cb91SLouis Dionne    reverse_iterator() : current() {}
7561055cb91SLouis Dionne    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
7571055cb91SLouis Dionne    explicit reverse_iterator(_Iter __x) : current(__x) {}
7581055cb91SLouis Dionne    template <class _Up>
7591055cb91SLouis Dionne        _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
7601055cb91SLouis Dionne        reverse_iterator(const reverse_iterator<_Up>& __u) : current(__u.base()) {}
7611055cb91SLouis Dionne    template <class _Up>
7621055cb91SLouis Dionne        _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
7631055cb91SLouis Dionne        reverse_iterator& operator=(const reverse_iterator<_Up>& __u)
7641055cb91SLouis Dionne            { current = __u.base(); return *this; }
7651055cb91SLouis Dionne#endif
7661b8f260eSMarshall Clow    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
7671b8f260eSMarshall Clow    _Iter base() const {return current;}
7681b8f260eSMarshall Clow    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
7691b8f260eSMarshall Clow    reference operator*() const {_Iter __tmp = current; return *--__tmp;}
7701b8f260eSMarshall Clow    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
7711b8f260eSMarshall Clow    pointer  operator->() const {return _VSTD::addressof(operator*());}
7721b8f260eSMarshall Clow    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
7731b8f260eSMarshall Clow    reverse_iterator& operator++() {--current; return *this;}
7741b8f260eSMarshall Clow    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
7751b8f260eSMarshall Clow    reverse_iterator  operator++(int) {reverse_iterator __tmp(*this); --current; return __tmp;}
7761b8f260eSMarshall Clow    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
7771b8f260eSMarshall Clow    reverse_iterator& operator--() {++current; return *this;}
7781b8f260eSMarshall Clow    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
7791b8f260eSMarshall Clow    reverse_iterator  operator--(int) {reverse_iterator __tmp(*this); ++current; return __tmp;}
7801b8f260eSMarshall Clow    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
7811b8f260eSMarshall Clow    reverse_iterator  operator+ (difference_type __n) const {return reverse_iterator(current - __n);}
7821b8f260eSMarshall Clow    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
7831b8f260eSMarshall Clow    reverse_iterator& operator+=(difference_type __n) {current -= __n; return *this;}
7841b8f260eSMarshall Clow    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
7851b8f260eSMarshall Clow    reverse_iterator  operator- (difference_type __n) const {return reverse_iterator(current + __n);}
7861b8f260eSMarshall Clow    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
7871b8f260eSMarshall Clow    reverse_iterator& operator-=(difference_type __n) {current += __n; return *this;}
7881b8f260eSMarshall Clow    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
7891b8f260eSMarshall Clow    reference         operator[](difference_type __n) const {return *(*this + __n);}
7903e519524SHoward Hinnant};
7913e519524SHoward Hinnant
7923e519524SHoward Hinnanttemplate <class _Iter1, class _Iter2>
7931b8f260eSMarshall Clowinline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
7943e519524SHoward Hinnantbool
7953e519524SHoward Hinnantoperator==(const reverse_iterator<_Iter1>& __x, const reverse_iterator<_Iter2>& __y)
7963e519524SHoward Hinnant{
7973e519524SHoward Hinnant    return __x.base() == __y.base();
7983e519524SHoward Hinnant}
7993e519524SHoward Hinnant
8003e519524SHoward Hinnanttemplate <class _Iter1, class _Iter2>
8011b8f260eSMarshall Clowinline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
8023e519524SHoward Hinnantbool
8033e519524SHoward Hinnantoperator<(const reverse_iterator<_Iter1>& __x, const reverse_iterator<_Iter2>& __y)
8043e519524SHoward Hinnant{
8053e519524SHoward Hinnant    return __x.base() > __y.base();
8063e519524SHoward Hinnant}
8073e519524SHoward Hinnant
8083e519524SHoward Hinnanttemplate <class _Iter1, class _Iter2>
8091b8f260eSMarshall Clowinline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
8103e519524SHoward Hinnantbool
8113e519524SHoward Hinnantoperator!=(const reverse_iterator<_Iter1>& __x, const reverse_iterator<_Iter2>& __y)
8123e519524SHoward Hinnant{
8133e519524SHoward Hinnant    return __x.base() != __y.base();
8143e519524SHoward Hinnant}
8153e519524SHoward Hinnant
8163e519524SHoward Hinnanttemplate <class _Iter1, class _Iter2>
8171b8f260eSMarshall Clowinline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
8183e519524SHoward Hinnantbool
8193e519524SHoward Hinnantoperator>(const reverse_iterator<_Iter1>& __x, const reverse_iterator<_Iter2>& __y)
8203e519524SHoward Hinnant{
8213e519524SHoward Hinnant    return __x.base() < __y.base();
8223e519524SHoward Hinnant}
8233e519524SHoward Hinnant
8243e519524SHoward Hinnanttemplate <class _Iter1, class _Iter2>
8251b8f260eSMarshall Clowinline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
8263e519524SHoward Hinnantbool
8273e519524SHoward Hinnantoperator>=(const reverse_iterator<_Iter1>& __x, const reverse_iterator<_Iter2>& __y)
8283e519524SHoward Hinnant{
8293e519524SHoward Hinnant    return __x.base() <= __y.base();
8303e519524SHoward Hinnant}
8313e519524SHoward Hinnant
8323e519524SHoward Hinnanttemplate <class _Iter1, class _Iter2>
8331b8f260eSMarshall Clowinline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
8343e519524SHoward Hinnantbool
8353e519524SHoward Hinnantoperator<=(const reverse_iterator<_Iter1>& __x, const reverse_iterator<_Iter2>& __y)
8363e519524SHoward Hinnant{
8373e519524SHoward Hinnant    return __x.base() >= __y.base();
8383e519524SHoward Hinnant}
8393e519524SHoward Hinnant
8402ee83725SMarshall Clow#ifndef _LIBCPP_CXX03_LANG
841947ce6b5SMarshall Clowtemplate <class _Iter1, class _Iter2>
8421b8f260eSMarshall Clowinline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
843947ce6b5SMarshall Clowauto
844947ce6b5SMarshall Clowoperator-(const reverse_iterator<_Iter1>& __x, const reverse_iterator<_Iter2>& __y)
845947ce6b5SMarshall Clow-> decltype(__y.base() - __x.base())
846947ce6b5SMarshall Clow{
847947ce6b5SMarshall Clow    return __y.base() - __x.base();
848947ce6b5SMarshall Clow}
849947ce6b5SMarshall Clow#else
8503e519524SHoward Hinnanttemplate <class _Iter1, class _Iter2>
8513e519524SHoward Hinnantinline _LIBCPP_INLINE_VISIBILITY
8523e519524SHoward Hinnanttypename reverse_iterator<_Iter1>::difference_type
8533e519524SHoward Hinnantoperator-(const reverse_iterator<_Iter1>& __x, const reverse_iterator<_Iter2>& __y)
8543e519524SHoward Hinnant{
8553e519524SHoward Hinnant    return __y.base() - __x.base();
8563e519524SHoward Hinnant}
857947ce6b5SMarshall Clow#endif
8583e519524SHoward Hinnant
8593e519524SHoward Hinnanttemplate <class _Iter>
8601b8f260eSMarshall Clowinline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
8613e519524SHoward Hinnantreverse_iterator<_Iter>
8623e519524SHoward Hinnantoperator+(typename reverse_iterator<_Iter>::difference_type __n, const reverse_iterator<_Iter>& __x)
8633e519524SHoward Hinnant{
8643e519524SHoward Hinnant    return reverse_iterator<_Iter>(__x.base() - __n);
8653e519524SHoward Hinnant}
8663e519524SHoward Hinnant
8676a640a18SMarshall Clow#if _LIBCPP_STD_VER > 11
8686a640a18SMarshall Clowtemplate <class _Iter>
8691b8f260eSMarshall Clowinline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
8706a640a18SMarshall Clowreverse_iterator<_Iter> make_reverse_iterator(_Iter __i)
8716a640a18SMarshall Clow{
8726a640a18SMarshall Clow    return reverse_iterator<_Iter>(__i);
8736a640a18SMarshall Clow}
8746a640a18SMarshall Clow#endif
8756a640a18SMarshall Clow
8761055cb91SLouis Dionne_LIBCPP_SUPPRESS_DEPRECATED_PUSH
8773e519524SHoward Hinnanttemplate <class _Container>
878e2f2d1edSEric Fiselierclass _LIBCPP_TEMPLATE_VIS back_insert_iterator
8791055cb91SLouis Dionne#if _LIBCPP_STD_VER <= 14 || !defined(_LIBCPP_ABI_NO_ITERATOR_BASES)
8801055cb91SLouis Dionne    : public iterator<output_iterator_tag, void, void, void, void>
8811055cb91SLouis Dionne#endif
8823e519524SHoward Hinnant{
8831055cb91SLouis Dionne_LIBCPP_SUPPRESS_DEPRECATED_POP
8843e519524SHoward Hinnantprotected:
8853e519524SHoward Hinnant    _Container* container;
8863e519524SHoward Hinnantpublic:
8871055cb91SLouis Dionne    typedef output_iterator_tag iterator_category;
8881055cb91SLouis Dionne    typedef void value_type;
889*41bdf64dSLouis Dionne#if _LIBCPP_STD_VER > 17
890*41bdf64dSLouis Dionne    typedef ptrdiff_t difference_type;
891*41bdf64dSLouis Dionne#else
8921055cb91SLouis Dionne    typedef void difference_type;
893*41bdf64dSLouis Dionne#endif
8941055cb91SLouis Dionne    typedef void pointer;
8951055cb91SLouis Dionne    typedef void reference;
8963e519524SHoward Hinnant    typedef _Container container_type;
8973e519524SHoward Hinnant
898*41bdf64dSLouis Dionne#if _LIBCPP_STD_VER > 17
899*41bdf64dSLouis Dionne    _LIBCPP_INLINE_VISIBILITY constexpr back_insert_iterator() noexcept = default;
900*41bdf64dSLouis Dionne#endif
90106e2b737SArthur O'Dwyer    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 explicit back_insert_iterator(_Container& __x) : container(_VSTD::addressof(__x)) {}
90206e2b737SArthur O'Dwyer    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 back_insert_iterator& operator=(const typename _Container::value_type& __value_)
903e4383379SHoward Hinnant        {container->push_back(__value_); return *this;}
904046492b9SEric Fiselier#ifndef _LIBCPP_CXX03_LANG
90506e2b737SArthur O'Dwyer    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 back_insert_iterator& operator=(typename _Container::value_type&& __value_)
906e4383379SHoward Hinnant        {container->push_back(_VSTD::move(__value_)); return *this;}
907046492b9SEric Fiselier#endif // _LIBCPP_CXX03_LANG
90806e2b737SArthur O'Dwyer    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 back_insert_iterator& operator*()     {return *this;}
90906e2b737SArthur O'Dwyer    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 back_insert_iterator& operator++()    {return *this;}
91006e2b737SArthur O'Dwyer    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 back_insert_iterator  operator++(int) {return *this;}
9113e519524SHoward Hinnant};
9123e519524SHoward Hinnant
9133e519524SHoward Hinnanttemplate <class _Container>
91406e2b737SArthur O'Dwyerinline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
9153e519524SHoward Hinnantback_insert_iterator<_Container>
9163e519524SHoward Hinnantback_inserter(_Container& __x)
9173e519524SHoward Hinnant{
9183e519524SHoward Hinnant    return back_insert_iterator<_Container>(__x);
9193e519524SHoward Hinnant}
9203e519524SHoward Hinnant
9211055cb91SLouis Dionne_LIBCPP_SUPPRESS_DEPRECATED_PUSH
9223e519524SHoward Hinnanttemplate <class _Container>
923e2f2d1edSEric Fiselierclass _LIBCPP_TEMPLATE_VIS front_insert_iterator
9241055cb91SLouis Dionne#if _LIBCPP_STD_VER <= 14 || !defined(_LIBCPP_ABI_NO_ITERATOR_BASES)
9251055cb91SLouis Dionne    : public iterator<output_iterator_tag, void, void, void, void>
9261055cb91SLouis Dionne#endif
9273e519524SHoward Hinnant{
9281055cb91SLouis Dionne_LIBCPP_SUPPRESS_DEPRECATED_POP
9293e519524SHoward Hinnantprotected:
9303e519524SHoward Hinnant    _Container* container;
9313e519524SHoward Hinnantpublic:
9321055cb91SLouis Dionne    typedef output_iterator_tag iterator_category;
9331055cb91SLouis Dionne    typedef void value_type;
934*41bdf64dSLouis Dionne#if _LIBCPP_STD_VER > 17
935*41bdf64dSLouis Dionne    typedef ptrdiff_t difference_type;
936*41bdf64dSLouis Dionne#else
9371055cb91SLouis Dionne    typedef void difference_type;
938*41bdf64dSLouis Dionne#endif
9391055cb91SLouis Dionne    typedef void pointer;
9401055cb91SLouis Dionne    typedef void reference;
9413e519524SHoward Hinnant    typedef _Container container_type;
9423e519524SHoward Hinnant
943*41bdf64dSLouis Dionne#if _LIBCPP_STD_VER > 17
944*41bdf64dSLouis Dionne    _LIBCPP_INLINE_VISIBILITY constexpr front_insert_iterator() noexcept = default;
945*41bdf64dSLouis Dionne#endif
94606e2b737SArthur O'Dwyer    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 explicit front_insert_iterator(_Container& __x) : container(_VSTD::addressof(__x)) {}
94706e2b737SArthur O'Dwyer    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 front_insert_iterator& operator=(const typename _Container::value_type& __value_)
948e4383379SHoward Hinnant        {container->push_front(__value_); return *this;}
949046492b9SEric Fiselier#ifndef _LIBCPP_CXX03_LANG
95006e2b737SArthur O'Dwyer    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 front_insert_iterator& operator=(typename _Container::value_type&& __value_)
951e4383379SHoward Hinnant        {container->push_front(_VSTD::move(__value_)); return *this;}
952046492b9SEric Fiselier#endif // _LIBCPP_CXX03_LANG
95306e2b737SArthur O'Dwyer    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 front_insert_iterator& operator*()     {return *this;}
95406e2b737SArthur O'Dwyer    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 front_insert_iterator& operator++()    {return *this;}
95506e2b737SArthur O'Dwyer    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 front_insert_iterator  operator++(int) {return *this;}
9563e519524SHoward Hinnant};
9573e519524SHoward Hinnant
9583e519524SHoward Hinnanttemplate <class _Container>
95906e2b737SArthur O'Dwyerinline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
9603e519524SHoward Hinnantfront_insert_iterator<_Container>
9613e519524SHoward Hinnantfront_inserter(_Container& __x)
9623e519524SHoward Hinnant{
9633e519524SHoward Hinnant    return front_insert_iterator<_Container>(__x);
9643e519524SHoward Hinnant}
9653e519524SHoward Hinnant
9661055cb91SLouis Dionne_LIBCPP_SUPPRESS_DEPRECATED_PUSH
9673e519524SHoward Hinnanttemplate <class _Container>
968e2f2d1edSEric Fiselierclass _LIBCPP_TEMPLATE_VIS insert_iterator
9691055cb91SLouis Dionne#if _LIBCPP_STD_VER <= 14 || !defined(_LIBCPP_ABI_NO_ITERATOR_BASES)
9701055cb91SLouis Dionne    : public iterator<output_iterator_tag, void, void, void, void>
9711055cb91SLouis Dionne#endif
9723e519524SHoward Hinnant{
9731055cb91SLouis Dionne_LIBCPP_SUPPRESS_DEPRECATED_POP
9743e519524SHoward Hinnantprotected:
9753e519524SHoward Hinnant    _Container* container;
9763e519524SHoward Hinnant    typename _Container::iterator iter;
9773e519524SHoward Hinnantpublic:
9781055cb91SLouis Dionne    typedef output_iterator_tag iterator_category;
9791055cb91SLouis Dionne    typedef void value_type;
980*41bdf64dSLouis Dionne#if _LIBCPP_STD_VER > 17
981*41bdf64dSLouis Dionne    typedef ptrdiff_t difference_type;
982*41bdf64dSLouis Dionne#else
9831055cb91SLouis Dionne    typedef void difference_type;
984*41bdf64dSLouis Dionne#endif
9851055cb91SLouis Dionne    typedef void pointer;
9861055cb91SLouis Dionne    typedef void reference;
9873e519524SHoward Hinnant    typedef _Container container_type;
9883e519524SHoward Hinnant
989*41bdf64dSLouis Dionne#if _LIBCPP_STD_VER > 17
990*41bdf64dSLouis Dionne    _LIBCPP_INLINE_VISIBILITY insert_iterator() = default;
991*41bdf64dSLouis Dionne#endif
99206e2b737SArthur O'Dwyer    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 insert_iterator(_Container& __x, typename _Container::iterator __i)
993f519be34SMarshall Clow        : container(_VSTD::addressof(__x)), iter(__i) {}
99406e2b737SArthur O'Dwyer    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 insert_iterator& operator=(const typename _Container::value_type& __value_)
995e4383379SHoward Hinnant        {iter = container->insert(iter, __value_); ++iter; return *this;}
996046492b9SEric Fiselier#ifndef _LIBCPP_CXX03_LANG
99706e2b737SArthur O'Dwyer    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 insert_iterator& operator=(typename _Container::value_type&& __value_)
998e4383379SHoward Hinnant        {iter = container->insert(iter, _VSTD::move(__value_)); ++iter; return *this;}
999046492b9SEric Fiselier#endif // _LIBCPP_CXX03_LANG
100006e2b737SArthur O'Dwyer    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 insert_iterator& operator*()        {return *this;}
100106e2b737SArthur O'Dwyer    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 insert_iterator& operator++()       {return *this;}
100206e2b737SArthur O'Dwyer    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 insert_iterator& operator++(int)    {return *this;}
10033e519524SHoward Hinnant};
10043e519524SHoward Hinnant
10053e519524SHoward Hinnanttemplate <class _Container>
100606e2b737SArthur O'Dwyerinline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
10073e519524SHoward Hinnantinsert_iterator<_Container>
10083e519524SHoward Hinnantinserter(_Container& __x, typename _Container::iterator __i)
10093e519524SHoward Hinnant{
10103e519524SHoward Hinnant    return insert_iterator<_Container>(__x, __i);
10113e519524SHoward Hinnant}
10123e519524SHoward Hinnant
10131055cb91SLouis Dionne_LIBCPP_SUPPRESS_DEPRECATED_PUSH
10143e519524SHoward Hinnanttemplate <class _Tp, class _CharT = char,
10153e519524SHoward Hinnant          class _Traits = char_traits<_CharT>, class _Distance = ptrdiff_t>
1016e2f2d1edSEric Fiselierclass _LIBCPP_TEMPLATE_VIS istream_iterator
10171055cb91SLouis Dionne#if _LIBCPP_STD_VER <= 14 || !defined(_LIBCPP_ABI_NO_ITERATOR_BASES)
10183e519524SHoward Hinnant    : public iterator<input_iterator_tag, _Tp, _Distance, const _Tp*, const _Tp&>
10191055cb91SLouis Dionne#endif
10203e519524SHoward Hinnant{
10211055cb91SLouis Dionne_LIBCPP_SUPPRESS_DEPRECATED_POP
10223e519524SHoward Hinnantpublic:
10231055cb91SLouis Dionne    typedef input_iterator_tag iterator_category;
10241055cb91SLouis Dionne    typedef _Tp value_type;
10251055cb91SLouis Dionne    typedef _Distance difference_type;
10261055cb91SLouis Dionne    typedef const _Tp* pointer;
10271055cb91SLouis Dionne    typedef const _Tp& reference;
10283e519524SHoward Hinnant    typedef _CharT char_type;
10293e519524SHoward Hinnant    typedef _Traits traits_type;
10303e519524SHoward Hinnant    typedef basic_istream<_CharT,_Traits> istream_type;
10313e519524SHoward Hinnantprivate:
10323e519524SHoward Hinnant    istream_type* __in_stream_;
10333e519524SHoward Hinnant    _Tp __value_;
10343e519524SHoward Hinnantpublic:
1035527a7fdfSBruce Mitchener    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR istream_iterator() : __in_stream_(nullptr), __value_() {}
1036bc6a7df0SMarshall Clow    _LIBCPP_INLINE_VISIBILITY istream_iterator(istream_type& __s) : __in_stream_(_VSTD::addressof(__s))
10373e519524SHoward Hinnant        {
10383e519524SHoward Hinnant            if (!(*__in_stream_ >> __value_))
1039527a7fdfSBruce Mitchener                __in_stream_ = nullptr;
10403e519524SHoward Hinnant        }
10413e519524SHoward Hinnant
10423e519524SHoward Hinnant    _LIBCPP_INLINE_VISIBILITY const _Tp& operator*() const {return __value_;}
1043bc6a7df0SMarshall Clow    _LIBCPP_INLINE_VISIBILITY const _Tp* operator->() const {return _VSTD::addressof((operator*()));}
10443e519524SHoward Hinnant    _LIBCPP_INLINE_VISIBILITY istream_iterator& operator++()
10453e519524SHoward Hinnant        {
10463e519524SHoward Hinnant            if (!(*__in_stream_ >> __value_))
1047527a7fdfSBruce Mitchener                __in_stream_ = nullptr;
10483e519524SHoward Hinnant            return *this;
10493e519524SHoward Hinnant        }
10503e519524SHoward Hinnant    _LIBCPP_INLINE_VISIBILITY istream_iterator  operator++(int)
10513e519524SHoward Hinnant        {istream_iterator __t(*this); ++(*this); return __t;}
10523e519524SHoward Hinnant
10536f56d3eeSRoger Ferrer Ibanez    template <class _Up, class _CharU, class _TraitsU, class _DistanceU>
10543e519524SHoward Hinnant    friend _LIBCPP_INLINE_VISIBILITY
10556f56d3eeSRoger Ferrer Ibanez    bool
10566f56d3eeSRoger Ferrer Ibanez    operator==(const istream_iterator<_Up, _CharU, _TraitsU, _DistanceU>& __x,
10576f56d3eeSRoger Ferrer Ibanez               const istream_iterator<_Up, _CharU, _TraitsU, _DistanceU>& __y);
10583e519524SHoward Hinnant
10596f56d3eeSRoger Ferrer Ibanez    template <class _Up, class _CharU, class _TraitsU, class _DistanceU>
10603e519524SHoward Hinnant    friend _LIBCPP_INLINE_VISIBILITY
10616f56d3eeSRoger Ferrer Ibanez    bool
10626f56d3eeSRoger Ferrer Ibanez    operator==(const istream_iterator<_Up, _CharU, _TraitsU, _DistanceU>& __x,
10636f56d3eeSRoger Ferrer Ibanez               const istream_iterator<_Up, _CharU, _TraitsU, _DistanceU>& __y);
10643e519524SHoward Hinnant};
10653e519524SHoward Hinnant
10666f56d3eeSRoger Ferrer Ibaneztemplate <class _Tp, class _CharT, class _Traits, class _Distance>
10676f56d3eeSRoger Ferrer Ibanezinline _LIBCPP_INLINE_VISIBILITY
10686f56d3eeSRoger Ferrer Ibanezbool
10696f56d3eeSRoger Ferrer Ibanezoperator==(const istream_iterator<_Tp, _CharT, _Traits, _Distance>& __x,
10706f56d3eeSRoger Ferrer Ibanez           const istream_iterator<_Tp, _CharT, _Traits, _Distance>& __y)
10716f56d3eeSRoger Ferrer Ibanez{
10726f56d3eeSRoger Ferrer Ibanez    return __x.__in_stream_ == __y.__in_stream_;
10736f56d3eeSRoger Ferrer Ibanez}
10746f56d3eeSRoger Ferrer Ibanez
10756f56d3eeSRoger Ferrer Ibaneztemplate <class _Tp, class _CharT, class _Traits, class _Distance>
10766f56d3eeSRoger Ferrer Ibanezinline _LIBCPP_INLINE_VISIBILITY
10776f56d3eeSRoger Ferrer Ibanezbool
10786f56d3eeSRoger Ferrer Ibanezoperator!=(const istream_iterator<_Tp, _CharT, _Traits, _Distance>& __x,
10796f56d3eeSRoger Ferrer Ibanez           const istream_iterator<_Tp, _CharT, _Traits, _Distance>& __y)
10806f56d3eeSRoger Ferrer Ibanez{
10816f56d3eeSRoger Ferrer Ibanez    return !(__x == __y);
10826f56d3eeSRoger Ferrer Ibanez}
10836f56d3eeSRoger Ferrer Ibanez
10841055cb91SLouis Dionne_LIBCPP_SUPPRESS_DEPRECATED_PUSH
10853e519524SHoward Hinnanttemplate <class _Tp, class _CharT = char, class _Traits = char_traits<_CharT> >
1086e2f2d1edSEric Fiselierclass _LIBCPP_TEMPLATE_VIS ostream_iterator
10871055cb91SLouis Dionne#if _LIBCPP_STD_VER <= 14 || !defined(_LIBCPP_ABI_NO_ITERATOR_BASES)
10883e519524SHoward Hinnant    : public iterator<output_iterator_tag, void, void, void, void>
10891055cb91SLouis Dionne#endif
10903e519524SHoward Hinnant{
10911055cb91SLouis Dionne_LIBCPP_SUPPRESS_DEPRECATED_POP
10923e519524SHoward Hinnantpublic:
109371a16e40SLouis Dionne    typedef output_iterator_tag             iterator_category;
109471a16e40SLouis Dionne    typedef void                            value_type;
109571a16e40SLouis Dionne#if _LIBCPP_STD_VER > 17
1096*41bdf64dSLouis Dionne    typedef ptrdiff_t                       difference_type;
109771a16e40SLouis Dionne#else
109871a16e40SLouis Dionne    typedef void                            difference_type;
109971a16e40SLouis Dionne#endif
110071a16e40SLouis Dionne    typedef void                            pointer;
110171a16e40SLouis Dionne    typedef void                            reference;
11023e519524SHoward Hinnant    typedef _CharT                          char_type;
11033e519524SHoward Hinnant    typedef _Traits                         traits_type;
11043e519524SHoward Hinnant    typedef basic_ostream<_CharT, _Traits>  ostream_type;
110571a16e40SLouis Dionne
11063e519524SHoward Hinnantprivate:
11073e519524SHoward Hinnant    ostream_type* __out_stream_;
11083e519524SHoward Hinnant    const char_type* __delim_;
11093e519524SHoward Hinnantpublic:
1110*41bdf64dSLouis Dionne#if _LIBCPP_STD_VER > 17
1111*41bdf64dSLouis Dionne    _LIBCPP_INLINE_VISIBILITY constexpr ostream_iterator() noexcept = default;
1112*41bdf64dSLouis Dionne#endif
1113853042cfSMarshall Clow    _LIBCPP_INLINE_VISIBILITY ostream_iterator(ostream_type& __s) _NOEXCEPT
1114527a7fdfSBruce Mitchener        : __out_stream_(_VSTD::addressof(__s)), __delim_(nullptr) {}
1115853042cfSMarshall Clow    _LIBCPP_INLINE_VISIBILITY ostream_iterator(ostream_type& __s, const _CharT* __delimiter) _NOEXCEPT
1116bc6a7df0SMarshall Clow        : __out_stream_(_VSTD::addressof(__s)), __delim_(__delimiter) {}
1117e4383379SHoward Hinnant    _LIBCPP_INLINE_VISIBILITY ostream_iterator& operator=(const _Tp& __value_)
11183e519524SHoward Hinnant        {
1119e4383379SHoward Hinnant            *__out_stream_ << __value_;
11203e519524SHoward Hinnant            if (__delim_)
11213e519524SHoward Hinnant                *__out_stream_ << __delim_;
11223e519524SHoward Hinnant            return *this;
11233e519524SHoward Hinnant        }
11243e519524SHoward Hinnant
11253e519524SHoward Hinnant    _LIBCPP_INLINE_VISIBILITY ostream_iterator& operator*()     {return *this;}
11263e519524SHoward Hinnant    _LIBCPP_INLINE_VISIBILITY ostream_iterator& operator++()    {return *this;}
11273e519524SHoward Hinnant    _LIBCPP_INLINE_VISIBILITY ostream_iterator& operator++(int) {return *this;}
11283e519524SHoward Hinnant};
11293e519524SHoward Hinnant
11301055cb91SLouis Dionne_LIBCPP_SUPPRESS_DEPRECATED_PUSH
11313e519524SHoward Hinnanttemplate<class _CharT, class _Traits>
1132e2f2d1edSEric Fiselierclass _LIBCPP_TEMPLATE_VIS istreambuf_iterator
11331055cb91SLouis Dionne#if _LIBCPP_STD_VER <= 14 || !defined(_LIBCPP_ABI_NO_ITERATOR_BASES)
11343e519524SHoward Hinnant    : public iterator<input_iterator_tag, _CharT,
11353e519524SHoward Hinnant                      typename _Traits::off_type, _CharT*,
11363e519524SHoward Hinnant                      _CharT>
11371055cb91SLouis Dionne#endif
11383e519524SHoward Hinnant{
11391055cb91SLouis Dionne_LIBCPP_SUPPRESS_DEPRECATED_POP
11403e519524SHoward Hinnantpublic:
11411055cb91SLouis Dionne    typedef input_iterator_tag              iterator_category;
11421055cb91SLouis Dionne    typedef _CharT                          value_type;
11431055cb91SLouis Dionne    typedef typename _Traits::off_type      difference_type;
11441055cb91SLouis Dionne    typedef _CharT*                         pointer;
11451055cb91SLouis Dionne    typedef _CharT                          reference;
11463e519524SHoward Hinnant    typedef _CharT                          char_type;
11473e519524SHoward Hinnant    typedef _Traits                         traits_type;
11483e519524SHoward Hinnant    typedef typename _Traits::int_type      int_type;
11493e519524SHoward Hinnant    typedef basic_streambuf<_CharT,_Traits> streambuf_type;
11503e519524SHoward Hinnant    typedef basic_istream<_CharT,_Traits>   istream_type;
11513e519524SHoward Hinnantprivate:
1152dfdf5085SHoward Hinnant    mutable streambuf_type* __sbuf_;
11533e519524SHoward Hinnant
11543e519524SHoward Hinnant    class __proxy
11553e519524SHoward Hinnant    {
11563e519524SHoward Hinnant        char_type __keep_;
11573e519524SHoward Hinnant        streambuf_type* __sbuf_;
11583e519524SHoward Hinnant        _LIBCPP_INLINE_VISIBILITY __proxy(char_type __c, streambuf_type* __s)
11593e519524SHoward Hinnant            : __keep_(__c), __sbuf_(__s) {}
11603e519524SHoward Hinnant        friend class istreambuf_iterator;
11613e519524SHoward Hinnant    public:
11623e519524SHoward Hinnant        _LIBCPP_INLINE_VISIBILITY char_type operator*() const {return __keep_;}
11633e519524SHoward Hinnant    };
11643e519524SHoward Hinnant
1165848a5374SHoward Hinnant    _LIBCPP_INLINE_VISIBILITY
1166dfdf5085SHoward Hinnant    bool __test_for_eof() const
11673e519524SHoward Hinnant    {
11683e519524SHoward Hinnant        if (__sbuf_ && traits_type::eq_int_type(__sbuf_->sgetc(), traits_type::eof()))
1169527a7fdfSBruce Mitchener            __sbuf_ = nullptr;
1170527a7fdfSBruce Mitchener        return __sbuf_ == nullptr;
11713e519524SHoward Hinnant    }
11723e519524SHoward Hinnantpublic:
1173527a7fdfSBruce Mitchener    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR istreambuf_iterator() _NOEXCEPT : __sbuf_(nullptr) {}
11748e882dcbSHoward Hinnant    _LIBCPP_INLINE_VISIBILITY istreambuf_iterator(istream_type& __s) _NOEXCEPT
1175a96d7458SHoward Hinnant        : __sbuf_(__s.rdbuf()) {}
11768e882dcbSHoward Hinnant    _LIBCPP_INLINE_VISIBILITY istreambuf_iterator(streambuf_type* __s) _NOEXCEPT
1177a96d7458SHoward Hinnant        : __sbuf_(__s) {}
11788e882dcbSHoward Hinnant    _LIBCPP_INLINE_VISIBILITY istreambuf_iterator(const __proxy& __p) _NOEXCEPT
11793e519524SHoward Hinnant        : __sbuf_(__p.__sbuf_) {}
11803e519524SHoward Hinnant
1181c206366fSHoward Hinnant    _LIBCPP_INLINE_VISIBILITY char_type  operator*() const
1182c206366fSHoward Hinnant        {return static_cast<char_type>(__sbuf_->sgetc());}
11833e519524SHoward Hinnant    _LIBCPP_INLINE_VISIBILITY istreambuf_iterator& operator++()
11843e519524SHoward Hinnant        {
1185dfdf5085SHoward Hinnant            __sbuf_->sbumpc();
11863e519524SHoward Hinnant            return *this;
11873e519524SHoward Hinnant        }
11883e519524SHoward Hinnant    _LIBCPP_INLINE_VISIBILITY __proxy              operator++(int)
11893e519524SHoward Hinnant        {
1190dfdf5085SHoward Hinnant            return __proxy(__sbuf_->sbumpc(), __sbuf_);
11913e519524SHoward Hinnant        }
11923e519524SHoward Hinnant
11933e519524SHoward Hinnant    _LIBCPP_INLINE_VISIBILITY bool equal(const istreambuf_iterator& __b) const
1194dfdf5085SHoward Hinnant        {return __test_for_eof() == __b.__test_for_eof();}
11953e519524SHoward Hinnant};
11963e519524SHoward Hinnant
11973e519524SHoward Hinnanttemplate <class _CharT, class _Traits>
11983e519524SHoward Hinnantinline _LIBCPP_INLINE_VISIBILITY
11993e519524SHoward Hinnantbool operator==(const istreambuf_iterator<_CharT,_Traits>& __a,
12003e519524SHoward Hinnant                const istreambuf_iterator<_CharT,_Traits>& __b)
12013e519524SHoward Hinnant                {return __a.equal(__b);}
12023e519524SHoward Hinnant
12033e519524SHoward Hinnanttemplate <class _CharT, class _Traits>
12043e519524SHoward Hinnantinline _LIBCPP_INLINE_VISIBILITY
12053e519524SHoward Hinnantbool operator!=(const istreambuf_iterator<_CharT,_Traits>& __a,
12063e519524SHoward Hinnant                const istreambuf_iterator<_CharT,_Traits>& __b)
12073e519524SHoward Hinnant                {return !__a.equal(__b);}
12083e519524SHoward Hinnant
12091055cb91SLouis Dionne_LIBCPP_SUPPRESS_DEPRECATED_PUSH
12103e519524SHoward Hinnanttemplate <class _CharT, class _Traits>
1211e2f2d1edSEric Fiselierclass _LIBCPP_TEMPLATE_VIS ostreambuf_iterator
12121055cb91SLouis Dionne#if _LIBCPP_STD_VER <= 14 || !defined(_LIBCPP_ABI_NO_ITERATOR_BASES)
12133e519524SHoward Hinnant    : public iterator<output_iterator_tag, void, void, void, void>
12141055cb91SLouis Dionne#endif
12153e519524SHoward Hinnant{
12161055cb91SLouis Dionne_LIBCPP_SUPPRESS_DEPRECATED_POP
12173e519524SHoward Hinnantpublic:
121871a16e40SLouis Dionne    typedef output_iterator_tag                 iterator_category;
121971a16e40SLouis Dionne    typedef void                                value_type;
122071a16e40SLouis Dionne#if _LIBCPP_STD_VER > 17
1221*41bdf64dSLouis Dionne    typedef ptrdiff_t                           difference_type;
122271a16e40SLouis Dionne#else
122371a16e40SLouis Dionne    typedef void                                difference_type;
122471a16e40SLouis Dionne#endif
122571a16e40SLouis Dionne    typedef void                                pointer;
122671a16e40SLouis Dionne    typedef void                                reference;
12273e519524SHoward Hinnant    typedef _CharT                              char_type;
12283e519524SHoward Hinnant    typedef _Traits                             traits_type;
12293e519524SHoward Hinnant    typedef basic_streambuf<_CharT, _Traits>    streambuf_type;
12303e519524SHoward Hinnant    typedef basic_ostream<_CharT, _Traits>      ostream_type;
123171a16e40SLouis Dionne
12323e519524SHoward Hinnantprivate:
12333e519524SHoward Hinnant    streambuf_type* __sbuf_;
12343e519524SHoward Hinnantpublic:
1235*41bdf64dSLouis Dionne#if _LIBCPP_STD_VER > 17
1236*41bdf64dSLouis Dionne    _LIBCPP_INLINE_VISIBILITY constexpr ostreambuf_iterator() noexcept = default;
1237*41bdf64dSLouis Dionne#endif
12388e882dcbSHoward Hinnant    _LIBCPP_INLINE_VISIBILITY ostreambuf_iterator(ostream_type& __s) _NOEXCEPT
12393e519524SHoward Hinnant        : __sbuf_(__s.rdbuf()) {}
12408e882dcbSHoward Hinnant    _LIBCPP_INLINE_VISIBILITY ostreambuf_iterator(streambuf_type* __s) _NOEXCEPT
12413e519524SHoward Hinnant        : __sbuf_(__s) {}
12423e519524SHoward Hinnant    _LIBCPP_INLINE_VISIBILITY ostreambuf_iterator& operator=(_CharT __c)
12433e519524SHoward Hinnant        {
12443e519524SHoward Hinnant            if (__sbuf_ && traits_type::eq_int_type(__sbuf_->sputc(__c), traits_type::eof()))
1245527a7fdfSBruce Mitchener                __sbuf_ = nullptr;
12463e519524SHoward Hinnant            return *this;
12473e519524SHoward Hinnant        }
12483e519524SHoward Hinnant    _LIBCPP_INLINE_VISIBILITY ostreambuf_iterator& operator*()     {return *this;}
12493e519524SHoward Hinnant    _LIBCPP_INLINE_VISIBILITY ostreambuf_iterator& operator++()    {return *this;}
12503e519524SHoward Hinnant    _LIBCPP_INLINE_VISIBILITY ostreambuf_iterator& operator++(int) {return *this;}
1251527a7fdfSBruce Mitchener    _LIBCPP_INLINE_VISIBILITY bool failed() const _NOEXCEPT {return __sbuf_ == nullptr;}
125292b5940fSHoward Hinnant
125392b5940fSHoward Hinnant    template <class _Ch, class _Tr>
125492b5940fSHoward Hinnant    friend
125592b5940fSHoward Hinnant    _LIBCPP_HIDDEN
125692b5940fSHoward Hinnant    ostreambuf_iterator<_Ch, _Tr>
125792b5940fSHoward Hinnant    __pad_and_output(ostreambuf_iterator<_Ch, _Tr> __s,
125892b5940fSHoward Hinnant                     const _Ch* __ob, const _Ch* __op, const _Ch* __oe,
125992b5940fSHoward Hinnant                     ios_base& __iob, _Ch __fl);
12603e519524SHoward Hinnant};
12613e519524SHoward Hinnant
12623e519524SHoward Hinnanttemplate <class _Iter>
1263e2f2d1edSEric Fiselierclass _LIBCPP_TEMPLATE_VIS move_iterator
12643e519524SHoward Hinnant{
12653e519524SHoward Hinnantprivate:
12663e519524SHoward Hinnant    _Iter __i;
12673e519524SHoward Hinnantpublic:
12683e519524SHoward Hinnant    typedef _Iter                                            iterator_type;
12693e519524SHoward Hinnant    typedef typename iterator_traits<iterator_type>::value_type value_type;
12703e519524SHoward Hinnant    typedef typename iterator_traits<iterator_type>::difference_type difference_type;
127105333fc8SMarshall Clow    typedef iterator_type pointer;
1272d41c6d51SArthur O'Dwyer    typedef _If<__is_cpp17_random_access_iterator<_Iter>::value,
1273d41c6d51SArthur O'Dwyer        random_access_iterator_tag,
1274d41c6d51SArthur O'Dwyer        typename iterator_traits<_Iter>::iterator_category>  iterator_category;
1275d41c6d51SArthur O'Dwyer#if _LIBCPP_STD_VER > 17
1276d41c6d51SArthur O'Dwyer    typedef input_iterator_tag                               iterator_concept;
1277d41c6d51SArthur O'Dwyer#endif
1278d41c6d51SArthur O'Dwyer
1279046492b9SEric Fiselier#ifndef _LIBCPP_CXX03_LANG
1280906c5085SEric Fiselier    typedef typename iterator_traits<iterator_type>::reference __reference;
1281906c5085SEric Fiselier    typedef typename conditional<
1282906c5085SEric Fiselier            is_reference<__reference>::value,
1283906c5085SEric Fiselier            typename remove_reference<__reference>::type&&,
1284906c5085SEric Fiselier            __reference
1285906c5085SEric Fiselier        >::type reference;
12863e519524SHoward Hinnant#else
12873e519524SHoward Hinnant    typedef typename iterator_traits<iterator_type>::reference reference;
12883e519524SHoward Hinnant#endif
12893e519524SHoward Hinnant
1290720ef472SMarshall Clow    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
1291720ef472SMarshall Clow    move_iterator() : __i() {}
1292720ef472SMarshall Clow    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
1293720ef472SMarshall Clow    explicit move_iterator(_Iter __x) : __i(__x) {}
1294720ef472SMarshall Clow    template <class _Up>
1295720ef472SMarshall Clow      _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
1296720ef472SMarshall Clow      move_iterator(const move_iterator<_Up>& __u) : __i(__u.base()) {}
1297720ef472SMarshall Clow    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 _Iter base() const {return __i;}
1298720ef472SMarshall Clow    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
1299720ef472SMarshall Clow    reference operator*() const { return static_cast<reference>(*__i); }
1300720ef472SMarshall Clow    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
1301720ef472SMarshall Clow    pointer  operator->() const { return __i;}
1302720ef472SMarshall Clow    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
1303720ef472SMarshall Clow    move_iterator& operator++() {++__i; return *this;}
1304720ef472SMarshall Clow    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
1305720ef472SMarshall Clow    move_iterator  operator++(int) {move_iterator __tmp(*this); ++__i; return __tmp;}
1306720ef472SMarshall Clow    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
1307720ef472SMarshall Clow    move_iterator& operator--() {--__i; return *this;}
1308720ef472SMarshall Clow    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
1309720ef472SMarshall Clow    move_iterator  operator--(int) {move_iterator __tmp(*this); --__i; return __tmp;}
1310720ef472SMarshall Clow    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
1311720ef472SMarshall Clow    move_iterator  operator+ (difference_type __n) const {return move_iterator(__i + __n);}
1312720ef472SMarshall Clow    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
1313720ef472SMarshall Clow    move_iterator& operator+=(difference_type __n) {__i += __n; return *this;}
1314720ef472SMarshall Clow    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
1315720ef472SMarshall Clow    move_iterator  operator- (difference_type __n) const {return move_iterator(__i - __n);}
1316720ef472SMarshall Clow    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
1317720ef472SMarshall Clow    move_iterator& operator-=(difference_type __n) {__i -= __n; return *this;}
1318720ef472SMarshall Clow    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
1319720ef472SMarshall Clow    reference operator[](difference_type __n) const { return static_cast<reference>(__i[__n]); }
13203e519524SHoward Hinnant};
13213e519524SHoward Hinnant
13223e519524SHoward Hinnanttemplate <class _Iter1, class _Iter2>
1323720ef472SMarshall Clowinline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
13243e519524SHoward Hinnantbool
13253e519524SHoward Hinnantoperator==(const move_iterator<_Iter1>& __x, const move_iterator<_Iter2>& __y)
13263e519524SHoward Hinnant{
13273e519524SHoward Hinnant    return __x.base() == __y.base();
13283e519524SHoward Hinnant}
13293e519524SHoward Hinnant
13303e519524SHoward Hinnanttemplate <class _Iter1, class _Iter2>
1331720ef472SMarshall Clowinline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
13323e519524SHoward Hinnantbool
13333e519524SHoward Hinnantoperator<(const move_iterator<_Iter1>& __x, const move_iterator<_Iter2>& __y)
13343e519524SHoward Hinnant{
13353e519524SHoward Hinnant    return __x.base() < __y.base();
13363e519524SHoward Hinnant}
13373e519524SHoward Hinnant
13383e519524SHoward Hinnanttemplate <class _Iter1, class _Iter2>
1339720ef472SMarshall Clowinline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
13403e519524SHoward Hinnantbool
13413e519524SHoward Hinnantoperator!=(const move_iterator<_Iter1>& __x, const move_iterator<_Iter2>& __y)
13423e519524SHoward Hinnant{
13433e519524SHoward Hinnant    return __x.base() != __y.base();
13443e519524SHoward Hinnant}
13453e519524SHoward Hinnant
13463e519524SHoward Hinnanttemplate <class _Iter1, class _Iter2>
1347720ef472SMarshall Clowinline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
13483e519524SHoward Hinnantbool
13493e519524SHoward Hinnantoperator>(const move_iterator<_Iter1>& __x, const move_iterator<_Iter2>& __y)
13503e519524SHoward Hinnant{
13513e519524SHoward Hinnant    return __x.base() > __y.base();
13523e519524SHoward Hinnant}
13533e519524SHoward Hinnant
13543e519524SHoward Hinnanttemplate <class _Iter1, class _Iter2>
1355720ef472SMarshall Clowinline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
13563e519524SHoward Hinnantbool
13573e519524SHoward Hinnantoperator>=(const move_iterator<_Iter1>& __x, const move_iterator<_Iter2>& __y)
13583e519524SHoward Hinnant{
13593e519524SHoward Hinnant    return __x.base() >= __y.base();
13603e519524SHoward Hinnant}
13613e519524SHoward Hinnant
13623e519524SHoward Hinnanttemplate <class _Iter1, class _Iter2>
1363720ef472SMarshall Clowinline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
13643e519524SHoward Hinnantbool
13653e519524SHoward Hinnantoperator<=(const move_iterator<_Iter1>& __x, const move_iterator<_Iter2>& __y)
13663e519524SHoward Hinnant{
13673e519524SHoward Hinnant    return __x.base() <= __y.base();
13683e519524SHoward Hinnant}
13693e519524SHoward Hinnant
13702ee83725SMarshall Clow#ifndef _LIBCPP_CXX03_LANG
1371947ce6b5SMarshall Clowtemplate <class _Iter1, class _Iter2>
1372720ef472SMarshall Clowinline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
1373947ce6b5SMarshall Clowauto
1374947ce6b5SMarshall Clowoperator-(const move_iterator<_Iter1>& __x, const move_iterator<_Iter2>& __y)
1375947ce6b5SMarshall Clow-> decltype(__x.base() - __y.base())
1376947ce6b5SMarshall Clow{
1377947ce6b5SMarshall Clow    return __x.base() - __y.base();
1378947ce6b5SMarshall Clow}
1379947ce6b5SMarshall Clow#else
13803e519524SHoward Hinnanttemplate <class _Iter1, class _Iter2>
13813e519524SHoward Hinnantinline _LIBCPP_INLINE_VISIBILITY
13823e519524SHoward Hinnanttypename move_iterator<_Iter1>::difference_type
13833e519524SHoward Hinnantoperator-(const move_iterator<_Iter1>& __x, const move_iterator<_Iter2>& __y)
13843e519524SHoward Hinnant{
13853e519524SHoward Hinnant    return __x.base() - __y.base();
13863e519524SHoward Hinnant}
1387947ce6b5SMarshall Clow#endif
13883e519524SHoward Hinnant
13893e519524SHoward Hinnanttemplate <class _Iter>
1390720ef472SMarshall Clowinline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
13913e519524SHoward Hinnantmove_iterator<_Iter>
13923e519524SHoward Hinnantoperator+(typename move_iterator<_Iter>::difference_type __n, const move_iterator<_Iter>& __x)
13933e519524SHoward Hinnant{
13943e519524SHoward Hinnant    return move_iterator<_Iter>(__x.base() + __n);
13953e519524SHoward Hinnant}
13963e519524SHoward Hinnant
13973e519524SHoward Hinnanttemplate <class _Iter>
1398720ef472SMarshall Clowinline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
13993e519524SHoward Hinnantmove_iterator<_Iter>
140054c83368SMarshall Clowmake_move_iterator(_Iter __i)
14013e519524SHoward Hinnant{
14023e519524SHoward Hinnant    return move_iterator<_Iter>(__i);
14033e519524SHoward Hinnant}
14043e519524SHoward Hinnant
14053e519524SHoward Hinnant// __wrap_iter
14063e519524SHoward Hinnant
14073e519524SHoward Hinnanttemplate <class _Iter> class __wrap_iter;
14083e519524SHoward Hinnant
14093e519524SHoward Hinnanttemplate <class _Iter1, class _Iter2>
14109cad5025SMarshall Clow_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG
14113e519524SHoward Hinnantbool
141261b302f9SEric Fiselieroperator==(const __wrap_iter<_Iter1>&, const __wrap_iter<_Iter2>&) _NOEXCEPT;
14133e519524SHoward Hinnant
14143e519524SHoward Hinnanttemplate <class _Iter1, class _Iter2>
14159cad5025SMarshall Clow_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG
14163e519524SHoward Hinnantbool
141761b302f9SEric Fiselieroperator<(const __wrap_iter<_Iter1>&, const __wrap_iter<_Iter2>&) _NOEXCEPT;
14183e519524SHoward Hinnant
14193e519524SHoward Hinnanttemplate <class _Iter1, class _Iter2>
14209cad5025SMarshall Clow_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG
14213e519524SHoward Hinnantbool
142261b302f9SEric Fiselieroperator!=(const __wrap_iter<_Iter1>&, const __wrap_iter<_Iter2>&) _NOEXCEPT;
14233e519524SHoward Hinnant
14243e519524SHoward Hinnanttemplate <class _Iter1, class _Iter2>
14259cad5025SMarshall Clow_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG
14263e519524SHoward Hinnantbool
142761b302f9SEric Fiselieroperator>(const __wrap_iter<_Iter1>&, const __wrap_iter<_Iter2>&) _NOEXCEPT;
14283e519524SHoward Hinnant
14293e519524SHoward Hinnanttemplate <class _Iter1, class _Iter2>
14309cad5025SMarshall Clow_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG
14313e519524SHoward Hinnantbool
143261b302f9SEric Fiselieroperator>=(const __wrap_iter<_Iter1>&, const __wrap_iter<_Iter2>&) _NOEXCEPT;
14333e519524SHoward Hinnant
14343e519524SHoward Hinnanttemplate <class _Iter1, class _Iter2>
14359cad5025SMarshall Clow_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG
14363e519524SHoward Hinnantbool
143761b302f9SEric Fiselieroperator<=(const __wrap_iter<_Iter1>&, const __wrap_iter<_Iter2>&) _NOEXCEPT;
14383e519524SHoward Hinnant
14392ee83725SMarshall Clow#ifndef _LIBCPP_CXX03_LANG
1440947ce6b5SMarshall Clowtemplate <class _Iter1, class _Iter2>
14419cad5025SMarshall Clow_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG
1442947ce6b5SMarshall Clowauto
144361b302f9SEric Fiselieroperator-(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter2>& __y) _NOEXCEPT
1444947ce6b5SMarshall Clow-> decltype(__x.base() - __y.base());
1445947ce6b5SMarshall Clow#else
14463e519524SHoward Hinnanttemplate <class _Iter1, class _Iter2>
1447aeb85680SHoward Hinnant_LIBCPP_INLINE_VISIBILITY
14483e519524SHoward Hinnanttypename __wrap_iter<_Iter1>::difference_type
144961b302f9SEric Fiselieroperator-(const __wrap_iter<_Iter1>&, const __wrap_iter<_Iter2>&) _NOEXCEPT;
1450947ce6b5SMarshall Clow#endif
14513e519524SHoward Hinnant
14523e519524SHoward Hinnanttemplate <class _Iter>
14539cad5025SMarshall Clow_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG
14543e519524SHoward Hinnant__wrap_iter<_Iter>
145561b302f9SEric Fiselieroperator+(typename __wrap_iter<_Iter>::difference_type, __wrap_iter<_Iter>) _NOEXCEPT;
14563e519524SHoward Hinnant
145713c90a57SLouis Dionnetemplate <class _Ip, class _Op> _Op _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 copy(_Ip, _Ip, _Op);
145813c90a57SLouis Dionnetemplate <class _B1, class _B2> _B2 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 copy_backward(_B1, _B1, _B2);
14593ed89b51Szoecarvertemplate <class _Ip, class _Op> _Op _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 move(_Ip, _Ip, _Op);
14603ed89b51Szoecarvertemplate <class _B1, class _B2> _B2 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 move_backward(_B1, _B1, _B2);
14613e519524SHoward Hinnant
14623e519524SHoward Hinnanttemplate <class _Iter>
14633e519524SHoward Hinnantclass __wrap_iter
14643e519524SHoward Hinnant{
14653e519524SHoward Hinnantpublic:
14663e519524SHoward Hinnant    typedef _Iter                                                      iterator_type;
14673e519524SHoward Hinnant    typedef typename iterator_traits<iterator_type>::value_type        value_type;
14683e519524SHoward Hinnant    typedef typename iterator_traits<iterator_type>::difference_type   difference_type;
14693e519524SHoward Hinnant    typedef typename iterator_traits<iterator_type>::pointer           pointer;
14703e519524SHoward Hinnant    typedef typename iterator_traits<iterator_type>::reference         reference;
1471d41c6d51SArthur O'Dwyer    typedef typename iterator_traits<iterator_type>::iterator_category iterator_category;
1472d41c6d51SArthur O'Dwyer#if _LIBCPP_STD_VER > 17
1473fc924887SArthur O'Dwyer    typedef contiguous_iterator_tag                                    iterator_concept;
1474d41c6d51SArthur O'Dwyer#endif
1475d41c6d51SArthur O'Dwyer
14763e519524SHoward Hinnantprivate:
14773e519524SHoward Hinnant    iterator_type __i;
14783e519524SHoward Hinnantpublic:
147961b302f9SEric Fiselier    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG __wrap_iter() _NOEXCEPT
148007186a7dSMarshall Clow#if _LIBCPP_STD_VER > 11
148107186a7dSMarshall Clow                : __i{}
148207186a7dSMarshall Clow#endif
1483c36bfc49SHoward Hinnant    {
148431e82037SLouis Dionne#if _LIBCPP_DEBUG_LEVEL == 2
1485c36bfc49SHoward Hinnant        __get_db()->__insert_i(this);
1486c36bfc49SHoward Hinnant#endif
1487c36bfc49SHoward Hinnant    }
14889cad5025SMarshall Clow    template <class _Up> _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG
14899cad5025SMarshall Clow        __wrap_iter(const __wrap_iter<_Up>& __u,
1490527a7fdfSBruce Mitchener            typename enable_if<is_convertible<_Up, iterator_type>::value>::type* = nullptr) _NOEXCEPT
1491f554add5SHoward Hinnant            : __i(__u.base())
1492f554add5SHoward Hinnant    {
149331e82037SLouis Dionne#if _LIBCPP_DEBUG_LEVEL == 2
1494f554add5SHoward Hinnant        __get_db()->__iterator_copy(this, &__u);
1495f554add5SHoward Hinnant#endif
1496f554add5SHoward Hinnant    }
149731e82037SLouis Dionne#if _LIBCPP_DEBUG_LEVEL == 2
14989cad5025SMarshall Clow    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG
1499f554add5SHoward Hinnant    __wrap_iter(const __wrap_iter& __x)
1500f554add5SHoward Hinnant        : __i(__x.base())
1501f554add5SHoward Hinnant    {
1502f554add5SHoward Hinnant        __get_db()->__iterator_copy(this, &__x);
1503f554add5SHoward Hinnant    }
15049cad5025SMarshall Clow    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG
1505f554add5SHoward Hinnant    __wrap_iter& operator=(const __wrap_iter& __x)
1506f554add5SHoward Hinnant    {
1507f554add5SHoward Hinnant        if (this != &__x)
1508f554add5SHoward Hinnant        {
1509f554add5SHoward Hinnant            __get_db()->__iterator_copy(this, &__x);
1510f554add5SHoward Hinnant            __i = __x.__i;
1511f554add5SHoward Hinnant        }
1512f554add5SHoward Hinnant        return *this;
1513f554add5SHoward Hinnant    }
15149cad5025SMarshall Clow    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG
1515f554add5SHoward Hinnant    ~__wrap_iter()
1516f554add5SHoward Hinnant    {
1517f554add5SHoward Hinnant        __get_db()->__erase_i(this);
1518f554add5SHoward Hinnant    }
1519f554add5SHoward Hinnant#endif
152061b302f9SEric Fiselier    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG reference operator*() const _NOEXCEPT
1521f554add5SHoward Hinnant    {
152231e82037SLouis Dionne#if _LIBCPP_DEBUG_LEVEL == 2
1523f554add5SHoward Hinnant        _LIBCPP_ASSERT(__get_const_db()->__dereferenceable(this),
1524f554add5SHoward Hinnant                       "Attempted to dereference a non-dereferenceable iterator");
1525cec9af9eSHoward Hinnant#endif
1526f554add5SHoward Hinnant        return *__i;
1527f554add5SHoward Hinnant    }
152861b302f9SEric Fiselier    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG pointer  operator->() const _NOEXCEPT
15293ec1f00bSHoward Hinnant    {
153031e82037SLouis Dionne#if _LIBCPP_DEBUG_LEVEL == 2
15313ec1f00bSHoward Hinnant        _LIBCPP_ASSERT(__get_const_db()->__dereferenceable(this),
15323ec1f00bSHoward Hinnant                       "Attempted to dereference a non-dereferenceable iterator");
15333ec1f00bSHoward Hinnant#endif
1534fe0e86e6SLouis Dionne        return _VSTD::__to_address(__i);
15353ec1f00bSHoward Hinnant    }
153661b302f9SEric Fiselier    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG __wrap_iter& operator++() _NOEXCEPT
1537f554add5SHoward Hinnant    {
153831e82037SLouis Dionne#if _LIBCPP_DEBUG_LEVEL == 2
1539f554add5SHoward Hinnant        _LIBCPP_ASSERT(__get_const_db()->__dereferenceable(this),
154096100f15SKristina Bessonova                       "Attempted to increment a non-incrementable iterator");
1541cec9af9eSHoward Hinnant#endif
1542f554add5SHoward Hinnant        ++__i;
1543f554add5SHoward Hinnant        return *this;
1544f554add5SHoward Hinnant    }
154561b302f9SEric Fiselier    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG __wrap_iter  operator++(int) _NOEXCEPT
1546f554add5SHoward Hinnant        {__wrap_iter __tmp(*this); ++(*this); return __tmp;}
15474ce0a916SMarshall Clow
154861b302f9SEric Fiselier    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG __wrap_iter& operator--() _NOEXCEPT
1549f554add5SHoward Hinnant    {
155031e82037SLouis Dionne#if _LIBCPP_DEBUG_LEVEL == 2
1551f554add5SHoward Hinnant        _LIBCPP_ASSERT(__get_const_db()->__decrementable(this),
155296100f15SKristina Bessonova                       "Attempted to decrement a non-decrementable iterator");
1553cec9af9eSHoward Hinnant#endif
1554f554add5SHoward Hinnant        --__i;
1555f554add5SHoward Hinnant        return *this;
1556f554add5SHoward Hinnant    }
155761b302f9SEric Fiselier    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG __wrap_iter  operator--(int) _NOEXCEPT
1558f554add5SHoward Hinnant        {__wrap_iter __tmp(*this); --(*this); return __tmp;}
155961b302f9SEric Fiselier    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG __wrap_iter  operator+ (difference_type __n) const _NOEXCEPT
1560f554add5SHoward Hinnant        {__wrap_iter __w(*this); __w += __n; return __w;}
156161b302f9SEric Fiselier    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG __wrap_iter& operator+=(difference_type __n) _NOEXCEPT
1562f554add5SHoward Hinnant    {
156331e82037SLouis Dionne#if _LIBCPP_DEBUG_LEVEL == 2
1564f554add5SHoward Hinnant        _LIBCPP_ASSERT(__get_const_db()->__addable(this, __n),
156596100f15SKristina Bessonova                   "Attempted to add/subtract an iterator outside its valid range");
1566cec9af9eSHoward Hinnant#endif
1567f554add5SHoward Hinnant        __i += __n;
1568f554add5SHoward Hinnant        return *this;
1569f554add5SHoward Hinnant    }
157061b302f9SEric Fiselier    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG __wrap_iter  operator- (difference_type __n) const _NOEXCEPT
1571f554add5SHoward Hinnant        {return *this + (-__n);}
157261b302f9SEric Fiselier    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG __wrap_iter& operator-=(difference_type __n) _NOEXCEPT
1573f554add5SHoward Hinnant        {*this += -__n; return *this;}
157461b302f9SEric Fiselier    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG reference    operator[](difference_type __n) const _NOEXCEPT
1575f554add5SHoward Hinnant    {
157631e82037SLouis Dionne#if _LIBCPP_DEBUG_LEVEL == 2
1577f554add5SHoward Hinnant        _LIBCPP_ASSERT(__get_const_db()->__subscriptable(this, __n),
157896100f15SKristina Bessonova                   "Attempted to subscript an iterator outside its valid range");
1579cec9af9eSHoward Hinnant#endif
1580f554add5SHoward Hinnant        return __i[__n];
1581f554add5SHoward Hinnant    }
15823e519524SHoward Hinnant
158361b302f9SEric Fiselier    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG iterator_type base() const _NOEXCEPT {return __i;}
15843e519524SHoward Hinnant
15853e519524SHoward Hinnantprivate:
158631e82037SLouis Dionne#if _LIBCPP_DEBUG_LEVEL == 2
15879cad5025SMarshall Clow    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG __wrap_iter(const void* __p, iterator_type __x) : __i(__x)
1588f554add5SHoward Hinnant    {
1589f554add5SHoward Hinnant        __get_db()->__insert_ic(this, __p);
1590f554add5SHoward Hinnant    }
1591fc88dbd2SHoward Hinnant#else
159261b302f9SEric Fiselier    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG __wrap_iter(iterator_type __x) _NOEXCEPT : __i(__x) {}
1593f554add5SHoward Hinnant#endif
15943e519524SHoward Hinnant
15953e519524SHoward Hinnant    template <class _Up> friend class __wrap_iter;
15963e519524SHoward Hinnant    template <class _CharT, class _Traits, class _Alloc> friend class basic_string;
1597e2f2d1edSEric Fiselier    template <class _Tp, class _Alloc> friend class _LIBCPP_TEMPLATE_VIS vector;
15987ad06a93SMarshall Clow    template <class _Tp, size_t> friend class _LIBCPP_TEMPLATE_VIS span;
15993e519524SHoward Hinnant
16003e519524SHoward Hinnant    template <class _Iter1, class _Iter2>
16019cad5025SMarshall Clow    _LIBCPP_CONSTEXPR_IF_NODEBUG friend
16023e519524SHoward Hinnant    bool
160361b302f9SEric Fiselier    operator==(const __wrap_iter<_Iter1>&, const __wrap_iter<_Iter2>&) _NOEXCEPT;
16043e519524SHoward Hinnant
16053e519524SHoward Hinnant    template <class _Iter1, class _Iter2>
16069cad5025SMarshall Clow    _LIBCPP_CONSTEXPR_IF_NODEBUG friend
16073e519524SHoward Hinnant    bool
160861b302f9SEric Fiselier    operator<(const __wrap_iter<_Iter1>&, const __wrap_iter<_Iter2>&) _NOEXCEPT;
16093e519524SHoward Hinnant
16103e519524SHoward Hinnant    template <class _Iter1, class _Iter2>
16119cad5025SMarshall Clow    _LIBCPP_CONSTEXPR_IF_NODEBUG friend
16123e519524SHoward Hinnant    bool
161361b302f9SEric Fiselier    operator!=(const __wrap_iter<_Iter1>&, const __wrap_iter<_Iter2>&) _NOEXCEPT;
16143e519524SHoward Hinnant
16153e519524SHoward Hinnant    template <class _Iter1, class _Iter2>
16169cad5025SMarshall Clow    _LIBCPP_CONSTEXPR_IF_NODEBUG friend
16173e519524SHoward Hinnant    bool
161861b302f9SEric Fiselier    operator>(const __wrap_iter<_Iter1>&, const __wrap_iter<_Iter2>&) _NOEXCEPT;
16193e519524SHoward Hinnant
16203e519524SHoward Hinnant    template <class _Iter1, class _Iter2>
16219cad5025SMarshall Clow    _LIBCPP_CONSTEXPR_IF_NODEBUG friend
16223e519524SHoward Hinnant    bool
162361b302f9SEric Fiselier    operator>=(const __wrap_iter<_Iter1>&, const __wrap_iter<_Iter2>&) _NOEXCEPT;
16243e519524SHoward Hinnant
16253e519524SHoward Hinnant    template <class _Iter1, class _Iter2>
16269cad5025SMarshall Clow    _LIBCPP_CONSTEXPR_IF_NODEBUG friend
16273e519524SHoward Hinnant    bool
162861b302f9SEric Fiselier    operator<=(const __wrap_iter<_Iter1>&, const __wrap_iter<_Iter2>&) _NOEXCEPT;
16293e519524SHoward Hinnant
16302ee83725SMarshall Clow#ifndef _LIBCPP_CXX03_LANG
1631947ce6b5SMarshall Clow    template <class _Iter1, class _Iter2>
16329cad5025SMarshall Clow    _LIBCPP_CONSTEXPR_IF_NODEBUG friend
1633947ce6b5SMarshall Clow    auto
163461b302f9SEric Fiselier    operator-(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter2>& __y) _NOEXCEPT
1635947ce6b5SMarshall Clow    -> decltype(__x.base() - __y.base());
1636947ce6b5SMarshall Clow#else
16373e519524SHoward Hinnant    template <class _Iter1, class _Iter2>
16389cad5025SMarshall Clow    _LIBCPP_CONSTEXPR_IF_NODEBUG friend
16393e519524SHoward Hinnant    typename __wrap_iter<_Iter1>::difference_type
164061b302f9SEric Fiselier    operator-(const __wrap_iter<_Iter1>&, const __wrap_iter<_Iter2>&) _NOEXCEPT;
1641947ce6b5SMarshall Clow#endif
16423e519524SHoward Hinnant
16433e519524SHoward Hinnant    template <class _Iter1>
16449cad5025SMarshall Clow    _LIBCPP_CONSTEXPR_IF_NODEBUG friend
16453e519524SHoward Hinnant    __wrap_iter<_Iter1>
164661b302f9SEric Fiselier    operator+(typename __wrap_iter<_Iter1>::difference_type, __wrap_iter<_Iter1>) _NOEXCEPT;
16473e519524SHoward Hinnant};
16483e519524SHoward Hinnant
1649d41c6d51SArthur O'Dwyer#if _LIBCPP_STD_VER <= 17
1650d41c6d51SArthur O'Dwyertemplate <class _It>
1651fc924887SArthur O'Dwyerstruct __is_cpp17_contiguous_iterator<__wrap_iter<_It> > : true_type {};
1652d41c6d51SArthur O'Dwyer#endif
1653d41c6d51SArthur O'Dwyer
1654d41c6d51SArthur O'Dwyertemplate <class _Iter>
1655d41c6d51SArthur O'Dwyer_LIBCPP_CONSTEXPR
1656fc924887SArthur O'Dwyerdecltype(_VSTD::__to_address(declval<_Iter>()))
1657d41c6d51SArthur O'Dwyer__to_address(__wrap_iter<_Iter> __w) _NOEXCEPT {
1658d41c6d51SArthur O'Dwyer    return _VSTD::__to_address(__w.base());
1659d41c6d51SArthur O'Dwyer}
1660d41c6d51SArthur O'Dwyer
16613e519524SHoward Hinnanttemplate <class _Iter1, class _Iter2>
16629cad5025SMarshall Clowinline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG
16633e519524SHoward Hinnantbool
166461b302f9SEric Fiselieroperator==(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter2>& __y) _NOEXCEPT
16653e519524SHoward Hinnant{
16663e519524SHoward Hinnant    return __x.base() == __y.base();
16673e519524SHoward Hinnant}
16683e519524SHoward Hinnant
16693e519524SHoward Hinnanttemplate <class _Iter1, class _Iter2>
16709cad5025SMarshall Clowinline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG
16713e519524SHoward Hinnantbool
167261b302f9SEric Fiselieroperator<(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter2>& __y) _NOEXCEPT
16733e519524SHoward Hinnant{
167431e82037SLouis Dionne#if _LIBCPP_DEBUG_LEVEL == 2
167542a3046eSHoward Hinnant    _LIBCPP_ASSERT(__get_const_db()->__less_than_comparable(&__x, &__y),
1676f554add5SHoward Hinnant                   "Attempted to compare incomparable iterators");
1677cec9af9eSHoward Hinnant#endif
16783e519524SHoward Hinnant    return __x.base() < __y.base();
16793e519524SHoward Hinnant}
16803e519524SHoward Hinnant
16813e519524SHoward Hinnanttemplate <class _Iter1, class _Iter2>
16829cad5025SMarshall Clowinline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG
16833e519524SHoward Hinnantbool
168461b302f9SEric Fiselieroperator!=(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter2>& __y) _NOEXCEPT
16853e519524SHoward Hinnant{
1686f554add5SHoward Hinnant    return !(__x == __y);
16873e519524SHoward Hinnant}
16883e519524SHoward Hinnant
16893e519524SHoward Hinnanttemplate <class _Iter1, class _Iter2>
16909cad5025SMarshall Clowinline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG
16913e519524SHoward Hinnantbool
169261b302f9SEric Fiselieroperator>(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter2>& __y) _NOEXCEPT
16933e519524SHoward Hinnant{
1694f554add5SHoward Hinnant    return __y < __x;
16953e519524SHoward Hinnant}
16963e519524SHoward Hinnant
16973e519524SHoward Hinnanttemplate <class _Iter1, class _Iter2>
16989cad5025SMarshall Clowinline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG
16993e519524SHoward Hinnantbool
170061b302f9SEric Fiselieroperator>=(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter2>& __y) _NOEXCEPT
17013e519524SHoward Hinnant{
1702f554add5SHoward Hinnant    return !(__x < __y);
17033e519524SHoward Hinnant}
17043e519524SHoward Hinnant
17053e519524SHoward Hinnanttemplate <class _Iter1, class _Iter2>
17069cad5025SMarshall Clowinline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG
17073e519524SHoward Hinnantbool
170861b302f9SEric Fiselieroperator<=(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter2>& __y) _NOEXCEPT
17093e519524SHoward Hinnant{
1710f554add5SHoward Hinnant    return !(__y < __x);
17113e519524SHoward Hinnant}
17123e519524SHoward Hinnant
17136e551ae1SHoward Hinnanttemplate <class _Iter1>
17149cad5025SMarshall Clowinline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG
17156e551ae1SHoward Hinnantbool
171661b302f9SEric Fiselieroperator!=(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter1>& __y) _NOEXCEPT
17176e551ae1SHoward Hinnant{
17186e551ae1SHoward Hinnant    return !(__x == __y);
17196e551ae1SHoward Hinnant}
17206e551ae1SHoward Hinnant
17216e551ae1SHoward Hinnanttemplate <class _Iter1>
17229cad5025SMarshall Clowinline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG
17236e551ae1SHoward Hinnantbool
172461b302f9SEric Fiselieroperator>(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter1>& __y) _NOEXCEPT
17256e551ae1SHoward Hinnant{
17266e551ae1SHoward Hinnant    return __y < __x;
17276e551ae1SHoward Hinnant}
17286e551ae1SHoward Hinnant
17296e551ae1SHoward Hinnanttemplate <class _Iter1>
17309cad5025SMarshall Clowinline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG
17316e551ae1SHoward Hinnantbool
173261b302f9SEric Fiselieroperator>=(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter1>& __y) _NOEXCEPT
17336e551ae1SHoward Hinnant{
17346e551ae1SHoward Hinnant    return !(__x < __y);
17356e551ae1SHoward Hinnant}
17366e551ae1SHoward Hinnant
17376e551ae1SHoward Hinnanttemplate <class _Iter1>
17389cad5025SMarshall Clowinline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG
17396e551ae1SHoward Hinnantbool
174061b302f9SEric Fiselieroperator<=(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter1>& __y) _NOEXCEPT
17416e551ae1SHoward Hinnant{
17426e551ae1SHoward Hinnant    return !(__y < __x);
17436e551ae1SHoward Hinnant}
17446e551ae1SHoward Hinnant
17452ee83725SMarshall Clow#ifndef _LIBCPP_CXX03_LANG
1746947ce6b5SMarshall Clowtemplate <class _Iter1, class _Iter2>
17479cad5025SMarshall Clowinline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG
1748947ce6b5SMarshall Clowauto
174961b302f9SEric Fiselieroperator-(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter2>& __y) _NOEXCEPT
1750947ce6b5SMarshall Clow-> decltype(__x.base() - __y.base())
1751947ce6b5SMarshall Clow{
175231e82037SLouis Dionne#if _LIBCPP_DEBUG_LEVEL == 2
1753947ce6b5SMarshall Clow    _LIBCPP_ASSERT(__get_const_db()->__less_than_comparable(&__x, &__y),
1754947ce6b5SMarshall Clow                   "Attempted to subtract incompatible iterators");
1755947ce6b5SMarshall Clow#endif
1756947ce6b5SMarshall Clow    return __x.base() - __y.base();
1757947ce6b5SMarshall Clow}
1758947ce6b5SMarshall Clow#else
17593e519524SHoward Hinnanttemplate <class _Iter1, class _Iter2>
17609cad5025SMarshall Clowinline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG
17613e519524SHoward Hinnanttypename __wrap_iter<_Iter1>::difference_type
176261b302f9SEric Fiselieroperator-(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter2>& __y) _NOEXCEPT
17633e519524SHoward Hinnant{
176431e82037SLouis Dionne#if _LIBCPP_DEBUG_LEVEL == 2
176542a3046eSHoward Hinnant    _LIBCPP_ASSERT(__get_const_db()->__less_than_comparable(&__x, &__y),
1766f554add5SHoward Hinnant                   "Attempted to subtract incompatible iterators");
1767cec9af9eSHoward Hinnant#endif
17683e519524SHoward Hinnant    return __x.base() - __y.base();
17693e519524SHoward Hinnant}
1770947ce6b5SMarshall Clow#endif
17713e519524SHoward Hinnant
17723e519524SHoward Hinnanttemplate <class _Iter>
17739cad5025SMarshall Clowinline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG
17743e519524SHoward Hinnant__wrap_iter<_Iter>
17753e519524SHoward Hinnantoperator+(typename __wrap_iter<_Iter>::difference_type __n,
177661b302f9SEric Fiselier          __wrap_iter<_Iter> __x) _NOEXCEPT
17773e519524SHoward Hinnant{
1778f554add5SHoward Hinnant    __x += __n;
1779f554add5SHoward Hinnant    return __x;
17803e519524SHoward Hinnant}
17813e519524SHoward Hinnant
17823772a46aSMarshall Clowtemplate <class _Tp, size_t _Np>
17832ffa1705SMarshall Clow_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
17843772a46aSMarshall Clow_Tp*
17853772a46aSMarshall Clowbegin(_Tp (&__array)[_Np])
17863772a46aSMarshall Clow{
17873772a46aSMarshall Clow    return __array;
17883772a46aSMarshall Clow}
17893772a46aSMarshall Clow
17903772a46aSMarshall Clowtemplate <class _Tp, size_t _Np>
17912ffa1705SMarshall Clow_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
17923772a46aSMarshall Clow_Tp*
17933772a46aSMarshall Clowend(_Tp (&__array)[_Np])
17943772a46aSMarshall Clow{
17953772a46aSMarshall Clow    return __array + _Np;
17963772a46aSMarshall Clow}
17973772a46aSMarshall Clow
179854613ab4SEric Fiselier#if !defined(_LIBCPP_CXX03_LANG)
1799c66a611bSMarshall Clow
1800c003db1fSHoward Hinnanttemplate <class _Cp>
18012ffa1705SMarshall Clow_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
18023e519524SHoward Hinnantauto
1803c003db1fSHoward Hinnantbegin(_Cp& __c) -> decltype(__c.begin())
18043e519524SHoward Hinnant{
18053e519524SHoward Hinnant    return __c.begin();
18063e519524SHoward Hinnant}
18073e519524SHoward Hinnant
1808c003db1fSHoward Hinnanttemplate <class _Cp>
18092ffa1705SMarshall Clow_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
18103e519524SHoward Hinnantauto
1811c003db1fSHoward Hinnantbegin(const _Cp& __c) -> decltype(__c.begin())
18123e519524SHoward Hinnant{
18133e519524SHoward Hinnant    return __c.begin();
18143e519524SHoward Hinnant}
18153e519524SHoward Hinnant
1816c003db1fSHoward Hinnanttemplate <class _Cp>
18172ffa1705SMarshall Clow_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
18183e519524SHoward Hinnantauto
1819c003db1fSHoward Hinnantend(_Cp& __c) -> decltype(__c.end())
18203e519524SHoward Hinnant{
18213e519524SHoward Hinnant    return __c.end();
18223e519524SHoward Hinnant}
18233e519524SHoward Hinnant
1824c003db1fSHoward Hinnanttemplate <class _Cp>
18252ffa1705SMarshall Clow_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
18263e519524SHoward Hinnantauto
1827c003db1fSHoward Hinnantend(const _Cp& __c) -> decltype(__c.end())
18283e519524SHoward Hinnant{
18293e519524SHoward Hinnant    return __c.end();
18303e519524SHoward Hinnant}
18313e519524SHoward Hinnant
18321e548c72SMarshall Clow#if _LIBCPP_STD_VER > 11
18331e548c72SMarshall Clow
18343772a46aSMarshall Clowtemplate <class _Tp, size_t _Np>
18352ffa1705SMarshall Clow_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
18363772a46aSMarshall Clowreverse_iterator<_Tp*> rbegin(_Tp (&__array)[_Np])
18373772a46aSMarshall Clow{
18383772a46aSMarshall Clow    return reverse_iterator<_Tp*>(__array + _Np);
18393772a46aSMarshall Clow}
18403772a46aSMarshall Clow
18413772a46aSMarshall Clowtemplate <class _Tp, size_t _Np>
18422ffa1705SMarshall Clow_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
18433772a46aSMarshall Clowreverse_iterator<_Tp*> rend(_Tp (&__array)[_Np])
18443772a46aSMarshall Clow{
18453772a46aSMarshall Clow    return reverse_iterator<_Tp*>(__array);
18463772a46aSMarshall Clow}
18473772a46aSMarshall Clow
18483772a46aSMarshall Clowtemplate <class _Ep>
18492ffa1705SMarshall Clow_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
18503772a46aSMarshall Clowreverse_iterator<const _Ep*> rbegin(initializer_list<_Ep> __il)
18513772a46aSMarshall Clow{
18523772a46aSMarshall Clow    return reverse_iterator<const _Ep*>(__il.end());
18533772a46aSMarshall Clow}
18543772a46aSMarshall Clow
18553772a46aSMarshall Clowtemplate <class _Ep>
18562ffa1705SMarshall Clow_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
18573772a46aSMarshall Clowreverse_iterator<const _Ep*> rend(initializer_list<_Ep> __il)
18583772a46aSMarshall Clow{
18593772a46aSMarshall Clow    return reverse_iterator<const _Ep*>(__il.begin());
18603772a46aSMarshall Clow}
18613772a46aSMarshall Clow
18621e548c72SMarshall Clowtemplate <class _Cp>
18632ffa1705SMarshall Clow_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
18647725546aSMarshall Clowauto cbegin(const _Cp& __c) -> decltype(_VSTD::begin(__c))
18651e548c72SMarshall Clow{
18667725546aSMarshall Clow    return _VSTD::begin(__c);
18671e548c72SMarshall Clow}
18681e548c72SMarshall Clow
18691e548c72SMarshall Clowtemplate <class _Cp>
18702ffa1705SMarshall Clow_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
18717725546aSMarshall Clowauto cend(const _Cp& __c) -> decltype(_VSTD::end(__c))
18721e548c72SMarshall Clow{
18737725546aSMarshall Clow    return _VSTD::end(__c);
18741e548c72SMarshall Clow}
18751e548c72SMarshall Clow
18761e548c72SMarshall Clowtemplate <class _Cp>
18772ffa1705SMarshall Clow_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
18781e548c72SMarshall Clowauto rbegin(_Cp& __c) -> decltype(__c.rbegin())
18791e548c72SMarshall Clow{
18801e548c72SMarshall Clow    return __c.rbegin();
18811e548c72SMarshall Clow}
18821e548c72SMarshall Clow
18831e548c72SMarshall Clowtemplate <class _Cp>
18842ffa1705SMarshall Clow_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
18851e548c72SMarshall Clowauto rbegin(const _Cp& __c) -> decltype(__c.rbegin())
18861e548c72SMarshall Clow{
18871e548c72SMarshall Clow    return __c.rbegin();
18881e548c72SMarshall Clow}
18891e548c72SMarshall Clow
18901e548c72SMarshall Clowtemplate <class _Cp>
18912ffa1705SMarshall Clow_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
18921e548c72SMarshall Clowauto rend(_Cp& __c) -> decltype(__c.rend())
18931e548c72SMarshall Clow{
18941e548c72SMarshall Clow    return __c.rend();
18951e548c72SMarshall Clow}
18961e548c72SMarshall Clow
18971e548c72SMarshall Clowtemplate <class _Cp>
18982ffa1705SMarshall Clow_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
18991e548c72SMarshall Clowauto rend(const _Cp& __c) -> decltype(__c.rend())
19001e548c72SMarshall Clow{
19011e548c72SMarshall Clow    return __c.rend();
19021e548c72SMarshall Clow}
19031e548c72SMarshall Clow
19041e548c72SMarshall Clowtemplate <class _Cp>
19052ffa1705SMarshall Clow_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
19067725546aSMarshall Clowauto crbegin(const _Cp& __c) -> decltype(_VSTD::rbegin(__c))
19071e548c72SMarshall Clow{
19087725546aSMarshall Clow    return _VSTD::rbegin(__c);
19091e548c72SMarshall Clow}
19101e548c72SMarshall Clow
19111e548c72SMarshall Clowtemplate <class _Cp>
19122ffa1705SMarshall Clow_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
19137725546aSMarshall Clowauto crend(const _Cp& __c) -> decltype(_VSTD::rend(__c))
19141e548c72SMarshall Clow{
19157725546aSMarshall Clow    return _VSTD::rend(__c);
19161e548c72SMarshall Clow}
19171e548c72SMarshall Clow
19181e548c72SMarshall Clow#endif
19191e548c72SMarshall Clow
19201e548c72SMarshall Clow
192154613ab4SEric Fiselier#else  // defined(_LIBCPP_CXX03_LANG)
19223e519524SHoward Hinnant
1923c003db1fSHoward Hinnanttemplate <class _Cp>
19242ffa1705SMarshall Clow_LIBCPP_INLINE_VISIBILITY
1925c003db1fSHoward Hinnanttypename _Cp::iterator
1926c003db1fSHoward Hinnantbegin(_Cp& __c)
19273e519524SHoward Hinnant{
19283e519524SHoward Hinnant    return __c.begin();
19293e519524SHoward Hinnant}
19303e519524SHoward Hinnant
1931c003db1fSHoward Hinnanttemplate <class _Cp>
19322ffa1705SMarshall Clow_LIBCPP_INLINE_VISIBILITY
1933c003db1fSHoward Hinnanttypename _Cp::const_iterator
1934c003db1fSHoward Hinnantbegin(const _Cp& __c)
19353e519524SHoward Hinnant{
19363e519524SHoward Hinnant    return __c.begin();
19373e519524SHoward Hinnant}
19383e519524SHoward Hinnant
1939c003db1fSHoward Hinnanttemplate <class _Cp>
19402ffa1705SMarshall Clow_LIBCPP_INLINE_VISIBILITY
1941c003db1fSHoward Hinnanttypename _Cp::iterator
1942c003db1fSHoward Hinnantend(_Cp& __c)
19433e519524SHoward Hinnant{
19443e519524SHoward Hinnant    return __c.end();
19453e519524SHoward Hinnant}
19463e519524SHoward Hinnant
1947c003db1fSHoward Hinnanttemplate <class _Cp>
19482ffa1705SMarshall Clow_LIBCPP_INLINE_VISIBILITY
1949c003db1fSHoward Hinnanttypename _Cp::const_iterator
1950c003db1fSHoward Hinnantend(const _Cp& __c)
19513e519524SHoward Hinnant{
19523e519524SHoward Hinnant    return __c.end();
19533e519524SHoward Hinnant}
19543e519524SHoward Hinnant
195554613ab4SEric Fiselier#endif // !defined(_LIBCPP_CXX03_LANG)
19563e519524SHoward Hinnant
1957ad755104SMarshall Clow#if _LIBCPP_STD_VER > 14
1958d1dcda19SMarshall Clow
1959d1dcda19SMarshall Clow// #if _LIBCPP_STD_VER > 11
1960d1dcda19SMarshall Clow// template <>
1961d1dcda19SMarshall Clow// struct _LIBCPP_TEMPLATE_VIS plus<void>
1962d1dcda19SMarshall Clow// {
1963d1dcda19SMarshall Clow//     template <class _T1, class _T2>
1964d1dcda19SMarshall Clow//     _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
1965d1dcda19SMarshall Clow//     auto operator()(_T1&& __t, _T2&& __u) const
1966d1dcda19SMarshall Clow//     _NOEXCEPT_(noexcept(_VSTD::forward<_T1>(__t) + _VSTD::forward<_T2>(__u)))
1967d1dcda19SMarshall Clow//     -> decltype        (_VSTD::forward<_T1>(__t) + _VSTD::forward<_T2>(__u))
1968d1dcda19SMarshall Clow//         { return        _VSTD::forward<_T1>(__t) + _VSTD::forward<_T2>(__u); }
1969d1dcda19SMarshall Clow//     typedef void is_transparent;
1970d1dcda19SMarshall Clow// };
1971d1dcda19SMarshall Clow// #endif
1972d1dcda19SMarshall Clow
197388d21343SMarshall Clowtemplate <class _Cont>
19742ffa1705SMarshall Clow_LIBCPP_INLINE_VISIBILITY
1975d1dcda19SMarshall Clowconstexpr auto size(const _Cont& __c)
1976d1dcda19SMarshall Clow_NOEXCEPT_(noexcept(__c.size()))
1977d1dcda19SMarshall Clow-> decltype        (__c.size())
1978d1dcda19SMarshall Clow{ return            __c.size(); }
1979ad755104SMarshall Clow
198088d21343SMarshall Clowtemplate <class _Tp, size_t _Sz>
19812ffa1705SMarshall Clow_LIBCPP_INLINE_VISIBILITY
1982fd838227SEric Fiselierconstexpr size_t size(const _Tp (&)[_Sz]) noexcept { return _Sz; }
1983ad755104SMarshall Clow
19847d3986eaSMarshall Clow#if _LIBCPP_STD_VER > 17
19857d3986eaSMarshall Clowtemplate <class _Cont>
19862ffa1705SMarshall Clow_LIBCPP_INLINE_VISIBILITY
19877d3986eaSMarshall Clowconstexpr auto ssize(const _Cont& __c)
19887d3986eaSMarshall Clow_NOEXCEPT_(noexcept(static_cast<common_type_t<ptrdiff_t, make_signed_t<decltype(__c.size())>>>(__c.size())))
19897d3986eaSMarshall Clow->                              common_type_t<ptrdiff_t, make_signed_t<decltype(__c.size())>>
19907d3986eaSMarshall Clow{ return            static_cast<common_type_t<ptrdiff_t, make_signed_t<decltype(__c.size())>>>(__c.size()); }
19917d3986eaSMarshall Clow
19927d3986eaSMarshall Clowtemplate <class _Tp, ptrdiff_t _Sz>
19932ffa1705SMarshall Clow_LIBCPP_INLINE_VISIBILITY
19947d3986eaSMarshall Clowconstexpr ptrdiff_t ssize(const _Tp (&)[_Sz]) noexcept { return _Sz; }
19957d3986eaSMarshall Clow#endif
19967d3986eaSMarshall Clow
199788d21343SMarshall Clowtemplate <class _Cont>
19982ffa1705SMarshall Clow_LIBCPP_NODISCARD_AFTER_CXX17 _LIBCPP_INLINE_VISIBILITY
1999d1dcda19SMarshall Clowconstexpr auto empty(const _Cont& __c)
2000d1dcda19SMarshall Clow_NOEXCEPT_(noexcept(__c.empty()))
2001d1dcda19SMarshall Clow-> decltype        (__c.empty())
2002d1dcda19SMarshall Clow{ return            __c.empty(); }
2003ad755104SMarshall Clow
200488d21343SMarshall Clowtemplate <class _Tp, size_t _Sz>
20052ffa1705SMarshall Clow_LIBCPP_NODISCARD_AFTER_CXX17 _LIBCPP_INLINE_VISIBILITY
2006fd838227SEric Fiselierconstexpr bool empty(const _Tp (&)[_Sz]) noexcept { return false; }
2007ad755104SMarshall Clow
2008ad755104SMarshall Clowtemplate <class _Ep>
20092ffa1705SMarshall Clow_LIBCPP_NODISCARD_AFTER_CXX17 _LIBCPP_INLINE_VISIBILITY
2010ad755104SMarshall Clowconstexpr bool empty(initializer_list<_Ep> __il) noexcept { return __il.size() == 0; }
2011ad755104SMarshall Clow
201288d21343SMarshall Clowtemplate <class _Cont> constexpr
20132ffa1705SMarshall Clow_LIBCPP_INLINE_VISIBILITY
2014d1dcda19SMarshall Clowauto data(_Cont& __c)
2015d1dcda19SMarshall Clow_NOEXCEPT_(noexcept(__c.data()))
2016d1dcda19SMarshall Clow-> decltype        (__c.data())
2017d1dcda19SMarshall Clow{ return            __c.data(); }
2018ad755104SMarshall Clow
201988d21343SMarshall Clowtemplate <class _Cont> constexpr
20202ffa1705SMarshall Clow_LIBCPP_INLINE_VISIBILITY
2021d1dcda19SMarshall Clowauto data(const _Cont& __c)
2022d1dcda19SMarshall Clow_NOEXCEPT_(noexcept(__c.data()))
2023d1dcda19SMarshall Clow-> decltype        (__c.data())
2024d1dcda19SMarshall Clow{ return            __c.data(); }
2025ad755104SMarshall Clow
202688d21343SMarshall Clowtemplate <class _Tp, size_t _Sz>
20272ffa1705SMarshall Clow_LIBCPP_INLINE_VISIBILITY
202888d21343SMarshall Clowconstexpr _Tp* data(_Tp (&__array)[_Sz]) noexcept { return __array; }
2029ad755104SMarshall Clow
2030ad755104SMarshall Clowtemplate <class _Ep>
20312ffa1705SMarshall Clow_LIBCPP_INLINE_VISIBILITY
2032ad755104SMarshall Clowconstexpr const _Ep* data(initializer_list<_Ep> __il) noexcept { return __il.begin(); }
2033ad755104SMarshall Clow#endif
2034ad755104SMarshall Clow
20352ac6babcSArthur O'Dwyertemplate <class _Container, class _Predicate>
20362ac6babcSArthur O'Dwyertypename _Container::size_type
20372ac6babcSArthur O'Dwyer__libcpp_erase_if_container(_Container& __c, _Predicate& __pred) {
20382ac6babcSArthur O'Dwyer  typename _Container::size_type __old_size = __c.size();
20392ac6babcSArthur O'Dwyer
20402ac6babcSArthur O'Dwyer  const typename _Container::iterator __last = __c.end();
20412ac6babcSArthur O'Dwyer  for (typename _Container::iterator __iter = __c.begin(); __iter != __last;) {
20422ac6babcSArthur O'Dwyer    if (__pred(*__iter))
20432ac6babcSArthur O'Dwyer      __iter = __c.erase(__iter);
20442ac6babcSArthur O'Dwyer    else
20452ac6babcSArthur O'Dwyer      ++__iter;
20462ac6babcSArthur O'Dwyer  }
20472ac6babcSArthur O'Dwyer
20482ac6babcSArthur O'Dwyer  return __old_size - __c.size();
20492ac6babcSArthur O'Dwyer}
2050ad755104SMarshall Clow
20513e519524SHoward Hinnant_LIBCPP_END_NAMESPACE_STD
20523e519524SHoward Hinnant
20533e519524SHoward Hinnant#endif // _LIBCPP_ITERATOR
2054