Home | History | Annotate | Line # | Download | only in include
iterator revision 1.1
      1  1.1  joerg // -*- C++ -*-
      2  1.1  joerg //===-------------------------- iterator ----------------------------------===//
      3  1.1  joerg //
      4  1.1  joerg // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
      5  1.1  joerg // See https://llvm.org/LICENSE.txt for license information.
      6  1.1  joerg // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
      7  1.1  joerg //
      8  1.1  joerg //===----------------------------------------------------------------------===//
      9  1.1  joerg 
     10  1.1  joerg #ifndef _LIBCPP_ITERATOR
     11  1.1  joerg #define _LIBCPP_ITERATOR
     12  1.1  joerg 
     13  1.1  joerg /*
     14  1.1  joerg     iterator synopsis
     15  1.1  joerg 
     16  1.1  joerg #include <concepts>
     17  1.1  joerg 
     18  1.1  joerg namespace std
     19  1.1  joerg {
     20  1.1  joerg template<class> struct incrementable_traits;       // since C++20
     21  1.1  joerg template<class T>
     22  1.1  joerg   using iter_difference_t = see below;             // since C++20
     23  1.1  joerg 
     24  1.1  joerg template<class> struct indirectly_readable_traits; // since C++20
     25  1.1  joerg template<class T>
     26  1.1  joerg   using iter_value_t = see below;                  // since C++20
     27  1.1  joerg 
     28  1.1  joerg template<class Iterator>
     29  1.1  joerg struct iterator_traits;
     30  1.1  joerg 
     31  1.1  joerg template<class T>
     32  1.1  joerg   requires is_object_v<T>                    // since C++20
     33  1.1  joerg struct iterator_traits<T*>;
     34  1.1  joerg 
     35  1.1  joerg template<dereferenceable T>
     36  1.1  joerg   using iter_reference_t = decltype(*declval<T&>());
     37  1.1  joerg 
     38  1.1  joerg namespace ranges::inline unspecified {
     39  1.1  joerg     inline constexpr unspecified iter_move = unspecified; // since C++20, nodiscard as an extension
     40  1.1  joerg }}
     41  1.1  joerg 
     42  1.1  joerg template<dereferenceable T>
     43  1.1  joerg   requires ...
     44  1.1  joerg using iter_rvalue_reference_t = decltype(ranges::iter_move(declval<T&>())); // since C++20
     45  1.1  joerg 
     46  1.1  joerg // [iterator.concepts], iterator concepts
     47  1.1  joerg // [iterator.concept.readable], concept indirectly_readable
     48  1.1  joerg template<class In>
     49  1.1  joerg   concept indirectly_readable = see below;                // since C++20
     50  1.1  joerg 
     51  1.1  joerg // [iterator.concept.writable], concept indirectly_writable
     52  1.1  joerg template<class Out, class T>
     53  1.1  joerg   concept indirectly_writable = see below;                // since C++20
     54  1.1  joerg 
     55  1.1  joerg // [iterator.concept.winc], concept weakly_incrementable
     56  1.1  joerg template<class I>
     57  1.1  joerg   concept weakly_incrementable = see below;                // since C++20
     58  1.1  joerg 
     59  1.1  joerg // [iterator.concept.inc], concept incrementable
     60  1.1  joerg template<class I>
     61  1.1  joerg   concept incrementable = see below;                       // since C++20
     62  1.1  joerg 
     63  1.1  joerg // [iterator.concept.iterator], concept input_or_output_iterator
     64  1.1  joerg   template<class I>
     65  1.1  joerg     concept input_or_output_iterator = see below;          // since C++20
     66  1.1  joerg 
     67  1.1  joerg // [iterator.concept.sentinel], concept sentinel_for
     68  1.1  joerg template<class S, class I>
     69  1.1  joerg   concept sentinel_for = see below;                        // since C++20
     70  1.1  joerg 
     71  1.1  joerg // [iterator.concept.sizedsentinel], concept sized_sentinel_for
     72  1.1  joerg template<class S, class I>
     73  1.1  joerg   inline constexpr bool disable_sized_sentinel_for = false;
     74  1.1  joerg 
     75  1.1  joerg template<class S, class I>
     76  1.1  joerg   concept sized_sentinel_for = see below;
     77  1.1  joerg 
     78  1.1  joerg // [iterator.concept.input], concept input_iterator
     79  1.1  joerg template<class I>
     80  1.1  joerg   concept input_iterator = see below;                      // since C++20
     81  1.1  joerg 
     82  1.1  joerg // [iterator.concept.forward], concept forward_iterator
     83  1.1  joerg template<class I>
     84  1.1  joerg   concept forward_iterator = see below;                    // since C++20
     85  1.1  joerg 
     86  1.1  joerg // [iterator.concept.bidir], concept bidirectional_iterator
     87  1.1  joerg template<class I>
     88  1.1  joerg   concept bidirectional_iterator = see below;              // since C++20
     89  1.1  joerg 
     90  1.1  joerg // [iterator.concept.random.access], concept random_access_iterator
     91  1.1  joerg template<class I>
     92  1.1  joerg   concept random_access_iterator = see below;              // since C++20
     93  1.1  joerg 
     94  1.1  joerg template<class Category, class T, class Distance = ptrdiff_t,
     95  1.1  joerg          class Pointer = T*, class Reference = T&>
     96  1.1  joerg struct iterator
     97  1.1  joerg {
     98  1.1  joerg     typedef T         value_type;
     99  1.1  joerg     typedef Distance  difference_type;
    100  1.1  joerg     typedef Pointer   pointer;
    101  1.1  joerg     typedef Reference reference;
    102  1.1  joerg     typedef Category  iterator_category;
    103  1.1  joerg };
    104  1.1  joerg 
    105  1.1  joerg struct input_iterator_tag  {};
    106  1.1  joerg struct output_iterator_tag {};
    107  1.1  joerg struct forward_iterator_tag       : public input_iterator_tag         {};
    108  1.1  joerg struct bidirectional_iterator_tag : public forward_iterator_tag       {};
    109  1.1  joerg struct random_access_iterator_tag : public bidirectional_iterator_tag {};
    110  1.1  joerg 
    111  1.1  joerg // 27.4.3, iterator operations
    112  1.1  joerg template <class InputIterator, class Distance>  // constexpr in C++17
    113  1.1  joerg   constexpr void advance(InputIterator& i, Distance n);
    114  1.1  joerg 
    115  1.1  joerg template <class InputIterator>  // constexpr in C++17
    116  1.1  joerg   constexpr typename iterator_traits<InputIterator>::difference_type
    117  1.1  joerg     distance(InputIterator first, InputIterator last);
    118  1.1  joerg 
    119  1.1  joerg template <class InputIterator>  // constexpr in C++17
    120  1.1  joerg   constexpr InputIterator next(InputIterator x,
    121  1.1  joerg typename iterator_traits<InputIterator>::difference_type n = 1);
    122  1.1  joerg 
    123  1.1  joerg template <class BidirectionalIterator>  // constexpr in C++17
    124  1.1  joerg   constexpr BidirectionalIterator prev(BidirectionalIterator x,
    125  1.1  joerg     typename iterator_traits<BidirectionalIterator>::difference_type n = 1);
    126  1.1  joerg 
    127  1.1  joerg template <class Iterator>
    128  1.1  joerg class reverse_iterator
    129  1.1  joerg     : public iterator<typename iterator_traits<Iterator>::iterator_category,
    130  1.1  joerg                       typename iterator_traits<Iterator>::value_type,
    131  1.1  joerg                       typename iterator_traits<Iterator>::difference_type,
    132  1.1  joerg                       typename iterator_traits<Iterator>::pointer,
    133  1.1  joerg                       typename iterator_traits<Iterator>::reference>
    134  1.1  joerg {
    135  1.1  joerg protected:
    136  1.1  joerg     Iterator current;
    137  1.1  joerg public:
    138  1.1  joerg     typedef Iterator                                            iterator_type;
    139  1.1  joerg     typedef typename iterator_traits<Iterator>::difference_type difference_type;
    140  1.1  joerg     typedef typename iterator_traits<Iterator>::reference       reference;
    141  1.1  joerg     typedef typename iterator_traits<Iterator>::pointer         pointer;
    142  1.1  joerg 
    143  1.1  joerg     constexpr reverse_iterator();
    144  1.1  joerg     constexpr explicit reverse_iterator(Iterator x);
    145  1.1  joerg     template <class U> constexpr reverse_iterator(const reverse_iterator<U>& u);
    146  1.1  joerg     template <class U> constexpr reverse_iterator& operator=(const reverse_iterator<U>& u);
    147  1.1  joerg     constexpr Iterator base() const;
    148  1.1  joerg     constexpr reference operator*() const;
    149  1.1  joerg     constexpr pointer   operator->() const;
    150  1.1  joerg     constexpr reverse_iterator& operator++();
    151  1.1  joerg     constexpr reverse_iterator  operator++(int);
    152  1.1  joerg     constexpr reverse_iterator& operator--();
    153  1.1  joerg     constexpr reverse_iterator  operator--(int);
    154  1.1  joerg     constexpr reverse_iterator  operator+ (difference_type n) const;
    155  1.1  joerg     constexpr reverse_iterator& operator+=(difference_type n);
    156  1.1  joerg     constexpr reverse_iterator  operator- (difference_type n) const;
    157  1.1  joerg     constexpr reverse_iterator& operator-=(difference_type n);
    158  1.1  joerg     constexpr reference         operator[](difference_type n) const;
    159  1.1  joerg };
    160  1.1  joerg 
    161  1.1  joerg template <class Iterator1, class Iterator2>
    162  1.1  joerg constexpr bool                          // constexpr in C++17
    163  1.1  joerg operator==(const reverse_iterator<Iterator1>& x, const reverse_iterator<Iterator2>& y);
    164  1.1  joerg 
    165  1.1  joerg template <class Iterator1, class Iterator2>
    166  1.1  joerg constexpr bool                          // constexpr in C++17
    167  1.1  joerg operator<(const reverse_iterator<Iterator1>& x, const reverse_iterator<Iterator2>& y);
    168  1.1  joerg 
    169  1.1  joerg template <class Iterator1, class Iterator2>
    170  1.1  joerg constexpr bool                          // constexpr in C++17
    171  1.1  joerg operator!=(const reverse_iterator<Iterator1>& x, const reverse_iterator<Iterator2>& y);
    172  1.1  joerg 
    173  1.1  joerg template <class Iterator1, class Iterator2>
    174  1.1  joerg constexpr bool                          // constexpr in C++17
    175  1.1  joerg operator>(const reverse_iterator<Iterator1>& x, const reverse_iterator<Iterator2>& y);
    176  1.1  joerg 
    177  1.1  joerg template <class Iterator1, class Iterator2>
    178  1.1  joerg constexpr bool                          // constexpr in C++17
    179  1.1  joerg operator>=(const reverse_iterator<Iterator1>& x, const reverse_iterator<Iterator2>& y);
    180  1.1  joerg 
    181  1.1  joerg template <class Iterator1, class Iterator2>
    182  1.1  joerg constexpr bool                          // constexpr in C++17
    183  1.1  joerg operator<=(const reverse_iterator<Iterator1>& x, const reverse_iterator<Iterator2>& y);
    184  1.1  joerg 
    185  1.1  joerg template <class Iterator1, class Iterator2>
    186  1.1  joerg constexpr auto
    187  1.1  joerg operator-(const reverse_iterator<Iterator1>& x, const reverse_iterator<Iterator2>& y)
    188  1.1  joerg -> decltype(__y.base() - __x.base());   // constexpr in C++17
    189  1.1  joerg 
    190  1.1  joerg template <class Iterator>
    191  1.1  joerg constexpr reverse_iterator<Iterator>
    192  1.1  joerg operator+(typename reverse_iterator<Iterator>::difference_type n,
    193  1.1  joerg           const reverse_iterator<Iterator>& x);   // constexpr in C++17
    194  1.1  joerg 
    195  1.1  joerg template <class Iterator>
    196  1.1  joerg constexpr reverse_iterator<Iterator> make_reverse_iterator(Iterator i); // C++14, constexpr in C++17
    197  1.1  joerg 
    198  1.1  joerg template <class Container>
    199  1.1  joerg class back_insert_iterator
    200  1.1  joerg {
    201  1.1  joerg protected:
    202  1.1  joerg     Container* container;
    203  1.1  joerg public:
    204  1.1  joerg     typedef Container                   container_type;
    205  1.1  joerg     typedef void                        value_type;
    206  1.1  joerg     typedef void                        difference_type;
    207  1.1  joerg     typedef void                        reference;
    208  1.1  joerg     typedef void                        pointer;
    209  1.1  joerg 
    210  1.1  joerg     explicit back_insert_iterator(Container& x);  // constexpr in C++20
    211  1.1  joerg     back_insert_iterator& operator=(const typename Container::value_type& value);  // constexpr in C++20
    212  1.1  joerg     back_insert_iterator& operator*();  // constexpr in C++20
    213  1.1  joerg     back_insert_iterator& operator++();  // constexpr in C++20
    214  1.1  joerg     back_insert_iterator  operator++(int);  // constexpr in C++20
    215  1.1  joerg };
    216  1.1  joerg 
    217  1.1  joerg template <class Container> back_insert_iterator<Container> back_inserter(Container& x);  // constexpr in C++20
    218  1.1  joerg 
    219  1.1  joerg template <class Container>
    220  1.1  joerg class front_insert_iterator
    221  1.1  joerg {
    222  1.1  joerg protected:
    223  1.1  joerg     Container* container;
    224  1.1  joerg public:
    225  1.1  joerg     typedef Container                    container_type;
    226  1.1  joerg     typedef void                         value_type;
    227  1.1  joerg     typedef void                         difference_type;
    228  1.1  joerg     typedef void                         reference;
    229  1.1  joerg     typedef void                         pointer;
    230  1.1  joerg 
    231  1.1  joerg     explicit front_insert_iterator(Container& x);  // constexpr in C++20
    232  1.1  joerg     front_insert_iterator& operator=(const typename Container::value_type& value);  // constexpr in C++20
    233  1.1  joerg     front_insert_iterator& operator*();  // constexpr in C++20
    234  1.1  joerg     front_insert_iterator& operator++();  // constexpr in C++20
    235  1.1  joerg     front_insert_iterator  operator++(int);  // constexpr in C++20
    236  1.1  joerg };
    237  1.1  joerg 
    238  1.1  joerg template <class Container> front_insert_iterator<Container> front_inserter(Container& x);  // constexpr in C++20
    239  1.1  joerg 
    240  1.1  joerg template <class Container>
    241  1.1  joerg class insert_iterator
    242  1.1  joerg {
    243  1.1  joerg protected:
    244  1.1  joerg     Container* container;
    245  1.1  joerg     typename Container::iterator iter;
    246  1.1  joerg public:
    247  1.1  joerg     typedef Container              container_type;
    248  1.1  joerg     typedef void                   value_type;
    249  1.1  joerg     typedef void                   difference_type;
    250  1.1  joerg     typedef void                   reference;
    251  1.1  joerg     typedef void                   pointer;
    252  1.1  joerg 
    253  1.1  joerg     insert_iterator(Container& x, typename Container::iterator i);  // constexpr in C++20
    254  1.1  joerg     insert_iterator& operator=(const typename Container::value_type& value);  // constexpr in C++20
    255  1.1  joerg     insert_iterator& operator*();  // constexpr in C++20
    256  1.1  joerg     insert_iterator& operator++();  // constexpr in C++20
    257  1.1  joerg     insert_iterator& operator++(int);  // constexpr in C++20
    258  1.1  joerg };
    259  1.1  joerg 
    260  1.1  joerg template <class Container, class Iterator>
    261  1.1  joerg insert_iterator<Container> inserter(Container& x, Iterator i);  // constexpr in C++20
    262  1.1  joerg 
    263  1.1  joerg template <class Iterator>
    264  1.1  joerg class move_iterator {
    265  1.1  joerg public:
    266  1.1  joerg     typedef Iterator                                              iterator_type;
    267  1.1  joerg     typedef typename iterator_traits<Iterator>::difference_type   difference_type;
    268  1.1  joerg     typedef Iterator                                              pointer;
    269  1.1  joerg     typedef typename iterator_traits<Iterator>::value_type        value_type;
    270  1.1  joerg     typedef typename iterator_traits<Iterator>::iterator_category iterator_category;
    271  1.1  joerg     typedef value_type&&                                          reference;
    272  1.1  joerg 
    273  1.1  joerg     constexpr move_iterator();  // all the constexprs are in C++17
    274  1.1  joerg     constexpr explicit move_iterator(Iterator i);
    275  1.1  joerg     template <class U>
    276  1.1  joerg       constexpr move_iterator(const move_iterator<U>& u);
    277  1.1  joerg     template <class U>
    278  1.1  joerg       constexpr move_iterator& operator=(const move_iterator<U>& u);
    279  1.1  joerg     constexpr iterator_type base() const;
    280  1.1  joerg     constexpr reference operator*() const;
    281  1.1  joerg     constexpr pointer operator->() const;
    282  1.1  joerg     constexpr move_iterator& operator++();
    283  1.1  joerg     constexpr move_iterator operator++(int);
    284  1.1  joerg     constexpr move_iterator& operator--();
    285  1.1  joerg     constexpr move_iterator operator--(int);
    286  1.1  joerg     constexpr move_iterator operator+(difference_type n) const;
    287  1.1  joerg     constexpr move_iterator& operator+=(difference_type n);
    288  1.1  joerg     constexpr move_iterator operator-(difference_type n) const;
    289  1.1  joerg     constexpr move_iterator& operator-=(difference_type n);
    290  1.1  joerg     constexpr unspecified operator[](difference_type n) const;
    291  1.1  joerg private:
    292  1.1  joerg     Iterator current; // exposition only
    293  1.1  joerg };
    294  1.1  joerg 
    295  1.1  joerg template <class Iterator1, class Iterator2>
    296  1.1  joerg constexpr bool   // constexpr in C++17
    297  1.1  joerg operator==(const move_iterator<Iterator1>& x, const move_iterator<Iterator2>& y);
    298  1.1  joerg 
    299  1.1  joerg template <class Iterator1, class Iterator2>
    300  1.1  joerg constexpr bool   // constexpr in C++17
    301  1.1  joerg operator!=(const move_iterator<Iterator1>& x, const move_iterator<Iterator2>& y);
    302  1.1  joerg 
    303  1.1  joerg template <class Iterator1, class Iterator2>
    304  1.1  joerg constexpr bool   // constexpr in C++17
    305  1.1  joerg operator<(const move_iterator<Iterator1>& x, const move_iterator<Iterator2>& y);
    306  1.1  joerg 
    307  1.1  joerg template <class Iterator1, class Iterator2>
    308  1.1  joerg constexpr bool   // constexpr in C++17
    309  1.1  joerg operator<=(const move_iterator<Iterator1>& x, const move_iterator<Iterator2>& y);
    310  1.1  joerg 
    311  1.1  joerg template <class Iterator1, class Iterator2>
    312  1.1  joerg constexpr bool   // constexpr in C++17
    313  1.1  joerg operator>(const move_iterator<Iterator1>& x, const move_iterator<Iterator2>& y);
    314  1.1  joerg 
    315  1.1  joerg template <class Iterator1, class Iterator2>
    316  1.1  joerg constexpr bool   // constexpr in C++17
    317  1.1  joerg operator>=(const move_iterator<Iterator1>& x, const move_iterator<Iterator2>& y);
    318  1.1  joerg 
    319  1.1  joerg template <class Iterator1, class Iterator2>
    320  1.1  joerg constexpr auto   // constexpr in C++17
    321  1.1  joerg operator-(const move_iterator<Iterator1>& x,
    322  1.1  joerg           const move_iterator<Iterator2>& y) -> decltype(x.base() - y.base());
    323  1.1  joerg 
    324  1.1  joerg template <class Iterator>
    325  1.1  joerg constexpr move_iterator<Iterator> operator+(   // constexpr in C++17
    326  1.1  joerg             typename move_iterator<Iterator>::difference_type n,
    327  1.1  joerg             const move_iterator<Iterator>& x);
    328  1.1  joerg 
    329  1.1  joerg template <class Iterator>   // constexpr in C++17
    330  1.1  joerg constexpr  move_iterator<Iterator> make_move_iterator(const Iterator& i);
    331  1.1  joerg 
    332  1.1  joerg 
    333  1.1  joerg template <class T, class charT = char, class traits = char_traits<charT>, class Distance = ptrdiff_t>
    334  1.1  joerg class istream_iterator
    335  1.1  joerg     : public iterator<input_iterator_tag, T, Distance, const T*, const T&>
    336  1.1  joerg {
    337  1.1  joerg public:
    338  1.1  joerg     typedef charT char_type;
    339  1.1  joerg     typedef traits traits_type;
    340  1.1  joerg     typedef basic_istream<charT,traits> istream_type;
    341  1.1  joerg 
    342  1.1  joerg     constexpr istream_iterator();
    343  1.1  joerg     istream_iterator(istream_type& s);
    344  1.1  joerg     istream_iterator(const istream_iterator& x);
    345  1.1  joerg     ~istream_iterator();
    346  1.1  joerg 
    347  1.1  joerg     const T& operator*() const;
    348  1.1  joerg     const T* operator->() const;
    349  1.1  joerg     istream_iterator& operator++();
    350  1.1  joerg     istream_iterator  operator++(int);
    351  1.1  joerg };
    352  1.1  joerg 
    353  1.1  joerg template <class T, class charT, class traits, class Distance>
    354  1.1  joerg bool operator==(const istream_iterator<T,charT,traits,Distance>& x,
    355  1.1  joerg                 const istream_iterator<T,charT,traits,Distance>& y);
    356  1.1  joerg template <class T, class charT, class traits, class Distance>
    357  1.1  joerg bool operator!=(const istream_iterator<T,charT,traits,Distance>& x,
    358  1.1  joerg                 const istream_iterator<T,charT,traits,Distance>& y);
    359  1.1  joerg 
    360  1.1  joerg template <class T, class charT = char, class traits = char_traits<charT> >
    361  1.1  joerg class ostream_iterator
    362  1.1  joerg     : public iterator<output_iterator_tag, void, void, void ,void>
    363  1.1  joerg {
    364  1.1  joerg public:
    365  1.1  joerg     typedef charT char_type;
    366  1.1  joerg     typedef traits traits_type;
    367  1.1  joerg     typedef basic_ostream<charT,traits> ostream_type;
    368  1.1  joerg 
    369  1.1  joerg     ostream_iterator(ostream_type& s);
    370  1.1  joerg     ostream_iterator(ostream_type& s, const charT* delimiter);
    371  1.1  joerg     ostream_iterator(const ostream_iterator& x);
    372  1.1  joerg     ~ostream_iterator();
    373  1.1  joerg     ostream_iterator& operator=(const T& value);
    374  1.1  joerg 
    375  1.1  joerg     ostream_iterator& operator*();
    376  1.1  joerg     ostream_iterator& operator++();
    377  1.1  joerg     ostream_iterator& operator++(int);
    378  1.1  joerg };
    379  1.1  joerg 
    380  1.1  joerg template<class charT, class traits = char_traits<charT> >
    381  1.1  joerg class istreambuf_iterator
    382  1.1  joerg     : public iterator<input_iterator_tag, charT,
    383  1.1  joerg                       typename traits::off_type, unspecified,
    384  1.1  joerg                       charT>
    385  1.1  joerg {
    386  1.1  joerg public:
    387  1.1  joerg     typedef charT                         char_type;
    388  1.1  joerg     typedef traits                        traits_type;
    389  1.1  joerg     typedef typename traits::int_type     int_type;
    390  1.1  joerg     typedef basic_streambuf<charT,traits> streambuf_type;
    391  1.1  joerg     typedef basic_istream<charT,traits>   istream_type;
    392  1.1  joerg 
    393  1.1  joerg     istreambuf_iterator() noexcept;
    394  1.1  joerg     istreambuf_iterator(istream_type& s) noexcept;
    395  1.1  joerg     istreambuf_iterator(streambuf_type* s) noexcept;
    396  1.1  joerg     istreambuf_iterator(a-private-type) noexcept;
    397  1.1  joerg 
    398  1.1  joerg     charT                operator*() const;
    399  1.1  joerg     pointer operator->() const;
    400  1.1  joerg     istreambuf_iterator& operator++();
    401  1.1  joerg     a-private-type       operator++(int);
    402  1.1  joerg 
    403  1.1  joerg     bool equal(const istreambuf_iterator& b) const;
    404  1.1  joerg };
    405  1.1  joerg 
    406  1.1  joerg template <class charT, class traits>
    407  1.1  joerg bool operator==(const istreambuf_iterator<charT,traits>& a,
    408  1.1  joerg                 const istreambuf_iterator<charT,traits>& b);
    409  1.1  joerg template <class charT, class traits>
    410  1.1  joerg bool operator!=(const istreambuf_iterator<charT,traits>& a,
    411  1.1  joerg                 const istreambuf_iterator<charT,traits>& b);
    412  1.1  joerg 
    413  1.1  joerg template <class charT, class traits = char_traits<charT> >
    414  1.1  joerg class ostreambuf_iterator
    415  1.1  joerg     : public iterator<output_iterator_tag, void, void, void, void>
    416  1.1  joerg {
    417  1.1  joerg public:
    418  1.1  joerg     typedef charT                         char_type;
    419  1.1  joerg     typedef traits                        traits_type;
    420  1.1  joerg     typedef basic_streambuf<charT,traits> streambuf_type;
    421  1.1  joerg     typedef basic_ostream<charT,traits>   ostream_type;
    422  1.1  joerg 
    423  1.1  joerg     ostreambuf_iterator(ostream_type& s) noexcept;
    424  1.1  joerg     ostreambuf_iterator(streambuf_type* s) noexcept;
    425  1.1  joerg     ostreambuf_iterator& operator=(charT c);
    426  1.1  joerg     ostreambuf_iterator& operator*();
    427  1.1  joerg     ostreambuf_iterator& operator++();
    428  1.1  joerg     ostreambuf_iterator& operator++(int);
    429  1.1  joerg     bool failed() const noexcept;
    430  1.1  joerg };
    431  1.1  joerg 
    432  1.1  joerg template <class C> constexpr auto begin(C& c) -> decltype(c.begin());
    433  1.1  joerg template <class C> constexpr auto begin(const C& c) -> decltype(c.begin());
    434  1.1  joerg template <class C> constexpr auto end(C& c) -> decltype(c.end());
    435  1.1  joerg template <class C> constexpr auto end(const C& c) -> decltype(c.end());
    436  1.1  joerg template <class T, size_t N> constexpr T* begin(T (&array)[N]);
    437  1.1  joerg template <class T, size_t N> constexpr T* end(T (&array)[N]);
    438  1.1  joerg 
    439  1.1  joerg template <class C> auto constexpr cbegin(const C& c) -> decltype(std::begin(c));        // C++14
    440  1.1  joerg template <class C> auto constexpr cend(const C& c) -> decltype(std::end(c));            // C++14
    441  1.1  joerg template <class C> auto constexpr rbegin(C& c) -> decltype(c.rbegin());                 // C++14
    442  1.1  joerg template <class C> auto constexpr rbegin(const C& c) -> decltype(c.rbegin());           // C++14
    443  1.1  joerg template <class C> auto constexpr rend(C& c) -> decltype(c.rend());                     // C++14
    444  1.1  joerg template <class C> constexpr auto rend(const C& c) -> decltype(c.rend());               // C++14
    445  1.1  joerg template <class E> reverse_iterator<const E*> constexpr rbegin(initializer_list<E> il); // C++14
    446  1.1  joerg template <class E> reverse_iterator<const E*> constexpr rend(initializer_list<E> il);   // C++14
    447  1.1  joerg template <class T, size_t N> reverse_iterator<T*> constexpr rbegin(T (&array)[N]);      // C++14
    448  1.1  joerg template <class T, size_t N> reverse_iterator<T*> constexpr rend(T (&array)[N]);        // C++14
    449  1.1  joerg template <class C> constexpr auto crbegin(const C& c) -> decltype(std::rbegin(c));      // C++14
    450  1.1  joerg template <class C> constexpr auto crend(const C& c) -> decltype(std::rend(c));          // C++14
    451  1.1  joerg 
    452  1.1  joerg // 24.8, container access:
    453  1.1  joerg template <class C> constexpr auto size(const C& c) -> decltype(c.size());         // C++17
    454  1.1  joerg template <class T, size_t N> constexpr size_t size(const T (&array)[N]) noexcept; // C++17
    455  1.1  joerg 
    456  1.1  joerg template <class C> constexpr auto ssize(const C& c)
    457  1.1  joerg     -> common_type_t<ptrdiff_t, make_signed_t<decltype(c.size())>>;                    // C++20
    458  1.1  joerg template <class T, ptrdiff_t> constexpr ptrdiff_t ssize(const T (&array)[N]) noexcept; // C++20
    459  1.1  joerg 
    460  1.1  joerg template <class C> constexpr auto empty(const C& c) -> decltype(c.empty());       // C++17
    461  1.1  joerg template <class T, size_t N> constexpr bool empty(const T (&array)[N]) noexcept;  // C++17
    462  1.1  joerg template <class E> constexpr bool empty(initializer_list<E> il) noexcept;         // C++17
    463  1.1  joerg template <class C> constexpr auto data(C& c) -> decltype(c.data());               // C++17
    464  1.1  joerg template <class C> constexpr auto data(const C& c) -> decltype(c.data());         // C++17
    465  1.1  joerg template <class T, size_t N> constexpr T* data(T (&array)[N]) noexcept;           // C++17
    466  1.1  joerg template <class E> constexpr const E* data(initializer_list<E> il) noexcept;      // C++17
    467  1.1  joerg 
    468  1.1  joerg }  // std
    469  1.1  joerg 
    470  1.1  joerg */
    471  1.1  joerg 
    472  1.1  joerg #include <__config>
    473  1.1  joerg #include <__debug>
    474  1.1  joerg #include <__functional_base>
    475  1.1  joerg #include <__iterator/concepts.h>
    476  1.1  joerg #include <__iterator/incrementable_traits.h>
    477  1.1  joerg #include <__iterator/iter_move.h>
    478  1.1  joerg #include <__iterator/iterator_traits.h>
    479  1.1  joerg #include <__iterator/readable_traits.h>
    480  1.1  joerg #include <__memory/addressof.h>
    481  1.1  joerg #include <__memory/pointer_traits.h>
    482  1.1  joerg #include <compare>
    483  1.1  joerg #include <concepts> // Mandated by the Standard.
    484  1.1  joerg #include <cstddef>
    485  1.1  joerg #include <initializer_list>
    486  1.1  joerg #include <iosfwd> // for forward declarations of vector and string
    487  1.1  joerg #include <type_traits>
    488  1.1  joerg #include <version>
    489  1.1  joerg 
    490  1.1  joerg #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
    491  1.1  joerg #pragma GCC system_header
    492  1.1  joerg #endif
    493  1.1  joerg 
    494  1.1  joerg _LIBCPP_BEGIN_NAMESPACE_STD
    495  1.1  joerg 
    496  1.1  joerg template<class _Category, class _Tp, class _Distance = ptrdiff_t,
    497  1.1  joerg          class _Pointer = _Tp*, class _Reference = _Tp&>
    498  1.1  joerg struct _LIBCPP_TEMPLATE_VIS iterator
    499  1.1  joerg {
    500  1.1  joerg     typedef _Tp        value_type;
    501  1.1  joerg     typedef _Distance  difference_type;
    502  1.1  joerg     typedef _Pointer   pointer;
    503  1.1  joerg     typedef _Reference reference;
    504  1.1  joerg     typedef _Category  iterator_category;
    505  1.1  joerg };
    506  1.1  joerg 
    507  1.1  joerg template <class _InputIter>
    508  1.1  joerg inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
    509  1.1  joerg void __advance(_InputIter& __i,
    510  1.1  joerg              typename iterator_traits<_InputIter>::difference_type __n, input_iterator_tag)
    511  1.1  joerg {
    512  1.1  joerg     for (; __n > 0; --__n)
    513  1.1  joerg         ++__i;
    514  1.1  joerg }
    515  1.1  joerg 
    516  1.1  joerg template <class _BiDirIter>
    517  1.1  joerg inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
    518  1.1  joerg void __advance(_BiDirIter& __i,
    519  1.1  joerg              typename iterator_traits<_BiDirIter>::difference_type __n, bidirectional_iterator_tag)
    520  1.1  joerg {
    521  1.1  joerg     if (__n >= 0)
    522  1.1  joerg         for (; __n > 0; --__n)
    523  1.1  joerg             ++__i;
    524  1.1  joerg     else
    525  1.1  joerg         for (; __n < 0; ++__n)
    526  1.1  joerg             --__i;
    527  1.1  joerg }
    528  1.1  joerg 
    529  1.1  joerg template <class _RandIter>
    530  1.1  joerg inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
    531  1.1  joerg void __advance(_RandIter& __i,
    532  1.1  joerg              typename iterator_traits<_RandIter>::difference_type __n, random_access_iterator_tag)
    533  1.1  joerg {
    534  1.1  joerg    __i += __n;
    535  1.1  joerg }
    536  1.1  joerg 
    537  1.1  joerg template <class _InputIter, class _Distance>
    538  1.1  joerg inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
    539  1.1  joerg void advance(_InputIter& __i, _Distance __orig_n)
    540  1.1  joerg {
    541  1.1  joerg     typedef decltype(_VSTD::__convert_to_integral(__orig_n)) _IntegralSize;
    542  1.1  joerg     _IntegralSize __n = __orig_n;
    543  1.1  joerg     _LIBCPP_ASSERT(__n >= 0 || __is_cpp17_bidirectional_iterator<_InputIter>::value,
    544  1.1  joerg                    "Attempt to advance(it, n) with negative n on a non-bidirectional iterator");
    545  1.1  joerg     _VSTD::__advance(__i, __n, typename iterator_traits<_InputIter>::iterator_category());
    546  1.1  joerg }
    547  1.1  joerg 
    548  1.1  joerg template <class _InputIter>
    549  1.1  joerg inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
    550  1.1  joerg typename iterator_traits<_InputIter>::difference_type
    551  1.1  joerg __distance(_InputIter __first, _InputIter __last, input_iterator_tag)
    552  1.1  joerg {
    553  1.1  joerg     typename iterator_traits<_InputIter>::difference_type __r(0);
    554  1.1  joerg     for (; __first != __last; ++__first)
    555  1.1  joerg         ++__r;
    556  1.1  joerg     return __r;
    557  1.1  joerg }
    558  1.1  joerg 
    559  1.1  joerg template <class _RandIter>
    560  1.1  joerg inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
    561  1.1  joerg typename iterator_traits<_RandIter>::difference_type
    562  1.1  joerg __distance(_RandIter __first, _RandIter __last, random_access_iterator_tag)
    563  1.1  joerg {
    564  1.1  joerg     return __last - __first;
    565  1.1  joerg }
    566  1.1  joerg 
    567  1.1  joerg template <class _InputIter>
    568  1.1  joerg inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
    569  1.1  joerg typename iterator_traits<_InputIter>::difference_type
    570  1.1  joerg distance(_InputIter __first, _InputIter __last)
    571  1.1  joerg {
    572  1.1  joerg     return _VSTD::__distance(__first, __last, typename iterator_traits<_InputIter>::iterator_category());
    573  1.1  joerg }
    574  1.1  joerg 
    575  1.1  joerg template <class _InputIter>
    576  1.1  joerg inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
    577  1.1  joerg typename enable_if
    578  1.1  joerg <
    579  1.1  joerg     __is_cpp17_input_iterator<_InputIter>::value,
    580  1.1  joerg     _InputIter
    581  1.1  joerg >::type
    582  1.1  joerg next(_InputIter __x,
    583  1.1  joerg      typename iterator_traits<_InputIter>::difference_type __n = 1)
    584  1.1  joerg {
    585  1.1  joerg     _LIBCPP_ASSERT(__n >= 0 || __is_cpp17_bidirectional_iterator<_InputIter>::value,
    586  1.1  joerg                        "Attempt to next(it, n) with negative n on a non-bidirectional iterator");
    587  1.1  joerg 
    588  1.1  joerg     _VSTD::advance(__x, __n);
    589  1.1  joerg     return __x;
    590  1.1  joerg }
    591  1.1  joerg 
    592  1.1  joerg template <class _InputIter>
    593  1.1  joerg inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
    594  1.1  joerg typename enable_if
    595  1.1  joerg <
    596  1.1  joerg     __is_cpp17_input_iterator<_InputIter>::value,
    597  1.1  joerg     _InputIter
    598  1.1  joerg >::type
    599  1.1  joerg prev(_InputIter __x,
    600  1.1  joerg      typename iterator_traits<_InputIter>::difference_type __n = 1)
    601  1.1  joerg {
    602  1.1  joerg     _LIBCPP_ASSERT(__n <= 0 || __is_cpp17_bidirectional_iterator<_InputIter>::value,
    603  1.1  joerg                        "Attempt to prev(it, n) with a positive n on a non-bidirectional iterator");
    604  1.1  joerg     _VSTD::advance(__x, -__n);
    605  1.1  joerg     return __x;
    606  1.1  joerg }
    607  1.1  joerg 
    608  1.1  joerg 
    609  1.1  joerg template <class _Tp, class = void>
    610  1.1  joerg struct __is_stashing_iterator : false_type {};
    611  1.1  joerg 
    612  1.1  joerg template <class _Tp>
    613  1.1  joerg struct __is_stashing_iterator<_Tp, typename __void_t<typename _Tp::__stashing_iterator_tag>::type>
    614  1.1  joerg   : true_type {};
    615  1.1  joerg 
    616  1.1  joerg template <class _Iter>
    617  1.1  joerg class _LIBCPP_TEMPLATE_VIS reverse_iterator
    618  1.1  joerg     : public iterator<typename iterator_traits<_Iter>::iterator_category,
    619  1.1  joerg                       typename iterator_traits<_Iter>::value_type,
    620  1.1  joerg                       typename iterator_traits<_Iter>::difference_type,
    621  1.1  joerg                       typename iterator_traits<_Iter>::pointer,
    622  1.1  joerg                       typename iterator_traits<_Iter>::reference>
    623  1.1  joerg {
    624  1.1  joerg private:
    625  1.1  joerg     /*mutable*/ _Iter __t;  // no longer used as of LWG #2360, not removed due to ABI break
    626  1.1  joerg 
    627  1.1  joerg     static_assert(!__is_stashing_iterator<_Iter>::value,
    628  1.1  joerg       "The specified iterator type cannot be used with reverse_iterator; "
    629  1.1  joerg       "Using stashing iterators with reverse_iterator causes undefined behavior");
    630  1.1  joerg 
    631  1.1  joerg protected:
    632  1.1  joerg     _Iter current;
    633  1.1  joerg public:
    634  1.1  joerg     typedef _Iter                                            iterator_type;
    635  1.1  joerg     typedef typename iterator_traits<_Iter>::difference_type difference_type;
    636  1.1  joerg     typedef typename iterator_traits<_Iter>::reference       reference;
    637  1.1  joerg     typedef typename iterator_traits<_Iter>::pointer         pointer;
    638  1.1  joerg     typedef _If<__is_cpp17_random_access_iterator<_Iter>::value,
    639  1.1  joerg         random_access_iterator_tag,
    640  1.1  joerg         typename iterator_traits<_Iter>::iterator_category>  iterator_category;
    641  1.1  joerg #if _LIBCPP_STD_VER > 17
    642  1.1  joerg     typedef _If<__is_cpp17_random_access_iterator<_Iter>::value,
    643  1.1  joerg         random_access_iterator_tag,
    644  1.1  joerg         bidirectional_iterator_tag>                          iterator_concept;
    645  1.1  joerg #endif
    646  1.1  joerg 
    647  1.1  joerg     _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
    648  1.1  joerg     reverse_iterator() : __t(), current() {}
    649  1.1  joerg     _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
    650  1.1  joerg     explicit reverse_iterator(_Iter __x) : __t(__x), current(__x) {}
    651  1.1  joerg     template <class _Up>
    652  1.1  joerg         _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
    653  1.1  joerg         reverse_iterator(const reverse_iterator<_Up>& __u) : __t(__u.base()), current(__u.base()) {}
    654  1.1  joerg     template <class _Up>
    655  1.1  joerg         _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
    656  1.1  joerg         reverse_iterator& operator=(const reverse_iterator<_Up>& __u)
    657  1.1  joerg             { __t = current = __u.base(); return *this; }
    658  1.1  joerg     _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
    659  1.1  joerg     _Iter base() const {return current;}
    660  1.1  joerg     _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
    661  1.1  joerg     reference operator*() const {_Iter __tmp = current; return *--__tmp;}
    662  1.1  joerg     _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
    663  1.1  joerg     pointer  operator->() const {return _VSTD::addressof(operator*());}
    664  1.1  joerg     _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
    665  1.1  joerg     reverse_iterator& operator++() {--current; return *this;}
    666  1.1  joerg     _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
    667  1.1  joerg     reverse_iterator  operator++(int) {reverse_iterator __tmp(*this); --current; return __tmp;}
    668  1.1  joerg     _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
    669  1.1  joerg     reverse_iterator& operator--() {++current; return *this;}
    670  1.1  joerg     _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
    671  1.1  joerg     reverse_iterator  operator--(int) {reverse_iterator __tmp(*this); ++current; return __tmp;}
    672  1.1  joerg     _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
    673  1.1  joerg     reverse_iterator  operator+ (difference_type __n) const {return reverse_iterator(current - __n);}
    674  1.1  joerg     _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
    675  1.1  joerg     reverse_iterator& operator+=(difference_type __n) {current -= __n; return *this;}
    676  1.1  joerg     _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
    677  1.1  joerg     reverse_iterator  operator- (difference_type __n) const {return reverse_iterator(current + __n);}
    678  1.1  joerg     _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
    679  1.1  joerg     reverse_iterator& operator-=(difference_type __n) {current += __n; return *this;}
    680  1.1  joerg     _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
    681  1.1  joerg     reference         operator[](difference_type __n) const {return *(*this + __n);}
    682  1.1  joerg };
    683  1.1  joerg 
    684  1.1  joerg template <class _Iter1, class _Iter2>
    685  1.1  joerg inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
    686  1.1  joerg bool
    687  1.1  joerg operator==(const reverse_iterator<_Iter1>& __x, const reverse_iterator<_Iter2>& __y)
    688  1.1  joerg {
    689  1.1  joerg     return __x.base() == __y.base();
    690  1.1  joerg }
    691  1.1  joerg 
    692  1.1  joerg template <class _Iter1, class _Iter2>
    693  1.1  joerg inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
    694  1.1  joerg bool
    695  1.1  joerg operator<(const reverse_iterator<_Iter1>& __x, const reverse_iterator<_Iter2>& __y)
    696  1.1  joerg {
    697  1.1  joerg     return __x.base() > __y.base();
    698  1.1  joerg }
    699  1.1  joerg 
    700  1.1  joerg template <class _Iter1, class _Iter2>
    701  1.1  joerg inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
    702  1.1  joerg bool
    703  1.1  joerg operator!=(const reverse_iterator<_Iter1>& __x, const reverse_iterator<_Iter2>& __y)
    704  1.1  joerg {
    705  1.1  joerg     return __x.base() != __y.base();
    706  1.1  joerg }
    707  1.1  joerg 
    708  1.1  joerg template <class _Iter1, class _Iter2>
    709  1.1  joerg inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
    710  1.1  joerg bool
    711  1.1  joerg operator>(const reverse_iterator<_Iter1>& __x, const reverse_iterator<_Iter2>& __y)
    712  1.1  joerg {
    713  1.1  joerg     return __x.base() < __y.base();
    714  1.1  joerg }
    715  1.1  joerg 
    716  1.1  joerg template <class _Iter1, class _Iter2>
    717  1.1  joerg inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
    718  1.1  joerg bool
    719  1.1  joerg operator>=(const reverse_iterator<_Iter1>& __x, const reverse_iterator<_Iter2>& __y)
    720  1.1  joerg {
    721  1.1  joerg     return __x.base() <= __y.base();
    722  1.1  joerg }
    723  1.1  joerg 
    724  1.1  joerg template <class _Iter1, class _Iter2>
    725  1.1  joerg inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
    726  1.1  joerg bool
    727  1.1  joerg operator<=(const reverse_iterator<_Iter1>& __x, const reverse_iterator<_Iter2>& __y)
    728  1.1  joerg {
    729  1.1  joerg     return __x.base() >= __y.base();
    730  1.1  joerg }
    731  1.1  joerg 
    732  1.1  joerg #ifndef _LIBCPP_CXX03_LANG
    733  1.1  joerg template <class _Iter1, class _Iter2>
    734  1.1  joerg inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
    735  1.1  joerg auto
    736  1.1  joerg operator-(const reverse_iterator<_Iter1>& __x, const reverse_iterator<_Iter2>& __y)
    737  1.1  joerg -> decltype(__y.base() - __x.base())
    738  1.1  joerg {
    739  1.1  joerg     return __y.base() - __x.base();
    740  1.1  joerg }
    741  1.1  joerg #else
    742  1.1  joerg template <class _Iter1, class _Iter2>
    743  1.1  joerg inline _LIBCPP_INLINE_VISIBILITY
    744  1.1  joerg typename reverse_iterator<_Iter1>::difference_type
    745  1.1  joerg operator-(const reverse_iterator<_Iter1>& __x, const reverse_iterator<_Iter2>& __y)
    746  1.1  joerg {
    747  1.1  joerg     return __y.base() - __x.base();
    748  1.1  joerg }
    749  1.1  joerg #endif
    750  1.1  joerg 
    751  1.1  joerg template <class _Iter>
    752  1.1  joerg inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
    753  1.1  joerg reverse_iterator<_Iter>
    754  1.1  joerg operator+(typename reverse_iterator<_Iter>::difference_type __n, const reverse_iterator<_Iter>& __x)
    755  1.1  joerg {
    756  1.1  joerg     return reverse_iterator<_Iter>(__x.base() - __n);
    757  1.1  joerg }
    758  1.1  joerg 
    759  1.1  joerg #if _LIBCPP_STD_VER > 11
    760  1.1  joerg template <class _Iter>
    761  1.1  joerg inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
    762  1.1  joerg reverse_iterator<_Iter> make_reverse_iterator(_Iter __i)
    763  1.1  joerg {
    764  1.1  joerg     return reverse_iterator<_Iter>(__i);
    765  1.1  joerg }
    766  1.1  joerg #endif
    767  1.1  joerg 
    768  1.1  joerg template <class _Container>
    769  1.1  joerg class _LIBCPP_TEMPLATE_VIS back_insert_iterator
    770  1.1  joerg     : public iterator<output_iterator_tag,
    771  1.1  joerg                       void,
    772  1.1  joerg                       void,
    773  1.1  joerg                       void,
    774  1.1  joerg                       void>
    775  1.1  joerg {
    776  1.1  joerg protected:
    777  1.1  joerg     _Container* container;
    778  1.1  joerg public:
    779  1.1  joerg     typedef _Container container_type;
    780  1.1  joerg 
    781  1.1  joerg     _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 explicit back_insert_iterator(_Container& __x) : container(_VSTD::addressof(__x)) {}
    782  1.1  joerg     _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 back_insert_iterator& operator=(const typename _Container::value_type& __value_)
    783  1.1  joerg         {container->push_back(__value_); return *this;}
    784  1.1  joerg #ifndef _LIBCPP_CXX03_LANG
    785  1.1  joerg     _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 back_insert_iterator& operator=(typename _Container::value_type&& __value_)
    786  1.1  joerg         {container->push_back(_VSTD::move(__value_)); return *this;}
    787  1.1  joerg #endif // _LIBCPP_CXX03_LANG
    788  1.1  joerg     _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 back_insert_iterator& operator*()     {return *this;}
    789  1.1  joerg     _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 back_insert_iterator& operator++()    {return *this;}
    790  1.1  joerg     _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 back_insert_iterator  operator++(int) {return *this;}
    791  1.1  joerg };
    792  1.1  joerg 
    793  1.1  joerg template <class _Container>
    794  1.1  joerg inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
    795  1.1  joerg back_insert_iterator<_Container>
    796  1.1  joerg back_inserter(_Container& __x)
    797  1.1  joerg {
    798  1.1  joerg     return back_insert_iterator<_Container>(__x);
    799  1.1  joerg }
    800  1.1  joerg 
    801  1.1  joerg template <class _Container>
    802  1.1  joerg class _LIBCPP_TEMPLATE_VIS front_insert_iterator
    803  1.1  joerg     : public iterator<output_iterator_tag,
    804  1.1  joerg                       void,
    805  1.1  joerg                       void,
    806  1.1  joerg                       void,
    807  1.1  joerg                       void>
    808  1.1  joerg {
    809  1.1  joerg protected:
    810  1.1  joerg     _Container* container;
    811  1.1  joerg public:
    812  1.1  joerg     typedef _Container container_type;
    813  1.1  joerg 
    814  1.1  joerg     _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 explicit front_insert_iterator(_Container& __x) : container(_VSTD::addressof(__x)) {}
    815  1.1  joerg     _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 front_insert_iterator& operator=(const typename _Container::value_type& __value_)
    816  1.1  joerg         {container->push_front(__value_); return *this;}
    817  1.1  joerg #ifndef _LIBCPP_CXX03_LANG
    818  1.1  joerg     _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 front_insert_iterator& operator=(typename _Container::value_type&& __value_)
    819  1.1  joerg         {container->push_front(_VSTD::move(__value_)); return *this;}
    820  1.1  joerg #endif // _LIBCPP_CXX03_LANG
    821  1.1  joerg     _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 front_insert_iterator& operator*()     {return *this;}
    822  1.1  joerg     _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 front_insert_iterator& operator++()    {return *this;}
    823  1.1  joerg     _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 front_insert_iterator  operator++(int) {return *this;}
    824  1.1  joerg };
    825  1.1  joerg 
    826  1.1  joerg template <class _Container>
    827  1.1  joerg inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
    828  1.1  joerg front_insert_iterator<_Container>
    829  1.1  joerg front_inserter(_Container& __x)
    830  1.1  joerg {
    831  1.1  joerg     return front_insert_iterator<_Container>(__x);
    832  1.1  joerg }
    833  1.1  joerg 
    834  1.1  joerg template <class _Container>
    835  1.1  joerg class _LIBCPP_TEMPLATE_VIS insert_iterator
    836  1.1  joerg     : public iterator<output_iterator_tag,
    837  1.1  joerg                       void,
    838  1.1  joerg                       void,
    839  1.1  joerg                       void,
    840  1.1  joerg                       void>
    841  1.1  joerg {
    842  1.1  joerg protected:
    843  1.1  joerg     _Container* container;
    844  1.1  joerg     typename _Container::iterator iter;
    845  1.1  joerg public:
    846  1.1  joerg     typedef _Container container_type;
    847  1.1  joerg 
    848  1.1  joerg     _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 insert_iterator(_Container& __x, typename _Container::iterator __i)
    849  1.1  joerg         : container(_VSTD::addressof(__x)), iter(__i) {}
    850  1.1  joerg     _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 insert_iterator& operator=(const typename _Container::value_type& __value_)
    851  1.1  joerg         {iter = container->insert(iter, __value_); ++iter; return *this;}
    852  1.1  joerg #ifndef _LIBCPP_CXX03_LANG
    853  1.1  joerg     _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 insert_iterator& operator=(typename _Container::value_type&& __value_)
    854  1.1  joerg         {iter = container->insert(iter, _VSTD::move(__value_)); ++iter; return *this;}
    855  1.1  joerg #endif // _LIBCPP_CXX03_LANG
    856  1.1  joerg     _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 insert_iterator& operator*()        {return *this;}
    857  1.1  joerg     _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 insert_iterator& operator++()       {return *this;}
    858  1.1  joerg     _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 insert_iterator& operator++(int)    {return *this;}
    859  1.1  joerg };
    860  1.1  joerg 
    861  1.1  joerg template <class _Container>
    862  1.1  joerg inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
    863  1.1  joerg insert_iterator<_Container>
    864  1.1  joerg inserter(_Container& __x, typename _Container::iterator __i)
    865  1.1  joerg {
    866  1.1  joerg     return insert_iterator<_Container>(__x, __i);
    867  1.1  joerg }
    868  1.1  joerg 
    869  1.1  joerg template <class _Tp, class _CharT = char,
    870  1.1  joerg           class _Traits = char_traits<_CharT>, class _Distance = ptrdiff_t>
    871  1.1  joerg class _LIBCPP_TEMPLATE_VIS istream_iterator
    872  1.1  joerg     : public iterator<input_iterator_tag, _Tp, _Distance, const _Tp*, const _Tp&>
    873  1.1  joerg {
    874  1.1  joerg public:
    875  1.1  joerg     typedef _CharT char_type;
    876  1.1  joerg     typedef _Traits traits_type;
    877  1.1  joerg     typedef basic_istream<_CharT,_Traits> istream_type;
    878  1.1  joerg private:
    879  1.1  joerg     istream_type* __in_stream_;
    880  1.1  joerg     _Tp __value_;
    881  1.1  joerg public:
    882  1.1  joerg     _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR istream_iterator() : __in_stream_(nullptr), __value_() {}
    883  1.1  joerg     _LIBCPP_INLINE_VISIBILITY istream_iterator(istream_type& __s) : __in_stream_(_VSTD::addressof(__s))
    884  1.1  joerg         {
    885  1.1  joerg             if (!(*__in_stream_ >> __value_))
    886  1.1  joerg                 __in_stream_ = nullptr;
    887  1.1  joerg         }
    888  1.1  joerg 
    889  1.1  joerg     _LIBCPP_INLINE_VISIBILITY const _Tp& operator*() const {return __value_;}
    890  1.1  joerg     _LIBCPP_INLINE_VISIBILITY const _Tp* operator->() const {return _VSTD::addressof((operator*()));}
    891  1.1  joerg     _LIBCPP_INLINE_VISIBILITY istream_iterator& operator++()
    892  1.1  joerg         {
    893  1.1  joerg             if (!(*__in_stream_ >> __value_))
    894  1.1  joerg                 __in_stream_ = nullptr;
    895  1.1  joerg             return *this;
    896  1.1  joerg         }
    897  1.1  joerg     _LIBCPP_INLINE_VISIBILITY istream_iterator  operator++(int)
    898  1.1  joerg         {istream_iterator __t(*this); ++(*this); return __t;}
    899  1.1  joerg 
    900  1.1  joerg     template <class _Up, class _CharU, class _TraitsU, class _DistanceU>
    901  1.1  joerg     friend _LIBCPP_INLINE_VISIBILITY
    902  1.1  joerg     bool
    903  1.1  joerg     operator==(const istream_iterator<_Up, _CharU, _TraitsU, _DistanceU>& __x,
    904  1.1  joerg                const istream_iterator<_Up, _CharU, _TraitsU, _DistanceU>& __y);
    905  1.1  joerg 
    906  1.1  joerg     template <class _Up, class _CharU, class _TraitsU, class _DistanceU>
    907  1.1  joerg     friend _LIBCPP_INLINE_VISIBILITY
    908  1.1  joerg     bool
    909  1.1  joerg     operator==(const istream_iterator<_Up, _CharU, _TraitsU, _DistanceU>& __x,
    910  1.1  joerg                const istream_iterator<_Up, _CharU, _TraitsU, _DistanceU>& __y);
    911  1.1  joerg };
    912  1.1  joerg 
    913  1.1  joerg template <class _Tp, class _CharT, class _Traits, class _Distance>
    914  1.1  joerg inline _LIBCPP_INLINE_VISIBILITY
    915  1.1  joerg bool
    916  1.1  joerg operator==(const istream_iterator<_Tp, _CharT, _Traits, _Distance>& __x,
    917  1.1  joerg            const istream_iterator<_Tp, _CharT, _Traits, _Distance>& __y)
    918  1.1  joerg {
    919  1.1  joerg     return __x.__in_stream_ == __y.__in_stream_;
    920  1.1  joerg }
    921  1.1  joerg 
    922  1.1  joerg template <class _Tp, class _CharT, class _Traits, class _Distance>
    923  1.1  joerg inline _LIBCPP_INLINE_VISIBILITY
    924  1.1  joerg bool
    925  1.1  joerg operator!=(const istream_iterator<_Tp, _CharT, _Traits, _Distance>& __x,
    926  1.1  joerg            const istream_iterator<_Tp, _CharT, _Traits, _Distance>& __y)
    927  1.1  joerg {
    928  1.1  joerg     return !(__x == __y);
    929  1.1  joerg }
    930  1.1  joerg 
    931  1.1  joerg template <class _Tp, class _CharT = char, class _Traits = char_traits<_CharT> >
    932  1.1  joerg class _LIBCPP_TEMPLATE_VIS ostream_iterator
    933  1.1  joerg     : public iterator<output_iterator_tag, void, void, void, void>
    934  1.1  joerg {
    935  1.1  joerg public:
    936  1.1  joerg     typedef output_iterator_tag             iterator_category;
    937  1.1  joerg     typedef void                            value_type;
    938  1.1  joerg #if _LIBCPP_STD_VER > 17
    939  1.1  joerg     typedef std::ptrdiff_t                  difference_type;
    940  1.1  joerg #else
    941  1.1  joerg     typedef void                            difference_type;
    942  1.1  joerg #endif
    943  1.1  joerg     typedef void                            pointer;
    944  1.1  joerg     typedef void                            reference;
    945  1.1  joerg     typedef _CharT                          char_type;
    946  1.1  joerg     typedef _Traits                         traits_type;
    947  1.1  joerg     typedef basic_ostream<_CharT, _Traits>  ostream_type;
    948  1.1  joerg 
    949  1.1  joerg private:
    950  1.1  joerg     ostream_type* __out_stream_;
    951  1.1  joerg     const char_type* __delim_;
    952  1.1  joerg public:
    953  1.1  joerg     _LIBCPP_INLINE_VISIBILITY ostream_iterator(ostream_type& __s) _NOEXCEPT
    954  1.1  joerg         : __out_stream_(_VSTD::addressof(__s)), __delim_(nullptr) {}
    955  1.1  joerg     _LIBCPP_INLINE_VISIBILITY ostream_iterator(ostream_type& __s, const _CharT* __delimiter) _NOEXCEPT
    956  1.1  joerg         : __out_stream_(_VSTD::addressof(__s)), __delim_(__delimiter) {}
    957  1.1  joerg     _LIBCPP_INLINE_VISIBILITY ostream_iterator& operator=(const _Tp& __value_)
    958  1.1  joerg         {
    959  1.1  joerg             *__out_stream_ << __value_;
    960  1.1  joerg             if (__delim_)
    961  1.1  joerg                 *__out_stream_ << __delim_;
    962  1.1  joerg             return *this;
    963  1.1  joerg         }
    964  1.1  joerg 
    965  1.1  joerg     _LIBCPP_INLINE_VISIBILITY ostream_iterator& operator*()     {return *this;}
    966  1.1  joerg     _LIBCPP_INLINE_VISIBILITY ostream_iterator& operator++()    {return *this;}
    967  1.1  joerg     _LIBCPP_INLINE_VISIBILITY ostream_iterator& operator++(int) {return *this;}
    968  1.1  joerg };
    969  1.1  joerg 
    970  1.1  joerg template<class _CharT, class _Traits>
    971  1.1  joerg class _LIBCPP_TEMPLATE_VIS istreambuf_iterator
    972  1.1  joerg     : public iterator<input_iterator_tag, _CharT,
    973  1.1  joerg                       typename _Traits::off_type, _CharT*,
    974  1.1  joerg                       _CharT>
    975  1.1  joerg {
    976  1.1  joerg public:
    977  1.1  joerg     typedef _CharT                          char_type;
    978  1.1  joerg     typedef _Traits                         traits_type;
    979  1.1  joerg     typedef typename _Traits::int_type      int_type;
    980  1.1  joerg     typedef basic_streambuf<_CharT,_Traits> streambuf_type;
    981  1.1  joerg     typedef basic_istream<_CharT,_Traits>   istream_type;
    982  1.1  joerg private:
    983  1.1  joerg     mutable streambuf_type* __sbuf_;
    984  1.1  joerg 
    985  1.1  joerg     class __proxy
    986  1.1  joerg     {
    987  1.1  joerg         char_type __keep_;
    988  1.1  joerg         streambuf_type* __sbuf_;
    989  1.1  joerg         _LIBCPP_INLINE_VISIBILITY __proxy(char_type __c, streambuf_type* __s)
    990  1.1  joerg             : __keep_(__c), __sbuf_(__s) {}
    991  1.1  joerg         friend class istreambuf_iterator;
    992  1.1  joerg     public:
    993  1.1  joerg         _LIBCPP_INLINE_VISIBILITY char_type operator*() const {return __keep_;}
    994  1.1  joerg     };
    995  1.1  joerg 
    996  1.1  joerg     _LIBCPP_INLINE_VISIBILITY
    997  1.1  joerg     bool __test_for_eof() const
    998  1.1  joerg     {
    999  1.1  joerg         if (__sbuf_ && traits_type::eq_int_type(__sbuf_->sgetc(), traits_type::eof()))
   1000  1.1  joerg             __sbuf_ = nullptr;
   1001  1.1  joerg         return __sbuf_ == nullptr;
   1002  1.1  joerg     }
   1003  1.1  joerg public:
   1004  1.1  joerg     _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR istreambuf_iterator() _NOEXCEPT : __sbuf_(nullptr) {}
   1005  1.1  joerg     _LIBCPP_INLINE_VISIBILITY istreambuf_iterator(istream_type& __s) _NOEXCEPT
   1006  1.1  joerg         : __sbuf_(__s.rdbuf()) {}
   1007  1.1  joerg     _LIBCPP_INLINE_VISIBILITY istreambuf_iterator(streambuf_type* __s) _NOEXCEPT
   1008  1.1  joerg         : __sbuf_(__s) {}
   1009  1.1  joerg     _LIBCPP_INLINE_VISIBILITY istreambuf_iterator(const __proxy& __p) _NOEXCEPT
   1010  1.1  joerg         : __sbuf_(__p.__sbuf_) {}
   1011  1.1  joerg 
   1012  1.1  joerg     _LIBCPP_INLINE_VISIBILITY char_type  operator*() const
   1013  1.1  joerg         {return static_cast<char_type>(__sbuf_->sgetc());}
   1014  1.1  joerg     _LIBCPP_INLINE_VISIBILITY istreambuf_iterator& operator++()
   1015  1.1  joerg         {
   1016  1.1  joerg             __sbuf_->sbumpc();
   1017  1.1  joerg             return *this;
   1018  1.1  joerg         }
   1019  1.1  joerg     _LIBCPP_INLINE_VISIBILITY __proxy              operator++(int)
   1020  1.1  joerg         {
   1021  1.1  joerg             return __proxy(__sbuf_->sbumpc(), __sbuf_);
   1022  1.1  joerg         }
   1023  1.1  joerg 
   1024  1.1  joerg     _LIBCPP_INLINE_VISIBILITY bool equal(const istreambuf_iterator& __b) const
   1025  1.1  joerg         {return __test_for_eof() == __b.__test_for_eof();}
   1026  1.1  joerg };
   1027  1.1  joerg 
   1028  1.1  joerg template <class _CharT, class _Traits>
   1029  1.1  joerg inline _LIBCPP_INLINE_VISIBILITY
   1030  1.1  joerg bool operator==(const istreambuf_iterator<_CharT,_Traits>& __a,
   1031  1.1  joerg                 const istreambuf_iterator<_CharT,_Traits>& __b)
   1032  1.1  joerg                 {return __a.equal(__b);}
   1033  1.1  joerg 
   1034  1.1  joerg template <class _CharT, class _Traits>
   1035  1.1  joerg inline _LIBCPP_INLINE_VISIBILITY
   1036  1.1  joerg bool operator!=(const istreambuf_iterator<_CharT,_Traits>& __a,
   1037  1.1  joerg                 const istreambuf_iterator<_CharT,_Traits>& __b)
   1038  1.1  joerg                 {return !__a.equal(__b);}
   1039  1.1  joerg 
   1040  1.1  joerg template <class _CharT, class _Traits>
   1041  1.1  joerg class _LIBCPP_TEMPLATE_VIS ostreambuf_iterator
   1042  1.1  joerg     : public iterator<output_iterator_tag, void, void, void, void>
   1043  1.1  joerg {
   1044  1.1  joerg public:
   1045  1.1  joerg     typedef output_iterator_tag                 iterator_category;
   1046  1.1  joerg     typedef void                                value_type;
   1047  1.1  joerg #if _LIBCPP_STD_VER > 17
   1048  1.1  joerg     typedef std::ptrdiff_t                      difference_type;
   1049  1.1  joerg #else
   1050  1.1  joerg     typedef void                                difference_type;
   1051  1.1  joerg #endif
   1052  1.1  joerg     typedef void                                pointer;
   1053  1.1  joerg     typedef void                                reference;
   1054  1.1  joerg     typedef _CharT                              char_type;
   1055  1.1  joerg     typedef _Traits                             traits_type;
   1056  1.1  joerg     typedef basic_streambuf<_CharT, _Traits>    streambuf_type;
   1057  1.1  joerg     typedef basic_ostream<_CharT, _Traits>      ostream_type;
   1058  1.1  joerg 
   1059  1.1  joerg private:
   1060  1.1  joerg     streambuf_type* __sbuf_;
   1061  1.1  joerg public:
   1062  1.1  joerg     _LIBCPP_INLINE_VISIBILITY ostreambuf_iterator(ostream_type& __s) _NOEXCEPT
   1063  1.1  joerg         : __sbuf_(__s.rdbuf()) {}
   1064  1.1  joerg     _LIBCPP_INLINE_VISIBILITY ostreambuf_iterator(streambuf_type* __s) _NOEXCEPT
   1065  1.1  joerg         : __sbuf_(__s) {}
   1066  1.1  joerg     _LIBCPP_INLINE_VISIBILITY ostreambuf_iterator& operator=(_CharT __c)
   1067  1.1  joerg         {
   1068  1.1  joerg             if (__sbuf_ && traits_type::eq_int_type(__sbuf_->sputc(__c), traits_type::eof()))
   1069  1.1  joerg                 __sbuf_ = nullptr;
   1070  1.1  joerg             return *this;
   1071  1.1  joerg         }
   1072  1.1  joerg     _LIBCPP_INLINE_VISIBILITY ostreambuf_iterator& operator*()     {return *this;}
   1073  1.1  joerg     _LIBCPP_INLINE_VISIBILITY ostreambuf_iterator& operator++()    {return *this;}
   1074  1.1  joerg     _LIBCPP_INLINE_VISIBILITY ostreambuf_iterator& operator++(int) {return *this;}
   1075  1.1  joerg     _LIBCPP_INLINE_VISIBILITY bool failed() const _NOEXCEPT {return __sbuf_ == nullptr;}
   1076  1.1  joerg 
   1077  1.1  joerg     template <class _Ch, class _Tr>
   1078  1.1  joerg     friend
   1079  1.1  joerg     _LIBCPP_HIDDEN
   1080  1.1  joerg     ostreambuf_iterator<_Ch, _Tr>
   1081  1.1  joerg     __pad_and_output(ostreambuf_iterator<_Ch, _Tr> __s,
   1082  1.1  joerg                      const _Ch* __ob, const _Ch* __op, const _Ch* __oe,
   1083  1.1  joerg                      ios_base& __iob, _Ch __fl);
   1084  1.1  joerg };
   1085  1.1  joerg 
   1086  1.1  joerg template <class _Iter>
   1087  1.1  joerg class _LIBCPP_TEMPLATE_VIS move_iterator
   1088  1.1  joerg {
   1089  1.1  joerg private:
   1090  1.1  joerg     _Iter __i;
   1091  1.1  joerg public:
   1092  1.1  joerg     typedef _Iter                                            iterator_type;
   1093  1.1  joerg     typedef typename iterator_traits<iterator_type>::value_type value_type;
   1094  1.1  joerg     typedef typename iterator_traits<iterator_type>::difference_type difference_type;
   1095  1.1  joerg     typedef iterator_type pointer;
   1096  1.1  joerg     typedef _If<__is_cpp17_random_access_iterator<_Iter>::value,
   1097  1.1  joerg         random_access_iterator_tag,
   1098  1.1  joerg         typename iterator_traits<_Iter>::iterator_category>  iterator_category;
   1099  1.1  joerg #if _LIBCPP_STD_VER > 17
   1100  1.1  joerg     typedef input_iterator_tag                               iterator_concept;
   1101  1.1  joerg #endif
   1102  1.1  joerg 
   1103  1.1  joerg #ifndef _LIBCPP_CXX03_LANG
   1104  1.1  joerg     typedef typename iterator_traits<iterator_type>::reference __reference;
   1105  1.1  joerg     typedef typename conditional<
   1106  1.1  joerg             is_reference<__reference>::value,
   1107  1.1  joerg             typename remove_reference<__reference>::type&&,
   1108  1.1  joerg             __reference
   1109  1.1  joerg         >::type reference;
   1110  1.1  joerg #else
   1111  1.1  joerg     typedef typename iterator_traits<iterator_type>::reference reference;
   1112  1.1  joerg #endif
   1113  1.1  joerg 
   1114  1.1  joerg     _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
   1115  1.1  joerg     move_iterator() : __i() {}
   1116  1.1  joerg     _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
   1117  1.1  joerg     explicit move_iterator(_Iter __x) : __i(__x) {}
   1118  1.1  joerg     template <class _Up>
   1119  1.1  joerg       _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
   1120  1.1  joerg       move_iterator(const move_iterator<_Up>& __u) : __i(__u.base()) {}
   1121  1.1  joerg     _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 _Iter base() const {return __i;}
   1122  1.1  joerg     _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
   1123  1.1  joerg     reference operator*() const { return static_cast<reference>(*__i); }
   1124  1.1  joerg     _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
   1125  1.1  joerg     pointer  operator->() const { return __i;}
   1126  1.1  joerg     _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
   1127  1.1  joerg     move_iterator& operator++() {++__i; return *this;}
   1128  1.1  joerg     _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
   1129  1.1  joerg     move_iterator  operator++(int) {move_iterator __tmp(*this); ++__i; return __tmp;}
   1130  1.1  joerg     _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
   1131  1.1  joerg     move_iterator& operator--() {--__i; return *this;}
   1132  1.1  joerg     _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
   1133  1.1  joerg     move_iterator  operator--(int) {move_iterator __tmp(*this); --__i; return __tmp;}
   1134  1.1  joerg     _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
   1135  1.1  joerg     move_iterator  operator+ (difference_type __n) const {return move_iterator(__i + __n);}
   1136  1.1  joerg     _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
   1137  1.1  joerg     move_iterator& operator+=(difference_type __n) {__i += __n; return *this;}
   1138  1.1  joerg     _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
   1139  1.1  joerg     move_iterator  operator- (difference_type __n) const {return move_iterator(__i - __n);}
   1140  1.1  joerg     _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
   1141  1.1  joerg     move_iterator& operator-=(difference_type __n) {__i -= __n; return *this;}
   1142  1.1  joerg     _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
   1143  1.1  joerg     reference operator[](difference_type __n) const { return static_cast<reference>(__i[__n]); }
   1144  1.1  joerg };
   1145  1.1  joerg 
   1146  1.1  joerg template <class _Iter1, class _Iter2>
   1147  1.1  joerg inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
   1148  1.1  joerg bool
   1149  1.1  joerg operator==(const move_iterator<_Iter1>& __x, const move_iterator<_Iter2>& __y)
   1150  1.1  joerg {
   1151  1.1  joerg     return __x.base() == __y.base();
   1152  1.1  joerg }
   1153  1.1  joerg 
   1154  1.1  joerg template <class _Iter1, class _Iter2>
   1155  1.1  joerg inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
   1156  1.1  joerg bool
   1157  1.1  joerg operator<(const move_iterator<_Iter1>& __x, const move_iterator<_Iter2>& __y)
   1158  1.1  joerg {
   1159  1.1  joerg     return __x.base() < __y.base();
   1160  1.1  joerg }
   1161  1.1  joerg 
   1162  1.1  joerg template <class _Iter1, class _Iter2>
   1163  1.1  joerg inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
   1164  1.1  joerg bool
   1165  1.1  joerg operator!=(const move_iterator<_Iter1>& __x, const move_iterator<_Iter2>& __y)
   1166  1.1  joerg {
   1167  1.1  joerg     return __x.base() != __y.base();
   1168  1.1  joerg }
   1169  1.1  joerg 
   1170  1.1  joerg template <class _Iter1, class _Iter2>
   1171  1.1  joerg inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
   1172  1.1  joerg bool
   1173  1.1  joerg operator>(const move_iterator<_Iter1>& __x, const move_iterator<_Iter2>& __y)
   1174  1.1  joerg {
   1175  1.1  joerg     return __x.base() > __y.base();
   1176  1.1  joerg }
   1177  1.1  joerg 
   1178  1.1  joerg template <class _Iter1, class _Iter2>
   1179  1.1  joerg inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
   1180  1.1  joerg bool
   1181  1.1  joerg operator>=(const move_iterator<_Iter1>& __x, const move_iterator<_Iter2>& __y)
   1182  1.1  joerg {
   1183  1.1  joerg     return __x.base() >= __y.base();
   1184  1.1  joerg }
   1185  1.1  joerg 
   1186  1.1  joerg template <class _Iter1, class _Iter2>
   1187  1.1  joerg inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
   1188  1.1  joerg bool
   1189  1.1  joerg operator<=(const move_iterator<_Iter1>& __x, const move_iterator<_Iter2>& __y)
   1190  1.1  joerg {
   1191  1.1  joerg     return __x.base() <= __y.base();
   1192  1.1  joerg }
   1193  1.1  joerg 
   1194  1.1  joerg #ifndef _LIBCPP_CXX03_LANG
   1195  1.1  joerg template <class _Iter1, class _Iter2>
   1196  1.1  joerg inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
   1197  1.1  joerg auto
   1198  1.1  joerg operator-(const move_iterator<_Iter1>& __x, const move_iterator<_Iter2>& __y)
   1199  1.1  joerg -> decltype(__x.base() - __y.base())
   1200  1.1  joerg {
   1201  1.1  joerg     return __x.base() - __y.base();
   1202  1.1  joerg }
   1203  1.1  joerg #else
   1204  1.1  joerg template <class _Iter1, class _Iter2>
   1205  1.1  joerg inline _LIBCPP_INLINE_VISIBILITY
   1206  1.1  joerg typename move_iterator<_Iter1>::difference_type
   1207  1.1  joerg operator-(const move_iterator<_Iter1>& __x, const move_iterator<_Iter2>& __y)
   1208  1.1  joerg {
   1209  1.1  joerg     return __x.base() - __y.base();
   1210  1.1  joerg }
   1211  1.1  joerg #endif
   1212  1.1  joerg 
   1213  1.1  joerg template <class _Iter>
   1214  1.1  joerg inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
   1215  1.1  joerg move_iterator<_Iter>
   1216  1.1  joerg operator+(typename move_iterator<_Iter>::difference_type __n, const move_iterator<_Iter>& __x)
   1217  1.1  joerg {
   1218  1.1  joerg     return move_iterator<_Iter>(__x.base() + __n);
   1219  1.1  joerg }
   1220  1.1  joerg 
   1221  1.1  joerg template <class _Iter>
   1222  1.1  joerg inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
   1223  1.1  joerg move_iterator<_Iter>
   1224  1.1  joerg make_move_iterator(_Iter __i)
   1225  1.1  joerg {
   1226  1.1  joerg     return move_iterator<_Iter>(__i);
   1227  1.1  joerg }
   1228  1.1  joerg 
   1229  1.1  joerg // __wrap_iter
   1230  1.1  joerg 
   1231  1.1  joerg template <class _Iter> class __wrap_iter;
   1232  1.1  joerg 
   1233  1.1  joerg template <class _Iter1, class _Iter2>
   1234  1.1  joerg _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG
   1235  1.1  joerg bool
   1236  1.1  joerg operator==(const __wrap_iter<_Iter1>&, const __wrap_iter<_Iter2>&) _NOEXCEPT;
   1237  1.1  joerg 
   1238  1.1  joerg template <class _Iter1, class _Iter2>
   1239  1.1  joerg _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG
   1240  1.1  joerg bool
   1241  1.1  joerg operator<(const __wrap_iter<_Iter1>&, const __wrap_iter<_Iter2>&) _NOEXCEPT;
   1242  1.1  joerg 
   1243  1.1  joerg template <class _Iter1, class _Iter2>
   1244  1.1  joerg _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG
   1245  1.1  joerg bool
   1246  1.1  joerg operator!=(const __wrap_iter<_Iter1>&, const __wrap_iter<_Iter2>&) _NOEXCEPT;
   1247  1.1  joerg 
   1248  1.1  joerg template <class _Iter1, class _Iter2>
   1249  1.1  joerg _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG
   1250  1.1  joerg bool
   1251  1.1  joerg operator>(const __wrap_iter<_Iter1>&, const __wrap_iter<_Iter2>&) _NOEXCEPT;
   1252  1.1  joerg 
   1253  1.1  joerg template <class _Iter1, class _Iter2>
   1254  1.1  joerg _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG
   1255  1.1  joerg bool
   1256  1.1  joerg operator>=(const __wrap_iter<_Iter1>&, const __wrap_iter<_Iter2>&) _NOEXCEPT;
   1257  1.1  joerg 
   1258  1.1  joerg template <class _Iter1, class _Iter2>
   1259  1.1  joerg _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG
   1260  1.1  joerg bool
   1261  1.1  joerg operator<=(const __wrap_iter<_Iter1>&, const __wrap_iter<_Iter2>&) _NOEXCEPT;
   1262  1.1  joerg 
   1263  1.1  joerg #ifndef _LIBCPP_CXX03_LANG
   1264  1.1  joerg template <class _Iter1, class _Iter2>
   1265  1.1  joerg _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG
   1266  1.1  joerg auto
   1267  1.1  joerg operator-(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter2>& __y) _NOEXCEPT
   1268  1.1  joerg -> decltype(__x.base() - __y.base());
   1269  1.1  joerg #else
   1270  1.1  joerg template <class _Iter1, class _Iter2>
   1271  1.1  joerg _LIBCPP_INLINE_VISIBILITY
   1272  1.1  joerg typename __wrap_iter<_Iter1>::difference_type
   1273  1.1  joerg operator-(const __wrap_iter<_Iter1>&, const __wrap_iter<_Iter2>&) _NOEXCEPT;
   1274  1.1  joerg #endif
   1275  1.1  joerg 
   1276  1.1  joerg template <class _Iter>
   1277  1.1  joerg _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG
   1278  1.1  joerg __wrap_iter<_Iter>
   1279  1.1  joerg operator+(typename __wrap_iter<_Iter>::difference_type, __wrap_iter<_Iter>) _NOEXCEPT;
   1280  1.1  joerg 
   1281  1.1  joerg template <class _Ip, class _Op> _Op _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 copy(_Ip, _Ip, _Op);
   1282  1.1  joerg template <class _B1, class _B2> _B2 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 copy_backward(_B1, _B1, _B2);
   1283  1.1  joerg template <class _Ip, class _Op> _Op _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 move(_Ip, _Ip, _Op);
   1284  1.1  joerg template <class _B1, class _B2> _B2 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 move_backward(_B1, _B1, _B2);
   1285  1.1  joerg 
   1286  1.1  joerg template <class _Iter>
   1287  1.1  joerg class __wrap_iter
   1288  1.1  joerg {
   1289  1.1  joerg public:
   1290  1.1  joerg     typedef _Iter                                                      iterator_type;
   1291  1.1  joerg     typedef typename iterator_traits<iterator_type>::value_type        value_type;
   1292  1.1  joerg     typedef typename iterator_traits<iterator_type>::difference_type   difference_type;
   1293  1.1  joerg     typedef typename iterator_traits<iterator_type>::pointer           pointer;
   1294  1.1  joerg     typedef typename iterator_traits<iterator_type>::reference         reference;
   1295  1.1  joerg     typedef typename iterator_traits<iterator_type>::iterator_category iterator_category;
   1296  1.1  joerg #if _LIBCPP_STD_VER > 17
   1297  1.1  joerg     typedef _If<__is_cpp17_contiguous_iterator<_Iter>::value,
   1298  1.1  joerg                 contiguous_iterator_tag, iterator_category>            iterator_concept;
   1299  1.1  joerg #endif
   1300  1.1  joerg 
   1301  1.1  joerg private:
   1302  1.1  joerg     iterator_type __i;
   1303  1.1  joerg public:
   1304  1.1  joerg     _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG __wrap_iter() _NOEXCEPT
   1305  1.1  joerg #if _LIBCPP_STD_VER > 11
   1306  1.1  joerg                 : __i{}
   1307  1.1  joerg #endif
   1308  1.1  joerg     {
   1309  1.1  joerg #if _LIBCPP_DEBUG_LEVEL == 2
   1310  1.1  joerg         __get_db()->__insert_i(this);
   1311  1.1  joerg #endif
   1312  1.1  joerg     }
   1313  1.1  joerg     template <class _Up> _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG
   1314  1.1  joerg         __wrap_iter(const __wrap_iter<_Up>& __u,
   1315  1.1  joerg             typename enable_if<is_convertible<_Up, iterator_type>::value>::type* = nullptr) _NOEXCEPT
   1316  1.1  joerg             : __i(__u.base())
   1317  1.1  joerg     {
   1318  1.1  joerg #if _LIBCPP_DEBUG_LEVEL == 2
   1319  1.1  joerg         __get_db()->__iterator_copy(this, &__u);
   1320  1.1  joerg #endif
   1321  1.1  joerg     }
   1322  1.1  joerg #if _LIBCPP_DEBUG_LEVEL == 2
   1323  1.1  joerg     _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG
   1324  1.1  joerg     __wrap_iter(const __wrap_iter& __x)
   1325  1.1  joerg         : __i(__x.base())
   1326  1.1  joerg     {
   1327  1.1  joerg         __get_db()->__iterator_copy(this, &__x);
   1328  1.1  joerg     }
   1329  1.1  joerg     _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG
   1330  1.1  joerg     __wrap_iter& operator=(const __wrap_iter& __x)
   1331  1.1  joerg     {
   1332  1.1  joerg         if (this != &__x)
   1333  1.1  joerg         {
   1334  1.1  joerg             __get_db()->__iterator_copy(this, &__x);
   1335  1.1  joerg             __i = __x.__i;
   1336  1.1  joerg         }
   1337  1.1  joerg         return *this;
   1338  1.1  joerg     }
   1339  1.1  joerg     _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG
   1340  1.1  joerg     ~__wrap_iter()
   1341  1.1  joerg     {
   1342  1.1  joerg         __get_db()->__erase_i(this);
   1343  1.1  joerg     }
   1344  1.1  joerg #endif
   1345  1.1  joerg     _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG reference operator*() const _NOEXCEPT
   1346  1.1  joerg     {
   1347  1.1  joerg #if _LIBCPP_DEBUG_LEVEL == 2
   1348  1.1  joerg         _LIBCPP_ASSERT(__get_const_db()->__dereferenceable(this),
   1349  1.1  joerg                        "Attempted to dereference a non-dereferenceable iterator");
   1350  1.1  joerg #endif
   1351  1.1  joerg         return *__i;
   1352  1.1  joerg     }
   1353  1.1  joerg     _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG pointer  operator->() const _NOEXCEPT
   1354  1.1  joerg     {
   1355  1.1  joerg #if _LIBCPP_DEBUG_LEVEL == 2
   1356  1.1  joerg         _LIBCPP_ASSERT(__get_const_db()->__dereferenceable(this),
   1357  1.1  joerg                        "Attempted to dereference a non-dereferenceable iterator");
   1358  1.1  joerg #endif
   1359  1.1  joerg         return _VSTD::__to_address(__i);
   1360  1.1  joerg     }
   1361  1.1  joerg     _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG __wrap_iter& operator++() _NOEXCEPT
   1362  1.1  joerg     {
   1363  1.1  joerg #if _LIBCPP_DEBUG_LEVEL == 2
   1364  1.1  joerg         _LIBCPP_ASSERT(__get_const_db()->__dereferenceable(this),
   1365  1.1  joerg                        "Attempted to increment a non-incrementable iterator");
   1366  1.1  joerg #endif
   1367  1.1  joerg         ++__i;
   1368  1.1  joerg         return *this;
   1369  1.1  joerg     }
   1370  1.1  joerg     _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG __wrap_iter  operator++(int) _NOEXCEPT
   1371  1.1  joerg         {__wrap_iter __tmp(*this); ++(*this); return __tmp;}
   1372  1.1  joerg 
   1373  1.1  joerg     _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG __wrap_iter& operator--() _NOEXCEPT
   1374  1.1  joerg     {
   1375  1.1  joerg #if _LIBCPP_DEBUG_LEVEL == 2
   1376  1.1  joerg         _LIBCPP_ASSERT(__get_const_db()->__decrementable(this),
   1377  1.1  joerg                        "Attempted to decrement a non-decrementable iterator");
   1378  1.1  joerg #endif
   1379  1.1  joerg         --__i;
   1380  1.1  joerg         return *this;
   1381  1.1  joerg     }
   1382  1.1  joerg     _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG __wrap_iter  operator--(int) _NOEXCEPT
   1383  1.1  joerg         {__wrap_iter __tmp(*this); --(*this); return __tmp;}
   1384  1.1  joerg     _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG __wrap_iter  operator+ (difference_type __n) const _NOEXCEPT
   1385  1.1  joerg         {__wrap_iter __w(*this); __w += __n; return __w;}
   1386  1.1  joerg     _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG __wrap_iter& operator+=(difference_type __n) _NOEXCEPT
   1387  1.1  joerg     {
   1388  1.1  joerg #if _LIBCPP_DEBUG_LEVEL == 2
   1389  1.1  joerg         _LIBCPP_ASSERT(__get_const_db()->__addable(this, __n),
   1390  1.1  joerg                    "Attempted to add/subtract an iterator outside its valid range");
   1391  1.1  joerg #endif
   1392  1.1  joerg         __i += __n;
   1393  1.1  joerg         return *this;
   1394  1.1  joerg     }
   1395  1.1  joerg     _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG __wrap_iter  operator- (difference_type __n) const _NOEXCEPT
   1396  1.1  joerg         {return *this + (-__n);}
   1397  1.1  joerg     _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG __wrap_iter& operator-=(difference_type __n) _NOEXCEPT
   1398  1.1  joerg         {*this += -__n; return *this;}
   1399  1.1  joerg     _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG reference    operator[](difference_type __n) const _NOEXCEPT
   1400  1.1  joerg     {
   1401  1.1  joerg #if _LIBCPP_DEBUG_LEVEL == 2
   1402  1.1  joerg         _LIBCPP_ASSERT(__get_const_db()->__subscriptable(this, __n),
   1403  1.1  joerg                    "Attempted to subscript an iterator outside its valid range");
   1404  1.1  joerg #endif
   1405  1.1  joerg         return __i[__n];
   1406  1.1  joerg     }
   1407  1.1  joerg 
   1408  1.1  joerg     _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG iterator_type base() const _NOEXCEPT {return __i;}
   1409  1.1  joerg 
   1410  1.1  joerg private:
   1411  1.1  joerg #if _LIBCPP_DEBUG_LEVEL == 2
   1412  1.1  joerg     _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG __wrap_iter(const void* __p, iterator_type __x) : __i(__x)
   1413  1.1  joerg     {
   1414  1.1  joerg         __get_db()->__insert_ic(this, __p);
   1415  1.1  joerg     }
   1416  1.1  joerg #else
   1417  1.1  joerg     _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG __wrap_iter(iterator_type __x) _NOEXCEPT : __i(__x) {}
   1418  1.1  joerg #endif
   1419  1.1  joerg 
   1420  1.1  joerg     template <class _Up> friend class __wrap_iter;
   1421  1.1  joerg     template <class _CharT, class _Traits, class _Alloc> friend class basic_string;
   1422  1.1  joerg     template <class _Tp, class _Alloc> friend class _LIBCPP_TEMPLATE_VIS vector;
   1423  1.1  joerg     template <class _Tp, size_t> friend class _LIBCPP_TEMPLATE_VIS span;
   1424  1.1  joerg 
   1425  1.1  joerg     template <class _Iter1, class _Iter2>
   1426  1.1  joerg     _LIBCPP_CONSTEXPR_IF_NODEBUG friend
   1427  1.1  joerg     bool
   1428  1.1  joerg     operator==(const __wrap_iter<_Iter1>&, const __wrap_iter<_Iter2>&) _NOEXCEPT;
   1429  1.1  joerg 
   1430  1.1  joerg     template <class _Iter1, class _Iter2>
   1431  1.1  joerg     _LIBCPP_CONSTEXPR_IF_NODEBUG friend
   1432  1.1  joerg     bool
   1433  1.1  joerg     operator<(const __wrap_iter<_Iter1>&, const __wrap_iter<_Iter2>&) _NOEXCEPT;
   1434  1.1  joerg 
   1435  1.1  joerg     template <class _Iter1, class _Iter2>
   1436  1.1  joerg     _LIBCPP_CONSTEXPR_IF_NODEBUG friend
   1437  1.1  joerg     bool
   1438  1.1  joerg     operator!=(const __wrap_iter<_Iter1>&, const __wrap_iter<_Iter2>&) _NOEXCEPT;
   1439  1.1  joerg 
   1440  1.1  joerg     template <class _Iter1, class _Iter2>
   1441  1.1  joerg     _LIBCPP_CONSTEXPR_IF_NODEBUG friend
   1442  1.1  joerg     bool
   1443  1.1  joerg     operator>(const __wrap_iter<_Iter1>&, const __wrap_iter<_Iter2>&) _NOEXCEPT;
   1444  1.1  joerg 
   1445  1.1  joerg     template <class _Iter1, class _Iter2>
   1446  1.1  joerg     _LIBCPP_CONSTEXPR_IF_NODEBUG friend
   1447  1.1  joerg     bool
   1448  1.1  joerg     operator>=(const __wrap_iter<_Iter1>&, const __wrap_iter<_Iter2>&) _NOEXCEPT;
   1449  1.1  joerg 
   1450  1.1  joerg     template <class _Iter1, class _Iter2>
   1451  1.1  joerg     _LIBCPP_CONSTEXPR_IF_NODEBUG friend
   1452  1.1  joerg     bool
   1453  1.1  joerg     operator<=(const __wrap_iter<_Iter1>&, const __wrap_iter<_Iter2>&) _NOEXCEPT;
   1454  1.1  joerg 
   1455  1.1  joerg #ifndef _LIBCPP_CXX03_LANG
   1456  1.1  joerg     template <class _Iter1, class _Iter2>
   1457  1.1  joerg     _LIBCPP_CONSTEXPR_IF_NODEBUG friend
   1458  1.1  joerg     auto
   1459  1.1  joerg     operator-(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter2>& __y) _NOEXCEPT
   1460  1.1  joerg     -> decltype(__x.base() - __y.base());
   1461  1.1  joerg #else
   1462  1.1  joerg     template <class _Iter1, class _Iter2>
   1463  1.1  joerg     _LIBCPP_CONSTEXPR_IF_NODEBUG friend
   1464  1.1  joerg     typename __wrap_iter<_Iter1>::difference_type
   1465  1.1  joerg     operator-(const __wrap_iter<_Iter1>&, const __wrap_iter<_Iter2>&) _NOEXCEPT;
   1466  1.1  joerg #endif
   1467  1.1  joerg 
   1468  1.1  joerg     template <class _Iter1>
   1469  1.1  joerg     _LIBCPP_CONSTEXPR_IF_NODEBUG friend
   1470  1.1  joerg     __wrap_iter<_Iter1>
   1471  1.1  joerg     operator+(typename __wrap_iter<_Iter1>::difference_type, __wrap_iter<_Iter1>) _NOEXCEPT;
   1472  1.1  joerg };
   1473  1.1  joerg 
   1474  1.1  joerg #if _LIBCPP_STD_VER <= 17
   1475  1.1  joerg template <class _It>
   1476  1.1  joerg struct __is_cpp17_contiguous_iterator<__wrap_iter<_It> > : __is_cpp17_contiguous_iterator<_It> {};
   1477  1.1  joerg #endif
   1478  1.1  joerg 
   1479  1.1  joerg template <class _Iter>
   1480  1.1  joerg _LIBCPP_CONSTEXPR
   1481  1.1  joerg _EnableIf<__is_cpp17_contiguous_iterator<_Iter>::value, decltype(_VSTD::__to_address(declval<_Iter>()))>
   1482  1.1  joerg __to_address(__wrap_iter<_Iter> __w) _NOEXCEPT {
   1483  1.1  joerg     return _VSTD::__to_address(__w.base());
   1484  1.1  joerg }
   1485  1.1  joerg 
   1486  1.1  joerg template <class _Iter1, class _Iter2>
   1487  1.1  joerg inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG
   1488  1.1  joerg bool
   1489  1.1  joerg operator==(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter2>& __y) _NOEXCEPT
   1490  1.1  joerg {
   1491  1.1  joerg     return __x.base() == __y.base();
   1492  1.1  joerg }
   1493  1.1  joerg 
   1494  1.1  joerg template <class _Iter1, class _Iter2>
   1495  1.1  joerg inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG
   1496  1.1  joerg bool
   1497  1.1  joerg operator<(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter2>& __y) _NOEXCEPT
   1498  1.1  joerg {
   1499  1.1  joerg #if _LIBCPP_DEBUG_LEVEL == 2
   1500  1.1  joerg     _LIBCPP_ASSERT(__get_const_db()->__less_than_comparable(&__x, &__y),
   1501  1.1  joerg                    "Attempted to compare incomparable iterators");
   1502  1.1  joerg #endif
   1503  1.1  joerg     return __x.base() < __y.base();
   1504  1.1  joerg }
   1505  1.1  joerg 
   1506  1.1  joerg template <class _Iter1, class _Iter2>
   1507  1.1  joerg inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG
   1508  1.1  joerg bool
   1509  1.1  joerg operator!=(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter2>& __y) _NOEXCEPT
   1510  1.1  joerg {
   1511  1.1  joerg     return !(__x == __y);
   1512  1.1  joerg }
   1513  1.1  joerg 
   1514  1.1  joerg template <class _Iter1, class _Iter2>
   1515  1.1  joerg inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG
   1516  1.1  joerg bool
   1517  1.1  joerg operator>(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter2>& __y) _NOEXCEPT
   1518  1.1  joerg {
   1519  1.1  joerg     return __y < __x;
   1520  1.1  joerg }
   1521  1.1  joerg 
   1522  1.1  joerg template <class _Iter1, class _Iter2>
   1523  1.1  joerg inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG
   1524  1.1  joerg bool
   1525  1.1  joerg operator>=(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter2>& __y) _NOEXCEPT
   1526  1.1  joerg {
   1527  1.1  joerg     return !(__x < __y);
   1528  1.1  joerg }
   1529  1.1  joerg 
   1530  1.1  joerg template <class _Iter1, class _Iter2>
   1531  1.1  joerg inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG
   1532  1.1  joerg bool
   1533  1.1  joerg operator<=(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter2>& __y) _NOEXCEPT
   1534  1.1  joerg {
   1535  1.1  joerg     return !(__y < __x);
   1536  1.1  joerg }
   1537  1.1  joerg 
   1538  1.1  joerg template <class _Iter1>
   1539  1.1  joerg inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG
   1540  1.1  joerg bool
   1541  1.1  joerg operator!=(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter1>& __y) _NOEXCEPT
   1542  1.1  joerg {
   1543  1.1  joerg     return !(__x == __y);
   1544  1.1  joerg }
   1545  1.1  joerg 
   1546  1.1  joerg template <class _Iter1>
   1547  1.1  joerg inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG
   1548  1.1  joerg bool
   1549  1.1  joerg operator>(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter1>& __y) _NOEXCEPT
   1550  1.1  joerg {
   1551  1.1  joerg     return __y < __x;
   1552  1.1  joerg }
   1553  1.1  joerg 
   1554  1.1  joerg template <class _Iter1>
   1555  1.1  joerg inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG
   1556  1.1  joerg bool
   1557  1.1  joerg operator>=(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter1>& __y) _NOEXCEPT
   1558  1.1  joerg {
   1559  1.1  joerg     return !(__x < __y);
   1560  1.1  joerg }
   1561  1.1  joerg 
   1562  1.1  joerg template <class _Iter1>
   1563  1.1  joerg inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG
   1564  1.1  joerg bool
   1565  1.1  joerg operator<=(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter1>& __y) _NOEXCEPT
   1566  1.1  joerg {
   1567  1.1  joerg     return !(__y < __x);
   1568  1.1  joerg }
   1569  1.1  joerg 
   1570  1.1  joerg #ifndef _LIBCPP_CXX03_LANG
   1571  1.1  joerg template <class _Iter1, class _Iter2>
   1572  1.1  joerg inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG
   1573  1.1  joerg auto
   1574  1.1  joerg operator-(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter2>& __y) _NOEXCEPT
   1575  1.1  joerg -> decltype(__x.base() - __y.base())
   1576  1.1  joerg {
   1577  1.1  joerg #if _LIBCPP_DEBUG_LEVEL == 2
   1578  1.1  joerg     _LIBCPP_ASSERT(__get_const_db()->__less_than_comparable(&__x, &__y),
   1579  1.1  joerg                    "Attempted to subtract incompatible iterators");
   1580  1.1  joerg #endif
   1581  1.1  joerg     return __x.base() - __y.base();
   1582  1.1  joerg }
   1583  1.1  joerg #else
   1584  1.1  joerg template <class _Iter1, class _Iter2>
   1585  1.1  joerg inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG
   1586  1.1  joerg typename __wrap_iter<_Iter1>::difference_type
   1587  1.1  joerg operator-(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter2>& __y) _NOEXCEPT
   1588  1.1  joerg {
   1589  1.1  joerg #if _LIBCPP_DEBUG_LEVEL == 2
   1590  1.1  joerg     _LIBCPP_ASSERT(__get_const_db()->__less_than_comparable(&__x, &__y),
   1591  1.1  joerg                    "Attempted to subtract incompatible iterators");
   1592  1.1  joerg #endif
   1593  1.1  joerg     return __x.base() - __y.base();
   1594  1.1  joerg }
   1595  1.1  joerg #endif
   1596  1.1  joerg 
   1597  1.1  joerg template <class _Iter>
   1598  1.1  joerg inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG
   1599  1.1  joerg __wrap_iter<_Iter>
   1600  1.1  joerg operator+(typename __wrap_iter<_Iter>::difference_type __n,
   1601  1.1  joerg           __wrap_iter<_Iter> __x) _NOEXCEPT
   1602  1.1  joerg {
   1603  1.1  joerg     __x += __n;
   1604  1.1  joerg     return __x;
   1605  1.1  joerg }
   1606  1.1  joerg 
   1607  1.1  joerg template <class _Tp, size_t _Np>
   1608  1.1  joerg _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
   1609  1.1  joerg _Tp*
   1610  1.1  joerg begin(_Tp (&__array)[_Np])
   1611  1.1  joerg {
   1612  1.1  joerg     return __array;
   1613  1.1  joerg }
   1614  1.1  joerg 
   1615  1.1  joerg template <class _Tp, size_t _Np>
   1616  1.1  joerg _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
   1617  1.1  joerg _Tp*
   1618  1.1  joerg end(_Tp (&__array)[_Np])
   1619  1.1  joerg {
   1620  1.1  joerg     return __array + _Np;
   1621  1.1  joerg }
   1622  1.1  joerg 
   1623  1.1  joerg #if !defined(_LIBCPP_CXX03_LANG)
   1624  1.1  joerg 
   1625  1.1  joerg template <class _Cp>
   1626  1.1  joerg _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
   1627  1.1  joerg auto
   1628  1.1  joerg begin(_Cp& __c) -> decltype(__c.begin())
   1629  1.1  joerg {
   1630  1.1  joerg     return __c.begin();
   1631  1.1  joerg }
   1632  1.1  joerg 
   1633  1.1  joerg template <class _Cp>
   1634  1.1  joerg _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
   1635  1.1  joerg auto
   1636  1.1  joerg begin(const _Cp& __c) -> decltype(__c.begin())
   1637  1.1  joerg {
   1638  1.1  joerg     return __c.begin();
   1639  1.1  joerg }
   1640  1.1  joerg 
   1641  1.1  joerg template <class _Cp>
   1642  1.1  joerg _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
   1643  1.1  joerg auto
   1644  1.1  joerg end(_Cp& __c) -> decltype(__c.end())
   1645  1.1  joerg {
   1646  1.1  joerg     return __c.end();
   1647  1.1  joerg }
   1648  1.1  joerg 
   1649  1.1  joerg template <class _Cp>
   1650  1.1  joerg _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
   1651  1.1  joerg auto
   1652  1.1  joerg end(const _Cp& __c) -> decltype(__c.end())
   1653  1.1  joerg {
   1654  1.1  joerg     return __c.end();
   1655  1.1  joerg }
   1656  1.1  joerg 
   1657  1.1  joerg #if _LIBCPP_STD_VER > 11
   1658  1.1  joerg 
   1659  1.1  joerg template <class _Tp, size_t _Np>
   1660  1.1  joerg _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
   1661  1.1  joerg reverse_iterator<_Tp*> rbegin(_Tp (&__array)[_Np])
   1662  1.1  joerg {
   1663  1.1  joerg     return reverse_iterator<_Tp*>(__array + _Np);
   1664  1.1  joerg }
   1665  1.1  joerg 
   1666  1.1  joerg template <class _Tp, size_t _Np>
   1667  1.1  joerg _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
   1668  1.1  joerg reverse_iterator<_Tp*> rend(_Tp (&__array)[_Np])
   1669  1.1  joerg {
   1670  1.1  joerg     return reverse_iterator<_Tp*>(__array);
   1671  1.1  joerg }
   1672  1.1  joerg 
   1673  1.1  joerg template <class _Ep>
   1674  1.1  joerg _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
   1675  1.1  joerg reverse_iterator<const _Ep*> rbegin(initializer_list<_Ep> __il)
   1676  1.1  joerg {
   1677  1.1  joerg     return reverse_iterator<const _Ep*>(__il.end());
   1678  1.1  joerg }
   1679  1.1  joerg 
   1680  1.1  joerg template <class _Ep>
   1681  1.1  joerg _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
   1682  1.1  joerg reverse_iterator<const _Ep*> rend(initializer_list<_Ep> __il)
   1683  1.1  joerg {
   1684  1.1  joerg     return reverse_iterator<const _Ep*>(__il.begin());
   1685  1.1  joerg }
   1686  1.1  joerg 
   1687  1.1  joerg template <class _Cp>
   1688  1.1  joerg _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
   1689  1.1  joerg auto cbegin(const _Cp& __c) -> decltype(_VSTD::begin(__c))
   1690  1.1  joerg {
   1691  1.1  joerg     return _VSTD::begin(__c);
   1692  1.1  joerg }
   1693  1.1  joerg 
   1694  1.1  joerg template <class _Cp>
   1695  1.1  joerg _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
   1696  1.1  joerg auto cend(const _Cp& __c) -> decltype(_VSTD::end(__c))
   1697  1.1  joerg {
   1698  1.1  joerg     return _VSTD::end(__c);
   1699  1.1  joerg }
   1700  1.1  joerg 
   1701  1.1  joerg template <class _Cp>
   1702  1.1  joerg _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
   1703  1.1  joerg auto rbegin(_Cp& __c) -> decltype(__c.rbegin())
   1704  1.1  joerg {
   1705  1.1  joerg     return __c.rbegin();
   1706  1.1  joerg }
   1707  1.1  joerg 
   1708  1.1  joerg template <class _Cp>
   1709  1.1  joerg _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
   1710  1.1  joerg auto rbegin(const _Cp& __c) -> decltype(__c.rbegin())
   1711  1.1  joerg {
   1712  1.1  joerg     return __c.rbegin();
   1713  1.1  joerg }
   1714  1.1  joerg 
   1715  1.1  joerg template <class _Cp>
   1716  1.1  joerg _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
   1717  1.1  joerg auto rend(_Cp& __c) -> decltype(__c.rend())
   1718  1.1  joerg {
   1719  1.1  joerg     return __c.rend();
   1720  1.1  joerg }
   1721  1.1  joerg 
   1722  1.1  joerg template <class _Cp>
   1723  1.1  joerg _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
   1724  1.1  joerg auto rend(const _Cp& __c) -> decltype(__c.rend())
   1725  1.1  joerg {
   1726  1.1  joerg     return __c.rend();
   1727  1.1  joerg }
   1728  1.1  joerg 
   1729  1.1  joerg template <class _Cp>
   1730  1.1  joerg _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
   1731  1.1  joerg auto crbegin(const _Cp& __c) -> decltype(_VSTD::rbegin(__c))
   1732  1.1  joerg {
   1733  1.1  joerg     return _VSTD::rbegin(__c);
   1734  1.1  joerg }
   1735  1.1  joerg 
   1736  1.1  joerg template <class _Cp>
   1737  1.1  joerg _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
   1738  1.1  joerg auto crend(const _Cp& __c) -> decltype(_VSTD::rend(__c))
   1739  1.1  joerg {
   1740  1.1  joerg     return _VSTD::rend(__c);
   1741  1.1  joerg }
   1742  1.1  joerg 
   1743  1.1  joerg #endif
   1744  1.1  joerg 
   1745  1.1  joerg 
   1746  1.1  joerg #else  // defined(_LIBCPP_CXX03_LANG)
   1747  1.1  joerg 
   1748  1.1  joerg template <class _Cp>
   1749  1.1  joerg _LIBCPP_INLINE_VISIBILITY
   1750  1.1  joerg typename _Cp::iterator
   1751  1.1  joerg begin(_Cp& __c)
   1752  1.1  joerg {
   1753  1.1  joerg     return __c.begin();
   1754  1.1  joerg }
   1755  1.1  joerg 
   1756  1.1  joerg template <class _Cp>
   1757  1.1  joerg _LIBCPP_INLINE_VISIBILITY
   1758  1.1  joerg typename _Cp::const_iterator
   1759  1.1  joerg begin(const _Cp& __c)
   1760  1.1  joerg {
   1761  1.1  joerg     return __c.begin();
   1762  1.1  joerg }
   1763  1.1  joerg 
   1764  1.1  joerg template <class _Cp>
   1765  1.1  joerg _LIBCPP_INLINE_VISIBILITY
   1766  1.1  joerg typename _Cp::iterator
   1767  1.1  joerg end(_Cp& __c)
   1768  1.1  joerg {
   1769  1.1  joerg     return __c.end();
   1770  1.1  joerg }
   1771  1.1  joerg 
   1772  1.1  joerg template <class _Cp>
   1773  1.1  joerg _LIBCPP_INLINE_VISIBILITY
   1774  1.1  joerg typename _Cp::const_iterator
   1775  1.1  joerg end(const _Cp& __c)
   1776  1.1  joerg {
   1777  1.1  joerg     return __c.end();
   1778  1.1  joerg }
   1779  1.1  joerg 
   1780  1.1  joerg #endif // !defined(_LIBCPP_CXX03_LANG)
   1781  1.1  joerg 
   1782  1.1  joerg #if _LIBCPP_STD_VER > 14
   1783  1.1  joerg 
   1784  1.1  joerg // #if _LIBCPP_STD_VER > 11
   1785  1.1  joerg // template <>
   1786  1.1  joerg // struct _LIBCPP_TEMPLATE_VIS plus<void>
   1787  1.1  joerg // {
   1788  1.1  joerg //     template <class _T1, class _T2>
   1789  1.1  joerg //     _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
   1790  1.1  joerg //     auto operator()(_T1&& __t, _T2&& __u) const
   1791  1.1  joerg //     _NOEXCEPT_(noexcept(_VSTD::forward<_T1>(__t) + _VSTD::forward<_T2>(__u)))
   1792  1.1  joerg //     -> decltype        (_VSTD::forward<_T1>(__t) + _VSTD::forward<_T2>(__u))
   1793  1.1  joerg //         { return        _VSTD::forward<_T1>(__t) + _VSTD::forward<_T2>(__u); }
   1794  1.1  joerg //     typedef void is_transparent;
   1795  1.1  joerg // };
   1796  1.1  joerg // #endif
   1797  1.1  joerg 
   1798  1.1  joerg template <class _Cont>
   1799  1.1  joerg _LIBCPP_INLINE_VISIBILITY
   1800  1.1  joerg constexpr auto size(const _Cont& __c)
   1801  1.1  joerg _NOEXCEPT_(noexcept(__c.size()))
   1802  1.1  joerg -> decltype        (__c.size())
   1803  1.1  joerg { return            __c.size(); }
   1804  1.1  joerg 
   1805  1.1  joerg template <class _Tp, size_t _Sz>
   1806  1.1  joerg _LIBCPP_INLINE_VISIBILITY
   1807  1.1  joerg constexpr size_t size(const _Tp (&)[_Sz]) noexcept { return _Sz; }
   1808  1.1  joerg 
   1809  1.1  joerg #if _LIBCPP_STD_VER > 17
   1810  1.1  joerg template <class _Cont>
   1811  1.1  joerg _LIBCPP_INLINE_VISIBILITY
   1812  1.1  joerg constexpr auto ssize(const _Cont& __c)
   1813  1.1  joerg _NOEXCEPT_(noexcept(static_cast<common_type_t<ptrdiff_t, make_signed_t<decltype(__c.size())>>>(__c.size())))
   1814  1.1  joerg ->                              common_type_t<ptrdiff_t, make_signed_t<decltype(__c.size())>>
   1815  1.1  joerg { return            static_cast<common_type_t<ptrdiff_t, make_signed_t<decltype(__c.size())>>>(__c.size()); }
   1816  1.1  joerg 
   1817  1.1  joerg template <class _Tp, ptrdiff_t _Sz>
   1818  1.1  joerg _LIBCPP_INLINE_VISIBILITY
   1819  1.1  joerg constexpr ptrdiff_t ssize(const _Tp (&)[_Sz]) noexcept { return _Sz; }
   1820  1.1  joerg #endif
   1821  1.1  joerg 
   1822  1.1  joerg template <class _Cont>
   1823  1.1  joerg _LIBCPP_NODISCARD_AFTER_CXX17 _LIBCPP_INLINE_VISIBILITY
   1824  1.1  joerg constexpr auto empty(const _Cont& __c)
   1825  1.1  joerg _NOEXCEPT_(noexcept(__c.empty()))
   1826  1.1  joerg -> decltype        (__c.empty())
   1827  1.1  joerg { return            __c.empty(); }
   1828  1.1  joerg 
   1829  1.1  joerg template <class _Tp, size_t _Sz>
   1830  1.1  joerg _LIBCPP_NODISCARD_AFTER_CXX17 _LIBCPP_INLINE_VISIBILITY
   1831  1.1  joerg constexpr bool empty(const _Tp (&)[_Sz]) noexcept { return false; }
   1832  1.1  joerg 
   1833  1.1  joerg template <class _Ep>
   1834  1.1  joerg _LIBCPP_NODISCARD_AFTER_CXX17 _LIBCPP_INLINE_VISIBILITY
   1835  1.1  joerg constexpr bool empty(initializer_list<_Ep> __il) noexcept { return __il.size() == 0; }
   1836  1.1  joerg 
   1837  1.1  joerg template <class _Cont> constexpr
   1838  1.1  joerg _LIBCPP_INLINE_VISIBILITY
   1839  1.1  joerg auto data(_Cont& __c)
   1840  1.1  joerg _NOEXCEPT_(noexcept(__c.data()))
   1841  1.1  joerg -> decltype        (__c.data())
   1842  1.1  joerg { return            __c.data(); }
   1843  1.1  joerg 
   1844  1.1  joerg template <class _Cont> constexpr
   1845  1.1  joerg _LIBCPP_INLINE_VISIBILITY
   1846  1.1  joerg auto data(const _Cont& __c)
   1847  1.1  joerg _NOEXCEPT_(noexcept(__c.data()))
   1848  1.1  joerg -> decltype        (__c.data())
   1849  1.1  joerg { return            __c.data(); }
   1850  1.1  joerg 
   1851  1.1  joerg template <class _Tp, size_t _Sz>
   1852  1.1  joerg _LIBCPP_INLINE_VISIBILITY
   1853  1.1  joerg constexpr _Tp* data(_Tp (&__array)[_Sz]) noexcept { return __array; }
   1854  1.1  joerg 
   1855  1.1  joerg template <class _Ep>
   1856  1.1  joerg _LIBCPP_INLINE_VISIBILITY
   1857  1.1  joerg constexpr const _Ep* data(initializer_list<_Ep> __il) noexcept { return __il.begin(); }
   1858  1.1  joerg #endif
   1859  1.1  joerg 
   1860  1.1  joerg template <class _Container, class _Predicate>
   1861  1.1  joerg typename _Container::size_type
   1862  1.1  joerg __libcpp_erase_if_container(_Container& __c, _Predicate& __pred) {
   1863  1.1  joerg   typename _Container::size_type __old_size = __c.size();
   1864  1.1  joerg 
   1865  1.1  joerg   const typename _Container::iterator __last = __c.end();
   1866  1.1  joerg   for (typename _Container::iterator __iter = __c.begin(); __iter != __last;) {
   1867  1.1  joerg     if (__pred(*__iter))
   1868  1.1  joerg       __iter = __c.erase(__iter);
   1869  1.1  joerg     else
   1870  1.1  joerg       ++__iter;
   1871  1.1  joerg   }
   1872  1.1  joerg 
   1873  1.1  joerg   return __old_size - __c.size();
   1874  1.1  joerg }
   1875  1.1  joerg 
   1876  1.1  joerg _LIBCPP_END_NAMESPACE_STD
   1877  1.1  joerg 
   1878  1.1  joerg #endif // _LIBCPP_ITERATOR
   1879