13e519524SHoward Hinnant// -*- C++ -*-
23e519524SHoward Hinnant//===-------------------------- iterator ----------------------------------===//
33e519524SHoward Hinnant//
457b08b09SChandler Carruth// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
557b08b09SChandler Carruth// See https://llvm.org/LICENSE.txt for license information.
657b08b09SChandler Carruth// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
73e519524SHoward Hinnant//
83e519524SHoward Hinnant//===----------------------------------------------------------------------===//
93e519524SHoward Hinnant
103e519524SHoward Hinnant#ifndef _LIBCPP_ITERATOR
113e519524SHoward Hinnant#define _LIBCPP_ITERATOR
123e519524SHoward Hinnant
133e519524SHoward Hinnant/*
143e519524SHoward Hinnant    iterator synopsis
153e519524SHoward Hinnant
16fe31f11cSChristopher Di Bella#include <concepts>
17fe31f11cSChristopher Di Bella
183e519524SHoward Hinnantnamespace std
193e519524SHoward Hinnant{
20fe31f11cSChristopher Di Bellatemplate<class> struct incrementable_traits;       // since C++20
219816d43cSChristopher Di Bellatemplate<class T>
229816d43cSChristopher Di Bella  using iter_difference_t = see below;             // since C++20
239816d43cSChristopher Di Bella
24f280505aSChristopher Di Bellatemplate<class> struct indirectly_readable_traits; // since C++20
259816d43cSChristopher Di Bellatemplate<class T>
269816d43cSChristopher Di Bella  using iter_value_t = see below;                  // since C++20
273e519524SHoward Hinnant
283e519524SHoward Hinnanttemplate<class Iterator>
299f01ac3bSzoecarverstruct iterator_traits;
303e519524SHoward Hinnant
313e519524SHoward Hinnanttemplate<class T>
329f01ac3bSzoecarver  requires is_object_v<T>                    // since C++20
339f01ac3bSzoecarverstruct iterator_traits<T*>;
343e519524SHoward Hinnant
350148b653SChristopher Di Bellatemplate<dereferenceable T>
360148b653SChristopher Di Bella  using iter_reference_t = decltype(*declval<T&>());
370148b653SChristopher Di Bella
3897e383aaSLouis Dionnenamespace ranges::inline unspecified {
3997e383aaSLouis Dionne    inline constexpr unspecified iter_move = unspecified; // since C++20, nodiscard as an extension
4097e383aaSLouis Dionne}}
4197e383aaSLouis Dionne
4297e383aaSLouis Dionnetemplate<dereferenceable T>
4397e383aaSLouis Dionne  requires ...
4497e383aaSLouis Dionneusing iter_rvalue_reference_t = decltype(ranges::iter_move(declval<T&>())); // since C++20
4597e383aaSLouis Dionne
4657ebf3d0SLouis Dionne// [iterator.concepts], iterator concepts
4757ebf3d0SLouis Dionne// [iterator.concept.readable], concept indirectly_readable
4857ebf3d0SLouis Dionnetemplate<class In>
4957ebf3d0SLouis Dionne  concept indirectly_readable = see below;                // since C++20
5057ebf3d0SLouis Dionne
5157ebf3d0SLouis Dionne// [iterator.concept.writable], concept indirectly_writable
5257ebf3d0SLouis Dionnetemplate<class Out, class T>
5357ebf3d0SLouis Dionne  concept indirectly_writable = see below;                // since C++20
5457ebf3d0SLouis Dionne
5518b03b00SMark de Wever// [iterator.concept.winc], concept weakly_incrementable
5622052860SChristopher Di Bellatemplate<class I>
5722052860SChristopher Di Bella  concept weakly_incrementable = see below;                // since C++20
5822052860SChristopher Di Bella
5922052860SChristopher Di Bella// [iterator.concept.inc], concept incrementable
6022052860SChristopher Di Bellatemplate<class I>
6122052860SChristopher Di Bella  concept incrementable = see below;                       // since C++20
6222052860SChristopher Di Bella
6318b03b00SMark de Wever// [iterator.concept.iterator], concept input_or_output_iterator
6438225d69SChristopher Di Bella  template<class I>
6538225d69SChristopher Di Bella    concept input_or_output_iterator = see below;          // since C++20
6638225d69SChristopher Di Bella
6718b03b00SMark de Wever// [iterator.concept.sentinel], concept sentinel_for
6838225d69SChristopher Di Bellatemplate<class S, class I>
6938225d69SChristopher Di Bella  concept sentinel_for = see below;                        // since C++20
7038225d69SChristopher Di Bella
71bdd68357Szoecarver// [iterator.concept.sizedsentinel], concept sized_sentinel_for
72bdd68357Szoecarvertemplate<class S, class I>
73bdd68357Szoecarver  inline constexpr bool disable_sized_sentinel_for = false;
74bdd68357Szoecarver
75bdd68357Szoecarvertemplate<class S, class I>
76bdd68357Szoecarver  concept sized_sentinel_for = see below;
77bdd68357Szoecarver
78c05d1eedSChristopher Di Bella// [iterator.concept.input], concept input_iterator
79c05d1eedSChristopher Di Bellatemplate<class I>
80c05d1eedSChristopher Di Bella  concept input_iterator = see below;                      // since C++20
81c05d1eedSChristopher Di Bella
82fa3e2626SChristopher Di Bella// [iterator.concept.forward], concept forward_iterator
83fa3e2626SChristopher Di Bellatemplate<class I>
84fa3e2626SChristopher Di Bella  concept forward_iterator = see below;                    // since C++20
85fa3e2626SChristopher Di Bella
869c5d86aaSChristopher Di Bella// [iterator.concept.bidir], concept bidirectional_iterator
879c5d86aaSChristopher Di Bellatemplate<class I>
889c5d86aaSChristopher Di Bella  concept bidirectional_iterator = see below;              // since C++20
899c5d86aaSChristopher Di Bella
906ffc41b0Szoecarver// [iterator.concept.random.access], concept random_access_iterator
916ffc41b0Szoecarvertemplate<class I>
926ffc41b0Szoecarver  concept random_access_iterator = see below;              // since C++20
936ffc41b0Szoecarver
943e519524SHoward Hinnanttemplate<class Category, class T, class Distance = ptrdiff_t,
953e519524SHoward Hinnant         class Pointer = T*, class Reference = T&>
963e519524SHoward Hinnantstruct iterator
973e519524SHoward Hinnant{
983e519524SHoward Hinnant    typedef T         value_type;
993e519524SHoward Hinnant    typedef Distance  difference_type;
1003e519524SHoward Hinnant    typedef Pointer   pointer;
1013e519524SHoward Hinnant    typedef Reference reference;
1023e519524SHoward Hinnant    typedef Category  iterator_category;
1033e519524SHoward Hinnant};
1043e519524SHoward Hinnant
1053e519524SHoward Hinnantstruct input_iterator_tag  {};
1063e519524SHoward Hinnantstruct output_iterator_tag {};
1073e519524SHoward Hinnantstruct forward_iterator_tag       : public input_iterator_tag         {};
1083e519524SHoward Hinnantstruct bidirectional_iterator_tag : public forward_iterator_tag       {};
1093e519524SHoward Hinnantstruct random_access_iterator_tag : public bidirectional_iterator_tag {};
1103e519524SHoward Hinnant
111f51ee632SMarshall Clow// 27.4.3, iterator operations
11212b01ab7SLouis Dionnetemplate <class InputIterator, class Distance>  // constexpr in C++17
11312b01ab7SLouis Dionne  constexpr void advance(InputIterator& i, Distance n);
1143e519524SHoward Hinnant
115f51ee632SMarshall Clowtemplate <class InputIterator>  // constexpr in C++17
116f51ee632SMarshall Clow  constexpr typename iterator_traits<InputIterator>::difference_type
1173e519524SHoward Hinnant    distance(InputIterator first, InputIterator last);
1183e519524SHoward Hinnant
119f51ee632SMarshall Clowtemplate <class InputIterator>  // constexpr in C++17
120f51ee632SMarshall Clow  constexpr InputIterator next(InputIterator x,
121f51ee632SMarshall Clowtypename iterator_traits<InputIterator>::difference_type n = 1);
122f51ee632SMarshall Clow
123f51ee632SMarshall Clowtemplate <class BidirectionalIterator>  // constexpr in C++17
124f51ee632SMarshall Clow  constexpr BidirectionalIterator prev(BidirectionalIterator x,
125f51ee632SMarshall Clow    typename iterator_traits<BidirectionalIterator>::difference_type n = 1);
126f51ee632SMarshall Clow
12736d0fdf9SChristopher Di Bella// [range.iter.ops], range iterator operations
12836d0fdf9SChristopher Di Bellanamespace ranges {
12936d0fdf9SChristopher Di Bella  // [range.iter.op.advance], ranges::advance
13036d0fdf9SChristopher Di Bella  template<input_or_output_iterator I>
13136d0fdf9SChristopher Di Bella    constexpr void advance(I& i, iter_difference_t<I> n);                          // since C++20
13236d0fdf9SChristopher Di Bella  template<input_or_output_iterator I, sentinel_for<I> S>
13336d0fdf9SChristopher Di Bella    constexpr void advance(I& i, S bound);                                         // since C++20
13436d0fdf9SChristopher Di Bella  template<input_or_output_iterator I, sentinel_for<I> S>
13536d0fdf9SChristopher Di Bella    constexpr iter_difference_t<I> advance(I& i, iter_difference_t<I> n, S bound); // since C++20
13636d0fdf9SChristopher Di Bella}
13736d0fdf9SChristopher Di Bella
1383e519524SHoward Hinnanttemplate <class Iterator>
1393e519524SHoward Hinnantclass reverse_iterator
1403e519524SHoward Hinnant    : public iterator<typename iterator_traits<Iterator>::iterator_category,
1413e519524SHoward Hinnant                      typename iterator_traits<Iterator>::value_type,
1423e519524SHoward Hinnant                      typename iterator_traits<Iterator>::difference_type,
1433e519524SHoward Hinnant                      typename iterator_traits<Iterator>::pointer,
1443e519524SHoward Hinnant                      typename iterator_traits<Iterator>::reference>
1453e519524SHoward Hinnant{
1463e519524SHoward Hinnantprotected:
1473e519524SHoward Hinnant    Iterator current;
1483e519524SHoward Hinnantpublic:
1493e519524SHoward Hinnant    typedef Iterator                                            iterator_type;
1503e519524SHoward Hinnant    typedef typename iterator_traits<Iterator>::difference_type difference_type;
1513e519524SHoward Hinnant    typedef typename iterator_traits<Iterator>::reference       reference;
1523e519524SHoward Hinnant    typedef typename iterator_traits<Iterator>::pointer         pointer;
1533e519524SHoward Hinnant
1541b8f260eSMarshall Clow    constexpr reverse_iterator();
1551b8f260eSMarshall Clow    constexpr explicit reverse_iterator(Iterator x);
1561b8f260eSMarshall Clow    template <class U> constexpr reverse_iterator(const reverse_iterator<U>& u);
1571b8f260eSMarshall Clow    template <class U> constexpr reverse_iterator& operator=(const reverse_iterator<U>& u);
1581b8f260eSMarshall Clow    constexpr Iterator base() const;
1591b8f260eSMarshall Clow    constexpr reference operator*() const;
1601b8f260eSMarshall Clow    constexpr pointer   operator->() const;
1611b8f260eSMarshall Clow    constexpr reverse_iterator& operator++();
1621b8f260eSMarshall Clow    constexpr reverse_iterator  operator++(int);
1631b8f260eSMarshall Clow    constexpr reverse_iterator& operator--();
1641b8f260eSMarshall Clow    constexpr reverse_iterator  operator--(int);
1651b8f260eSMarshall Clow    constexpr reverse_iterator  operator+ (difference_type n) const;
1661b8f260eSMarshall Clow    constexpr reverse_iterator& operator+=(difference_type n);
1671b8f260eSMarshall Clow    constexpr reverse_iterator  operator- (difference_type n) const;
1681b8f260eSMarshall Clow    constexpr reverse_iterator& operator-=(difference_type n);
1691b8f260eSMarshall Clow    constexpr reference         operator[](difference_type n) const;
1703e519524SHoward Hinnant};
1713e519524SHoward Hinnant
1723e519524SHoward Hinnanttemplate <class Iterator1, class Iterator2>
1731b8f260eSMarshall Clowconstexpr bool                          // constexpr in C++17
1743e519524SHoward Hinnantoperator==(const reverse_iterator<Iterator1>& x, const reverse_iterator<Iterator2>& y);
1753e519524SHoward Hinnant
1763e519524SHoward Hinnanttemplate <class Iterator1, class Iterator2>
1771b8f260eSMarshall Clowconstexpr bool                          // constexpr in C++17
1783e519524SHoward Hinnantoperator<(const reverse_iterator<Iterator1>& x, const reverse_iterator<Iterator2>& y);
1793e519524SHoward Hinnant
1803e519524SHoward Hinnanttemplate <class Iterator1, class Iterator2>
1811b8f260eSMarshall Clowconstexpr bool                          // constexpr in C++17
1823e519524SHoward Hinnantoperator!=(const reverse_iterator<Iterator1>& x, const reverse_iterator<Iterator2>& y);
1833e519524SHoward Hinnant
1843e519524SHoward Hinnanttemplate <class Iterator1, class Iterator2>
1851b8f260eSMarshall Clowconstexpr bool                          // constexpr in C++17
1863e519524SHoward Hinnantoperator>(const reverse_iterator<Iterator1>& x, const reverse_iterator<Iterator2>& y);
1873e519524SHoward Hinnant
1883e519524SHoward Hinnanttemplate <class Iterator1, class Iterator2>
1891b8f260eSMarshall Clowconstexpr bool                          // constexpr in C++17
1903e519524SHoward Hinnantoperator>=(const reverse_iterator<Iterator1>& x, const reverse_iterator<Iterator2>& y);
1913e519524SHoward Hinnant
1923e519524SHoward Hinnanttemplate <class Iterator1, class Iterator2>
1931b8f260eSMarshall Clowconstexpr bool                          // constexpr in C++17
1943e519524SHoward Hinnantoperator<=(const reverse_iterator<Iterator1>& x, const reverse_iterator<Iterator2>& y);
1953e519524SHoward Hinnant
1963e519524SHoward Hinnanttemplate <class Iterator1, class Iterator2>
1971b8f260eSMarshall Clowconstexpr auto
198947ce6b5SMarshall Clowoperator-(const reverse_iterator<Iterator1>& x, const reverse_iterator<Iterator2>& y)
1991b8f260eSMarshall Clow-> decltype(__y.base() - __x.base());   // constexpr in C++17
2003e519524SHoward Hinnant
2013e519524SHoward Hinnanttemplate <class Iterator>
2021b8f260eSMarshall Clowconstexpr reverse_iterator<Iterator>
2031b8f260eSMarshall Clowoperator+(typename reverse_iterator<Iterator>::difference_type n,
2041b8f260eSMarshall Clow          const reverse_iterator<Iterator>& x);   // constexpr in C++17
2053e519524SHoward Hinnant
2061b8f260eSMarshall Clowtemplate <class Iterator>
2071b8f260eSMarshall Clowconstexpr reverse_iterator<Iterator> make_reverse_iterator(Iterator i); // C++14, constexpr in C++17
2086a640a18SMarshall Clow
2093e519524SHoward Hinnanttemplate <class Container>
2103e519524SHoward Hinnantclass back_insert_iterator
2113e519524SHoward Hinnant{
2123e519524SHoward Hinnantprotected:
2133e519524SHoward Hinnant    Container* container;
2143e519524SHoward Hinnantpublic:
2153e519524SHoward Hinnant    typedef Container                   container_type;
2163e519524SHoward Hinnant    typedef void                        value_type;
2173e519524SHoward Hinnant    typedef void                        difference_type;
2188892b4eeSEric Fiselier    typedef void                        reference;
2193e519524SHoward Hinnant    typedef void                        pointer;
2203e519524SHoward Hinnant
22106e2b737SArthur O'Dwyer    explicit back_insert_iterator(Container& x);  // constexpr in C++20
22206e2b737SArthur O'Dwyer    back_insert_iterator& operator=(const typename Container::value_type& value);  // constexpr in C++20
22306e2b737SArthur O'Dwyer    back_insert_iterator& operator*();  // constexpr in C++20
22406e2b737SArthur O'Dwyer    back_insert_iterator& operator++();  // constexpr in C++20
22506e2b737SArthur O'Dwyer    back_insert_iterator  operator++(int);  // constexpr in C++20
2263e519524SHoward Hinnant};
2273e519524SHoward Hinnant
22806e2b737SArthur O'Dwyertemplate <class Container> back_insert_iterator<Container> back_inserter(Container& x);  // constexpr in C++20
2293e519524SHoward Hinnant
2303e519524SHoward Hinnanttemplate <class Container>
2313e519524SHoward Hinnantclass front_insert_iterator
2323e519524SHoward Hinnant{
2333e519524SHoward Hinnantprotected:
2343e519524SHoward Hinnant    Container* container;
2353e519524SHoward Hinnantpublic:
2363e519524SHoward Hinnant    typedef Container                    container_type;
2373e519524SHoward Hinnant    typedef void                         value_type;
2383e519524SHoward Hinnant    typedef void                         difference_type;
2398892b4eeSEric Fiselier    typedef void                         reference;
2403e519524SHoward Hinnant    typedef void                         pointer;
2413e519524SHoward Hinnant
24206e2b737SArthur O'Dwyer    explicit front_insert_iterator(Container& x);  // constexpr in C++20
24306e2b737SArthur O'Dwyer    front_insert_iterator& operator=(const typename Container::value_type& value);  // constexpr in C++20
24406e2b737SArthur O'Dwyer    front_insert_iterator& operator*();  // constexpr in C++20
24506e2b737SArthur O'Dwyer    front_insert_iterator& operator++();  // constexpr in C++20
24606e2b737SArthur O'Dwyer    front_insert_iterator  operator++(int);  // constexpr in C++20
2473e519524SHoward Hinnant};
2483e519524SHoward Hinnant
24906e2b737SArthur O'Dwyertemplate <class Container> front_insert_iterator<Container> front_inserter(Container& x);  // constexpr in C++20
2503e519524SHoward Hinnant
2513e519524SHoward Hinnanttemplate <class Container>
2523e519524SHoward Hinnantclass insert_iterator
2533e519524SHoward Hinnant{
2543e519524SHoward Hinnantprotected:
2553e519524SHoward Hinnant    Container* container;
2563e519524SHoward Hinnant    typename Container::iterator iter;
2573e519524SHoward Hinnantpublic:
2583e519524SHoward Hinnant    typedef Container              container_type;
2593e519524SHoward Hinnant    typedef void                   value_type;
2603e519524SHoward Hinnant    typedef void                   difference_type;
2618892b4eeSEric Fiselier    typedef void                   reference;
2623e519524SHoward Hinnant    typedef void                   pointer;
2633e519524SHoward Hinnant
26406e2b737SArthur O'Dwyer    insert_iterator(Container& x, typename Container::iterator i);  // constexpr in C++20
26506e2b737SArthur O'Dwyer    insert_iterator& operator=(const typename Container::value_type& value);  // constexpr in C++20
26606e2b737SArthur O'Dwyer    insert_iterator& operator*();  // constexpr in C++20
26706e2b737SArthur O'Dwyer    insert_iterator& operator++();  // constexpr in C++20
26806e2b737SArthur O'Dwyer    insert_iterator& operator++(int);  // constexpr in C++20
2693e519524SHoward Hinnant};
2703e519524SHoward Hinnant
2713e519524SHoward Hinnanttemplate <class Container, class Iterator>
27206e2b737SArthur O'Dwyerinsert_iterator<Container> inserter(Container& x, Iterator i);  // constexpr in C++20
2733e519524SHoward Hinnant
274947ce6b5SMarshall Clowtemplate <class Iterator>
275947ce6b5SMarshall Clowclass move_iterator {
276947ce6b5SMarshall Clowpublic:
277947ce6b5SMarshall Clow    typedef Iterator                                              iterator_type;
278947ce6b5SMarshall Clow    typedef typename iterator_traits<Iterator>::difference_type   difference_type;
279947ce6b5SMarshall Clow    typedef Iterator                                              pointer;
280947ce6b5SMarshall Clow    typedef typename iterator_traits<Iterator>::value_type        value_type;
281947ce6b5SMarshall Clow    typedef typename iterator_traits<Iterator>::iterator_category iterator_category;
282947ce6b5SMarshall Clow    typedef value_type&&                                          reference;
283947ce6b5SMarshall Clow
284720ef472SMarshall Clow    constexpr move_iterator();  // all the constexprs are in C++17
285720ef472SMarshall Clow    constexpr explicit move_iterator(Iterator i);
286720ef472SMarshall Clow    template <class U>
287720ef472SMarshall Clow      constexpr move_iterator(const move_iterator<U>& u);
288720ef472SMarshall Clow    template <class U>
289720ef472SMarshall Clow      constexpr move_iterator& operator=(const move_iterator<U>& u);
290720ef472SMarshall Clow    constexpr iterator_type base() const;
291720ef472SMarshall Clow    constexpr reference operator*() const;
292720ef472SMarshall Clow    constexpr pointer operator->() const;
293720ef472SMarshall Clow    constexpr move_iterator& operator++();
294720ef472SMarshall Clow    constexpr move_iterator operator++(int);
295720ef472SMarshall Clow    constexpr move_iterator& operator--();
296720ef472SMarshall Clow    constexpr move_iterator operator--(int);
297720ef472SMarshall Clow    constexpr move_iterator operator+(difference_type n) const;
298720ef472SMarshall Clow    constexpr move_iterator& operator+=(difference_type n);
299720ef472SMarshall Clow    constexpr move_iterator operator-(difference_type n) const;
300720ef472SMarshall Clow    constexpr move_iterator& operator-=(difference_type n);
301720ef472SMarshall Clow    constexpr unspecified operator[](difference_type n) const;
302947ce6b5SMarshall Clowprivate:
303947ce6b5SMarshall Clow    Iterator current; // exposition only
304947ce6b5SMarshall Clow};
305947ce6b5SMarshall Clow
306947ce6b5SMarshall Clowtemplate <class Iterator1, class Iterator2>
307720ef472SMarshall Clowconstexpr bool   // constexpr in C++17
308947ce6b5SMarshall Clowoperator==(const move_iterator<Iterator1>& x, const move_iterator<Iterator2>& y);
309947ce6b5SMarshall Clow
310947ce6b5SMarshall Clowtemplate <class Iterator1, class Iterator2>
311720ef472SMarshall Clowconstexpr bool   // constexpr in C++17
312947ce6b5SMarshall Clowoperator!=(const move_iterator<Iterator1>& x, const move_iterator<Iterator2>& y);
313947ce6b5SMarshall Clow
314947ce6b5SMarshall Clowtemplate <class Iterator1, class Iterator2>
315720ef472SMarshall Clowconstexpr bool   // constexpr in C++17
316947ce6b5SMarshall Clowoperator<(const move_iterator<Iterator1>& x, const move_iterator<Iterator2>& y);
317947ce6b5SMarshall Clow
318947ce6b5SMarshall Clowtemplate <class Iterator1, class Iterator2>
319720ef472SMarshall Clowconstexpr bool   // constexpr in C++17
320947ce6b5SMarshall Clowoperator<=(const move_iterator<Iterator1>& x, const move_iterator<Iterator2>& y);
321947ce6b5SMarshall Clow
322947ce6b5SMarshall Clowtemplate <class Iterator1, class Iterator2>
323720ef472SMarshall Clowconstexpr bool   // constexpr in C++17
324947ce6b5SMarshall Clowoperator>(const move_iterator<Iterator1>& x, const move_iterator<Iterator2>& y);
325947ce6b5SMarshall Clow
326947ce6b5SMarshall Clowtemplate <class Iterator1, class Iterator2>
327720ef472SMarshall Clowconstexpr bool   // constexpr in C++17
328947ce6b5SMarshall Clowoperator>=(const move_iterator<Iterator1>& x, const move_iterator<Iterator2>& y);
329947ce6b5SMarshall Clow
330947ce6b5SMarshall Clowtemplate <class Iterator1, class Iterator2>
331720ef472SMarshall Clowconstexpr auto   // constexpr in C++17
332947ce6b5SMarshall Clowoperator-(const move_iterator<Iterator1>& x,
333947ce6b5SMarshall Clow          const move_iterator<Iterator2>& y) -> decltype(x.base() - y.base());
334947ce6b5SMarshall Clow
335947ce6b5SMarshall Clowtemplate <class Iterator>
336720ef472SMarshall Clowconstexpr move_iterator<Iterator> operator+(   // constexpr in C++17
337720ef472SMarshall Clow            typename move_iterator<Iterator>::difference_type n,
338947ce6b5SMarshall Clow            const move_iterator<Iterator>& x);
339947ce6b5SMarshall Clow
340720ef472SMarshall Clowtemplate <class Iterator>   // constexpr in C++17
341720ef472SMarshall Clowconstexpr  move_iterator<Iterator> make_move_iterator(const Iterator& i);
342947ce6b5SMarshall Clow
343947ce6b5SMarshall Clow
3443e519524SHoward Hinnanttemplate <class T, class charT = char, class traits = char_traits<charT>, class Distance = ptrdiff_t>
3453e519524SHoward Hinnantclass istream_iterator
3463e519524SHoward Hinnant    : public iterator<input_iterator_tag, T, Distance, const T*, const T&>
3473e519524SHoward Hinnant{
3483e519524SHoward Hinnantpublic:
3493e519524SHoward Hinnant    typedef charT char_type;
3503e519524SHoward Hinnant    typedef traits traits_type;
3513e519524SHoward Hinnant    typedef basic_istream<charT,traits> istream_type;
3523e519524SHoward Hinnant
35360d5e0e0SMarshall Clow    constexpr istream_iterator();
3543e519524SHoward Hinnant    istream_iterator(istream_type& s);
3553e519524SHoward Hinnant    istream_iterator(const istream_iterator& x);
3563e519524SHoward Hinnant    ~istream_iterator();
3573e519524SHoward Hinnant
3583e519524SHoward Hinnant    const T& operator*() const;
3593e519524SHoward Hinnant    const T* operator->() const;
3603e519524SHoward Hinnant    istream_iterator& operator++();
3613e519524SHoward Hinnant    istream_iterator  operator++(int);
3623e519524SHoward Hinnant};
3633e519524SHoward Hinnant
3643e519524SHoward Hinnanttemplate <class T, class charT, class traits, class Distance>
3653e519524SHoward Hinnantbool operator==(const istream_iterator<T,charT,traits,Distance>& x,
3663e519524SHoward Hinnant                const istream_iterator<T,charT,traits,Distance>& y);
3673e519524SHoward Hinnanttemplate <class T, class charT, class traits, class Distance>
3683e519524SHoward Hinnantbool operator!=(const istream_iterator<T,charT,traits,Distance>& x,
3693e519524SHoward Hinnant                const istream_iterator<T,charT,traits,Distance>& y);
3703e519524SHoward Hinnant
3713e519524SHoward Hinnanttemplate <class T, class charT = char, class traits = char_traits<charT> >
3723e519524SHoward Hinnantclass ostream_iterator
3733e519524SHoward Hinnant    : public iterator<output_iterator_tag, void, void, void ,void>
3743e519524SHoward Hinnant{
3753e519524SHoward Hinnantpublic:
3763e519524SHoward Hinnant    typedef charT char_type;
3773e519524SHoward Hinnant    typedef traits traits_type;
3783e519524SHoward Hinnant    typedef basic_ostream<charT,traits> ostream_type;
3793e519524SHoward Hinnant
3803e519524SHoward Hinnant    ostream_iterator(ostream_type& s);
3813e519524SHoward Hinnant    ostream_iterator(ostream_type& s, const charT* delimiter);
3823e519524SHoward Hinnant    ostream_iterator(const ostream_iterator& x);
3833e519524SHoward Hinnant    ~ostream_iterator();
3843e519524SHoward Hinnant    ostream_iterator& operator=(const T& value);
3853e519524SHoward Hinnant
3863e519524SHoward Hinnant    ostream_iterator& operator*();
3873e519524SHoward Hinnant    ostream_iterator& operator++();
3883e519524SHoward Hinnant    ostream_iterator& operator++(int);
3893e519524SHoward Hinnant};
3903e519524SHoward Hinnant
3913e519524SHoward Hinnanttemplate<class charT, class traits = char_traits<charT> >
3923e519524SHoward Hinnantclass istreambuf_iterator
3933e519524SHoward Hinnant    : public iterator<input_iterator_tag, charT,
3943e519524SHoward Hinnant                      typename traits::off_type, unspecified,
3953e519524SHoward Hinnant                      charT>
3963e519524SHoward Hinnant{
3973e519524SHoward Hinnantpublic:
3983e519524SHoward Hinnant    typedef charT                         char_type;
3993e519524SHoward Hinnant    typedef traits                        traits_type;
4003e519524SHoward Hinnant    typedef typename traits::int_type     int_type;
4013e519524SHoward Hinnant    typedef basic_streambuf<charT,traits> streambuf_type;
4023e519524SHoward Hinnant    typedef basic_istream<charT,traits>   istream_type;
4033e519524SHoward Hinnant
4048e882dcbSHoward Hinnant    istreambuf_iterator() noexcept;
4058e882dcbSHoward Hinnant    istreambuf_iterator(istream_type& s) noexcept;
4068e882dcbSHoward Hinnant    istreambuf_iterator(streambuf_type* s) noexcept;
4078e882dcbSHoward Hinnant    istreambuf_iterator(a-private-type) noexcept;
4083e519524SHoward Hinnant
4093e519524SHoward Hinnant    charT                operator*() const;
4103e519524SHoward Hinnant    pointer operator->() const;
4113e519524SHoward Hinnant    istreambuf_iterator& operator++();
4123e519524SHoward Hinnant    a-private-type       operator++(int);
4133e519524SHoward Hinnant
4143e519524SHoward Hinnant    bool equal(const istreambuf_iterator& b) const;
4153e519524SHoward Hinnant};
4163e519524SHoward Hinnant
4173e519524SHoward Hinnanttemplate <class charT, class traits>
4183e519524SHoward Hinnantbool operator==(const istreambuf_iterator<charT,traits>& a,
4193e519524SHoward Hinnant                const istreambuf_iterator<charT,traits>& b);
4203e519524SHoward Hinnanttemplate <class charT, class traits>
4213e519524SHoward Hinnantbool operator!=(const istreambuf_iterator<charT,traits>& a,
4223e519524SHoward Hinnant                const istreambuf_iterator<charT,traits>& b);
4233e519524SHoward Hinnant
4243e519524SHoward Hinnanttemplate <class charT, class traits = char_traits<charT> >
4253e519524SHoward Hinnantclass ostreambuf_iterator
4263e519524SHoward Hinnant    : public iterator<output_iterator_tag, void, void, void, void>
4273e519524SHoward Hinnant{
4283e519524SHoward Hinnantpublic:
4293e519524SHoward Hinnant    typedef charT                         char_type;
4303e519524SHoward Hinnant    typedef traits                        traits_type;
4313e519524SHoward Hinnant    typedef basic_streambuf<charT,traits> streambuf_type;
4323e519524SHoward Hinnant    typedef basic_ostream<charT,traits>   ostream_type;
4333e519524SHoward Hinnant
4348e882dcbSHoward Hinnant    ostreambuf_iterator(ostream_type& s) noexcept;
4358e882dcbSHoward Hinnant    ostreambuf_iterator(streambuf_type* s) noexcept;
4363e519524SHoward Hinnant    ostreambuf_iterator& operator=(charT c);
4373e519524SHoward Hinnant    ostreambuf_iterator& operator*();
4383e519524SHoward Hinnant    ostreambuf_iterator& operator++();
4393e519524SHoward Hinnant    ostreambuf_iterator& operator++(int);
4408e882dcbSHoward Hinnant    bool failed() const noexcept;
4413e519524SHoward Hinnant};
4423e519524SHoward Hinnant
443020b623aSMarshall Clowtemplate <class C> constexpr auto begin(C& c) -> decltype(c.begin());
444020b623aSMarshall Clowtemplate <class C> constexpr auto begin(const C& c) -> decltype(c.begin());
445020b623aSMarshall Clowtemplate <class C> constexpr auto end(C& c) -> decltype(c.end());
446020b623aSMarshall Clowtemplate <class C> constexpr auto end(const C& c) -> decltype(c.end());
447020b623aSMarshall Clowtemplate <class T, size_t N> constexpr T* begin(T (&array)[N]);
448020b623aSMarshall Clowtemplate <class T, size_t N> constexpr T* end(T (&array)[N]);
4493e519524SHoward Hinnant
450020b623aSMarshall Clowtemplate <class C> auto constexpr cbegin(const C& c) -> decltype(std::begin(c));        // C++14
451020b623aSMarshall Clowtemplate <class C> auto constexpr cend(const C& c) -> decltype(std::end(c));            // C++14
452020b623aSMarshall Clowtemplate <class C> auto constexpr rbegin(C& c) -> decltype(c.rbegin());                 // C++14
453020b623aSMarshall Clowtemplate <class C> auto constexpr rbegin(const C& c) -> decltype(c.rbegin());           // C++14
454020b623aSMarshall Clowtemplate <class C> auto constexpr rend(C& c) -> decltype(c.rend());                     // C++14
455020b623aSMarshall Clowtemplate <class C> constexpr auto rend(const C& c) -> decltype(c.rend());               // C++14
456020b623aSMarshall Clowtemplate <class E> reverse_iterator<const E*> constexpr rbegin(initializer_list<E> il); // C++14
457020b623aSMarshall Clowtemplate <class E> reverse_iterator<const E*> constexpr rend(initializer_list<E> il);   // C++14
458020b623aSMarshall Clowtemplate <class T, size_t N> reverse_iterator<T*> constexpr rbegin(T (&array)[N]);      // C++14
459020b623aSMarshall Clowtemplate <class T, size_t N> reverse_iterator<T*> constexpr rend(T (&array)[N]);        // C++14
460020b623aSMarshall Clowtemplate <class C> constexpr auto crbegin(const C& c) -> decltype(std::rbegin(c));      // C++14
461020b623aSMarshall Clowtemplate <class C> constexpr auto crend(const C& c) -> decltype(std::rend(c));          // C++14
4621e548c72SMarshall Clow
463ad755104SMarshall Clow// 24.8, container access:
464ad755104SMarshall Clowtemplate <class C> constexpr auto size(const C& c) -> decltype(c.size());         // C++17
465ad755104SMarshall Clowtemplate <class T, size_t N> constexpr size_t size(const T (&array)[N]) noexcept; // C++17
4667d3986eaSMarshall Clow
4677d3986eaSMarshall Clowtemplate <class C> constexpr auto ssize(const C& c)
4687d3986eaSMarshall Clow    -> common_type_t<ptrdiff_t, make_signed_t<decltype(c.size())>>;                    // C++20
4697d3986eaSMarshall Clowtemplate <class T, ptrdiff_t> constexpr ptrdiff_t ssize(const T (&array)[N]) noexcept; // C++20
4707d3986eaSMarshall Clow
471ad755104SMarshall Clowtemplate <class C> constexpr auto empty(const C& c) -> decltype(c.empty());       // C++17
472ad755104SMarshall Clowtemplate <class T, size_t N> constexpr bool empty(const T (&array)[N]) noexcept;  // C++17
473ad755104SMarshall Clowtemplate <class E> constexpr bool empty(initializer_list<E> il) noexcept;         // C++17
474ad755104SMarshall Clowtemplate <class C> constexpr auto data(C& c) -> decltype(c.data());               // C++17
475ad755104SMarshall Clowtemplate <class C> constexpr auto data(const C& c) -> decltype(c.data());         // C++17
476ad755104SMarshall Clowtemplate <class T, size_t N> constexpr T* data(T (&array)[N]) noexcept;           // C++17
477ad755104SMarshall Clowtemplate <class E> constexpr const E* data(initializer_list<E> il) noexcept;      // C++17
478ad755104SMarshall Clow
4793e519524SHoward Hinnant}  // std
4803e519524SHoward Hinnant
4813e519524SHoward Hinnant*/
4823e519524SHoward Hinnant
4833e519524SHoward Hinnant#include <__config>
4845f51fb34SArthur O'Dwyer#include <__debug>
485c204c130SMarshall Clow#include <__functional_base>
48636d0fdf9SChristopher Di Bella#include <__iterator/advance.h>
48757ebf3d0SLouis Dionne#include <__iterator/concepts.h>
488e0adf7e0Szoecarver#include <__iterator/incrementable_traits.h>
48997e383aaSLouis Dionne#include <__iterator/iter_move.h>
490120fa829Szoecarver#include <__iterator/iterator_traits.h>
491857fa7b7SChristopher Di Bella#include <__iterator/next.h>
492*0dc7fd1bSChristopher Di Bella#include <__iterator/prev.h>
493e0adf7e0Szoecarver#include <__iterator/readable_traits.h>
494f992cfbaSLouis Dionne#include <__memory/addressof.h>
495d41c6d51SArthur O'Dwyer#include <__memory/pointer_traits.h>
4965f51fb34SArthur O'Dwyer#include <compare>
4975f51fb34SArthur O'Dwyer#include <concepts> // Mandated by the Standard.
4985f51fb34SArthur O'Dwyer#include <cstddef>
4995f51fb34SArthur O'Dwyer#include <initializer_list>
5005f51fb34SArthur O'Dwyer#include <iosfwd> // for forward declarations of vector and string
5015f51fb34SArthur O'Dwyer#include <type_traits>
502f56972e2SMarshall Clow#include <version>
503b5c63a2eSHoward Hinnant
504073458b1SHoward Hinnant#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
5053e519524SHoward Hinnant#pragma GCC system_header
506073458b1SHoward Hinnant#endif
5073e519524SHoward Hinnant
5083e519524SHoward Hinnant_LIBCPP_BEGIN_NAMESPACE_STD
509fe31f11cSChristopher Di Bella
5103e519524SHoward Hinnanttemplate<class _Category, class _Tp, class _Distance = ptrdiff_t,
5113e519524SHoward Hinnant         class _Pointer = _Tp*, class _Reference = _Tp&>
512e2f2d1edSEric Fiselierstruct _LIBCPP_TEMPLATE_VIS iterator
5133e519524SHoward Hinnant{
5143e519524SHoward Hinnant    typedef _Tp        value_type;
5153e519524SHoward Hinnant    typedef _Distance  difference_type;
5163e519524SHoward Hinnant    typedef _Pointer   pointer;
5173e519524SHoward Hinnant    typedef _Reference reference;
5183e519524SHoward Hinnant    typedef _Category  iterator_category;
5193e519524SHoward Hinnant};
5203e519524SHoward Hinnant
5213e519524SHoward Hinnanttemplate <class _InputIter>
522f51ee632SMarshall Clowinline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
5233e519524SHoward Hinnantvoid __advance(_InputIter& __i,
5243e519524SHoward Hinnant             typename iterator_traits<_InputIter>::difference_type __n, input_iterator_tag)
5253e519524SHoward Hinnant{
5263e519524SHoward Hinnant    for (; __n > 0; --__n)
5273e519524SHoward Hinnant        ++__i;
5283e519524SHoward Hinnant}
5293e519524SHoward Hinnant
5303e519524SHoward Hinnanttemplate <class _BiDirIter>
531f51ee632SMarshall Clowinline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
5323e519524SHoward Hinnantvoid __advance(_BiDirIter& __i,
5333e519524SHoward Hinnant             typename iterator_traits<_BiDirIter>::difference_type __n, bidirectional_iterator_tag)
5343e519524SHoward Hinnant{
5353e519524SHoward Hinnant    if (__n >= 0)
5363e519524SHoward Hinnant        for (; __n > 0; --__n)
5373e519524SHoward Hinnant            ++__i;
5383e519524SHoward Hinnant    else
5393e519524SHoward Hinnant        for (; __n < 0; ++__n)
5403e519524SHoward Hinnant            --__i;
5413e519524SHoward Hinnant}
5423e519524SHoward Hinnant
5433e519524SHoward Hinnanttemplate <class _RandIter>
544f51ee632SMarshall Clowinline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
5453e519524SHoward Hinnantvoid __advance(_RandIter& __i,
5463e519524SHoward Hinnant             typename iterator_traits<_RandIter>::difference_type __n, random_access_iterator_tag)
5473e519524SHoward Hinnant{
5483e519524SHoward Hinnant   __i += __n;
5493e519524SHoward Hinnant}
5503e519524SHoward Hinnant
55136d0fdf9SChristopher Di Bellatemplate <class _InputIter, class _Distance,
55236d0fdf9SChristopher Di Bella          class = typename enable_if<is_integral<decltype(_VSTD::__convert_to_integral(declval<_Distance>()))>::value>::type>
553f51ee632SMarshall Clowinline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
55412b01ab7SLouis Dionnevoid advance(_InputIter& __i, _Distance __orig_n)
5553e519524SHoward Hinnant{
556c0428b3cSArthur O'Dwyer    typedef decltype(_VSTD::__convert_to_integral(__orig_n)) _IntegralSize;
55712b01ab7SLouis Dionne    _IntegralSize __n = __orig_n;
5589571b8f2SArthur O'Dwyer    _LIBCPP_ASSERT(__n >= 0 || __is_cpp17_bidirectional_iterator<_InputIter>::value,
5599571b8f2SArthur O'Dwyer                   "Attempt to advance(it, n) with negative n on a non-bidirectional iterator");
560c0428b3cSArthur O'Dwyer    _VSTD::__advance(__i, __n, typename iterator_traits<_InputIter>::iterator_category());
5613e519524SHoward Hinnant}
5623e519524SHoward Hinnant
5633e519524SHoward Hinnanttemplate <class _InputIter>
564f51ee632SMarshall Clowinline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
5653e519524SHoward Hinnanttypename iterator_traits<_InputIter>::difference_type
5663e519524SHoward Hinnant__distance(_InputIter __first, _InputIter __last, input_iterator_tag)
5673e519524SHoward Hinnant{
5683e519524SHoward Hinnant    typename iterator_traits<_InputIter>::difference_type __r(0);
5693e519524SHoward Hinnant    for (; __first != __last; ++__first)
5703e519524SHoward Hinnant        ++__r;
5713e519524SHoward Hinnant    return __r;
5723e519524SHoward Hinnant}
5733e519524SHoward Hinnant
5743e519524SHoward Hinnanttemplate <class _RandIter>
575f51ee632SMarshall Clowinline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
5763e519524SHoward Hinnanttypename iterator_traits<_RandIter>::difference_type
5773e519524SHoward Hinnant__distance(_RandIter __first, _RandIter __last, random_access_iterator_tag)
5783e519524SHoward Hinnant{
5793e519524SHoward Hinnant    return __last - __first;
5803e519524SHoward Hinnant}
5813e519524SHoward Hinnant
5823e519524SHoward Hinnanttemplate <class _InputIter>
583f51ee632SMarshall Clowinline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
5843e519524SHoward Hinnanttypename iterator_traits<_InputIter>::difference_type
5853e519524SHoward Hinnantdistance(_InputIter __first, _InputIter __last)
5863e519524SHoward Hinnant{
587c0428b3cSArthur O'Dwyer    return _VSTD::__distance(__first, __last, typename iterator_traits<_InputIter>::iterator_category());
5883e519524SHoward Hinnant}
5893e519524SHoward Hinnant
590e5f1288fSMarshall Clowtemplate <class _InputIter>
591f51ee632SMarshall Clowinline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
5923e2ef408SRachel Craiktypename enable_if
5933e2ef408SRachel Craik<
594f82dba01SEric Fiselier    __is_cpp17_input_iterator<_InputIter>::value,
595e5f1288fSMarshall Clow    _InputIter
5963e2ef408SRachel Craik>::type
597e5f1288fSMarshall Clownext(_InputIter __x,
5983e2ef408SRachel Craik     typename iterator_traits<_InputIter>::difference_type __n = 1)
5993e519524SHoward Hinnant{
600f82dba01SEric Fiselier    _LIBCPP_ASSERT(__n >= 0 || __is_cpp17_bidirectional_iterator<_InputIter>::value,
60112b01ab7SLouis Dionne                       "Attempt to next(it, n) with negative n on a non-bidirectional iterator");
602e1cd11d8SMarshall Clow
603ce48a113SHoward Hinnant    _VSTD::advance(__x, __n);
6043e519524SHoward Hinnant    return __x;
6053e519524SHoward Hinnant}
6063e519524SHoward Hinnant
607e1cd11d8SMarshall Clowtemplate <class _InputIter>
608f51ee632SMarshall Clowinline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
6093e2ef408SRachel Craiktypename enable_if
6103e2ef408SRachel Craik<
611f82dba01SEric Fiselier    __is_cpp17_input_iterator<_InputIter>::value,
612e1cd11d8SMarshall Clow    _InputIter
6133e2ef408SRachel Craik>::type
614e1cd11d8SMarshall Clowprev(_InputIter __x,
615e1cd11d8SMarshall Clow     typename iterator_traits<_InputIter>::difference_type __n = 1)
6163e519524SHoward Hinnant{
617f82dba01SEric Fiselier    _LIBCPP_ASSERT(__n <= 0 || __is_cpp17_bidirectional_iterator<_InputIter>::value,
61812b01ab7SLouis Dionne                       "Attempt to prev(it, n) with a positive n on a non-bidirectional iterator");
619ce48a113SHoward Hinnant    _VSTD::advance(__x, -__n);
6203e519524SHoward Hinnant    return __x;
6213e519524SHoward Hinnant}
6223e519524SHoward Hinnant
623e02ed1c2SEric Fiselier
624e02ed1c2SEric Fiseliertemplate <class _Tp, class = void>
625e02ed1c2SEric Fiselierstruct __is_stashing_iterator : false_type {};
626e02ed1c2SEric Fiselier
627e02ed1c2SEric Fiseliertemplate <class _Tp>
628e02ed1c2SEric Fiselierstruct __is_stashing_iterator<_Tp, typename __void_t<typename _Tp::__stashing_iterator_tag>::type>
629e02ed1c2SEric Fiselier  : true_type {};
630e02ed1c2SEric Fiselier
6313e519524SHoward Hinnanttemplate <class _Iter>
632e2f2d1edSEric Fiselierclass _LIBCPP_TEMPLATE_VIS reverse_iterator
6333e519524SHoward Hinnant    : public iterator<typename iterator_traits<_Iter>::iterator_category,
6343e519524SHoward Hinnant                      typename iterator_traits<_Iter>::value_type,
6353e519524SHoward Hinnant                      typename iterator_traits<_Iter>::difference_type,
6363e519524SHoward Hinnant                      typename iterator_traits<_Iter>::pointer,
6373e519524SHoward Hinnant                      typename iterator_traits<_Iter>::reference>
6383e519524SHoward Hinnant{
6393b83496dSMarshall Clowprivate:
6401b8f260eSMarshall Clow    /*mutable*/ _Iter __t;  // no longer used as of LWG #2360, not removed due to ABI break
641e02ed1c2SEric Fiselier
642e02ed1c2SEric Fiselier    static_assert(!__is_stashing_iterator<_Iter>::value,
643e02ed1c2SEric Fiselier      "The specified iterator type cannot be used with reverse_iterator; "
644e02ed1c2SEric Fiselier      "Using stashing iterators with reverse_iterator causes undefined behavior");
645e02ed1c2SEric Fiselier
646b2d74f29SMarshall Clowprotected:
647b2d74f29SMarshall Clow    _Iter current;
6483e519524SHoward Hinnantpublic:
6493e519524SHoward Hinnant    typedef _Iter                                            iterator_type;
6503e519524SHoward Hinnant    typedef typename iterator_traits<_Iter>::difference_type difference_type;
6513e519524SHoward Hinnant    typedef typename iterator_traits<_Iter>::reference       reference;
6523e519524SHoward Hinnant    typedef typename iterator_traits<_Iter>::pointer         pointer;
653d41c6d51SArthur O'Dwyer    typedef _If<__is_cpp17_random_access_iterator<_Iter>::value,
654d41c6d51SArthur O'Dwyer        random_access_iterator_tag,
655d41c6d51SArthur O'Dwyer        typename iterator_traits<_Iter>::iterator_category>  iterator_category;
656d41c6d51SArthur O'Dwyer#if _LIBCPP_STD_VER > 17
657d41c6d51SArthur O'Dwyer    typedef _If<__is_cpp17_random_access_iterator<_Iter>::value,
658d41c6d51SArthur O'Dwyer        random_access_iterator_tag,
659d41c6d51SArthur O'Dwyer        bidirectional_iterator_tag>                          iterator_concept;
660d41c6d51SArthur O'Dwyer#endif
6613e519524SHoward Hinnant
6621b8f260eSMarshall Clow    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
6631b8f260eSMarshall Clow    reverse_iterator() : __t(), current() {}
6641b8f260eSMarshall Clow    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
6651b8f260eSMarshall Clow    explicit reverse_iterator(_Iter __x) : __t(__x), current(__x) {}
6661b8f260eSMarshall Clow    template <class _Up>
6671b8f260eSMarshall Clow        _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
6681b8f260eSMarshall Clow        reverse_iterator(const reverse_iterator<_Up>& __u) : __t(__u.base()), current(__u.base()) {}
6691b8f260eSMarshall Clow    template <class _Up>
6701b8f260eSMarshall Clow        _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
6711b8f260eSMarshall Clow        reverse_iterator& operator=(const reverse_iterator<_Up>& __u)
6721b8f260eSMarshall Clow            { __t = current = __u.base(); return *this; }
6731b8f260eSMarshall Clow    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
6741b8f260eSMarshall Clow    _Iter base() const {return current;}
6751b8f260eSMarshall Clow    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
6761b8f260eSMarshall Clow    reference operator*() const {_Iter __tmp = current; return *--__tmp;}
6771b8f260eSMarshall Clow    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
6781b8f260eSMarshall Clow    pointer  operator->() const {return _VSTD::addressof(operator*());}
6791b8f260eSMarshall Clow    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
6801b8f260eSMarshall Clow    reverse_iterator& operator++() {--current; return *this;}
6811b8f260eSMarshall Clow    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
6821b8f260eSMarshall Clow    reverse_iterator  operator++(int) {reverse_iterator __tmp(*this); --current; return __tmp;}
6831b8f260eSMarshall Clow    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
6841b8f260eSMarshall Clow    reverse_iterator& operator--() {++current; return *this;}
6851b8f260eSMarshall Clow    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
6861b8f260eSMarshall Clow    reverse_iterator  operator--(int) {reverse_iterator __tmp(*this); ++current; return __tmp;}
6871b8f260eSMarshall Clow    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
6881b8f260eSMarshall Clow    reverse_iterator  operator+ (difference_type __n) const {return reverse_iterator(current - __n);}
6891b8f260eSMarshall Clow    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
6901b8f260eSMarshall Clow    reverse_iterator& operator+=(difference_type __n) {current -= __n; return *this;}
6911b8f260eSMarshall Clow    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
6921b8f260eSMarshall Clow    reverse_iterator  operator- (difference_type __n) const {return reverse_iterator(current + __n);}
6931b8f260eSMarshall Clow    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
6941b8f260eSMarshall Clow    reverse_iterator& operator-=(difference_type __n) {current += __n; return *this;}
6951b8f260eSMarshall Clow    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
6961b8f260eSMarshall Clow    reference         operator[](difference_type __n) const {return *(*this + __n);}
6973e519524SHoward Hinnant};
6983e519524SHoward Hinnant
6993e519524SHoward Hinnanttemplate <class _Iter1, class _Iter2>
7001b8f260eSMarshall Clowinline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
7013e519524SHoward Hinnantbool
7023e519524SHoward Hinnantoperator==(const reverse_iterator<_Iter1>& __x, const reverse_iterator<_Iter2>& __y)
7033e519524SHoward Hinnant{
7043e519524SHoward Hinnant    return __x.base() == __y.base();
7053e519524SHoward Hinnant}
7063e519524SHoward Hinnant
7073e519524SHoward Hinnanttemplate <class _Iter1, class _Iter2>
7081b8f260eSMarshall Clowinline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
7093e519524SHoward Hinnantbool
7103e519524SHoward Hinnantoperator<(const reverse_iterator<_Iter1>& __x, const reverse_iterator<_Iter2>& __y)
7113e519524SHoward Hinnant{
7123e519524SHoward Hinnant    return __x.base() > __y.base();
7133e519524SHoward Hinnant}
7143e519524SHoward Hinnant
7153e519524SHoward Hinnanttemplate <class _Iter1, class _Iter2>
7161b8f260eSMarshall Clowinline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
7173e519524SHoward Hinnantbool
7183e519524SHoward Hinnantoperator!=(const reverse_iterator<_Iter1>& __x, const reverse_iterator<_Iter2>& __y)
7193e519524SHoward Hinnant{
7203e519524SHoward Hinnant    return __x.base() != __y.base();
7213e519524SHoward Hinnant}
7223e519524SHoward Hinnant
7233e519524SHoward Hinnanttemplate <class _Iter1, class _Iter2>
7241b8f260eSMarshall Clowinline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
7253e519524SHoward Hinnantbool
7263e519524SHoward Hinnantoperator>(const reverse_iterator<_Iter1>& __x, const reverse_iterator<_Iter2>& __y)
7273e519524SHoward Hinnant{
7283e519524SHoward Hinnant    return __x.base() < __y.base();
7293e519524SHoward Hinnant}
7303e519524SHoward Hinnant
7313e519524SHoward Hinnanttemplate <class _Iter1, class _Iter2>
7321b8f260eSMarshall Clowinline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
7333e519524SHoward Hinnantbool
7343e519524SHoward Hinnantoperator>=(const reverse_iterator<_Iter1>& __x, const reverse_iterator<_Iter2>& __y)
7353e519524SHoward Hinnant{
7363e519524SHoward Hinnant    return __x.base() <= __y.base();
7373e519524SHoward Hinnant}
7383e519524SHoward Hinnant
7393e519524SHoward Hinnanttemplate <class _Iter1, class _Iter2>
7401b8f260eSMarshall Clowinline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
7413e519524SHoward Hinnantbool
7423e519524SHoward Hinnantoperator<=(const reverse_iterator<_Iter1>& __x, const reverse_iterator<_Iter2>& __y)
7433e519524SHoward Hinnant{
7443e519524SHoward Hinnant    return __x.base() >= __y.base();
7453e519524SHoward Hinnant}
7463e519524SHoward Hinnant
7472ee83725SMarshall Clow#ifndef _LIBCPP_CXX03_LANG
748947ce6b5SMarshall Clowtemplate <class _Iter1, class _Iter2>
7491b8f260eSMarshall Clowinline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
750947ce6b5SMarshall Clowauto
751947ce6b5SMarshall Clowoperator-(const reverse_iterator<_Iter1>& __x, const reverse_iterator<_Iter2>& __y)
752947ce6b5SMarshall Clow-> decltype(__y.base() - __x.base())
753947ce6b5SMarshall Clow{
754947ce6b5SMarshall Clow    return __y.base() - __x.base();
755947ce6b5SMarshall Clow}
756947ce6b5SMarshall Clow#else
7573e519524SHoward Hinnanttemplate <class _Iter1, class _Iter2>
7583e519524SHoward Hinnantinline _LIBCPP_INLINE_VISIBILITY
7593e519524SHoward Hinnanttypename reverse_iterator<_Iter1>::difference_type
7603e519524SHoward Hinnantoperator-(const reverse_iterator<_Iter1>& __x, const reverse_iterator<_Iter2>& __y)
7613e519524SHoward Hinnant{
7623e519524SHoward Hinnant    return __y.base() - __x.base();
7633e519524SHoward Hinnant}
764947ce6b5SMarshall Clow#endif
7653e519524SHoward Hinnant
7663e519524SHoward Hinnanttemplate <class _Iter>
7671b8f260eSMarshall Clowinline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
7683e519524SHoward Hinnantreverse_iterator<_Iter>
7693e519524SHoward Hinnantoperator+(typename reverse_iterator<_Iter>::difference_type __n, const reverse_iterator<_Iter>& __x)
7703e519524SHoward Hinnant{
7713e519524SHoward Hinnant    return reverse_iterator<_Iter>(__x.base() - __n);
7723e519524SHoward Hinnant}
7733e519524SHoward Hinnant
7746a640a18SMarshall Clow#if _LIBCPP_STD_VER > 11
7756a640a18SMarshall Clowtemplate <class _Iter>
7761b8f260eSMarshall Clowinline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
7776a640a18SMarshall Clowreverse_iterator<_Iter> make_reverse_iterator(_Iter __i)
7786a640a18SMarshall Clow{
7796a640a18SMarshall Clow    return reverse_iterator<_Iter>(__i);
7806a640a18SMarshall Clow}
7816a640a18SMarshall Clow#endif
7826a640a18SMarshall Clow
7833e519524SHoward Hinnanttemplate <class _Container>
784e2f2d1edSEric Fiselierclass _LIBCPP_TEMPLATE_VIS back_insert_iterator
7853e519524SHoward Hinnant    : public iterator<output_iterator_tag,
7863e519524SHoward Hinnant                      void,
7873e519524SHoward Hinnant                      void,
7883e519524SHoward Hinnant                      void,
7898892b4eeSEric Fiselier                      void>
7903e519524SHoward Hinnant{
7913e519524SHoward Hinnantprotected:
7923e519524SHoward Hinnant    _Container* container;
7933e519524SHoward Hinnantpublic:
7943e519524SHoward Hinnant    typedef _Container container_type;
7953e519524SHoward Hinnant
79606e2b737SArthur O'Dwyer    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 explicit back_insert_iterator(_Container& __x) : container(_VSTD::addressof(__x)) {}
79706e2b737SArthur O'Dwyer    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 back_insert_iterator& operator=(const typename _Container::value_type& __value_)
798e4383379SHoward Hinnant        {container->push_back(__value_); return *this;}
799046492b9SEric Fiselier#ifndef _LIBCPP_CXX03_LANG
80006e2b737SArthur O'Dwyer    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 back_insert_iterator& operator=(typename _Container::value_type&& __value_)
801e4383379SHoward Hinnant        {container->push_back(_VSTD::move(__value_)); return *this;}
802046492b9SEric Fiselier#endif // _LIBCPP_CXX03_LANG
80306e2b737SArthur O'Dwyer    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 back_insert_iterator& operator*()     {return *this;}
80406e2b737SArthur O'Dwyer    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 back_insert_iterator& operator++()    {return *this;}
80506e2b737SArthur O'Dwyer    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 back_insert_iterator  operator++(int) {return *this;}
8063e519524SHoward Hinnant};
8073e519524SHoward Hinnant
8083e519524SHoward Hinnanttemplate <class _Container>
80906e2b737SArthur O'Dwyerinline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
8103e519524SHoward Hinnantback_insert_iterator<_Container>
8113e519524SHoward Hinnantback_inserter(_Container& __x)
8123e519524SHoward Hinnant{
8133e519524SHoward Hinnant    return back_insert_iterator<_Container>(__x);
8143e519524SHoward Hinnant}
8153e519524SHoward Hinnant
8163e519524SHoward Hinnanttemplate <class _Container>
817e2f2d1edSEric Fiselierclass _LIBCPP_TEMPLATE_VIS front_insert_iterator
8183e519524SHoward Hinnant    : public iterator<output_iterator_tag,
8193e519524SHoward Hinnant                      void,
8203e519524SHoward Hinnant                      void,
8213e519524SHoward Hinnant                      void,
8228892b4eeSEric Fiselier                      void>
8233e519524SHoward Hinnant{
8243e519524SHoward Hinnantprotected:
8253e519524SHoward Hinnant    _Container* container;
8263e519524SHoward Hinnantpublic:
8273e519524SHoward Hinnant    typedef _Container container_type;
8283e519524SHoward Hinnant
82906e2b737SArthur O'Dwyer    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 explicit front_insert_iterator(_Container& __x) : container(_VSTD::addressof(__x)) {}
83006e2b737SArthur O'Dwyer    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 front_insert_iterator& operator=(const typename _Container::value_type& __value_)
831e4383379SHoward Hinnant        {container->push_front(__value_); return *this;}
832046492b9SEric Fiselier#ifndef _LIBCPP_CXX03_LANG
83306e2b737SArthur O'Dwyer    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 front_insert_iterator& operator=(typename _Container::value_type&& __value_)
834e4383379SHoward Hinnant        {container->push_front(_VSTD::move(__value_)); return *this;}
835046492b9SEric Fiselier#endif // _LIBCPP_CXX03_LANG
83606e2b737SArthur O'Dwyer    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 front_insert_iterator& operator*()     {return *this;}
83706e2b737SArthur O'Dwyer    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 front_insert_iterator& operator++()    {return *this;}
83806e2b737SArthur O'Dwyer    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 front_insert_iterator  operator++(int) {return *this;}
8393e519524SHoward Hinnant};
8403e519524SHoward Hinnant
8413e519524SHoward Hinnanttemplate <class _Container>
84206e2b737SArthur O'Dwyerinline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
8433e519524SHoward Hinnantfront_insert_iterator<_Container>
8443e519524SHoward Hinnantfront_inserter(_Container& __x)
8453e519524SHoward Hinnant{
8463e519524SHoward Hinnant    return front_insert_iterator<_Container>(__x);
8473e519524SHoward Hinnant}
8483e519524SHoward Hinnant
8493e519524SHoward Hinnanttemplate <class _Container>
850e2f2d1edSEric Fiselierclass _LIBCPP_TEMPLATE_VIS insert_iterator
8513e519524SHoward Hinnant    : public iterator<output_iterator_tag,
8523e519524SHoward Hinnant                      void,
8533e519524SHoward Hinnant                      void,
8543e519524SHoward Hinnant                      void,
8558892b4eeSEric Fiselier                      void>
8563e519524SHoward Hinnant{
8573e519524SHoward Hinnantprotected:
8583e519524SHoward Hinnant    _Container* container;
8593e519524SHoward Hinnant    typename _Container::iterator iter;
8603e519524SHoward Hinnantpublic:
8613e519524SHoward Hinnant    typedef _Container container_type;
8623e519524SHoward Hinnant
86306e2b737SArthur O'Dwyer    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 insert_iterator(_Container& __x, typename _Container::iterator __i)
864f519be34SMarshall Clow        : container(_VSTD::addressof(__x)), iter(__i) {}
86506e2b737SArthur O'Dwyer    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 insert_iterator& operator=(const typename _Container::value_type& __value_)
866e4383379SHoward Hinnant        {iter = container->insert(iter, __value_); ++iter; return *this;}
867046492b9SEric Fiselier#ifndef _LIBCPP_CXX03_LANG
86806e2b737SArthur O'Dwyer    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 insert_iterator& operator=(typename _Container::value_type&& __value_)
869e4383379SHoward Hinnant        {iter = container->insert(iter, _VSTD::move(__value_)); ++iter; return *this;}
870046492b9SEric Fiselier#endif // _LIBCPP_CXX03_LANG
87106e2b737SArthur O'Dwyer    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 insert_iterator& operator*()        {return *this;}
87206e2b737SArthur O'Dwyer    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 insert_iterator& operator++()       {return *this;}
87306e2b737SArthur O'Dwyer    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 insert_iterator& operator++(int)    {return *this;}
8743e519524SHoward Hinnant};
8753e519524SHoward Hinnant
8763e519524SHoward Hinnanttemplate <class _Container>
87706e2b737SArthur O'Dwyerinline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
8783e519524SHoward Hinnantinsert_iterator<_Container>
8793e519524SHoward Hinnantinserter(_Container& __x, typename _Container::iterator __i)
8803e519524SHoward Hinnant{
8813e519524SHoward Hinnant    return insert_iterator<_Container>(__x, __i);
8823e519524SHoward Hinnant}
8833e519524SHoward Hinnant
8843e519524SHoward Hinnanttemplate <class _Tp, class _CharT = char,
8853e519524SHoward Hinnant          class _Traits = char_traits<_CharT>, class _Distance = ptrdiff_t>
886e2f2d1edSEric Fiselierclass _LIBCPP_TEMPLATE_VIS istream_iterator
8873e519524SHoward Hinnant    : public iterator<input_iterator_tag, _Tp, _Distance, const _Tp*, const _Tp&>
8883e519524SHoward Hinnant{
8893e519524SHoward Hinnantpublic:
8903e519524SHoward Hinnant    typedef _CharT char_type;
8913e519524SHoward Hinnant    typedef _Traits traits_type;
8923e519524SHoward Hinnant    typedef basic_istream<_CharT,_Traits> istream_type;
8933e519524SHoward Hinnantprivate:
8943e519524SHoward Hinnant    istream_type* __in_stream_;
8953e519524SHoward Hinnant    _Tp __value_;
8963e519524SHoward Hinnantpublic:
897527a7fdfSBruce Mitchener    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR istream_iterator() : __in_stream_(nullptr), __value_() {}
898bc6a7df0SMarshall Clow    _LIBCPP_INLINE_VISIBILITY istream_iterator(istream_type& __s) : __in_stream_(_VSTD::addressof(__s))
8993e519524SHoward Hinnant        {
9003e519524SHoward Hinnant            if (!(*__in_stream_ >> __value_))
901527a7fdfSBruce Mitchener                __in_stream_ = nullptr;
9023e519524SHoward Hinnant        }
9033e519524SHoward Hinnant
9043e519524SHoward Hinnant    _LIBCPP_INLINE_VISIBILITY const _Tp& operator*() const {return __value_;}
905bc6a7df0SMarshall Clow    _LIBCPP_INLINE_VISIBILITY const _Tp* operator->() const {return _VSTD::addressof((operator*()));}
9063e519524SHoward Hinnant    _LIBCPP_INLINE_VISIBILITY istream_iterator& operator++()
9073e519524SHoward Hinnant        {
9083e519524SHoward Hinnant            if (!(*__in_stream_ >> __value_))
909527a7fdfSBruce Mitchener                __in_stream_ = nullptr;
9103e519524SHoward Hinnant            return *this;
9113e519524SHoward Hinnant        }
9123e519524SHoward Hinnant    _LIBCPP_INLINE_VISIBILITY istream_iterator  operator++(int)
9133e519524SHoward Hinnant        {istream_iterator __t(*this); ++(*this); return __t;}
9143e519524SHoward Hinnant
9156f56d3eeSRoger Ferrer Ibanez    template <class _Up, class _CharU, class _TraitsU, class _DistanceU>
9163e519524SHoward Hinnant    friend _LIBCPP_INLINE_VISIBILITY
9176f56d3eeSRoger Ferrer Ibanez    bool
9186f56d3eeSRoger Ferrer Ibanez    operator==(const istream_iterator<_Up, _CharU, _TraitsU, _DistanceU>& __x,
9196f56d3eeSRoger Ferrer Ibanez               const istream_iterator<_Up, _CharU, _TraitsU, _DistanceU>& __y);
9203e519524SHoward Hinnant
9216f56d3eeSRoger Ferrer Ibanez    template <class _Up, class _CharU, class _TraitsU, class _DistanceU>
9223e519524SHoward Hinnant    friend _LIBCPP_INLINE_VISIBILITY
9236f56d3eeSRoger Ferrer Ibanez    bool
9246f56d3eeSRoger Ferrer Ibanez    operator==(const istream_iterator<_Up, _CharU, _TraitsU, _DistanceU>& __x,
9256f56d3eeSRoger Ferrer Ibanez               const istream_iterator<_Up, _CharU, _TraitsU, _DistanceU>& __y);
9263e519524SHoward Hinnant};
9273e519524SHoward Hinnant
9286f56d3eeSRoger Ferrer Ibaneztemplate <class _Tp, class _CharT, class _Traits, class _Distance>
9296f56d3eeSRoger Ferrer Ibanezinline _LIBCPP_INLINE_VISIBILITY
9306f56d3eeSRoger Ferrer Ibanezbool
9316f56d3eeSRoger Ferrer Ibanezoperator==(const istream_iterator<_Tp, _CharT, _Traits, _Distance>& __x,
9326f56d3eeSRoger Ferrer Ibanez           const istream_iterator<_Tp, _CharT, _Traits, _Distance>& __y)
9336f56d3eeSRoger Ferrer Ibanez{
9346f56d3eeSRoger Ferrer Ibanez    return __x.__in_stream_ == __y.__in_stream_;
9356f56d3eeSRoger Ferrer Ibanez}
9366f56d3eeSRoger Ferrer Ibanez
9376f56d3eeSRoger Ferrer Ibaneztemplate <class _Tp, class _CharT, class _Traits, class _Distance>
9386f56d3eeSRoger Ferrer Ibanezinline _LIBCPP_INLINE_VISIBILITY
9396f56d3eeSRoger Ferrer Ibanezbool
9406f56d3eeSRoger Ferrer Ibanezoperator!=(const istream_iterator<_Tp, _CharT, _Traits, _Distance>& __x,
9416f56d3eeSRoger Ferrer Ibanez           const istream_iterator<_Tp, _CharT, _Traits, _Distance>& __y)
9426f56d3eeSRoger Ferrer Ibanez{
9436f56d3eeSRoger Ferrer Ibanez    return !(__x == __y);
9446f56d3eeSRoger Ferrer Ibanez}
9456f56d3eeSRoger Ferrer Ibanez
9463e519524SHoward Hinnanttemplate <class _Tp, class _CharT = char, class _Traits = char_traits<_CharT> >
947e2f2d1edSEric Fiselierclass _LIBCPP_TEMPLATE_VIS ostream_iterator
9483e519524SHoward Hinnant    : public iterator<output_iterator_tag, void, void, void, void>
9493e519524SHoward Hinnant{
9503e519524SHoward Hinnantpublic:
95171a16e40SLouis Dionne    typedef output_iterator_tag             iterator_category;
95271a16e40SLouis Dionne    typedef void                            value_type;
95371a16e40SLouis Dionne#if _LIBCPP_STD_VER > 17
95471a16e40SLouis Dionne    typedef std::ptrdiff_t                  difference_type;
95571a16e40SLouis Dionne#else
95671a16e40SLouis Dionne    typedef void                            difference_type;
95771a16e40SLouis Dionne#endif
95871a16e40SLouis Dionne    typedef void                            pointer;
95971a16e40SLouis Dionne    typedef void                            reference;
9603e519524SHoward Hinnant    typedef _CharT                          char_type;
9613e519524SHoward Hinnant    typedef _Traits                         traits_type;
9623e519524SHoward Hinnant    typedef basic_ostream<_CharT, _Traits>  ostream_type;
96371a16e40SLouis Dionne
9643e519524SHoward Hinnantprivate:
9653e519524SHoward Hinnant    ostream_type* __out_stream_;
9663e519524SHoward Hinnant    const char_type* __delim_;
9673e519524SHoward Hinnantpublic:
968853042cfSMarshall Clow    _LIBCPP_INLINE_VISIBILITY ostream_iterator(ostream_type& __s) _NOEXCEPT
969527a7fdfSBruce Mitchener        : __out_stream_(_VSTD::addressof(__s)), __delim_(nullptr) {}
970853042cfSMarshall Clow    _LIBCPP_INLINE_VISIBILITY ostream_iterator(ostream_type& __s, const _CharT* __delimiter) _NOEXCEPT
971bc6a7df0SMarshall Clow        : __out_stream_(_VSTD::addressof(__s)), __delim_(__delimiter) {}
972e4383379SHoward Hinnant    _LIBCPP_INLINE_VISIBILITY ostream_iterator& operator=(const _Tp& __value_)
9733e519524SHoward Hinnant        {
974e4383379SHoward Hinnant            *__out_stream_ << __value_;
9753e519524SHoward Hinnant            if (__delim_)
9763e519524SHoward Hinnant                *__out_stream_ << __delim_;
9773e519524SHoward Hinnant            return *this;
9783e519524SHoward Hinnant        }
9793e519524SHoward Hinnant
9803e519524SHoward Hinnant    _LIBCPP_INLINE_VISIBILITY ostream_iterator& operator*()     {return *this;}
9813e519524SHoward Hinnant    _LIBCPP_INLINE_VISIBILITY ostream_iterator& operator++()    {return *this;}
9823e519524SHoward Hinnant    _LIBCPP_INLINE_VISIBILITY ostream_iterator& operator++(int) {return *this;}
9833e519524SHoward Hinnant};
9843e519524SHoward Hinnant
9853e519524SHoward Hinnanttemplate<class _CharT, class _Traits>
986e2f2d1edSEric Fiselierclass _LIBCPP_TEMPLATE_VIS istreambuf_iterator
9873e519524SHoward Hinnant    : public iterator<input_iterator_tag, _CharT,
9883e519524SHoward Hinnant                      typename _Traits::off_type, _CharT*,
9893e519524SHoward Hinnant                      _CharT>
9903e519524SHoward Hinnant{
9913e519524SHoward Hinnantpublic:
9923e519524SHoward Hinnant    typedef _CharT                          char_type;
9933e519524SHoward Hinnant    typedef _Traits                         traits_type;
9943e519524SHoward Hinnant    typedef typename _Traits::int_type      int_type;
9953e519524SHoward Hinnant    typedef basic_streambuf<_CharT,_Traits> streambuf_type;
9963e519524SHoward Hinnant    typedef basic_istream<_CharT,_Traits>   istream_type;
9973e519524SHoward Hinnantprivate:
998dfdf5085SHoward Hinnant    mutable streambuf_type* __sbuf_;
9993e519524SHoward Hinnant
10003e519524SHoward Hinnant    class __proxy
10013e519524SHoward Hinnant    {
10023e519524SHoward Hinnant        char_type __keep_;
10033e519524SHoward Hinnant        streambuf_type* __sbuf_;
10043e519524SHoward Hinnant        _LIBCPP_INLINE_VISIBILITY __proxy(char_type __c, streambuf_type* __s)
10053e519524SHoward Hinnant            : __keep_(__c), __sbuf_(__s) {}
10063e519524SHoward Hinnant        friend class istreambuf_iterator;
10073e519524SHoward Hinnant    public:
10083e519524SHoward Hinnant        _LIBCPP_INLINE_VISIBILITY char_type operator*() const {return __keep_;}
10093e519524SHoward Hinnant    };
10103e519524SHoward Hinnant
1011848a5374SHoward Hinnant    _LIBCPP_INLINE_VISIBILITY
1012dfdf5085SHoward Hinnant    bool __test_for_eof() const
10133e519524SHoward Hinnant    {
10143e519524SHoward Hinnant        if (__sbuf_ && traits_type::eq_int_type(__sbuf_->sgetc(), traits_type::eof()))
1015527a7fdfSBruce Mitchener            __sbuf_ = nullptr;
1016527a7fdfSBruce Mitchener        return __sbuf_ == nullptr;
10173e519524SHoward Hinnant    }
10183e519524SHoward Hinnantpublic:
1019527a7fdfSBruce Mitchener    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR istreambuf_iterator() _NOEXCEPT : __sbuf_(nullptr) {}
10208e882dcbSHoward Hinnant    _LIBCPP_INLINE_VISIBILITY istreambuf_iterator(istream_type& __s) _NOEXCEPT
1021a96d7458SHoward Hinnant        : __sbuf_(__s.rdbuf()) {}
10228e882dcbSHoward Hinnant    _LIBCPP_INLINE_VISIBILITY istreambuf_iterator(streambuf_type* __s) _NOEXCEPT
1023a96d7458SHoward Hinnant        : __sbuf_(__s) {}
10248e882dcbSHoward Hinnant    _LIBCPP_INLINE_VISIBILITY istreambuf_iterator(const __proxy& __p) _NOEXCEPT
10253e519524SHoward Hinnant        : __sbuf_(__p.__sbuf_) {}
10263e519524SHoward Hinnant
1027c206366fSHoward Hinnant    _LIBCPP_INLINE_VISIBILITY char_type  operator*() const
1028c206366fSHoward Hinnant        {return static_cast<char_type>(__sbuf_->sgetc());}
10293e519524SHoward Hinnant    _LIBCPP_INLINE_VISIBILITY istreambuf_iterator& operator++()
10303e519524SHoward Hinnant        {
1031dfdf5085SHoward Hinnant            __sbuf_->sbumpc();
10323e519524SHoward Hinnant            return *this;
10333e519524SHoward Hinnant        }
10343e519524SHoward Hinnant    _LIBCPP_INLINE_VISIBILITY __proxy              operator++(int)
10353e519524SHoward Hinnant        {
1036dfdf5085SHoward Hinnant            return __proxy(__sbuf_->sbumpc(), __sbuf_);
10373e519524SHoward Hinnant        }
10383e519524SHoward Hinnant
10393e519524SHoward Hinnant    _LIBCPP_INLINE_VISIBILITY bool equal(const istreambuf_iterator& __b) const
1040dfdf5085SHoward Hinnant        {return __test_for_eof() == __b.__test_for_eof();}
10413e519524SHoward Hinnant};
10423e519524SHoward Hinnant
10433e519524SHoward Hinnanttemplate <class _CharT, class _Traits>
10443e519524SHoward Hinnantinline _LIBCPP_INLINE_VISIBILITY
10453e519524SHoward Hinnantbool operator==(const istreambuf_iterator<_CharT,_Traits>& __a,
10463e519524SHoward Hinnant                const istreambuf_iterator<_CharT,_Traits>& __b)
10473e519524SHoward Hinnant                {return __a.equal(__b);}
10483e519524SHoward Hinnant
10493e519524SHoward Hinnanttemplate <class _CharT, class _Traits>
10503e519524SHoward Hinnantinline _LIBCPP_INLINE_VISIBILITY
10513e519524SHoward Hinnantbool operator!=(const istreambuf_iterator<_CharT,_Traits>& __a,
10523e519524SHoward Hinnant                const istreambuf_iterator<_CharT,_Traits>& __b)
10533e519524SHoward Hinnant                {return !__a.equal(__b);}
10543e519524SHoward Hinnant
10553e519524SHoward Hinnanttemplate <class _CharT, class _Traits>
1056e2f2d1edSEric Fiselierclass _LIBCPP_TEMPLATE_VIS ostreambuf_iterator
10573e519524SHoward Hinnant    : public iterator<output_iterator_tag, void, void, void, void>
10583e519524SHoward Hinnant{
10593e519524SHoward Hinnantpublic:
106071a16e40SLouis Dionne    typedef output_iterator_tag                 iterator_category;
106171a16e40SLouis Dionne    typedef void                                value_type;
106271a16e40SLouis Dionne#if _LIBCPP_STD_VER > 17
106371a16e40SLouis Dionne    typedef std::ptrdiff_t                      difference_type;
106471a16e40SLouis Dionne#else
106571a16e40SLouis Dionne    typedef void                                difference_type;
106671a16e40SLouis Dionne#endif
106771a16e40SLouis Dionne    typedef void                                pointer;
106871a16e40SLouis Dionne    typedef void                                reference;
10693e519524SHoward Hinnant    typedef _CharT                              char_type;
10703e519524SHoward Hinnant    typedef _Traits                             traits_type;
10713e519524SHoward Hinnant    typedef basic_streambuf<_CharT, _Traits>    streambuf_type;
10723e519524SHoward Hinnant    typedef basic_ostream<_CharT, _Traits>      ostream_type;
107371a16e40SLouis Dionne
10743e519524SHoward Hinnantprivate:
10753e519524SHoward Hinnant    streambuf_type* __sbuf_;
10763e519524SHoward Hinnantpublic:
10778e882dcbSHoward Hinnant    _LIBCPP_INLINE_VISIBILITY ostreambuf_iterator(ostream_type& __s) _NOEXCEPT
10783e519524SHoward Hinnant        : __sbuf_(__s.rdbuf()) {}
10798e882dcbSHoward Hinnant    _LIBCPP_INLINE_VISIBILITY ostreambuf_iterator(streambuf_type* __s) _NOEXCEPT
10803e519524SHoward Hinnant        : __sbuf_(__s) {}
10813e519524SHoward Hinnant    _LIBCPP_INLINE_VISIBILITY ostreambuf_iterator& operator=(_CharT __c)
10823e519524SHoward Hinnant        {
10833e519524SHoward Hinnant            if (__sbuf_ && traits_type::eq_int_type(__sbuf_->sputc(__c), traits_type::eof()))
1084527a7fdfSBruce Mitchener                __sbuf_ = nullptr;
10853e519524SHoward Hinnant            return *this;
10863e519524SHoward Hinnant        }
10873e519524SHoward Hinnant    _LIBCPP_INLINE_VISIBILITY ostreambuf_iterator& operator*()     {return *this;}
10883e519524SHoward Hinnant    _LIBCPP_INLINE_VISIBILITY ostreambuf_iterator& operator++()    {return *this;}
10893e519524SHoward Hinnant    _LIBCPP_INLINE_VISIBILITY ostreambuf_iterator& operator++(int) {return *this;}
1090527a7fdfSBruce Mitchener    _LIBCPP_INLINE_VISIBILITY bool failed() const _NOEXCEPT {return __sbuf_ == nullptr;}
109192b5940fSHoward Hinnant
109292b5940fSHoward Hinnant    template <class _Ch, class _Tr>
109392b5940fSHoward Hinnant    friend
109492b5940fSHoward Hinnant    _LIBCPP_HIDDEN
109592b5940fSHoward Hinnant    ostreambuf_iterator<_Ch, _Tr>
109692b5940fSHoward Hinnant    __pad_and_output(ostreambuf_iterator<_Ch, _Tr> __s,
109792b5940fSHoward Hinnant                     const _Ch* __ob, const _Ch* __op, const _Ch* __oe,
109892b5940fSHoward Hinnant                     ios_base& __iob, _Ch __fl);
10993e519524SHoward Hinnant};
11003e519524SHoward Hinnant
11013e519524SHoward Hinnanttemplate <class _Iter>
1102e2f2d1edSEric Fiselierclass _LIBCPP_TEMPLATE_VIS move_iterator
11033e519524SHoward Hinnant{
11043e519524SHoward Hinnantprivate:
11053e519524SHoward Hinnant    _Iter __i;
11063e519524SHoward Hinnantpublic:
11073e519524SHoward Hinnant    typedef _Iter                                            iterator_type;
11083e519524SHoward Hinnant    typedef typename iterator_traits<iterator_type>::value_type value_type;
11093e519524SHoward Hinnant    typedef typename iterator_traits<iterator_type>::difference_type difference_type;
111005333fc8SMarshall Clow    typedef iterator_type pointer;
1111d41c6d51SArthur O'Dwyer    typedef _If<__is_cpp17_random_access_iterator<_Iter>::value,
1112d41c6d51SArthur O'Dwyer        random_access_iterator_tag,
1113d41c6d51SArthur O'Dwyer        typename iterator_traits<_Iter>::iterator_category>  iterator_category;
1114d41c6d51SArthur O'Dwyer#if _LIBCPP_STD_VER > 17
1115d41c6d51SArthur O'Dwyer    typedef input_iterator_tag                               iterator_concept;
1116d41c6d51SArthur O'Dwyer#endif
1117d41c6d51SArthur O'Dwyer
1118046492b9SEric Fiselier#ifndef _LIBCPP_CXX03_LANG
1119906c5085SEric Fiselier    typedef typename iterator_traits<iterator_type>::reference __reference;
1120906c5085SEric Fiselier    typedef typename conditional<
1121906c5085SEric Fiselier            is_reference<__reference>::value,
1122906c5085SEric Fiselier            typename remove_reference<__reference>::type&&,
1123906c5085SEric Fiselier            __reference
1124906c5085SEric Fiselier        >::type reference;
11253e519524SHoward Hinnant#else
11263e519524SHoward Hinnant    typedef typename iterator_traits<iterator_type>::reference reference;
11273e519524SHoward Hinnant#endif
11283e519524SHoward Hinnant
1129720ef472SMarshall Clow    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
1130720ef472SMarshall Clow    move_iterator() : __i() {}
1131720ef472SMarshall Clow    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
1132720ef472SMarshall Clow    explicit move_iterator(_Iter __x) : __i(__x) {}
1133720ef472SMarshall Clow    template <class _Up>
1134720ef472SMarshall Clow      _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
1135720ef472SMarshall Clow      move_iterator(const move_iterator<_Up>& __u) : __i(__u.base()) {}
1136720ef472SMarshall Clow    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 _Iter base() const {return __i;}
1137720ef472SMarshall Clow    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
1138720ef472SMarshall Clow    reference operator*() const { return static_cast<reference>(*__i); }
1139720ef472SMarshall Clow    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
1140720ef472SMarshall Clow    pointer  operator->() const { return __i;}
1141720ef472SMarshall Clow    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
1142720ef472SMarshall Clow    move_iterator& operator++() {++__i; return *this;}
1143720ef472SMarshall Clow    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
1144720ef472SMarshall Clow    move_iterator  operator++(int) {move_iterator __tmp(*this); ++__i; return __tmp;}
1145720ef472SMarshall Clow    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
1146720ef472SMarshall Clow    move_iterator& operator--() {--__i; return *this;}
1147720ef472SMarshall Clow    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
1148720ef472SMarshall Clow    move_iterator  operator--(int) {move_iterator __tmp(*this); --__i; return __tmp;}
1149720ef472SMarshall Clow    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
1150720ef472SMarshall Clow    move_iterator  operator+ (difference_type __n) const {return move_iterator(__i + __n);}
1151720ef472SMarshall Clow    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
1152720ef472SMarshall Clow    move_iterator& operator+=(difference_type __n) {__i += __n; return *this;}
1153720ef472SMarshall Clow    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
1154720ef472SMarshall Clow    move_iterator  operator- (difference_type __n) const {return move_iterator(__i - __n);}
1155720ef472SMarshall Clow    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
1156720ef472SMarshall Clow    move_iterator& operator-=(difference_type __n) {__i -= __n; return *this;}
1157720ef472SMarshall Clow    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
1158720ef472SMarshall Clow    reference operator[](difference_type __n) const { return static_cast<reference>(__i[__n]); }
11593e519524SHoward Hinnant};
11603e519524SHoward Hinnant
11613e519524SHoward Hinnanttemplate <class _Iter1, class _Iter2>
1162720ef472SMarshall Clowinline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
11633e519524SHoward Hinnantbool
11643e519524SHoward Hinnantoperator==(const move_iterator<_Iter1>& __x, const move_iterator<_Iter2>& __y)
11653e519524SHoward Hinnant{
11663e519524SHoward Hinnant    return __x.base() == __y.base();
11673e519524SHoward Hinnant}
11683e519524SHoward Hinnant
11693e519524SHoward Hinnanttemplate <class _Iter1, class _Iter2>
1170720ef472SMarshall Clowinline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
11713e519524SHoward Hinnantbool
11723e519524SHoward Hinnantoperator<(const move_iterator<_Iter1>& __x, const move_iterator<_Iter2>& __y)
11733e519524SHoward Hinnant{
11743e519524SHoward Hinnant    return __x.base() < __y.base();
11753e519524SHoward Hinnant}
11763e519524SHoward Hinnant
11773e519524SHoward Hinnanttemplate <class _Iter1, class _Iter2>
1178720ef472SMarshall Clowinline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
11793e519524SHoward Hinnantbool
11803e519524SHoward Hinnantoperator!=(const move_iterator<_Iter1>& __x, const move_iterator<_Iter2>& __y)
11813e519524SHoward Hinnant{
11823e519524SHoward Hinnant    return __x.base() != __y.base();
11833e519524SHoward Hinnant}
11843e519524SHoward Hinnant
11853e519524SHoward Hinnanttemplate <class _Iter1, class _Iter2>
1186720ef472SMarshall Clowinline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
11873e519524SHoward Hinnantbool
11883e519524SHoward Hinnantoperator>(const move_iterator<_Iter1>& __x, const move_iterator<_Iter2>& __y)
11893e519524SHoward Hinnant{
11903e519524SHoward Hinnant    return __x.base() > __y.base();
11913e519524SHoward Hinnant}
11923e519524SHoward Hinnant
11933e519524SHoward Hinnanttemplate <class _Iter1, class _Iter2>
1194720ef472SMarshall Clowinline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
11953e519524SHoward Hinnantbool
11963e519524SHoward Hinnantoperator>=(const move_iterator<_Iter1>& __x, const move_iterator<_Iter2>& __y)
11973e519524SHoward Hinnant{
11983e519524SHoward Hinnant    return __x.base() >= __y.base();
11993e519524SHoward Hinnant}
12003e519524SHoward Hinnant
12013e519524SHoward Hinnanttemplate <class _Iter1, class _Iter2>
1202720ef472SMarshall Clowinline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
12033e519524SHoward Hinnantbool
12043e519524SHoward Hinnantoperator<=(const move_iterator<_Iter1>& __x, const move_iterator<_Iter2>& __y)
12053e519524SHoward Hinnant{
12063e519524SHoward Hinnant    return __x.base() <= __y.base();
12073e519524SHoward Hinnant}
12083e519524SHoward Hinnant
12092ee83725SMarshall Clow#ifndef _LIBCPP_CXX03_LANG
1210947ce6b5SMarshall Clowtemplate <class _Iter1, class _Iter2>
1211720ef472SMarshall Clowinline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
1212947ce6b5SMarshall Clowauto
1213947ce6b5SMarshall Clowoperator-(const move_iterator<_Iter1>& __x, const move_iterator<_Iter2>& __y)
1214947ce6b5SMarshall Clow-> decltype(__x.base() - __y.base())
1215947ce6b5SMarshall Clow{
1216947ce6b5SMarshall Clow    return __x.base() - __y.base();
1217947ce6b5SMarshall Clow}
1218947ce6b5SMarshall Clow#else
12193e519524SHoward Hinnanttemplate <class _Iter1, class _Iter2>
12203e519524SHoward Hinnantinline _LIBCPP_INLINE_VISIBILITY
12213e519524SHoward Hinnanttypename move_iterator<_Iter1>::difference_type
12223e519524SHoward Hinnantoperator-(const move_iterator<_Iter1>& __x, const move_iterator<_Iter2>& __y)
12233e519524SHoward Hinnant{
12243e519524SHoward Hinnant    return __x.base() - __y.base();
12253e519524SHoward Hinnant}
1226947ce6b5SMarshall Clow#endif
12273e519524SHoward Hinnant
12283e519524SHoward Hinnanttemplate <class _Iter>
1229720ef472SMarshall Clowinline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
12303e519524SHoward Hinnantmove_iterator<_Iter>
12313e519524SHoward Hinnantoperator+(typename move_iterator<_Iter>::difference_type __n, const move_iterator<_Iter>& __x)
12323e519524SHoward Hinnant{
12333e519524SHoward Hinnant    return move_iterator<_Iter>(__x.base() + __n);
12343e519524SHoward Hinnant}
12353e519524SHoward Hinnant
12363e519524SHoward Hinnanttemplate <class _Iter>
1237720ef472SMarshall Clowinline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
12383e519524SHoward Hinnantmove_iterator<_Iter>
123954c83368SMarshall Clowmake_move_iterator(_Iter __i)
12403e519524SHoward Hinnant{
12413e519524SHoward Hinnant    return move_iterator<_Iter>(__i);
12423e519524SHoward Hinnant}
12433e519524SHoward Hinnant
12443e519524SHoward Hinnant// __wrap_iter
12453e519524SHoward Hinnant
12463e519524SHoward Hinnanttemplate <class _Iter> class __wrap_iter;
12473e519524SHoward Hinnant
12483e519524SHoward Hinnanttemplate <class _Iter1, class _Iter2>
12499cad5025SMarshall Clow_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG
12503e519524SHoward Hinnantbool
125161b302f9SEric Fiselieroperator==(const __wrap_iter<_Iter1>&, const __wrap_iter<_Iter2>&) _NOEXCEPT;
12523e519524SHoward Hinnant
12533e519524SHoward Hinnanttemplate <class _Iter1, class _Iter2>
12549cad5025SMarshall Clow_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG
12553e519524SHoward Hinnantbool
125661b302f9SEric Fiselieroperator<(const __wrap_iter<_Iter1>&, const __wrap_iter<_Iter2>&) _NOEXCEPT;
12573e519524SHoward Hinnant
12583e519524SHoward Hinnanttemplate <class _Iter1, class _Iter2>
12599cad5025SMarshall Clow_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG
12603e519524SHoward Hinnantbool
126161b302f9SEric Fiselieroperator!=(const __wrap_iter<_Iter1>&, const __wrap_iter<_Iter2>&) _NOEXCEPT;
12623e519524SHoward Hinnant
12633e519524SHoward Hinnanttemplate <class _Iter1, class _Iter2>
12649cad5025SMarshall Clow_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG
12653e519524SHoward Hinnantbool
126661b302f9SEric Fiselieroperator>(const __wrap_iter<_Iter1>&, const __wrap_iter<_Iter2>&) _NOEXCEPT;
12673e519524SHoward Hinnant
12683e519524SHoward Hinnanttemplate <class _Iter1, class _Iter2>
12699cad5025SMarshall Clow_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG
12703e519524SHoward Hinnantbool
127161b302f9SEric Fiselieroperator>=(const __wrap_iter<_Iter1>&, const __wrap_iter<_Iter2>&) _NOEXCEPT;
12723e519524SHoward Hinnant
12733e519524SHoward Hinnanttemplate <class _Iter1, class _Iter2>
12749cad5025SMarshall Clow_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG
12753e519524SHoward Hinnantbool
127661b302f9SEric Fiselieroperator<=(const __wrap_iter<_Iter1>&, const __wrap_iter<_Iter2>&) _NOEXCEPT;
12773e519524SHoward Hinnant
12782ee83725SMarshall Clow#ifndef _LIBCPP_CXX03_LANG
1279947ce6b5SMarshall Clowtemplate <class _Iter1, class _Iter2>
12809cad5025SMarshall Clow_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG
1281947ce6b5SMarshall Clowauto
128261b302f9SEric Fiselieroperator-(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter2>& __y) _NOEXCEPT
1283947ce6b5SMarshall Clow-> decltype(__x.base() - __y.base());
1284947ce6b5SMarshall Clow#else
12853e519524SHoward Hinnanttemplate <class _Iter1, class _Iter2>
1286aeb85680SHoward Hinnant_LIBCPP_INLINE_VISIBILITY
12873e519524SHoward Hinnanttypename __wrap_iter<_Iter1>::difference_type
128861b302f9SEric Fiselieroperator-(const __wrap_iter<_Iter1>&, const __wrap_iter<_Iter2>&) _NOEXCEPT;
1289947ce6b5SMarshall Clow#endif
12903e519524SHoward Hinnant
12913e519524SHoward Hinnanttemplate <class _Iter>
12929cad5025SMarshall Clow_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG
12933e519524SHoward Hinnant__wrap_iter<_Iter>
129461b302f9SEric Fiselieroperator+(typename __wrap_iter<_Iter>::difference_type, __wrap_iter<_Iter>) _NOEXCEPT;
12953e519524SHoward Hinnant
129613c90a57SLouis Dionnetemplate <class _Ip, class _Op> _Op _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 copy(_Ip, _Ip, _Op);
129713c90a57SLouis Dionnetemplate <class _B1, class _B2> _B2 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 copy_backward(_B1, _B1, _B2);
12983ed89b51Szoecarvertemplate <class _Ip, class _Op> _Op _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 move(_Ip, _Ip, _Op);
12993ed89b51Szoecarvertemplate <class _B1, class _B2> _B2 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 move_backward(_B1, _B1, _B2);
13003e519524SHoward Hinnant
13013e519524SHoward Hinnanttemplate <class _Iter>
13023e519524SHoward Hinnantclass __wrap_iter
13033e519524SHoward Hinnant{
13043e519524SHoward Hinnantpublic:
13053e519524SHoward Hinnant    typedef _Iter                                                      iterator_type;
13063e519524SHoward Hinnant    typedef typename iterator_traits<iterator_type>::value_type        value_type;
13073e519524SHoward Hinnant    typedef typename iterator_traits<iterator_type>::difference_type   difference_type;
13083e519524SHoward Hinnant    typedef typename iterator_traits<iterator_type>::pointer           pointer;
13093e519524SHoward Hinnant    typedef typename iterator_traits<iterator_type>::reference         reference;
1310d41c6d51SArthur O'Dwyer    typedef typename iterator_traits<iterator_type>::iterator_category iterator_category;
1311d41c6d51SArthur O'Dwyer#if _LIBCPP_STD_VER > 17
1312fc924887SArthur O'Dwyer    typedef contiguous_iterator_tag                                    iterator_concept;
1313d41c6d51SArthur O'Dwyer#endif
1314d41c6d51SArthur O'Dwyer
13153e519524SHoward Hinnantprivate:
13163e519524SHoward Hinnant    iterator_type __i;
13173e519524SHoward Hinnantpublic:
131861b302f9SEric Fiselier    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG __wrap_iter() _NOEXCEPT
131907186a7dSMarshall Clow#if _LIBCPP_STD_VER > 11
132007186a7dSMarshall Clow                : __i{}
132107186a7dSMarshall Clow#endif
1322c36bfc49SHoward Hinnant    {
132331e82037SLouis Dionne#if _LIBCPP_DEBUG_LEVEL == 2
1324c36bfc49SHoward Hinnant        __get_db()->__insert_i(this);
1325c36bfc49SHoward Hinnant#endif
1326c36bfc49SHoward Hinnant    }
13279cad5025SMarshall Clow    template <class _Up> _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG
13289cad5025SMarshall Clow        __wrap_iter(const __wrap_iter<_Up>& __u,
1329527a7fdfSBruce Mitchener            typename enable_if<is_convertible<_Up, iterator_type>::value>::type* = nullptr) _NOEXCEPT
1330f554add5SHoward Hinnant            : __i(__u.base())
1331f554add5SHoward Hinnant    {
133231e82037SLouis Dionne#if _LIBCPP_DEBUG_LEVEL == 2
1333f554add5SHoward Hinnant        __get_db()->__iterator_copy(this, &__u);
1334f554add5SHoward Hinnant#endif
1335f554add5SHoward Hinnant    }
133631e82037SLouis Dionne#if _LIBCPP_DEBUG_LEVEL == 2
13379cad5025SMarshall Clow    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG
1338f554add5SHoward Hinnant    __wrap_iter(const __wrap_iter& __x)
1339f554add5SHoward Hinnant        : __i(__x.base())
1340f554add5SHoward Hinnant    {
1341f554add5SHoward Hinnant        __get_db()->__iterator_copy(this, &__x);
1342f554add5SHoward Hinnant    }
13439cad5025SMarshall Clow    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG
1344f554add5SHoward Hinnant    __wrap_iter& operator=(const __wrap_iter& __x)
1345f554add5SHoward Hinnant    {
1346f554add5SHoward Hinnant        if (this != &__x)
1347f554add5SHoward Hinnant        {
1348f554add5SHoward Hinnant            __get_db()->__iterator_copy(this, &__x);
1349f554add5SHoward Hinnant            __i = __x.__i;
1350f554add5SHoward Hinnant        }
1351f554add5SHoward Hinnant        return *this;
1352f554add5SHoward Hinnant    }
13539cad5025SMarshall Clow    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG
1354f554add5SHoward Hinnant    ~__wrap_iter()
1355f554add5SHoward Hinnant    {
1356f554add5SHoward Hinnant        __get_db()->__erase_i(this);
1357f554add5SHoward Hinnant    }
1358f554add5SHoward Hinnant#endif
135961b302f9SEric Fiselier    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG reference operator*() const _NOEXCEPT
1360f554add5SHoward Hinnant    {
136131e82037SLouis Dionne#if _LIBCPP_DEBUG_LEVEL == 2
1362f554add5SHoward Hinnant        _LIBCPP_ASSERT(__get_const_db()->__dereferenceable(this),
1363f554add5SHoward Hinnant                       "Attempted to dereference a non-dereferenceable iterator");
1364cec9af9eSHoward Hinnant#endif
1365f554add5SHoward Hinnant        return *__i;
1366f554add5SHoward Hinnant    }
136761b302f9SEric Fiselier    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG pointer  operator->() const _NOEXCEPT
13683ec1f00bSHoward Hinnant    {
136931e82037SLouis Dionne#if _LIBCPP_DEBUG_LEVEL == 2
13703ec1f00bSHoward Hinnant        _LIBCPP_ASSERT(__get_const_db()->__dereferenceable(this),
13713ec1f00bSHoward Hinnant                       "Attempted to dereference a non-dereferenceable iterator");
13723ec1f00bSHoward Hinnant#endif
1373fe0e86e6SLouis Dionne        return _VSTD::__to_address(__i);
13743ec1f00bSHoward Hinnant    }
137561b302f9SEric Fiselier    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG __wrap_iter& operator++() _NOEXCEPT
1376f554add5SHoward Hinnant    {
137731e82037SLouis Dionne#if _LIBCPP_DEBUG_LEVEL == 2
1378f554add5SHoward Hinnant        _LIBCPP_ASSERT(__get_const_db()->__dereferenceable(this),
137996100f15SKristina Bessonova                       "Attempted to increment a non-incrementable iterator");
1380cec9af9eSHoward Hinnant#endif
1381f554add5SHoward Hinnant        ++__i;
1382f554add5SHoward Hinnant        return *this;
1383f554add5SHoward Hinnant    }
138461b302f9SEric Fiselier    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG __wrap_iter  operator++(int) _NOEXCEPT
1385f554add5SHoward Hinnant        {__wrap_iter __tmp(*this); ++(*this); return __tmp;}
13864ce0a916SMarshall Clow
138761b302f9SEric Fiselier    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG __wrap_iter& operator--() _NOEXCEPT
1388f554add5SHoward Hinnant    {
138931e82037SLouis Dionne#if _LIBCPP_DEBUG_LEVEL == 2
1390f554add5SHoward Hinnant        _LIBCPP_ASSERT(__get_const_db()->__decrementable(this),
139196100f15SKristina Bessonova                       "Attempted to decrement a non-decrementable iterator");
1392cec9af9eSHoward Hinnant#endif
1393f554add5SHoward Hinnant        --__i;
1394f554add5SHoward Hinnant        return *this;
1395f554add5SHoward Hinnant    }
139661b302f9SEric Fiselier    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG __wrap_iter  operator--(int) _NOEXCEPT
1397f554add5SHoward Hinnant        {__wrap_iter __tmp(*this); --(*this); return __tmp;}
139861b302f9SEric Fiselier    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG __wrap_iter  operator+ (difference_type __n) const _NOEXCEPT
1399f554add5SHoward Hinnant        {__wrap_iter __w(*this); __w += __n; return __w;}
140061b302f9SEric Fiselier    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG __wrap_iter& operator+=(difference_type __n) _NOEXCEPT
1401f554add5SHoward Hinnant    {
140231e82037SLouis Dionne#if _LIBCPP_DEBUG_LEVEL == 2
1403f554add5SHoward Hinnant        _LIBCPP_ASSERT(__get_const_db()->__addable(this, __n),
140496100f15SKristina Bessonova                   "Attempted to add/subtract an iterator outside its valid range");
1405cec9af9eSHoward Hinnant#endif
1406f554add5SHoward Hinnant        __i += __n;
1407f554add5SHoward Hinnant        return *this;
1408f554add5SHoward Hinnant    }
140961b302f9SEric Fiselier    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG __wrap_iter  operator- (difference_type __n) const _NOEXCEPT
1410f554add5SHoward Hinnant        {return *this + (-__n);}
141161b302f9SEric Fiselier    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG __wrap_iter& operator-=(difference_type __n) _NOEXCEPT
1412f554add5SHoward Hinnant        {*this += -__n; return *this;}
141361b302f9SEric Fiselier    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG reference    operator[](difference_type __n) const _NOEXCEPT
1414f554add5SHoward Hinnant    {
141531e82037SLouis Dionne#if _LIBCPP_DEBUG_LEVEL == 2
1416f554add5SHoward Hinnant        _LIBCPP_ASSERT(__get_const_db()->__subscriptable(this, __n),
141796100f15SKristina Bessonova                   "Attempted to subscript an iterator outside its valid range");
1418cec9af9eSHoward Hinnant#endif
1419f554add5SHoward Hinnant        return __i[__n];
1420f554add5SHoward Hinnant    }
14213e519524SHoward Hinnant
142261b302f9SEric Fiselier    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG iterator_type base() const _NOEXCEPT {return __i;}
14233e519524SHoward Hinnant
14243e519524SHoward Hinnantprivate:
142531e82037SLouis Dionne#if _LIBCPP_DEBUG_LEVEL == 2
14269cad5025SMarshall Clow    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG __wrap_iter(const void* __p, iterator_type __x) : __i(__x)
1427f554add5SHoward Hinnant    {
1428f554add5SHoward Hinnant        __get_db()->__insert_ic(this, __p);
1429f554add5SHoward Hinnant    }
1430fc88dbd2SHoward Hinnant#else
143161b302f9SEric Fiselier    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG __wrap_iter(iterator_type __x) _NOEXCEPT : __i(__x) {}
1432f554add5SHoward Hinnant#endif
14333e519524SHoward Hinnant
14343e519524SHoward Hinnant    template <class _Up> friend class __wrap_iter;
14353e519524SHoward Hinnant    template <class _CharT, class _Traits, class _Alloc> friend class basic_string;
1436e2f2d1edSEric Fiselier    template <class _Tp, class _Alloc> friend class _LIBCPP_TEMPLATE_VIS vector;
14377ad06a93SMarshall Clow    template <class _Tp, size_t> friend class _LIBCPP_TEMPLATE_VIS span;
14383e519524SHoward Hinnant
14393e519524SHoward Hinnant    template <class _Iter1, class _Iter2>
14409cad5025SMarshall Clow    _LIBCPP_CONSTEXPR_IF_NODEBUG friend
14413e519524SHoward Hinnant    bool
144261b302f9SEric Fiselier    operator==(const __wrap_iter<_Iter1>&, const __wrap_iter<_Iter2>&) _NOEXCEPT;
14433e519524SHoward Hinnant
14443e519524SHoward Hinnant    template <class _Iter1, class _Iter2>
14459cad5025SMarshall Clow    _LIBCPP_CONSTEXPR_IF_NODEBUG friend
14463e519524SHoward Hinnant    bool
144761b302f9SEric Fiselier    operator<(const __wrap_iter<_Iter1>&, const __wrap_iter<_Iter2>&) _NOEXCEPT;
14483e519524SHoward Hinnant
14493e519524SHoward Hinnant    template <class _Iter1, class _Iter2>
14509cad5025SMarshall Clow    _LIBCPP_CONSTEXPR_IF_NODEBUG friend
14513e519524SHoward Hinnant    bool
145261b302f9SEric Fiselier    operator!=(const __wrap_iter<_Iter1>&, const __wrap_iter<_Iter2>&) _NOEXCEPT;
14533e519524SHoward Hinnant
14543e519524SHoward Hinnant    template <class _Iter1, class _Iter2>
14559cad5025SMarshall Clow    _LIBCPP_CONSTEXPR_IF_NODEBUG friend
14563e519524SHoward Hinnant    bool
145761b302f9SEric Fiselier    operator>(const __wrap_iter<_Iter1>&, const __wrap_iter<_Iter2>&) _NOEXCEPT;
14583e519524SHoward Hinnant
14593e519524SHoward Hinnant    template <class _Iter1, class _Iter2>
14609cad5025SMarshall Clow    _LIBCPP_CONSTEXPR_IF_NODEBUG friend
14613e519524SHoward Hinnant    bool
146261b302f9SEric Fiselier    operator>=(const __wrap_iter<_Iter1>&, const __wrap_iter<_Iter2>&) _NOEXCEPT;
14633e519524SHoward Hinnant
14643e519524SHoward Hinnant    template <class _Iter1, class _Iter2>
14659cad5025SMarshall Clow    _LIBCPP_CONSTEXPR_IF_NODEBUG friend
14663e519524SHoward Hinnant    bool
146761b302f9SEric Fiselier    operator<=(const __wrap_iter<_Iter1>&, const __wrap_iter<_Iter2>&) _NOEXCEPT;
14683e519524SHoward Hinnant
14692ee83725SMarshall Clow#ifndef _LIBCPP_CXX03_LANG
1470947ce6b5SMarshall Clow    template <class _Iter1, class _Iter2>
14719cad5025SMarshall Clow    _LIBCPP_CONSTEXPR_IF_NODEBUG friend
1472947ce6b5SMarshall Clow    auto
147361b302f9SEric Fiselier    operator-(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter2>& __y) _NOEXCEPT
1474947ce6b5SMarshall Clow    -> decltype(__x.base() - __y.base());
1475947ce6b5SMarshall Clow#else
14763e519524SHoward Hinnant    template <class _Iter1, class _Iter2>
14779cad5025SMarshall Clow    _LIBCPP_CONSTEXPR_IF_NODEBUG friend
14783e519524SHoward Hinnant    typename __wrap_iter<_Iter1>::difference_type
147961b302f9SEric Fiselier    operator-(const __wrap_iter<_Iter1>&, const __wrap_iter<_Iter2>&) _NOEXCEPT;
1480947ce6b5SMarshall Clow#endif
14813e519524SHoward Hinnant
14823e519524SHoward Hinnant    template <class _Iter1>
14839cad5025SMarshall Clow    _LIBCPP_CONSTEXPR_IF_NODEBUG friend
14843e519524SHoward Hinnant    __wrap_iter<_Iter1>
148561b302f9SEric Fiselier    operator+(typename __wrap_iter<_Iter1>::difference_type, __wrap_iter<_Iter1>) _NOEXCEPT;
14863e519524SHoward Hinnant};
14873e519524SHoward Hinnant
1488d41c6d51SArthur O'Dwyer#if _LIBCPP_STD_VER <= 17
1489d41c6d51SArthur O'Dwyertemplate <class _It>
1490fc924887SArthur O'Dwyerstruct __is_cpp17_contiguous_iterator<__wrap_iter<_It> > : true_type {};
1491d41c6d51SArthur O'Dwyer#endif
1492d41c6d51SArthur O'Dwyer
1493d41c6d51SArthur O'Dwyertemplate <class _Iter>
1494d41c6d51SArthur O'Dwyer_LIBCPP_CONSTEXPR
1495fc924887SArthur O'Dwyerdecltype(_VSTD::__to_address(declval<_Iter>()))
1496d41c6d51SArthur O'Dwyer__to_address(__wrap_iter<_Iter> __w) _NOEXCEPT {
1497d41c6d51SArthur O'Dwyer    return _VSTD::__to_address(__w.base());
1498d41c6d51SArthur O'Dwyer}
1499d41c6d51SArthur O'Dwyer
15003e519524SHoward Hinnanttemplate <class _Iter1, class _Iter2>
15019cad5025SMarshall Clowinline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG
15023e519524SHoward Hinnantbool
150361b302f9SEric Fiselieroperator==(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter2>& __y) _NOEXCEPT
15043e519524SHoward Hinnant{
15053e519524SHoward Hinnant    return __x.base() == __y.base();
15063e519524SHoward Hinnant}
15073e519524SHoward Hinnant
15083e519524SHoward Hinnanttemplate <class _Iter1, class _Iter2>
15099cad5025SMarshall Clowinline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG
15103e519524SHoward Hinnantbool
151161b302f9SEric Fiselieroperator<(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter2>& __y) _NOEXCEPT
15123e519524SHoward Hinnant{
151331e82037SLouis Dionne#if _LIBCPP_DEBUG_LEVEL == 2
151442a3046eSHoward Hinnant    _LIBCPP_ASSERT(__get_const_db()->__less_than_comparable(&__x, &__y),
1515f554add5SHoward Hinnant                   "Attempted to compare incomparable iterators");
1516cec9af9eSHoward Hinnant#endif
15173e519524SHoward Hinnant    return __x.base() < __y.base();
15183e519524SHoward Hinnant}
15193e519524SHoward Hinnant
15203e519524SHoward Hinnanttemplate <class _Iter1, class _Iter2>
15219cad5025SMarshall Clowinline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG
15223e519524SHoward Hinnantbool
152361b302f9SEric Fiselieroperator!=(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter2>& __y) _NOEXCEPT
15243e519524SHoward Hinnant{
1525f554add5SHoward Hinnant    return !(__x == __y);
15263e519524SHoward Hinnant}
15273e519524SHoward Hinnant
15283e519524SHoward Hinnanttemplate <class _Iter1, class _Iter2>
15299cad5025SMarshall Clowinline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG
15303e519524SHoward Hinnantbool
153161b302f9SEric Fiselieroperator>(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter2>& __y) _NOEXCEPT
15323e519524SHoward Hinnant{
1533f554add5SHoward Hinnant    return __y < __x;
15343e519524SHoward Hinnant}
15353e519524SHoward Hinnant
15363e519524SHoward Hinnanttemplate <class _Iter1, class _Iter2>
15379cad5025SMarshall Clowinline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG
15383e519524SHoward Hinnantbool
153961b302f9SEric Fiselieroperator>=(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter2>& __y) _NOEXCEPT
15403e519524SHoward Hinnant{
1541f554add5SHoward Hinnant    return !(__x < __y);
15423e519524SHoward Hinnant}
15433e519524SHoward Hinnant
15443e519524SHoward Hinnanttemplate <class _Iter1, class _Iter2>
15459cad5025SMarshall Clowinline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG
15463e519524SHoward Hinnantbool
154761b302f9SEric Fiselieroperator<=(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter2>& __y) _NOEXCEPT
15483e519524SHoward Hinnant{
1549f554add5SHoward Hinnant    return !(__y < __x);
15503e519524SHoward Hinnant}
15513e519524SHoward Hinnant
15526e551ae1SHoward Hinnanttemplate <class _Iter1>
15539cad5025SMarshall Clowinline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG
15546e551ae1SHoward Hinnantbool
155561b302f9SEric Fiselieroperator!=(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter1>& __y) _NOEXCEPT
15566e551ae1SHoward Hinnant{
15576e551ae1SHoward Hinnant    return !(__x == __y);
15586e551ae1SHoward Hinnant}
15596e551ae1SHoward Hinnant
15606e551ae1SHoward Hinnanttemplate <class _Iter1>
15619cad5025SMarshall Clowinline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG
15626e551ae1SHoward Hinnantbool
156361b302f9SEric Fiselieroperator>(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter1>& __y) _NOEXCEPT
15646e551ae1SHoward Hinnant{
15656e551ae1SHoward Hinnant    return __y < __x;
15666e551ae1SHoward Hinnant}
15676e551ae1SHoward Hinnant
15686e551ae1SHoward Hinnanttemplate <class _Iter1>
15699cad5025SMarshall Clowinline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG
15706e551ae1SHoward Hinnantbool
157161b302f9SEric Fiselieroperator>=(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter1>& __y) _NOEXCEPT
15726e551ae1SHoward Hinnant{
15736e551ae1SHoward Hinnant    return !(__x < __y);
15746e551ae1SHoward Hinnant}
15756e551ae1SHoward Hinnant
15766e551ae1SHoward Hinnanttemplate <class _Iter1>
15779cad5025SMarshall Clowinline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG
15786e551ae1SHoward Hinnantbool
157961b302f9SEric Fiselieroperator<=(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter1>& __y) _NOEXCEPT
15806e551ae1SHoward Hinnant{
15816e551ae1SHoward Hinnant    return !(__y < __x);
15826e551ae1SHoward Hinnant}
15836e551ae1SHoward Hinnant
15842ee83725SMarshall Clow#ifndef _LIBCPP_CXX03_LANG
1585947ce6b5SMarshall Clowtemplate <class _Iter1, class _Iter2>
15869cad5025SMarshall Clowinline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG
1587947ce6b5SMarshall Clowauto
158861b302f9SEric Fiselieroperator-(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter2>& __y) _NOEXCEPT
1589947ce6b5SMarshall Clow-> decltype(__x.base() - __y.base())
1590947ce6b5SMarshall Clow{
159131e82037SLouis Dionne#if _LIBCPP_DEBUG_LEVEL == 2
1592947ce6b5SMarshall Clow    _LIBCPP_ASSERT(__get_const_db()->__less_than_comparable(&__x, &__y),
1593947ce6b5SMarshall Clow                   "Attempted to subtract incompatible iterators");
1594947ce6b5SMarshall Clow#endif
1595947ce6b5SMarshall Clow    return __x.base() - __y.base();
1596947ce6b5SMarshall Clow}
1597947ce6b5SMarshall Clow#else
15983e519524SHoward Hinnanttemplate <class _Iter1, class _Iter2>
15999cad5025SMarshall Clowinline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG
16003e519524SHoward Hinnanttypename __wrap_iter<_Iter1>::difference_type
160161b302f9SEric Fiselieroperator-(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter2>& __y) _NOEXCEPT
16023e519524SHoward Hinnant{
160331e82037SLouis Dionne#if _LIBCPP_DEBUG_LEVEL == 2
160442a3046eSHoward Hinnant    _LIBCPP_ASSERT(__get_const_db()->__less_than_comparable(&__x, &__y),
1605f554add5SHoward Hinnant                   "Attempted to subtract incompatible iterators");
1606cec9af9eSHoward Hinnant#endif
16073e519524SHoward Hinnant    return __x.base() - __y.base();
16083e519524SHoward Hinnant}
1609947ce6b5SMarshall Clow#endif
16103e519524SHoward Hinnant
16113e519524SHoward Hinnanttemplate <class _Iter>
16129cad5025SMarshall Clowinline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG
16133e519524SHoward Hinnant__wrap_iter<_Iter>
16143e519524SHoward Hinnantoperator+(typename __wrap_iter<_Iter>::difference_type __n,
161561b302f9SEric Fiselier          __wrap_iter<_Iter> __x) _NOEXCEPT
16163e519524SHoward Hinnant{
1617f554add5SHoward Hinnant    __x += __n;
1618f554add5SHoward Hinnant    return __x;
16193e519524SHoward Hinnant}
16203e519524SHoward Hinnant
16213772a46aSMarshall Clowtemplate <class _Tp, size_t _Np>
16222ffa1705SMarshall Clow_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
16233772a46aSMarshall Clow_Tp*
16243772a46aSMarshall Clowbegin(_Tp (&__array)[_Np])
16253772a46aSMarshall Clow{
16263772a46aSMarshall Clow    return __array;
16273772a46aSMarshall Clow}
16283772a46aSMarshall Clow
16293772a46aSMarshall Clowtemplate <class _Tp, size_t _Np>
16302ffa1705SMarshall Clow_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
16313772a46aSMarshall Clow_Tp*
16323772a46aSMarshall Clowend(_Tp (&__array)[_Np])
16333772a46aSMarshall Clow{
16343772a46aSMarshall Clow    return __array + _Np;
16353772a46aSMarshall Clow}
16363772a46aSMarshall Clow
163754613ab4SEric Fiselier#if !defined(_LIBCPP_CXX03_LANG)
1638c66a611bSMarshall Clow
1639c003db1fSHoward Hinnanttemplate <class _Cp>
16402ffa1705SMarshall Clow_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
16413e519524SHoward Hinnantauto
1642c003db1fSHoward Hinnantbegin(_Cp& __c) -> decltype(__c.begin())
16433e519524SHoward Hinnant{
16443e519524SHoward Hinnant    return __c.begin();
16453e519524SHoward Hinnant}
16463e519524SHoward Hinnant
1647c003db1fSHoward Hinnanttemplate <class _Cp>
16482ffa1705SMarshall Clow_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
16493e519524SHoward Hinnantauto
1650c003db1fSHoward Hinnantbegin(const _Cp& __c) -> decltype(__c.begin())
16513e519524SHoward Hinnant{
16523e519524SHoward Hinnant    return __c.begin();
16533e519524SHoward Hinnant}
16543e519524SHoward Hinnant
1655c003db1fSHoward Hinnanttemplate <class _Cp>
16562ffa1705SMarshall Clow_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
16573e519524SHoward Hinnantauto
1658c003db1fSHoward Hinnantend(_Cp& __c) -> decltype(__c.end())
16593e519524SHoward Hinnant{
16603e519524SHoward Hinnant    return __c.end();
16613e519524SHoward Hinnant}
16623e519524SHoward Hinnant
1663c003db1fSHoward Hinnanttemplate <class _Cp>
16642ffa1705SMarshall Clow_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
16653e519524SHoward Hinnantauto
1666c003db1fSHoward Hinnantend(const _Cp& __c) -> decltype(__c.end())
16673e519524SHoward Hinnant{
16683e519524SHoward Hinnant    return __c.end();
16693e519524SHoward Hinnant}
16703e519524SHoward Hinnant
16711e548c72SMarshall Clow#if _LIBCPP_STD_VER > 11
16721e548c72SMarshall Clow
16733772a46aSMarshall Clowtemplate <class _Tp, size_t _Np>
16742ffa1705SMarshall Clow_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
16753772a46aSMarshall Clowreverse_iterator<_Tp*> rbegin(_Tp (&__array)[_Np])
16763772a46aSMarshall Clow{
16773772a46aSMarshall Clow    return reverse_iterator<_Tp*>(__array + _Np);
16783772a46aSMarshall Clow}
16793772a46aSMarshall Clow
16803772a46aSMarshall Clowtemplate <class _Tp, size_t _Np>
16812ffa1705SMarshall Clow_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
16823772a46aSMarshall Clowreverse_iterator<_Tp*> rend(_Tp (&__array)[_Np])
16833772a46aSMarshall Clow{
16843772a46aSMarshall Clow    return reverse_iterator<_Tp*>(__array);
16853772a46aSMarshall Clow}
16863772a46aSMarshall Clow
16873772a46aSMarshall Clowtemplate <class _Ep>
16882ffa1705SMarshall Clow_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
16893772a46aSMarshall Clowreverse_iterator<const _Ep*> rbegin(initializer_list<_Ep> __il)
16903772a46aSMarshall Clow{
16913772a46aSMarshall Clow    return reverse_iterator<const _Ep*>(__il.end());
16923772a46aSMarshall Clow}
16933772a46aSMarshall Clow
16943772a46aSMarshall Clowtemplate <class _Ep>
16952ffa1705SMarshall Clow_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
16963772a46aSMarshall Clowreverse_iterator<const _Ep*> rend(initializer_list<_Ep> __il)
16973772a46aSMarshall Clow{
16983772a46aSMarshall Clow    return reverse_iterator<const _Ep*>(__il.begin());
16993772a46aSMarshall Clow}
17003772a46aSMarshall Clow
17011e548c72SMarshall Clowtemplate <class _Cp>
17022ffa1705SMarshall Clow_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
17037725546aSMarshall Clowauto cbegin(const _Cp& __c) -> decltype(_VSTD::begin(__c))
17041e548c72SMarshall Clow{
17057725546aSMarshall Clow    return _VSTD::begin(__c);
17061e548c72SMarshall Clow}
17071e548c72SMarshall Clow
17081e548c72SMarshall Clowtemplate <class _Cp>
17092ffa1705SMarshall Clow_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
17107725546aSMarshall Clowauto cend(const _Cp& __c) -> decltype(_VSTD::end(__c))
17111e548c72SMarshall Clow{
17127725546aSMarshall Clow    return _VSTD::end(__c);
17131e548c72SMarshall Clow}
17141e548c72SMarshall Clow
17151e548c72SMarshall Clowtemplate <class _Cp>
17162ffa1705SMarshall Clow_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
17171e548c72SMarshall Clowauto rbegin(_Cp& __c) -> decltype(__c.rbegin())
17181e548c72SMarshall Clow{
17191e548c72SMarshall Clow    return __c.rbegin();
17201e548c72SMarshall Clow}
17211e548c72SMarshall Clow
17221e548c72SMarshall Clowtemplate <class _Cp>
17232ffa1705SMarshall Clow_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
17241e548c72SMarshall Clowauto rbegin(const _Cp& __c) -> decltype(__c.rbegin())
17251e548c72SMarshall Clow{
17261e548c72SMarshall Clow    return __c.rbegin();
17271e548c72SMarshall Clow}
17281e548c72SMarshall Clow
17291e548c72SMarshall Clowtemplate <class _Cp>
17302ffa1705SMarshall Clow_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
17311e548c72SMarshall Clowauto rend(_Cp& __c) -> decltype(__c.rend())
17321e548c72SMarshall Clow{
17331e548c72SMarshall Clow    return __c.rend();
17341e548c72SMarshall Clow}
17351e548c72SMarshall Clow
17361e548c72SMarshall Clowtemplate <class _Cp>
17372ffa1705SMarshall Clow_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
17381e548c72SMarshall Clowauto rend(const _Cp& __c) -> decltype(__c.rend())
17391e548c72SMarshall Clow{
17401e548c72SMarshall Clow    return __c.rend();
17411e548c72SMarshall Clow}
17421e548c72SMarshall Clow
17431e548c72SMarshall Clowtemplate <class _Cp>
17442ffa1705SMarshall Clow_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
17457725546aSMarshall Clowauto crbegin(const _Cp& __c) -> decltype(_VSTD::rbegin(__c))
17461e548c72SMarshall Clow{
17477725546aSMarshall Clow    return _VSTD::rbegin(__c);
17481e548c72SMarshall Clow}
17491e548c72SMarshall Clow
17501e548c72SMarshall Clowtemplate <class _Cp>
17512ffa1705SMarshall Clow_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
17527725546aSMarshall Clowauto crend(const _Cp& __c) -> decltype(_VSTD::rend(__c))
17531e548c72SMarshall Clow{
17547725546aSMarshall Clow    return _VSTD::rend(__c);
17551e548c72SMarshall Clow}
17561e548c72SMarshall Clow
17571e548c72SMarshall Clow#endif
17581e548c72SMarshall Clow
17591e548c72SMarshall Clow
176054613ab4SEric Fiselier#else  // defined(_LIBCPP_CXX03_LANG)
17613e519524SHoward Hinnant
1762c003db1fSHoward Hinnanttemplate <class _Cp>
17632ffa1705SMarshall Clow_LIBCPP_INLINE_VISIBILITY
1764c003db1fSHoward Hinnanttypename _Cp::iterator
1765c003db1fSHoward Hinnantbegin(_Cp& __c)
17663e519524SHoward Hinnant{
17673e519524SHoward Hinnant    return __c.begin();
17683e519524SHoward Hinnant}
17693e519524SHoward Hinnant
1770c003db1fSHoward Hinnanttemplate <class _Cp>
17712ffa1705SMarshall Clow_LIBCPP_INLINE_VISIBILITY
1772c003db1fSHoward Hinnanttypename _Cp::const_iterator
1773c003db1fSHoward Hinnantbegin(const _Cp& __c)
17743e519524SHoward Hinnant{
17753e519524SHoward Hinnant    return __c.begin();
17763e519524SHoward Hinnant}
17773e519524SHoward Hinnant
1778c003db1fSHoward Hinnanttemplate <class _Cp>
17792ffa1705SMarshall Clow_LIBCPP_INLINE_VISIBILITY
1780c003db1fSHoward Hinnanttypename _Cp::iterator
1781c003db1fSHoward Hinnantend(_Cp& __c)
17823e519524SHoward Hinnant{
17833e519524SHoward Hinnant    return __c.end();
17843e519524SHoward Hinnant}
17853e519524SHoward Hinnant
1786c003db1fSHoward Hinnanttemplate <class _Cp>
17872ffa1705SMarshall Clow_LIBCPP_INLINE_VISIBILITY
1788c003db1fSHoward Hinnanttypename _Cp::const_iterator
1789c003db1fSHoward Hinnantend(const _Cp& __c)
17903e519524SHoward Hinnant{
17913e519524SHoward Hinnant    return __c.end();
17923e519524SHoward Hinnant}
17933e519524SHoward Hinnant
179454613ab4SEric Fiselier#endif // !defined(_LIBCPP_CXX03_LANG)
17953e519524SHoward Hinnant
1796ad755104SMarshall Clow#if _LIBCPP_STD_VER > 14
1797d1dcda19SMarshall Clow
1798d1dcda19SMarshall Clow// #if _LIBCPP_STD_VER > 11
1799d1dcda19SMarshall Clow// template <>
1800d1dcda19SMarshall Clow// struct _LIBCPP_TEMPLATE_VIS plus<void>
1801d1dcda19SMarshall Clow// {
1802d1dcda19SMarshall Clow//     template <class _T1, class _T2>
1803d1dcda19SMarshall Clow//     _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
1804d1dcda19SMarshall Clow//     auto operator()(_T1&& __t, _T2&& __u) const
1805d1dcda19SMarshall Clow//     _NOEXCEPT_(noexcept(_VSTD::forward<_T1>(__t) + _VSTD::forward<_T2>(__u)))
1806d1dcda19SMarshall Clow//     -> decltype        (_VSTD::forward<_T1>(__t) + _VSTD::forward<_T2>(__u))
1807d1dcda19SMarshall Clow//         { return        _VSTD::forward<_T1>(__t) + _VSTD::forward<_T2>(__u); }
1808d1dcda19SMarshall Clow//     typedef void is_transparent;
1809d1dcda19SMarshall Clow// };
1810d1dcda19SMarshall Clow// #endif
1811d1dcda19SMarshall Clow
181288d21343SMarshall Clowtemplate <class _Cont>
18132ffa1705SMarshall Clow_LIBCPP_INLINE_VISIBILITY
1814d1dcda19SMarshall Clowconstexpr auto size(const _Cont& __c)
1815d1dcda19SMarshall Clow_NOEXCEPT_(noexcept(__c.size()))
1816d1dcda19SMarshall Clow-> decltype        (__c.size())
1817d1dcda19SMarshall Clow{ return            __c.size(); }
1818ad755104SMarshall Clow
181988d21343SMarshall Clowtemplate <class _Tp, size_t _Sz>
18202ffa1705SMarshall Clow_LIBCPP_INLINE_VISIBILITY
1821fd838227SEric Fiselierconstexpr size_t size(const _Tp (&)[_Sz]) noexcept { return _Sz; }
1822ad755104SMarshall Clow
18237d3986eaSMarshall Clow#if _LIBCPP_STD_VER > 17
18247d3986eaSMarshall Clowtemplate <class _Cont>
18252ffa1705SMarshall Clow_LIBCPP_INLINE_VISIBILITY
18267d3986eaSMarshall Clowconstexpr auto ssize(const _Cont& __c)
18277d3986eaSMarshall Clow_NOEXCEPT_(noexcept(static_cast<common_type_t<ptrdiff_t, make_signed_t<decltype(__c.size())>>>(__c.size())))
18287d3986eaSMarshall Clow->                              common_type_t<ptrdiff_t, make_signed_t<decltype(__c.size())>>
18297d3986eaSMarshall Clow{ return            static_cast<common_type_t<ptrdiff_t, make_signed_t<decltype(__c.size())>>>(__c.size()); }
18307d3986eaSMarshall Clow
18317d3986eaSMarshall Clowtemplate <class _Tp, ptrdiff_t _Sz>
18322ffa1705SMarshall Clow_LIBCPP_INLINE_VISIBILITY
18337d3986eaSMarshall Clowconstexpr ptrdiff_t ssize(const _Tp (&)[_Sz]) noexcept { return _Sz; }
18347d3986eaSMarshall Clow#endif
18357d3986eaSMarshall Clow
183688d21343SMarshall Clowtemplate <class _Cont>
18372ffa1705SMarshall Clow_LIBCPP_NODISCARD_AFTER_CXX17 _LIBCPP_INLINE_VISIBILITY
1838d1dcda19SMarshall Clowconstexpr auto empty(const _Cont& __c)
1839d1dcda19SMarshall Clow_NOEXCEPT_(noexcept(__c.empty()))
1840d1dcda19SMarshall Clow-> decltype        (__c.empty())
1841d1dcda19SMarshall Clow{ return            __c.empty(); }
1842ad755104SMarshall Clow
184388d21343SMarshall Clowtemplate <class _Tp, size_t _Sz>
18442ffa1705SMarshall Clow_LIBCPP_NODISCARD_AFTER_CXX17 _LIBCPP_INLINE_VISIBILITY
1845fd838227SEric Fiselierconstexpr bool empty(const _Tp (&)[_Sz]) noexcept { return false; }
1846ad755104SMarshall Clow
1847ad755104SMarshall Clowtemplate <class _Ep>
18482ffa1705SMarshall Clow_LIBCPP_NODISCARD_AFTER_CXX17 _LIBCPP_INLINE_VISIBILITY
1849ad755104SMarshall Clowconstexpr bool empty(initializer_list<_Ep> __il) noexcept { return __il.size() == 0; }
1850ad755104SMarshall Clow
185188d21343SMarshall Clowtemplate <class _Cont> constexpr
18522ffa1705SMarshall Clow_LIBCPP_INLINE_VISIBILITY
1853d1dcda19SMarshall Clowauto data(_Cont& __c)
1854d1dcda19SMarshall Clow_NOEXCEPT_(noexcept(__c.data()))
1855d1dcda19SMarshall Clow-> decltype        (__c.data())
1856d1dcda19SMarshall Clow{ return            __c.data(); }
1857ad755104SMarshall Clow
185888d21343SMarshall Clowtemplate <class _Cont> constexpr
18592ffa1705SMarshall Clow_LIBCPP_INLINE_VISIBILITY
1860d1dcda19SMarshall Clowauto data(const _Cont& __c)
1861d1dcda19SMarshall Clow_NOEXCEPT_(noexcept(__c.data()))
1862d1dcda19SMarshall Clow-> decltype        (__c.data())
1863d1dcda19SMarshall Clow{ return            __c.data(); }
1864ad755104SMarshall Clow
186588d21343SMarshall Clowtemplate <class _Tp, size_t _Sz>
18662ffa1705SMarshall Clow_LIBCPP_INLINE_VISIBILITY
186788d21343SMarshall Clowconstexpr _Tp* data(_Tp (&__array)[_Sz]) noexcept { return __array; }
1868ad755104SMarshall Clow
1869ad755104SMarshall Clowtemplate <class _Ep>
18702ffa1705SMarshall Clow_LIBCPP_INLINE_VISIBILITY
1871ad755104SMarshall Clowconstexpr const _Ep* data(initializer_list<_Ep> __il) noexcept { return __il.begin(); }
1872ad755104SMarshall Clow#endif
1873ad755104SMarshall Clow
18742ac6babcSArthur O'Dwyertemplate <class _Container, class _Predicate>
18752ac6babcSArthur O'Dwyertypename _Container::size_type
18762ac6babcSArthur O'Dwyer__libcpp_erase_if_container(_Container& __c, _Predicate& __pred) {
18772ac6babcSArthur O'Dwyer  typename _Container::size_type __old_size = __c.size();
18782ac6babcSArthur O'Dwyer
18792ac6babcSArthur O'Dwyer  const typename _Container::iterator __last = __c.end();
18802ac6babcSArthur O'Dwyer  for (typename _Container::iterator __iter = __c.begin(); __iter != __last;) {
18812ac6babcSArthur O'Dwyer    if (__pred(*__iter))
18822ac6babcSArthur O'Dwyer      __iter = __c.erase(__iter);
18832ac6babcSArthur O'Dwyer    else
18842ac6babcSArthur O'Dwyer      ++__iter;
18852ac6babcSArthur O'Dwyer  }
18862ac6babcSArthur O'Dwyer
18872ac6babcSArthur O'Dwyer  return __old_size - __c.size();
18882ac6babcSArthur O'Dwyer}
1889ad755104SMarshall Clow
18903e519524SHoward Hinnant_LIBCPP_END_NAMESPACE_STD
18913e519524SHoward Hinnant
18923e519524SHoward Hinnant#endif // _LIBCPP_ITERATOR
1893