10b57cec5SDimitry Andric// -*- C++ -*- 20b57cec5SDimitry Andric//===-------------------------- iterator ----------------------------------===// 30b57cec5SDimitry Andric// 40b57cec5SDimitry Andric// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 50b57cec5SDimitry Andric// See https://llvm.org/LICENSE.txt for license information. 60b57cec5SDimitry Andric// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 70b57cec5SDimitry Andric// 80b57cec5SDimitry Andric//===----------------------------------------------------------------------===// 90b57cec5SDimitry Andric 100b57cec5SDimitry Andric#ifndef _LIBCPP_ITERATOR 110b57cec5SDimitry Andric#define _LIBCPP_ITERATOR 120b57cec5SDimitry Andric 130b57cec5SDimitry Andric/* 140b57cec5SDimitry Andric iterator synopsis 150b57cec5SDimitry Andric 160b57cec5SDimitry Andricnamespace std 170b57cec5SDimitry Andric{ 180b57cec5SDimitry Andric 190b57cec5SDimitry Andrictemplate<class Iterator> 200b57cec5SDimitry Andricstruct iterator_traits 210b57cec5SDimitry Andric{ 220b57cec5SDimitry Andric typedef typename Iterator::difference_type difference_type; 230b57cec5SDimitry Andric typedef typename Iterator::value_type value_type; 240b57cec5SDimitry Andric typedef typename Iterator::pointer pointer; 250b57cec5SDimitry Andric typedef typename Iterator::reference reference; 260b57cec5SDimitry Andric typedef typename Iterator::iterator_category iterator_category; 270b57cec5SDimitry Andric}; 280b57cec5SDimitry Andric 290b57cec5SDimitry Andrictemplate<class T> 300b57cec5SDimitry Andricstruct iterator_traits<T*> 310b57cec5SDimitry Andric{ 320b57cec5SDimitry Andric typedef ptrdiff_t difference_type; 330b57cec5SDimitry Andric typedef T value_type; 340b57cec5SDimitry Andric typedef T* pointer; 350b57cec5SDimitry Andric typedef T& reference; 360b57cec5SDimitry Andric typedef random_access_iterator_tag iterator_category; 370b57cec5SDimitry Andric}; 380b57cec5SDimitry Andric 390b57cec5SDimitry Andrictemplate<class Category, class T, class Distance = ptrdiff_t, 400b57cec5SDimitry Andric class Pointer = T*, class Reference = T&> 410b57cec5SDimitry Andricstruct iterator 420b57cec5SDimitry Andric{ 430b57cec5SDimitry Andric typedef T value_type; 440b57cec5SDimitry Andric typedef Distance difference_type; 450b57cec5SDimitry Andric typedef Pointer pointer; 460b57cec5SDimitry Andric typedef Reference reference; 470b57cec5SDimitry Andric typedef Category iterator_category; 480b57cec5SDimitry Andric}; 490b57cec5SDimitry Andric 500b57cec5SDimitry Andricstruct input_iterator_tag {}; 510b57cec5SDimitry Andricstruct output_iterator_tag {}; 520b57cec5SDimitry Andricstruct forward_iterator_tag : public input_iterator_tag {}; 530b57cec5SDimitry Andricstruct bidirectional_iterator_tag : public forward_iterator_tag {}; 540b57cec5SDimitry Andricstruct random_access_iterator_tag : public bidirectional_iterator_tag {}; 550b57cec5SDimitry Andric 560b57cec5SDimitry Andric// 27.4.3, iterator operations 57*5ffd83dbSDimitry Andrictemplate <class InputIterator, class Distance> // constexpr in C++17 58*5ffd83dbSDimitry Andric constexpr void advance(InputIterator& i, Distance n); 590b57cec5SDimitry Andric 600b57cec5SDimitry Andrictemplate <class InputIterator> // constexpr in C++17 610b57cec5SDimitry Andric constexpr typename iterator_traits<InputIterator>::difference_type 620b57cec5SDimitry Andric distance(InputIterator first, InputIterator last); 630b57cec5SDimitry Andric 640b57cec5SDimitry Andrictemplate <class InputIterator> // constexpr in C++17 650b57cec5SDimitry Andric constexpr InputIterator next(InputIterator x, 660b57cec5SDimitry Andrictypename iterator_traits<InputIterator>::difference_type n = 1); 670b57cec5SDimitry Andric 680b57cec5SDimitry Andrictemplate <class BidirectionalIterator> // constexpr in C++17 690b57cec5SDimitry Andric constexpr BidirectionalIterator prev(BidirectionalIterator x, 700b57cec5SDimitry Andric typename iterator_traits<BidirectionalIterator>::difference_type n = 1); 710b57cec5SDimitry Andric 720b57cec5SDimitry Andrictemplate <class Iterator> 730b57cec5SDimitry Andricclass reverse_iterator 740b57cec5SDimitry Andric : public iterator<typename iterator_traits<Iterator>::iterator_category, 750b57cec5SDimitry Andric typename iterator_traits<Iterator>::value_type, 760b57cec5SDimitry Andric typename iterator_traits<Iterator>::difference_type, 770b57cec5SDimitry Andric typename iterator_traits<Iterator>::pointer, 780b57cec5SDimitry Andric typename iterator_traits<Iterator>::reference> 790b57cec5SDimitry Andric{ 800b57cec5SDimitry Andricprotected: 810b57cec5SDimitry Andric Iterator current; 820b57cec5SDimitry Andricpublic: 830b57cec5SDimitry Andric typedef Iterator iterator_type; 840b57cec5SDimitry Andric typedef typename iterator_traits<Iterator>::difference_type difference_type; 850b57cec5SDimitry Andric typedef typename iterator_traits<Iterator>::reference reference; 860b57cec5SDimitry Andric typedef typename iterator_traits<Iterator>::pointer pointer; 870b57cec5SDimitry Andric 880b57cec5SDimitry Andric constexpr reverse_iterator(); 890b57cec5SDimitry Andric constexpr explicit reverse_iterator(Iterator x); 900b57cec5SDimitry Andric template <class U> constexpr reverse_iterator(const reverse_iterator<U>& u); 910b57cec5SDimitry Andric template <class U> constexpr reverse_iterator& operator=(const reverse_iterator<U>& u); 920b57cec5SDimitry Andric constexpr Iterator base() const; 930b57cec5SDimitry Andric constexpr reference operator*() const; 940b57cec5SDimitry Andric constexpr pointer operator->() const; 950b57cec5SDimitry Andric constexpr reverse_iterator& operator++(); 960b57cec5SDimitry Andric constexpr reverse_iterator operator++(int); 970b57cec5SDimitry Andric constexpr reverse_iterator& operator--(); 980b57cec5SDimitry Andric constexpr reverse_iterator operator--(int); 990b57cec5SDimitry Andric constexpr reverse_iterator operator+ (difference_type n) const; 1000b57cec5SDimitry Andric constexpr reverse_iterator& operator+=(difference_type n); 1010b57cec5SDimitry Andric constexpr reverse_iterator operator- (difference_type n) const; 1020b57cec5SDimitry Andric constexpr reverse_iterator& operator-=(difference_type n); 1030b57cec5SDimitry Andric constexpr reference operator[](difference_type n) const; 1040b57cec5SDimitry Andric}; 1050b57cec5SDimitry Andric 1060b57cec5SDimitry Andrictemplate <class Iterator1, class Iterator2> 1070b57cec5SDimitry Andricconstexpr bool // constexpr in C++17 1080b57cec5SDimitry Andricoperator==(const reverse_iterator<Iterator1>& x, const reverse_iterator<Iterator2>& y); 1090b57cec5SDimitry Andric 1100b57cec5SDimitry Andrictemplate <class Iterator1, class Iterator2> 1110b57cec5SDimitry Andricconstexpr bool // constexpr in C++17 1120b57cec5SDimitry Andricoperator<(const reverse_iterator<Iterator1>& x, const reverse_iterator<Iterator2>& y); 1130b57cec5SDimitry Andric 1140b57cec5SDimitry Andrictemplate <class Iterator1, class Iterator2> 1150b57cec5SDimitry Andricconstexpr bool // constexpr in C++17 1160b57cec5SDimitry Andricoperator!=(const reverse_iterator<Iterator1>& x, const reverse_iterator<Iterator2>& y); 1170b57cec5SDimitry Andric 1180b57cec5SDimitry Andrictemplate <class Iterator1, class Iterator2> 1190b57cec5SDimitry Andricconstexpr bool // constexpr in C++17 1200b57cec5SDimitry Andricoperator>(const reverse_iterator<Iterator1>& x, const reverse_iterator<Iterator2>& y); 1210b57cec5SDimitry Andric 1220b57cec5SDimitry Andrictemplate <class Iterator1, class Iterator2> 1230b57cec5SDimitry Andricconstexpr bool // constexpr in C++17 1240b57cec5SDimitry Andricoperator>=(const reverse_iterator<Iterator1>& x, const reverse_iterator<Iterator2>& y); 1250b57cec5SDimitry Andric 1260b57cec5SDimitry Andrictemplate <class Iterator1, class Iterator2> 1270b57cec5SDimitry Andricconstexpr bool // constexpr in C++17 1280b57cec5SDimitry Andricoperator<=(const reverse_iterator<Iterator1>& x, const reverse_iterator<Iterator2>& y); 1290b57cec5SDimitry Andric 1300b57cec5SDimitry Andrictemplate <class Iterator1, class Iterator2> 1310b57cec5SDimitry Andricconstexpr auto 1320b57cec5SDimitry Andricoperator-(const reverse_iterator<Iterator1>& x, const reverse_iterator<Iterator2>& y) 1330b57cec5SDimitry Andric-> decltype(__y.base() - __x.base()); // constexpr in C++17 1340b57cec5SDimitry Andric 1350b57cec5SDimitry Andrictemplate <class Iterator> 1360b57cec5SDimitry Andricconstexpr reverse_iterator<Iterator> 1370b57cec5SDimitry Andricoperator+(typename reverse_iterator<Iterator>::difference_type n, 1380b57cec5SDimitry Andric const reverse_iterator<Iterator>& x); // constexpr in C++17 1390b57cec5SDimitry Andric 1400b57cec5SDimitry Andrictemplate <class Iterator> 1410b57cec5SDimitry Andricconstexpr reverse_iterator<Iterator> make_reverse_iterator(Iterator i); // C++14, constexpr in C++17 1420b57cec5SDimitry Andric 1430b57cec5SDimitry Andrictemplate <class Container> 1440b57cec5SDimitry Andricclass back_insert_iterator 1450b57cec5SDimitry Andric{ 1460b57cec5SDimitry Andricprotected: 1470b57cec5SDimitry Andric Container* container; 1480b57cec5SDimitry Andricpublic: 1490b57cec5SDimitry Andric typedef Container container_type; 1500b57cec5SDimitry Andric typedef void value_type; 1510b57cec5SDimitry Andric typedef void difference_type; 1520b57cec5SDimitry Andric typedef void reference; 1530b57cec5SDimitry Andric typedef void pointer; 1540b57cec5SDimitry Andric 1550b57cec5SDimitry Andric explicit back_insert_iterator(Container& x); 1560b57cec5SDimitry Andric back_insert_iterator& operator=(const typename Container::value_type& value); 1570b57cec5SDimitry Andric back_insert_iterator& operator*(); 1580b57cec5SDimitry Andric back_insert_iterator& operator++(); 1590b57cec5SDimitry Andric back_insert_iterator operator++(int); 1600b57cec5SDimitry Andric}; 1610b57cec5SDimitry Andric 1620b57cec5SDimitry Andrictemplate <class Container> back_insert_iterator<Container> back_inserter(Container& x); 1630b57cec5SDimitry Andric 1640b57cec5SDimitry Andrictemplate <class Container> 1650b57cec5SDimitry Andricclass front_insert_iterator 1660b57cec5SDimitry Andric{ 1670b57cec5SDimitry Andricprotected: 1680b57cec5SDimitry Andric Container* container; 1690b57cec5SDimitry Andricpublic: 1700b57cec5SDimitry Andric typedef Container container_type; 1710b57cec5SDimitry Andric typedef void value_type; 1720b57cec5SDimitry Andric typedef void difference_type; 1730b57cec5SDimitry Andric typedef void reference; 1740b57cec5SDimitry Andric typedef void pointer; 1750b57cec5SDimitry Andric 1760b57cec5SDimitry Andric explicit front_insert_iterator(Container& x); 1770b57cec5SDimitry Andric front_insert_iterator& operator=(const typename Container::value_type& value); 1780b57cec5SDimitry Andric front_insert_iterator& operator*(); 1790b57cec5SDimitry Andric front_insert_iterator& operator++(); 1800b57cec5SDimitry Andric front_insert_iterator operator++(int); 1810b57cec5SDimitry Andric}; 1820b57cec5SDimitry Andric 1830b57cec5SDimitry Andrictemplate <class Container> front_insert_iterator<Container> front_inserter(Container& x); 1840b57cec5SDimitry Andric 1850b57cec5SDimitry Andrictemplate <class Container> 1860b57cec5SDimitry Andricclass insert_iterator 1870b57cec5SDimitry Andric{ 1880b57cec5SDimitry Andricprotected: 1890b57cec5SDimitry Andric Container* container; 1900b57cec5SDimitry Andric typename Container::iterator iter; 1910b57cec5SDimitry Andricpublic: 1920b57cec5SDimitry Andric typedef Container container_type; 1930b57cec5SDimitry Andric typedef void value_type; 1940b57cec5SDimitry Andric typedef void difference_type; 1950b57cec5SDimitry Andric typedef void reference; 1960b57cec5SDimitry Andric typedef void pointer; 1970b57cec5SDimitry Andric 1980b57cec5SDimitry Andric insert_iterator(Container& x, typename Container::iterator i); 1990b57cec5SDimitry Andric insert_iterator& operator=(const typename Container::value_type& value); 2000b57cec5SDimitry Andric insert_iterator& operator*(); 2010b57cec5SDimitry Andric insert_iterator& operator++(); 2020b57cec5SDimitry Andric insert_iterator& operator++(int); 2030b57cec5SDimitry Andric}; 2040b57cec5SDimitry Andric 2050b57cec5SDimitry Andrictemplate <class Container, class Iterator> 2060b57cec5SDimitry Andricinsert_iterator<Container> inserter(Container& x, Iterator i); 2070b57cec5SDimitry Andric 2080b57cec5SDimitry Andrictemplate <class Iterator> 2090b57cec5SDimitry Andricclass move_iterator { 2100b57cec5SDimitry Andricpublic: 2110b57cec5SDimitry Andric typedef Iterator iterator_type; 2120b57cec5SDimitry Andric typedef typename iterator_traits<Iterator>::difference_type difference_type; 2130b57cec5SDimitry Andric typedef Iterator pointer; 2140b57cec5SDimitry Andric typedef typename iterator_traits<Iterator>::value_type value_type; 2150b57cec5SDimitry Andric typedef typename iterator_traits<Iterator>::iterator_category iterator_category; 2160b57cec5SDimitry Andric typedef value_type&& reference; 2170b57cec5SDimitry Andric 2180b57cec5SDimitry Andric constexpr move_iterator(); // all the constexprs are in C++17 2190b57cec5SDimitry Andric constexpr explicit move_iterator(Iterator i); 2200b57cec5SDimitry Andric template <class U> 2210b57cec5SDimitry Andric constexpr move_iterator(const move_iterator<U>& u); 2220b57cec5SDimitry Andric template <class U> 2230b57cec5SDimitry Andric constexpr move_iterator& operator=(const move_iterator<U>& u); 2240b57cec5SDimitry Andric constexpr iterator_type base() const; 2250b57cec5SDimitry Andric constexpr reference operator*() const; 2260b57cec5SDimitry Andric constexpr pointer operator->() const; 2270b57cec5SDimitry Andric constexpr move_iterator& operator++(); 2280b57cec5SDimitry Andric constexpr move_iterator operator++(int); 2290b57cec5SDimitry Andric constexpr move_iterator& operator--(); 2300b57cec5SDimitry Andric constexpr move_iterator operator--(int); 2310b57cec5SDimitry Andric constexpr move_iterator operator+(difference_type n) const; 2320b57cec5SDimitry Andric constexpr move_iterator& operator+=(difference_type n); 2330b57cec5SDimitry Andric constexpr move_iterator operator-(difference_type n) const; 2340b57cec5SDimitry Andric constexpr move_iterator& operator-=(difference_type n); 2350b57cec5SDimitry Andric constexpr unspecified operator[](difference_type n) const; 2360b57cec5SDimitry Andricprivate: 2370b57cec5SDimitry Andric Iterator current; // exposition only 2380b57cec5SDimitry Andric}; 2390b57cec5SDimitry Andric 2400b57cec5SDimitry Andrictemplate <class Iterator1, class Iterator2> 2410b57cec5SDimitry Andricconstexpr bool // constexpr in C++17 2420b57cec5SDimitry Andricoperator==(const move_iterator<Iterator1>& x, const move_iterator<Iterator2>& y); 2430b57cec5SDimitry Andric 2440b57cec5SDimitry Andrictemplate <class Iterator1, class Iterator2> 2450b57cec5SDimitry Andricconstexpr bool // constexpr in C++17 2460b57cec5SDimitry Andricoperator!=(const move_iterator<Iterator1>& x, const move_iterator<Iterator2>& y); 2470b57cec5SDimitry Andric 2480b57cec5SDimitry Andrictemplate <class Iterator1, class Iterator2> 2490b57cec5SDimitry Andricconstexpr bool // constexpr in C++17 2500b57cec5SDimitry Andricoperator<(const move_iterator<Iterator1>& x, const move_iterator<Iterator2>& y); 2510b57cec5SDimitry Andric 2520b57cec5SDimitry Andrictemplate <class Iterator1, class Iterator2> 2530b57cec5SDimitry Andricconstexpr bool // constexpr in C++17 2540b57cec5SDimitry Andricoperator<=(const move_iterator<Iterator1>& x, const move_iterator<Iterator2>& y); 2550b57cec5SDimitry Andric 2560b57cec5SDimitry Andrictemplate <class Iterator1, class Iterator2> 2570b57cec5SDimitry Andricconstexpr bool // constexpr in C++17 2580b57cec5SDimitry Andricoperator>(const move_iterator<Iterator1>& x, const move_iterator<Iterator2>& y); 2590b57cec5SDimitry Andric 2600b57cec5SDimitry Andrictemplate <class Iterator1, class Iterator2> 2610b57cec5SDimitry Andricconstexpr bool // constexpr in C++17 2620b57cec5SDimitry Andricoperator>=(const move_iterator<Iterator1>& x, const move_iterator<Iterator2>& y); 2630b57cec5SDimitry Andric 2640b57cec5SDimitry Andrictemplate <class Iterator1, class Iterator2> 2650b57cec5SDimitry Andricconstexpr auto // constexpr in C++17 2660b57cec5SDimitry Andricoperator-(const move_iterator<Iterator1>& x, 2670b57cec5SDimitry Andric const move_iterator<Iterator2>& y) -> decltype(x.base() - y.base()); 2680b57cec5SDimitry Andric 2690b57cec5SDimitry Andrictemplate <class Iterator> 2700b57cec5SDimitry Andricconstexpr move_iterator<Iterator> operator+( // constexpr in C++17 2710b57cec5SDimitry Andric typename move_iterator<Iterator>::difference_type n, 2720b57cec5SDimitry Andric const move_iterator<Iterator>& x); 2730b57cec5SDimitry Andric 2740b57cec5SDimitry Andrictemplate <class Iterator> // constexpr in C++17 2750b57cec5SDimitry Andricconstexpr move_iterator<Iterator> make_move_iterator(const Iterator& i); 2760b57cec5SDimitry Andric 2770b57cec5SDimitry Andric 2780b57cec5SDimitry Andrictemplate <class T, class charT = char, class traits = char_traits<charT>, class Distance = ptrdiff_t> 2790b57cec5SDimitry Andricclass istream_iterator 2800b57cec5SDimitry Andric : public iterator<input_iterator_tag, T, Distance, const T*, const T&> 2810b57cec5SDimitry Andric{ 2820b57cec5SDimitry Andricpublic: 2830b57cec5SDimitry Andric typedef charT char_type; 2840b57cec5SDimitry Andric typedef traits traits_type; 2850b57cec5SDimitry Andric typedef basic_istream<charT,traits> istream_type; 2860b57cec5SDimitry Andric 2870b57cec5SDimitry Andric constexpr istream_iterator(); 2880b57cec5SDimitry Andric istream_iterator(istream_type& s); 2890b57cec5SDimitry Andric istream_iterator(const istream_iterator& x); 2900b57cec5SDimitry Andric ~istream_iterator(); 2910b57cec5SDimitry Andric 2920b57cec5SDimitry Andric const T& operator*() const; 2930b57cec5SDimitry Andric const T* operator->() const; 2940b57cec5SDimitry Andric istream_iterator& operator++(); 2950b57cec5SDimitry Andric istream_iterator operator++(int); 2960b57cec5SDimitry Andric}; 2970b57cec5SDimitry Andric 2980b57cec5SDimitry Andrictemplate <class T, class charT, class traits, class Distance> 2990b57cec5SDimitry Andricbool operator==(const istream_iterator<T,charT,traits,Distance>& x, 3000b57cec5SDimitry Andric const istream_iterator<T,charT,traits,Distance>& y); 3010b57cec5SDimitry Andrictemplate <class T, class charT, class traits, class Distance> 3020b57cec5SDimitry Andricbool operator!=(const istream_iterator<T,charT,traits,Distance>& x, 3030b57cec5SDimitry Andric const istream_iterator<T,charT,traits,Distance>& y); 3040b57cec5SDimitry Andric 3050b57cec5SDimitry Andrictemplate <class T, class charT = char, class traits = char_traits<charT> > 3060b57cec5SDimitry Andricclass ostream_iterator 3070b57cec5SDimitry Andric : public iterator<output_iterator_tag, void, void, void ,void> 3080b57cec5SDimitry Andric{ 3090b57cec5SDimitry Andricpublic: 3100b57cec5SDimitry Andric typedef charT char_type; 3110b57cec5SDimitry Andric typedef traits traits_type; 3120b57cec5SDimitry Andric typedef basic_ostream<charT,traits> ostream_type; 3130b57cec5SDimitry Andric 3140b57cec5SDimitry Andric ostream_iterator(ostream_type& s); 3150b57cec5SDimitry Andric ostream_iterator(ostream_type& s, const charT* delimiter); 3160b57cec5SDimitry Andric ostream_iterator(const ostream_iterator& x); 3170b57cec5SDimitry Andric ~ostream_iterator(); 3180b57cec5SDimitry Andric ostream_iterator& operator=(const T& value); 3190b57cec5SDimitry Andric 3200b57cec5SDimitry Andric ostream_iterator& operator*(); 3210b57cec5SDimitry Andric ostream_iterator& operator++(); 3220b57cec5SDimitry Andric ostream_iterator& operator++(int); 3230b57cec5SDimitry Andric}; 3240b57cec5SDimitry Andric 3250b57cec5SDimitry Andrictemplate<class charT, class traits = char_traits<charT> > 3260b57cec5SDimitry Andricclass istreambuf_iterator 3270b57cec5SDimitry Andric : public iterator<input_iterator_tag, charT, 3280b57cec5SDimitry Andric typename traits::off_type, unspecified, 3290b57cec5SDimitry Andric charT> 3300b57cec5SDimitry Andric{ 3310b57cec5SDimitry Andricpublic: 3320b57cec5SDimitry Andric typedef charT char_type; 3330b57cec5SDimitry Andric typedef traits traits_type; 3340b57cec5SDimitry Andric typedef typename traits::int_type int_type; 3350b57cec5SDimitry Andric typedef basic_streambuf<charT,traits> streambuf_type; 3360b57cec5SDimitry Andric typedef basic_istream<charT,traits> istream_type; 3370b57cec5SDimitry Andric 3380b57cec5SDimitry Andric istreambuf_iterator() noexcept; 3390b57cec5SDimitry Andric istreambuf_iterator(istream_type& s) noexcept; 3400b57cec5SDimitry Andric istreambuf_iterator(streambuf_type* s) noexcept; 3410b57cec5SDimitry Andric istreambuf_iterator(a-private-type) noexcept; 3420b57cec5SDimitry Andric 3430b57cec5SDimitry Andric charT operator*() const; 3440b57cec5SDimitry Andric pointer operator->() const; 3450b57cec5SDimitry Andric istreambuf_iterator& operator++(); 3460b57cec5SDimitry Andric a-private-type operator++(int); 3470b57cec5SDimitry Andric 3480b57cec5SDimitry Andric bool equal(const istreambuf_iterator& b) const; 3490b57cec5SDimitry Andric}; 3500b57cec5SDimitry Andric 3510b57cec5SDimitry Andrictemplate <class charT, class traits> 3520b57cec5SDimitry Andricbool operator==(const istreambuf_iterator<charT,traits>& a, 3530b57cec5SDimitry Andric const istreambuf_iterator<charT,traits>& b); 3540b57cec5SDimitry Andrictemplate <class charT, class traits> 3550b57cec5SDimitry Andricbool operator!=(const istreambuf_iterator<charT,traits>& a, 3560b57cec5SDimitry Andric const istreambuf_iterator<charT,traits>& b); 3570b57cec5SDimitry Andric 3580b57cec5SDimitry Andrictemplate <class charT, class traits = char_traits<charT> > 3590b57cec5SDimitry Andricclass ostreambuf_iterator 3600b57cec5SDimitry Andric : public iterator<output_iterator_tag, void, void, void, void> 3610b57cec5SDimitry Andric{ 3620b57cec5SDimitry Andricpublic: 3630b57cec5SDimitry Andric typedef charT char_type; 3640b57cec5SDimitry Andric typedef traits traits_type; 3650b57cec5SDimitry Andric typedef basic_streambuf<charT,traits> streambuf_type; 3660b57cec5SDimitry Andric typedef basic_ostream<charT,traits> ostream_type; 3670b57cec5SDimitry Andric 3680b57cec5SDimitry Andric ostreambuf_iterator(ostream_type& s) noexcept; 3690b57cec5SDimitry Andric ostreambuf_iterator(streambuf_type* s) noexcept; 3700b57cec5SDimitry Andric ostreambuf_iterator& operator=(charT c); 3710b57cec5SDimitry Andric ostreambuf_iterator& operator*(); 3720b57cec5SDimitry Andric ostreambuf_iterator& operator++(); 3730b57cec5SDimitry Andric ostreambuf_iterator& operator++(int); 3740b57cec5SDimitry Andric bool failed() const noexcept; 3750b57cec5SDimitry Andric}; 3760b57cec5SDimitry Andric 3770b57cec5SDimitry Andrictemplate <class C> constexpr auto begin(C& c) -> decltype(c.begin()); 3780b57cec5SDimitry Andrictemplate <class C> constexpr auto begin(const C& c) -> decltype(c.begin()); 3790b57cec5SDimitry Andrictemplate <class C> constexpr auto end(C& c) -> decltype(c.end()); 3800b57cec5SDimitry Andrictemplate <class C> constexpr auto end(const C& c) -> decltype(c.end()); 3810b57cec5SDimitry Andrictemplate <class T, size_t N> constexpr T* begin(T (&array)[N]); 3820b57cec5SDimitry Andrictemplate <class T, size_t N> constexpr T* end(T (&array)[N]); 3830b57cec5SDimitry Andric 3840b57cec5SDimitry Andrictemplate <class C> auto constexpr cbegin(const C& c) -> decltype(std::begin(c)); // C++14 3850b57cec5SDimitry Andrictemplate <class C> auto constexpr cend(const C& c) -> decltype(std::end(c)); // C++14 3860b57cec5SDimitry Andrictemplate <class C> auto constexpr rbegin(C& c) -> decltype(c.rbegin()); // C++14 3870b57cec5SDimitry Andrictemplate <class C> auto constexpr rbegin(const C& c) -> decltype(c.rbegin()); // C++14 3880b57cec5SDimitry Andrictemplate <class C> auto constexpr rend(C& c) -> decltype(c.rend()); // C++14 3890b57cec5SDimitry Andrictemplate <class C> constexpr auto rend(const C& c) -> decltype(c.rend()); // C++14 3900b57cec5SDimitry Andrictemplate <class E> reverse_iterator<const E*> constexpr rbegin(initializer_list<E> il); // C++14 3910b57cec5SDimitry Andrictemplate <class E> reverse_iterator<const E*> constexpr rend(initializer_list<E> il); // C++14 3920b57cec5SDimitry Andrictemplate <class T, size_t N> reverse_iterator<T*> constexpr rbegin(T (&array)[N]); // C++14 3930b57cec5SDimitry Andrictemplate <class T, size_t N> reverse_iterator<T*> constexpr rend(T (&array)[N]); // C++14 3940b57cec5SDimitry Andrictemplate <class C> constexpr auto crbegin(const C& c) -> decltype(std::rbegin(c)); // C++14 3950b57cec5SDimitry Andrictemplate <class C> constexpr auto crend(const C& c) -> decltype(std::rend(c)); // C++14 3960b57cec5SDimitry Andric 3970b57cec5SDimitry Andric// 24.8, container access: 3980b57cec5SDimitry Andrictemplate <class C> constexpr auto size(const C& c) -> decltype(c.size()); // C++17 3990b57cec5SDimitry Andrictemplate <class T, size_t N> constexpr size_t size(const T (&array)[N]) noexcept; // C++17 4000b57cec5SDimitry Andric 4010b57cec5SDimitry Andrictemplate <class C> constexpr auto ssize(const C& c) 4020b57cec5SDimitry Andric -> common_type_t<ptrdiff_t, make_signed_t<decltype(c.size())>>; // C++20 4030b57cec5SDimitry Andrictemplate <class T, ptrdiff_t> constexpr ptrdiff_t ssize(const T (&array)[N]) noexcept; // C++20 4040b57cec5SDimitry Andric 4050b57cec5SDimitry Andrictemplate <class C> constexpr auto empty(const C& c) -> decltype(c.empty()); // C++17 4060b57cec5SDimitry Andrictemplate <class T, size_t N> constexpr bool empty(const T (&array)[N]) noexcept; // C++17 4070b57cec5SDimitry Andrictemplate <class E> constexpr bool empty(initializer_list<E> il) noexcept; // C++17 4080b57cec5SDimitry Andrictemplate <class C> constexpr auto data(C& c) -> decltype(c.data()); // C++17 4090b57cec5SDimitry Andrictemplate <class C> constexpr auto data(const C& c) -> decltype(c.data()); // C++17 4100b57cec5SDimitry Andrictemplate <class T, size_t N> constexpr T* data(T (&array)[N]) noexcept; // C++17 4110b57cec5SDimitry Andrictemplate <class E> constexpr const E* data(initializer_list<E> il) noexcept; // C++17 4120b57cec5SDimitry Andric 4130b57cec5SDimitry Andric} // std 4140b57cec5SDimitry Andric 4150b57cec5SDimitry Andric*/ 4160b57cec5SDimitry Andric 4170b57cec5SDimitry Andric#include <__config> 4180b57cec5SDimitry Andric#include <iosfwd> // for forward declarations of vector and string. 4190b57cec5SDimitry Andric#include <__functional_base> 4200b57cec5SDimitry Andric#include <type_traits> 4210b57cec5SDimitry Andric#include <cstddef> 4220b57cec5SDimitry Andric#include <initializer_list> 4230b57cec5SDimitry Andric#include <version> 4240b57cec5SDimitry Andric#ifdef __APPLE__ 4250b57cec5SDimitry Andric#include <Availability.h> 4260b57cec5SDimitry Andric#endif 4270b57cec5SDimitry Andric 4280b57cec5SDimitry Andric#include <__debug> 4290b57cec5SDimitry Andric 4300b57cec5SDimitry Andric#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) 4310b57cec5SDimitry Andric#pragma GCC system_header 4320b57cec5SDimitry Andric#endif 4330b57cec5SDimitry Andric 4340b57cec5SDimitry Andric_LIBCPP_BEGIN_NAMESPACE_STD 435480093f4SDimitry Andrictemplate <class _Iter> 436480093f4SDimitry Andricstruct _LIBCPP_TEMPLATE_VIS iterator_traits; 4370b57cec5SDimitry Andric 4380b57cec5SDimitry Andricstruct _LIBCPP_TEMPLATE_VIS input_iterator_tag {}; 4390b57cec5SDimitry Andricstruct _LIBCPP_TEMPLATE_VIS output_iterator_tag {}; 4400b57cec5SDimitry Andricstruct _LIBCPP_TEMPLATE_VIS forward_iterator_tag : public input_iterator_tag {}; 4410b57cec5SDimitry Andricstruct _LIBCPP_TEMPLATE_VIS bidirectional_iterator_tag : public forward_iterator_tag {}; 4420b57cec5SDimitry Andricstruct _LIBCPP_TEMPLATE_VIS random_access_iterator_tag : public bidirectional_iterator_tag {}; 443480093f4SDimitry Andric#if _LIBCPP_STD_VER > 17 444480093f4SDimitry Andric// TODO(EricWF) contiguous_iterator_tag is provided as an extension prior to 445480093f4SDimitry Andric// C++20 to allow optimizations for users providing wrapped iterator types. 446480093f4SDimitry Andricstruct _LIBCPP_TEMPLATE_VIS contiguous_iterator_tag: public random_access_iterator_tag { }; 447480093f4SDimitry Andric#endif 448480093f4SDimitry Andric 449480093f4SDimitry Andrictemplate <class _Iter> 450480093f4SDimitry Andricstruct __iter_traits_cache { 451480093f4SDimitry Andric using type = _If< 452480093f4SDimitry Andric __is_primary_template<iterator_traits<_Iter> >::value, 453480093f4SDimitry Andric _Iter, 454480093f4SDimitry Andric iterator_traits<_Iter> 455480093f4SDimitry Andric >; 456480093f4SDimitry Andric}; 457480093f4SDimitry Andrictemplate <class _Iter> 458480093f4SDimitry Andricusing _ITER_TRAITS = typename __iter_traits_cache<_Iter>::type; 459480093f4SDimitry Andric 460480093f4SDimitry Andricstruct __iter_concept_concept_test { 461480093f4SDimitry Andric template <class _Iter> 462480093f4SDimitry Andric using _Apply = typename _ITER_TRAITS<_Iter>::iterator_concept; 463480093f4SDimitry Andric}; 464480093f4SDimitry Andricstruct __iter_concept_category_test { 465480093f4SDimitry Andric template <class _Iter> 466480093f4SDimitry Andric using _Apply = typename _ITER_TRAITS<_Iter>::iterator_category; 467480093f4SDimitry Andric}; 468480093f4SDimitry Andricstruct __iter_concept_random_fallback { 469480093f4SDimitry Andric template <class _Iter> 470480093f4SDimitry Andric using _Apply = _EnableIf< 471480093f4SDimitry Andric __is_primary_template<iterator_traits<_Iter> >::value, 472480093f4SDimitry Andric random_access_iterator_tag 473480093f4SDimitry Andric >; 474480093f4SDimitry Andric}; 475480093f4SDimitry Andric 476480093f4SDimitry Andrictemplate <class _Iter, class _Tester> struct __test_iter_concept 477480093f4SDimitry Andric : _IsValidExpansion<_Tester::template _Apply, _Iter>, 478480093f4SDimitry Andric _Tester 479480093f4SDimitry Andric{ 480480093f4SDimitry Andric}; 481480093f4SDimitry Andric 482480093f4SDimitry Andrictemplate <class _Iter> 483480093f4SDimitry Andricstruct __iter_concept_cache { 484480093f4SDimitry Andric using type = _Or< 485480093f4SDimitry Andric __test_iter_concept<_Iter, __iter_concept_concept_test>, 486480093f4SDimitry Andric __test_iter_concept<_Iter, __iter_concept_category_test>, 487480093f4SDimitry Andric __test_iter_concept<_Iter, __iter_concept_random_fallback> 488480093f4SDimitry Andric >; 489480093f4SDimitry Andric}; 490480093f4SDimitry Andric 491480093f4SDimitry Andrictemplate <class _Iter> 492480093f4SDimitry Andricusing _ITER_CONCEPT = typename __iter_concept_cache<_Iter>::type::template _Apply<_Iter>; 493480093f4SDimitry Andric 4940b57cec5SDimitry Andric 4950b57cec5SDimitry Andrictemplate <class _Tp> 4960b57cec5SDimitry Andricstruct __has_iterator_typedefs 4970b57cec5SDimitry Andric{ 4980b57cec5SDimitry Andricprivate: 4990b57cec5SDimitry Andric struct __two {char __lx; char __lxx;}; 5000b57cec5SDimitry Andric template <class _Up> static __two __test(...); 5010b57cec5SDimitry Andric template <class _Up> static char __test(typename std::__void_t<typename _Up::iterator_category>::type* = 0, 5020b57cec5SDimitry Andric typename std::__void_t<typename _Up::difference_type>::type* = 0, 5030b57cec5SDimitry Andric typename std::__void_t<typename _Up::value_type>::type* = 0, 5040b57cec5SDimitry Andric typename std::__void_t<typename _Up::reference>::type* = 0, 5050b57cec5SDimitry Andric typename std::__void_t<typename _Up::pointer>::type* = 0 5060b57cec5SDimitry Andric ); 5070b57cec5SDimitry Andricpublic: 5080b57cec5SDimitry Andric static const bool value = sizeof(__test<_Tp>(0,0,0,0,0)) == 1; 5090b57cec5SDimitry Andric}; 5100b57cec5SDimitry Andric 5110b57cec5SDimitry Andric 5120b57cec5SDimitry Andrictemplate <class _Tp> 5130b57cec5SDimitry Andricstruct __has_iterator_category 5140b57cec5SDimitry Andric{ 5150b57cec5SDimitry Andricprivate: 5160b57cec5SDimitry Andric struct __two {char __lx; char __lxx;}; 5170b57cec5SDimitry Andric template <class _Up> static __two __test(...); 5180b57cec5SDimitry Andric template <class _Up> static char __test(typename _Up::iterator_category* = 0); 5190b57cec5SDimitry Andricpublic: 5200b57cec5SDimitry Andric static const bool value = sizeof(__test<_Tp>(0)) == 1; 5210b57cec5SDimitry Andric}; 5220b57cec5SDimitry Andric 5230b57cec5SDimitry Andrictemplate <class _Iter, bool> struct __iterator_traits_impl {}; 5240b57cec5SDimitry Andric 5250b57cec5SDimitry Andrictemplate <class _Iter> 5260b57cec5SDimitry Andricstruct __iterator_traits_impl<_Iter, true> 5270b57cec5SDimitry Andric{ 5280b57cec5SDimitry Andric typedef typename _Iter::difference_type difference_type; 5290b57cec5SDimitry Andric typedef typename _Iter::value_type value_type; 5300b57cec5SDimitry Andric typedef typename _Iter::pointer pointer; 5310b57cec5SDimitry Andric typedef typename _Iter::reference reference; 5320b57cec5SDimitry Andric typedef typename _Iter::iterator_category iterator_category; 5330b57cec5SDimitry Andric}; 5340b57cec5SDimitry Andric 5350b57cec5SDimitry Andrictemplate <class _Iter, bool> struct __iterator_traits {}; 5360b57cec5SDimitry Andric 5370b57cec5SDimitry Andrictemplate <class _Iter> 5380b57cec5SDimitry Andricstruct __iterator_traits<_Iter, true> 5390b57cec5SDimitry Andric : __iterator_traits_impl 5400b57cec5SDimitry Andric < 5410b57cec5SDimitry Andric _Iter, 5420b57cec5SDimitry Andric is_convertible<typename _Iter::iterator_category, input_iterator_tag>::value || 5430b57cec5SDimitry Andric is_convertible<typename _Iter::iterator_category, output_iterator_tag>::value 5440b57cec5SDimitry Andric > 5450b57cec5SDimitry Andric{}; 5460b57cec5SDimitry Andric 5470b57cec5SDimitry Andric// iterator_traits<Iterator> will only have the nested types if Iterator::iterator_category 5480b57cec5SDimitry Andric// exists. Else iterator_traits<Iterator> will be an empty class. This is a 5490b57cec5SDimitry Andric// conforming extension which allows some programs to compile and behave as 5500b57cec5SDimitry Andric// the client expects instead of failing at compile time. 5510b57cec5SDimitry Andric 5520b57cec5SDimitry Andrictemplate <class _Iter> 5530b57cec5SDimitry Andricstruct _LIBCPP_TEMPLATE_VIS iterator_traits 554480093f4SDimitry Andric : __iterator_traits<_Iter, __has_iterator_typedefs<_Iter>::value> { 555480093f4SDimitry Andric 556480093f4SDimitry Andric using __primary_template = iterator_traits; 557480093f4SDimitry Andric}; 5580b57cec5SDimitry Andric 5590b57cec5SDimitry Andrictemplate<class _Tp> 5600b57cec5SDimitry Andricstruct _LIBCPP_TEMPLATE_VIS iterator_traits<_Tp*> 5610b57cec5SDimitry Andric{ 5620b57cec5SDimitry Andric typedef ptrdiff_t difference_type; 5630b57cec5SDimitry Andric typedef typename remove_cv<_Tp>::type value_type; 5640b57cec5SDimitry Andric typedef _Tp* pointer; 5650b57cec5SDimitry Andric typedef _Tp& reference; 5660b57cec5SDimitry Andric typedef random_access_iterator_tag iterator_category; 567480093f4SDimitry Andric#if _LIBCPP_STD_VER > 17 568480093f4SDimitry Andric typedef contiguous_iterator_tag iterator_concept; 569480093f4SDimitry Andric#endif 5700b57cec5SDimitry Andric}; 5710b57cec5SDimitry Andric 5720b57cec5SDimitry Andrictemplate <class _Tp, class _Up, bool = __has_iterator_category<iterator_traits<_Tp> >::value> 5730b57cec5SDimitry Andricstruct __has_iterator_category_convertible_to 5740b57cec5SDimitry Andric : public integral_constant<bool, is_convertible<typename iterator_traits<_Tp>::iterator_category, _Up>::value> 5750b57cec5SDimitry Andric{}; 5760b57cec5SDimitry Andric 5770b57cec5SDimitry Andrictemplate <class _Tp, class _Up> 5780b57cec5SDimitry Andricstruct __has_iterator_category_convertible_to<_Tp, _Up, false> : public false_type {}; 5790b57cec5SDimitry Andric 5800b57cec5SDimitry Andrictemplate <class _Tp> 581480093f4SDimitry Andricstruct __is_cpp17_input_iterator : public __has_iterator_category_convertible_to<_Tp, input_iterator_tag> {}; 5820b57cec5SDimitry Andric 5830b57cec5SDimitry Andrictemplate <class _Tp> 584480093f4SDimitry Andricstruct __is_cpp17_forward_iterator : public __has_iterator_category_convertible_to<_Tp, forward_iterator_tag> {}; 5850b57cec5SDimitry Andric 5860b57cec5SDimitry Andrictemplate <class _Tp> 587480093f4SDimitry Andricstruct __is_cpp17_bidirectional_iterator : public __has_iterator_category_convertible_to<_Tp, bidirectional_iterator_tag> {}; 5880b57cec5SDimitry Andric 5890b57cec5SDimitry Andrictemplate <class _Tp> 590480093f4SDimitry Andricstruct __is_cpp17_random_access_iterator : public __has_iterator_category_convertible_to<_Tp, random_access_iterator_tag> {}; 591480093f4SDimitry Andric 592480093f4SDimitry Andric#if _LIBCPP_STD_VER > 17 593480093f4SDimitry Andrictemplate <class _Tp> 594480093f4SDimitry Andricstruct __is_cpp17_contiguous_iterator : public __has_iterator_category_convertible_to<_Tp, contiguous_iterator_tag> {}; 595480093f4SDimitry Andric#else 596480093f4SDimitry Andrictemplate <class _Tp> 597480093f4SDimitry Andricstruct __is_cpp17_contiguous_iterator : public false_type {}; 598480093f4SDimitry Andric#endif 599480093f4SDimitry Andric 6000b57cec5SDimitry Andric 6010b57cec5SDimitry Andrictemplate <class _Tp> 602480093f4SDimitry Andricstruct __is_exactly_cpp17_input_iterator 6030b57cec5SDimitry Andric : public integral_constant<bool, 6040b57cec5SDimitry Andric __has_iterator_category_convertible_to<_Tp, input_iterator_tag>::value && 6050b57cec5SDimitry Andric !__has_iterator_category_convertible_to<_Tp, forward_iterator_tag>::value> {}; 6060b57cec5SDimitry Andric 6070b57cec5SDimitry Andric#ifndef _LIBCPP_HAS_NO_DEDUCTION_GUIDES 6080b57cec5SDimitry Andrictemplate<class _InputIterator> 6090b57cec5SDimitry Andricusing __iter_value_type = typename iterator_traits<_InputIterator>::value_type; 6100b57cec5SDimitry Andric 6110b57cec5SDimitry Andrictemplate<class _InputIterator> 6120b57cec5SDimitry Andricusing __iter_key_type = remove_const_t<typename iterator_traits<_InputIterator>::value_type::first_type>; 6130b57cec5SDimitry Andric 6140b57cec5SDimitry Andrictemplate<class _InputIterator> 6150b57cec5SDimitry Andricusing __iter_mapped_type = typename iterator_traits<_InputIterator>::value_type::second_type; 6160b57cec5SDimitry Andric 6170b57cec5SDimitry Andrictemplate<class _InputIterator> 6180b57cec5SDimitry Andricusing __iter_to_alloc_type = pair< 6190b57cec5SDimitry Andric add_const_t<typename iterator_traits<_InputIterator>::value_type::first_type>, 6200b57cec5SDimitry Andric typename iterator_traits<_InputIterator>::value_type::second_type>; 6210b57cec5SDimitry Andric#endif 6220b57cec5SDimitry Andric 6230b57cec5SDimitry Andrictemplate<class _Category, class _Tp, class _Distance = ptrdiff_t, 6240b57cec5SDimitry Andric class _Pointer = _Tp*, class _Reference = _Tp&> 6250b57cec5SDimitry Andricstruct _LIBCPP_TEMPLATE_VIS iterator 6260b57cec5SDimitry Andric{ 6270b57cec5SDimitry Andric typedef _Tp value_type; 6280b57cec5SDimitry Andric typedef _Distance difference_type; 6290b57cec5SDimitry Andric typedef _Pointer pointer; 6300b57cec5SDimitry Andric typedef _Reference reference; 6310b57cec5SDimitry Andric typedef _Category iterator_category; 6320b57cec5SDimitry Andric}; 6330b57cec5SDimitry Andric 6340b57cec5SDimitry Andrictemplate <class _InputIter> 6350b57cec5SDimitry Andricinline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 6360b57cec5SDimitry Andricvoid __advance(_InputIter& __i, 6370b57cec5SDimitry Andric typename iterator_traits<_InputIter>::difference_type __n, input_iterator_tag) 6380b57cec5SDimitry Andric{ 6390b57cec5SDimitry Andric for (; __n > 0; --__n) 6400b57cec5SDimitry Andric ++__i; 6410b57cec5SDimitry Andric} 6420b57cec5SDimitry Andric 6430b57cec5SDimitry Andrictemplate <class _BiDirIter> 6440b57cec5SDimitry Andricinline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 6450b57cec5SDimitry Andricvoid __advance(_BiDirIter& __i, 6460b57cec5SDimitry Andric typename iterator_traits<_BiDirIter>::difference_type __n, bidirectional_iterator_tag) 6470b57cec5SDimitry Andric{ 6480b57cec5SDimitry Andric if (__n >= 0) 6490b57cec5SDimitry Andric for (; __n > 0; --__n) 6500b57cec5SDimitry Andric ++__i; 6510b57cec5SDimitry Andric else 6520b57cec5SDimitry Andric for (; __n < 0; ++__n) 6530b57cec5SDimitry Andric --__i; 6540b57cec5SDimitry Andric} 6550b57cec5SDimitry Andric 6560b57cec5SDimitry Andrictemplate <class _RandIter> 6570b57cec5SDimitry Andricinline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 6580b57cec5SDimitry Andricvoid __advance(_RandIter& __i, 6590b57cec5SDimitry Andric typename iterator_traits<_RandIter>::difference_type __n, random_access_iterator_tag) 6600b57cec5SDimitry Andric{ 6610b57cec5SDimitry Andric __i += __n; 6620b57cec5SDimitry Andric} 6630b57cec5SDimitry Andric 664*5ffd83dbSDimitry Andrictemplate <class _InputIter, class _Distance> 6650b57cec5SDimitry Andricinline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 666*5ffd83dbSDimitry Andricvoid advance(_InputIter& __i, _Distance __orig_n) 6670b57cec5SDimitry Andric{ 668*5ffd83dbSDimitry Andric _LIBCPP_ASSERT(__orig_n >= 0 || __is_cpp17_bidirectional_iterator<_InputIter>::value, 669*5ffd83dbSDimitry Andric "Attempt to advance(it, n) with negative n on a non-bidirectional iterator"); 670*5ffd83dbSDimitry Andric typedef decltype(__convert_to_integral(__orig_n)) _IntegralSize; 671*5ffd83dbSDimitry Andric _IntegralSize __n = __orig_n; 6720b57cec5SDimitry Andric __advance(__i, __n, typename iterator_traits<_InputIter>::iterator_category()); 6730b57cec5SDimitry Andric} 6740b57cec5SDimitry Andric 6750b57cec5SDimitry Andrictemplate <class _InputIter> 6760b57cec5SDimitry Andricinline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 6770b57cec5SDimitry Andrictypename iterator_traits<_InputIter>::difference_type 6780b57cec5SDimitry Andric__distance(_InputIter __first, _InputIter __last, input_iterator_tag) 6790b57cec5SDimitry Andric{ 6800b57cec5SDimitry Andric typename iterator_traits<_InputIter>::difference_type __r(0); 6810b57cec5SDimitry Andric for (; __first != __last; ++__first) 6820b57cec5SDimitry Andric ++__r; 6830b57cec5SDimitry Andric return __r; 6840b57cec5SDimitry Andric} 6850b57cec5SDimitry Andric 6860b57cec5SDimitry Andrictemplate <class _RandIter> 6870b57cec5SDimitry Andricinline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 6880b57cec5SDimitry Andrictypename iterator_traits<_RandIter>::difference_type 6890b57cec5SDimitry Andric__distance(_RandIter __first, _RandIter __last, random_access_iterator_tag) 6900b57cec5SDimitry Andric{ 6910b57cec5SDimitry Andric return __last - __first; 6920b57cec5SDimitry Andric} 6930b57cec5SDimitry Andric 6940b57cec5SDimitry Andrictemplate <class _InputIter> 6950b57cec5SDimitry Andricinline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 6960b57cec5SDimitry Andrictypename iterator_traits<_InputIter>::difference_type 6970b57cec5SDimitry Andricdistance(_InputIter __first, _InputIter __last) 6980b57cec5SDimitry Andric{ 6990b57cec5SDimitry Andric return __distance(__first, __last, typename iterator_traits<_InputIter>::iterator_category()); 7000b57cec5SDimitry Andric} 7010b57cec5SDimitry Andric 7020b57cec5SDimitry Andrictemplate <class _InputIter> 7030b57cec5SDimitry Andricinline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 7040b57cec5SDimitry Andrictypename enable_if 7050b57cec5SDimitry Andric< 706480093f4SDimitry Andric __is_cpp17_input_iterator<_InputIter>::value, 7070b57cec5SDimitry Andric _InputIter 7080b57cec5SDimitry Andric>::type 7090b57cec5SDimitry Andricnext(_InputIter __x, 7100b57cec5SDimitry Andric typename iterator_traits<_InputIter>::difference_type __n = 1) 7110b57cec5SDimitry Andric{ 712480093f4SDimitry Andric _LIBCPP_ASSERT(__n >= 0 || __is_cpp17_bidirectional_iterator<_InputIter>::value, 713*5ffd83dbSDimitry Andric "Attempt to next(it, n) with negative n on a non-bidirectional iterator"); 7140b57cec5SDimitry Andric 7150b57cec5SDimitry Andric _VSTD::advance(__x, __n); 7160b57cec5SDimitry Andric return __x; 7170b57cec5SDimitry Andric} 7180b57cec5SDimitry Andric 7190b57cec5SDimitry Andrictemplate <class _InputIter> 7200b57cec5SDimitry Andricinline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 7210b57cec5SDimitry Andrictypename enable_if 7220b57cec5SDimitry Andric< 723480093f4SDimitry Andric __is_cpp17_input_iterator<_InputIter>::value, 7240b57cec5SDimitry Andric _InputIter 7250b57cec5SDimitry Andric>::type 7260b57cec5SDimitry Andricprev(_InputIter __x, 7270b57cec5SDimitry Andric typename iterator_traits<_InputIter>::difference_type __n = 1) 7280b57cec5SDimitry Andric{ 729480093f4SDimitry Andric _LIBCPP_ASSERT(__n <= 0 || __is_cpp17_bidirectional_iterator<_InputIter>::value, 730*5ffd83dbSDimitry Andric "Attempt to prev(it, n) with a positive n on a non-bidirectional iterator"); 7310b57cec5SDimitry Andric _VSTD::advance(__x, -__n); 7320b57cec5SDimitry Andric return __x; 7330b57cec5SDimitry Andric} 7340b57cec5SDimitry Andric 7350b57cec5SDimitry Andric 7360b57cec5SDimitry Andrictemplate <class _Tp, class = void> 7370b57cec5SDimitry Andricstruct __is_stashing_iterator : false_type {}; 7380b57cec5SDimitry Andric 7390b57cec5SDimitry Andrictemplate <class _Tp> 7400b57cec5SDimitry Andricstruct __is_stashing_iterator<_Tp, typename __void_t<typename _Tp::__stashing_iterator_tag>::type> 7410b57cec5SDimitry Andric : true_type {}; 7420b57cec5SDimitry Andric 7430b57cec5SDimitry Andrictemplate <class _Iter> 7440b57cec5SDimitry Andricclass _LIBCPP_TEMPLATE_VIS reverse_iterator 7450b57cec5SDimitry Andric : public iterator<typename iterator_traits<_Iter>::iterator_category, 7460b57cec5SDimitry Andric typename iterator_traits<_Iter>::value_type, 7470b57cec5SDimitry Andric typename iterator_traits<_Iter>::difference_type, 7480b57cec5SDimitry Andric typename iterator_traits<_Iter>::pointer, 7490b57cec5SDimitry Andric typename iterator_traits<_Iter>::reference> 7500b57cec5SDimitry Andric{ 7510b57cec5SDimitry Andricprivate: 7520b57cec5SDimitry Andric /*mutable*/ _Iter __t; // no longer used as of LWG #2360, not removed due to ABI break 7530b57cec5SDimitry Andric 7540b57cec5SDimitry Andric static_assert(!__is_stashing_iterator<_Iter>::value, 7550b57cec5SDimitry Andric "The specified iterator type cannot be used with reverse_iterator; " 7560b57cec5SDimitry Andric "Using stashing iterators with reverse_iterator causes undefined behavior"); 7570b57cec5SDimitry Andric 7580b57cec5SDimitry Andricprotected: 7590b57cec5SDimitry Andric _Iter current; 7600b57cec5SDimitry Andricpublic: 7610b57cec5SDimitry Andric typedef _Iter iterator_type; 7620b57cec5SDimitry Andric typedef typename iterator_traits<_Iter>::difference_type difference_type; 7630b57cec5SDimitry Andric typedef typename iterator_traits<_Iter>::reference reference; 7640b57cec5SDimitry Andric typedef typename iterator_traits<_Iter>::pointer pointer; 7650b57cec5SDimitry Andric 7660b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 7670b57cec5SDimitry Andric reverse_iterator() : __t(), current() {} 7680b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 7690b57cec5SDimitry Andric explicit reverse_iterator(_Iter __x) : __t(__x), current(__x) {} 7700b57cec5SDimitry Andric template <class _Up> 7710b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 7720b57cec5SDimitry Andric reverse_iterator(const reverse_iterator<_Up>& __u) : __t(__u.base()), current(__u.base()) {} 7730b57cec5SDimitry Andric template <class _Up> 7740b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 7750b57cec5SDimitry Andric reverse_iterator& operator=(const reverse_iterator<_Up>& __u) 7760b57cec5SDimitry Andric { __t = current = __u.base(); return *this; } 7770b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 7780b57cec5SDimitry Andric _Iter base() const {return current;} 7790b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 7800b57cec5SDimitry Andric reference operator*() const {_Iter __tmp = current; return *--__tmp;} 7810b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 7820b57cec5SDimitry Andric pointer operator->() const {return _VSTD::addressof(operator*());} 7830b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 7840b57cec5SDimitry Andric reverse_iterator& operator++() {--current; return *this;} 7850b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 7860b57cec5SDimitry Andric reverse_iterator operator++(int) {reverse_iterator __tmp(*this); --current; return __tmp;} 7870b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 7880b57cec5SDimitry Andric reverse_iterator& operator--() {++current; return *this;} 7890b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 7900b57cec5SDimitry Andric reverse_iterator operator--(int) {reverse_iterator __tmp(*this); ++current; return __tmp;} 7910b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 7920b57cec5SDimitry Andric reverse_iterator operator+ (difference_type __n) const {return reverse_iterator(current - __n);} 7930b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 7940b57cec5SDimitry Andric reverse_iterator& operator+=(difference_type __n) {current -= __n; return *this;} 7950b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 7960b57cec5SDimitry Andric reverse_iterator operator- (difference_type __n) const {return reverse_iterator(current + __n);} 7970b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 7980b57cec5SDimitry Andric reverse_iterator& operator-=(difference_type __n) {current += __n; return *this;} 7990b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 8000b57cec5SDimitry Andric reference operator[](difference_type __n) const {return *(*this + __n);} 8010b57cec5SDimitry Andric}; 8020b57cec5SDimitry Andric 8030b57cec5SDimitry Andrictemplate <class _Iter1, class _Iter2> 8040b57cec5SDimitry Andricinline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 8050b57cec5SDimitry Andricbool 8060b57cec5SDimitry Andricoperator==(const reverse_iterator<_Iter1>& __x, const reverse_iterator<_Iter2>& __y) 8070b57cec5SDimitry Andric{ 8080b57cec5SDimitry Andric return __x.base() == __y.base(); 8090b57cec5SDimitry Andric} 8100b57cec5SDimitry Andric 8110b57cec5SDimitry Andrictemplate <class _Iter1, class _Iter2> 8120b57cec5SDimitry Andricinline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 8130b57cec5SDimitry Andricbool 8140b57cec5SDimitry Andricoperator<(const reverse_iterator<_Iter1>& __x, const reverse_iterator<_Iter2>& __y) 8150b57cec5SDimitry Andric{ 8160b57cec5SDimitry Andric return __x.base() > __y.base(); 8170b57cec5SDimitry Andric} 8180b57cec5SDimitry Andric 8190b57cec5SDimitry Andrictemplate <class _Iter1, class _Iter2> 8200b57cec5SDimitry Andricinline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 8210b57cec5SDimitry Andricbool 8220b57cec5SDimitry Andricoperator!=(const reverse_iterator<_Iter1>& __x, const reverse_iterator<_Iter2>& __y) 8230b57cec5SDimitry Andric{ 8240b57cec5SDimitry Andric return __x.base() != __y.base(); 8250b57cec5SDimitry Andric} 8260b57cec5SDimitry Andric 8270b57cec5SDimitry Andrictemplate <class _Iter1, class _Iter2> 8280b57cec5SDimitry Andricinline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 8290b57cec5SDimitry Andricbool 8300b57cec5SDimitry Andricoperator>(const reverse_iterator<_Iter1>& __x, const reverse_iterator<_Iter2>& __y) 8310b57cec5SDimitry Andric{ 8320b57cec5SDimitry Andric return __x.base() < __y.base(); 8330b57cec5SDimitry Andric} 8340b57cec5SDimitry Andric 8350b57cec5SDimitry Andrictemplate <class _Iter1, class _Iter2> 8360b57cec5SDimitry Andricinline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 8370b57cec5SDimitry Andricbool 8380b57cec5SDimitry Andricoperator>=(const reverse_iterator<_Iter1>& __x, const reverse_iterator<_Iter2>& __y) 8390b57cec5SDimitry Andric{ 8400b57cec5SDimitry Andric return __x.base() <= __y.base(); 8410b57cec5SDimitry Andric} 8420b57cec5SDimitry Andric 8430b57cec5SDimitry Andrictemplate <class _Iter1, class _Iter2> 8440b57cec5SDimitry Andricinline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 8450b57cec5SDimitry Andricbool 8460b57cec5SDimitry Andricoperator<=(const reverse_iterator<_Iter1>& __x, const reverse_iterator<_Iter2>& __y) 8470b57cec5SDimitry Andric{ 8480b57cec5SDimitry Andric return __x.base() >= __y.base(); 8490b57cec5SDimitry Andric} 8500b57cec5SDimitry Andric 8510b57cec5SDimitry Andric#ifndef _LIBCPP_CXX03_LANG 8520b57cec5SDimitry Andrictemplate <class _Iter1, class _Iter2> 8530b57cec5SDimitry Andricinline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 8540b57cec5SDimitry Andricauto 8550b57cec5SDimitry Andricoperator-(const reverse_iterator<_Iter1>& __x, const reverse_iterator<_Iter2>& __y) 8560b57cec5SDimitry Andric-> decltype(__y.base() - __x.base()) 8570b57cec5SDimitry Andric{ 8580b57cec5SDimitry Andric return __y.base() - __x.base(); 8590b57cec5SDimitry Andric} 8600b57cec5SDimitry Andric#else 8610b57cec5SDimitry Andrictemplate <class _Iter1, class _Iter2> 8620b57cec5SDimitry Andricinline _LIBCPP_INLINE_VISIBILITY 8630b57cec5SDimitry Andrictypename reverse_iterator<_Iter1>::difference_type 8640b57cec5SDimitry Andricoperator-(const reverse_iterator<_Iter1>& __x, const reverse_iterator<_Iter2>& __y) 8650b57cec5SDimitry Andric{ 8660b57cec5SDimitry Andric return __y.base() - __x.base(); 8670b57cec5SDimitry Andric} 8680b57cec5SDimitry Andric#endif 8690b57cec5SDimitry Andric 8700b57cec5SDimitry Andrictemplate <class _Iter> 8710b57cec5SDimitry Andricinline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 8720b57cec5SDimitry Andricreverse_iterator<_Iter> 8730b57cec5SDimitry Andricoperator+(typename reverse_iterator<_Iter>::difference_type __n, const reverse_iterator<_Iter>& __x) 8740b57cec5SDimitry Andric{ 8750b57cec5SDimitry Andric return reverse_iterator<_Iter>(__x.base() - __n); 8760b57cec5SDimitry Andric} 8770b57cec5SDimitry Andric 8780b57cec5SDimitry Andric#if _LIBCPP_STD_VER > 11 8790b57cec5SDimitry Andrictemplate <class _Iter> 8800b57cec5SDimitry Andricinline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 8810b57cec5SDimitry Andricreverse_iterator<_Iter> make_reverse_iterator(_Iter __i) 8820b57cec5SDimitry Andric{ 8830b57cec5SDimitry Andric return reverse_iterator<_Iter>(__i); 8840b57cec5SDimitry Andric} 8850b57cec5SDimitry Andric#endif 8860b57cec5SDimitry Andric 8870b57cec5SDimitry Andrictemplate <class _Container> 8880b57cec5SDimitry Andricclass _LIBCPP_TEMPLATE_VIS back_insert_iterator 8890b57cec5SDimitry Andric : public iterator<output_iterator_tag, 8900b57cec5SDimitry Andric void, 8910b57cec5SDimitry Andric void, 8920b57cec5SDimitry Andric void, 8930b57cec5SDimitry Andric void> 8940b57cec5SDimitry Andric{ 8950b57cec5SDimitry Andricprotected: 8960b57cec5SDimitry Andric _Container* container; 8970b57cec5SDimitry Andricpublic: 8980b57cec5SDimitry Andric typedef _Container container_type; 8990b57cec5SDimitry Andric 9000b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY explicit back_insert_iterator(_Container& __x) : container(_VSTD::addressof(__x)) {} 9010b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY back_insert_iterator& operator=(const typename _Container::value_type& __value_) 9020b57cec5SDimitry Andric {container->push_back(__value_); return *this;} 9030b57cec5SDimitry Andric#ifndef _LIBCPP_CXX03_LANG 9040b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY back_insert_iterator& operator=(typename _Container::value_type&& __value_) 9050b57cec5SDimitry Andric {container->push_back(_VSTD::move(__value_)); return *this;} 9060b57cec5SDimitry Andric#endif // _LIBCPP_CXX03_LANG 9070b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY back_insert_iterator& operator*() {return *this;} 9080b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY back_insert_iterator& operator++() {return *this;} 9090b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY back_insert_iterator operator++(int) {return *this;} 9100b57cec5SDimitry Andric}; 9110b57cec5SDimitry Andric 9120b57cec5SDimitry Andrictemplate <class _Container> 9130b57cec5SDimitry Andricinline _LIBCPP_INLINE_VISIBILITY 9140b57cec5SDimitry Andricback_insert_iterator<_Container> 9150b57cec5SDimitry Andricback_inserter(_Container& __x) 9160b57cec5SDimitry Andric{ 9170b57cec5SDimitry Andric return back_insert_iterator<_Container>(__x); 9180b57cec5SDimitry Andric} 9190b57cec5SDimitry Andric 9200b57cec5SDimitry Andrictemplate <class _Container> 9210b57cec5SDimitry Andricclass _LIBCPP_TEMPLATE_VIS front_insert_iterator 9220b57cec5SDimitry Andric : public iterator<output_iterator_tag, 9230b57cec5SDimitry Andric void, 9240b57cec5SDimitry Andric void, 9250b57cec5SDimitry Andric void, 9260b57cec5SDimitry Andric void> 9270b57cec5SDimitry Andric{ 9280b57cec5SDimitry Andricprotected: 9290b57cec5SDimitry Andric _Container* container; 9300b57cec5SDimitry Andricpublic: 9310b57cec5SDimitry Andric typedef _Container container_type; 9320b57cec5SDimitry Andric 9330b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY explicit front_insert_iterator(_Container& __x) : container(_VSTD::addressof(__x)) {} 9340b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY front_insert_iterator& operator=(const typename _Container::value_type& __value_) 9350b57cec5SDimitry Andric {container->push_front(__value_); return *this;} 9360b57cec5SDimitry Andric#ifndef _LIBCPP_CXX03_LANG 9370b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY front_insert_iterator& operator=(typename _Container::value_type&& __value_) 9380b57cec5SDimitry Andric {container->push_front(_VSTD::move(__value_)); return *this;} 9390b57cec5SDimitry Andric#endif // _LIBCPP_CXX03_LANG 9400b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY front_insert_iterator& operator*() {return *this;} 9410b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY front_insert_iterator& operator++() {return *this;} 9420b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY front_insert_iterator operator++(int) {return *this;} 9430b57cec5SDimitry Andric}; 9440b57cec5SDimitry Andric 9450b57cec5SDimitry Andrictemplate <class _Container> 9460b57cec5SDimitry Andricinline _LIBCPP_INLINE_VISIBILITY 9470b57cec5SDimitry Andricfront_insert_iterator<_Container> 9480b57cec5SDimitry Andricfront_inserter(_Container& __x) 9490b57cec5SDimitry Andric{ 9500b57cec5SDimitry Andric return front_insert_iterator<_Container>(__x); 9510b57cec5SDimitry Andric} 9520b57cec5SDimitry Andric 9530b57cec5SDimitry Andrictemplate <class _Container> 9540b57cec5SDimitry Andricclass _LIBCPP_TEMPLATE_VIS insert_iterator 9550b57cec5SDimitry Andric : public iterator<output_iterator_tag, 9560b57cec5SDimitry Andric void, 9570b57cec5SDimitry Andric void, 9580b57cec5SDimitry Andric void, 9590b57cec5SDimitry Andric void> 9600b57cec5SDimitry Andric{ 9610b57cec5SDimitry Andricprotected: 9620b57cec5SDimitry Andric _Container* container; 9630b57cec5SDimitry Andric typename _Container::iterator iter; 9640b57cec5SDimitry Andricpublic: 9650b57cec5SDimitry Andric typedef _Container container_type; 9660b57cec5SDimitry Andric 9670b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY insert_iterator(_Container& __x, typename _Container::iterator __i) 9680b57cec5SDimitry Andric : container(_VSTD::addressof(__x)), iter(__i) {} 9690b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY insert_iterator& operator=(const typename _Container::value_type& __value_) 9700b57cec5SDimitry Andric {iter = container->insert(iter, __value_); ++iter; return *this;} 9710b57cec5SDimitry Andric#ifndef _LIBCPP_CXX03_LANG 9720b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY insert_iterator& operator=(typename _Container::value_type&& __value_) 9730b57cec5SDimitry Andric {iter = container->insert(iter, _VSTD::move(__value_)); ++iter; return *this;} 9740b57cec5SDimitry Andric#endif // _LIBCPP_CXX03_LANG 9750b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY insert_iterator& operator*() {return *this;} 9760b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY insert_iterator& operator++() {return *this;} 9770b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY insert_iterator& operator++(int) {return *this;} 9780b57cec5SDimitry Andric}; 9790b57cec5SDimitry Andric 9800b57cec5SDimitry Andrictemplate <class _Container> 9810b57cec5SDimitry Andricinline _LIBCPP_INLINE_VISIBILITY 9820b57cec5SDimitry Andricinsert_iterator<_Container> 9830b57cec5SDimitry Andricinserter(_Container& __x, typename _Container::iterator __i) 9840b57cec5SDimitry Andric{ 9850b57cec5SDimitry Andric return insert_iterator<_Container>(__x, __i); 9860b57cec5SDimitry Andric} 9870b57cec5SDimitry Andric 9880b57cec5SDimitry Andrictemplate <class _Tp, class _CharT = char, 9890b57cec5SDimitry Andric class _Traits = char_traits<_CharT>, class _Distance = ptrdiff_t> 9900b57cec5SDimitry Andricclass _LIBCPP_TEMPLATE_VIS istream_iterator 9910b57cec5SDimitry Andric : public iterator<input_iterator_tag, _Tp, _Distance, const _Tp*, const _Tp&> 9920b57cec5SDimitry Andric{ 9930b57cec5SDimitry Andricpublic: 9940b57cec5SDimitry Andric typedef _CharT char_type; 9950b57cec5SDimitry Andric typedef _Traits traits_type; 9960b57cec5SDimitry Andric typedef basic_istream<_CharT,_Traits> istream_type; 9970b57cec5SDimitry Andricprivate: 9980b57cec5SDimitry Andric istream_type* __in_stream_; 9990b57cec5SDimitry Andric _Tp __value_; 10000b57cec5SDimitry Andricpublic: 10010b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR istream_iterator() : __in_stream_(0), __value_() {} 10020b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY istream_iterator(istream_type& __s) : __in_stream_(_VSTD::addressof(__s)) 10030b57cec5SDimitry Andric { 10040b57cec5SDimitry Andric if (!(*__in_stream_ >> __value_)) 10050b57cec5SDimitry Andric __in_stream_ = 0; 10060b57cec5SDimitry Andric } 10070b57cec5SDimitry Andric 10080b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY const _Tp& operator*() const {return __value_;} 10090b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY const _Tp* operator->() const {return _VSTD::addressof((operator*()));} 10100b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY istream_iterator& operator++() 10110b57cec5SDimitry Andric { 10120b57cec5SDimitry Andric if (!(*__in_stream_ >> __value_)) 10130b57cec5SDimitry Andric __in_stream_ = 0; 10140b57cec5SDimitry Andric return *this; 10150b57cec5SDimitry Andric } 10160b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY istream_iterator operator++(int) 10170b57cec5SDimitry Andric {istream_iterator __t(*this); ++(*this); return __t;} 10180b57cec5SDimitry Andric 10190b57cec5SDimitry Andric template <class _Up, class _CharU, class _TraitsU, class _DistanceU> 10200b57cec5SDimitry Andric friend _LIBCPP_INLINE_VISIBILITY 10210b57cec5SDimitry Andric bool 10220b57cec5SDimitry Andric operator==(const istream_iterator<_Up, _CharU, _TraitsU, _DistanceU>& __x, 10230b57cec5SDimitry Andric const istream_iterator<_Up, _CharU, _TraitsU, _DistanceU>& __y); 10240b57cec5SDimitry Andric 10250b57cec5SDimitry Andric template <class _Up, class _CharU, class _TraitsU, class _DistanceU> 10260b57cec5SDimitry Andric friend _LIBCPP_INLINE_VISIBILITY 10270b57cec5SDimitry Andric bool 10280b57cec5SDimitry Andric operator==(const istream_iterator<_Up, _CharU, _TraitsU, _DistanceU>& __x, 10290b57cec5SDimitry Andric const istream_iterator<_Up, _CharU, _TraitsU, _DistanceU>& __y); 10300b57cec5SDimitry Andric}; 10310b57cec5SDimitry Andric 10320b57cec5SDimitry Andrictemplate <class _Tp, class _CharT, class _Traits, class _Distance> 10330b57cec5SDimitry Andricinline _LIBCPP_INLINE_VISIBILITY 10340b57cec5SDimitry Andricbool 10350b57cec5SDimitry Andricoperator==(const istream_iterator<_Tp, _CharT, _Traits, _Distance>& __x, 10360b57cec5SDimitry Andric const istream_iterator<_Tp, _CharT, _Traits, _Distance>& __y) 10370b57cec5SDimitry Andric{ 10380b57cec5SDimitry Andric return __x.__in_stream_ == __y.__in_stream_; 10390b57cec5SDimitry Andric} 10400b57cec5SDimitry Andric 10410b57cec5SDimitry Andrictemplate <class _Tp, class _CharT, class _Traits, class _Distance> 10420b57cec5SDimitry Andricinline _LIBCPP_INLINE_VISIBILITY 10430b57cec5SDimitry Andricbool 10440b57cec5SDimitry Andricoperator!=(const istream_iterator<_Tp, _CharT, _Traits, _Distance>& __x, 10450b57cec5SDimitry Andric const istream_iterator<_Tp, _CharT, _Traits, _Distance>& __y) 10460b57cec5SDimitry Andric{ 10470b57cec5SDimitry Andric return !(__x == __y); 10480b57cec5SDimitry Andric} 10490b57cec5SDimitry Andric 10500b57cec5SDimitry Andrictemplate <class _Tp, class _CharT = char, class _Traits = char_traits<_CharT> > 10510b57cec5SDimitry Andricclass _LIBCPP_TEMPLATE_VIS ostream_iterator 10520b57cec5SDimitry Andric : public iterator<output_iterator_tag, void, void, void, void> 10530b57cec5SDimitry Andric{ 10540b57cec5SDimitry Andricpublic: 10550b57cec5SDimitry Andric typedef _CharT char_type; 10560b57cec5SDimitry Andric typedef _Traits traits_type; 10570b57cec5SDimitry Andric typedef basic_ostream<_CharT,_Traits> ostream_type; 10580b57cec5SDimitry Andricprivate: 10590b57cec5SDimitry Andric ostream_type* __out_stream_; 10600b57cec5SDimitry Andric const char_type* __delim_; 10610b57cec5SDimitry Andricpublic: 10620b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY ostream_iterator(ostream_type& __s) _NOEXCEPT 10630b57cec5SDimitry Andric : __out_stream_(_VSTD::addressof(__s)), __delim_(0) {} 10640b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY ostream_iterator(ostream_type& __s, const _CharT* __delimiter) _NOEXCEPT 10650b57cec5SDimitry Andric : __out_stream_(_VSTD::addressof(__s)), __delim_(__delimiter) {} 10660b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY ostream_iterator& operator=(const _Tp& __value_) 10670b57cec5SDimitry Andric { 10680b57cec5SDimitry Andric *__out_stream_ << __value_; 10690b57cec5SDimitry Andric if (__delim_) 10700b57cec5SDimitry Andric *__out_stream_ << __delim_; 10710b57cec5SDimitry Andric return *this; 10720b57cec5SDimitry Andric } 10730b57cec5SDimitry Andric 10740b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY ostream_iterator& operator*() {return *this;} 10750b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY ostream_iterator& operator++() {return *this;} 10760b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY ostream_iterator& operator++(int) {return *this;} 10770b57cec5SDimitry Andric}; 10780b57cec5SDimitry Andric 10790b57cec5SDimitry Andrictemplate<class _CharT, class _Traits> 10800b57cec5SDimitry Andricclass _LIBCPP_TEMPLATE_VIS istreambuf_iterator 10810b57cec5SDimitry Andric : public iterator<input_iterator_tag, _CharT, 10820b57cec5SDimitry Andric typename _Traits::off_type, _CharT*, 10830b57cec5SDimitry Andric _CharT> 10840b57cec5SDimitry Andric{ 10850b57cec5SDimitry Andricpublic: 10860b57cec5SDimitry Andric typedef _CharT char_type; 10870b57cec5SDimitry Andric typedef _Traits traits_type; 10880b57cec5SDimitry Andric typedef typename _Traits::int_type int_type; 10890b57cec5SDimitry Andric typedef basic_streambuf<_CharT,_Traits> streambuf_type; 10900b57cec5SDimitry Andric typedef basic_istream<_CharT,_Traits> istream_type; 10910b57cec5SDimitry Andricprivate: 10920b57cec5SDimitry Andric mutable streambuf_type* __sbuf_; 10930b57cec5SDimitry Andric 10940b57cec5SDimitry Andric class __proxy 10950b57cec5SDimitry Andric { 10960b57cec5SDimitry Andric char_type __keep_; 10970b57cec5SDimitry Andric streambuf_type* __sbuf_; 10980b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY __proxy(char_type __c, streambuf_type* __s) 10990b57cec5SDimitry Andric : __keep_(__c), __sbuf_(__s) {} 11000b57cec5SDimitry Andric friend class istreambuf_iterator; 11010b57cec5SDimitry Andric public: 11020b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY char_type operator*() const {return __keep_;} 11030b57cec5SDimitry Andric }; 11040b57cec5SDimitry Andric 11050b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 11060b57cec5SDimitry Andric bool __test_for_eof() const 11070b57cec5SDimitry Andric { 11080b57cec5SDimitry Andric if (__sbuf_ && traits_type::eq_int_type(__sbuf_->sgetc(), traits_type::eof())) 11090b57cec5SDimitry Andric __sbuf_ = 0; 11100b57cec5SDimitry Andric return __sbuf_ == 0; 11110b57cec5SDimitry Andric } 11120b57cec5SDimitry Andricpublic: 11130b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR istreambuf_iterator() _NOEXCEPT : __sbuf_(0) {} 11140b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY istreambuf_iterator(istream_type& __s) _NOEXCEPT 11150b57cec5SDimitry Andric : __sbuf_(__s.rdbuf()) {} 11160b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY istreambuf_iterator(streambuf_type* __s) _NOEXCEPT 11170b57cec5SDimitry Andric : __sbuf_(__s) {} 11180b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY istreambuf_iterator(const __proxy& __p) _NOEXCEPT 11190b57cec5SDimitry Andric : __sbuf_(__p.__sbuf_) {} 11200b57cec5SDimitry Andric 11210b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY char_type operator*() const 11220b57cec5SDimitry Andric {return static_cast<char_type>(__sbuf_->sgetc());} 11230b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY istreambuf_iterator& operator++() 11240b57cec5SDimitry Andric { 11250b57cec5SDimitry Andric __sbuf_->sbumpc(); 11260b57cec5SDimitry Andric return *this; 11270b57cec5SDimitry Andric } 11280b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY __proxy operator++(int) 11290b57cec5SDimitry Andric { 11300b57cec5SDimitry Andric return __proxy(__sbuf_->sbumpc(), __sbuf_); 11310b57cec5SDimitry Andric } 11320b57cec5SDimitry Andric 11330b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY bool equal(const istreambuf_iterator& __b) const 11340b57cec5SDimitry Andric {return __test_for_eof() == __b.__test_for_eof();} 11350b57cec5SDimitry Andric}; 11360b57cec5SDimitry Andric 11370b57cec5SDimitry Andrictemplate <class _CharT, class _Traits> 11380b57cec5SDimitry Andricinline _LIBCPP_INLINE_VISIBILITY 11390b57cec5SDimitry Andricbool operator==(const istreambuf_iterator<_CharT,_Traits>& __a, 11400b57cec5SDimitry Andric const istreambuf_iterator<_CharT,_Traits>& __b) 11410b57cec5SDimitry Andric {return __a.equal(__b);} 11420b57cec5SDimitry Andric 11430b57cec5SDimitry Andrictemplate <class _CharT, class _Traits> 11440b57cec5SDimitry Andricinline _LIBCPP_INLINE_VISIBILITY 11450b57cec5SDimitry Andricbool operator!=(const istreambuf_iterator<_CharT,_Traits>& __a, 11460b57cec5SDimitry Andric const istreambuf_iterator<_CharT,_Traits>& __b) 11470b57cec5SDimitry Andric {return !__a.equal(__b);} 11480b57cec5SDimitry Andric 11490b57cec5SDimitry Andrictemplate <class _CharT, class _Traits> 11500b57cec5SDimitry Andricclass _LIBCPP_TEMPLATE_VIS ostreambuf_iterator 11510b57cec5SDimitry Andric : public iterator<output_iterator_tag, void, void, void, void> 11520b57cec5SDimitry Andric{ 11530b57cec5SDimitry Andricpublic: 11540b57cec5SDimitry Andric typedef _CharT char_type; 11550b57cec5SDimitry Andric typedef _Traits traits_type; 11560b57cec5SDimitry Andric typedef basic_streambuf<_CharT,_Traits> streambuf_type; 11570b57cec5SDimitry Andric typedef basic_ostream<_CharT,_Traits> ostream_type; 11580b57cec5SDimitry Andricprivate: 11590b57cec5SDimitry Andric streambuf_type* __sbuf_; 11600b57cec5SDimitry Andricpublic: 11610b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY ostreambuf_iterator(ostream_type& __s) _NOEXCEPT 11620b57cec5SDimitry Andric : __sbuf_(__s.rdbuf()) {} 11630b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY ostreambuf_iterator(streambuf_type* __s) _NOEXCEPT 11640b57cec5SDimitry Andric : __sbuf_(__s) {} 11650b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY ostreambuf_iterator& operator=(_CharT __c) 11660b57cec5SDimitry Andric { 11670b57cec5SDimitry Andric if (__sbuf_ && traits_type::eq_int_type(__sbuf_->sputc(__c), traits_type::eof())) 11680b57cec5SDimitry Andric __sbuf_ = 0; 11690b57cec5SDimitry Andric return *this; 11700b57cec5SDimitry Andric } 11710b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY ostreambuf_iterator& operator*() {return *this;} 11720b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY ostreambuf_iterator& operator++() {return *this;} 11730b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY ostreambuf_iterator& operator++(int) {return *this;} 11740b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY bool failed() const _NOEXCEPT {return __sbuf_ == 0;} 11750b57cec5SDimitry Andric 11760b57cec5SDimitry Andric template <class _Ch, class _Tr> 11770b57cec5SDimitry Andric friend 11780b57cec5SDimitry Andric _LIBCPP_HIDDEN 11790b57cec5SDimitry Andric ostreambuf_iterator<_Ch, _Tr> 11800b57cec5SDimitry Andric __pad_and_output(ostreambuf_iterator<_Ch, _Tr> __s, 11810b57cec5SDimitry Andric const _Ch* __ob, const _Ch* __op, const _Ch* __oe, 11820b57cec5SDimitry Andric ios_base& __iob, _Ch __fl); 11830b57cec5SDimitry Andric}; 11840b57cec5SDimitry Andric 11850b57cec5SDimitry Andrictemplate <class _Iter> 11860b57cec5SDimitry Andricclass _LIBCPP_TEMPLATE_VIS move_iterator 11870b57cec5SDimitry Andric{ 11880b57cec5SDimitry Andricprivate: 11890b57cec5SDimitry Andric _Iter __i; 11900b57cec5SDimitry Andricpublic: 11910b57cec5SDimitry Andric typedef _Iter iterator_type; 11920b57cec5SDimitry Andric typedef typename iterator_traits<iterator_type>::iterator_category iterator_category; 11930b57cec5SDimitry Andric typedef typename iterator_traits<iterator_type>::value_type value_type; 11940b57cec5SDimitry Andric typedef typename iterator_traits<iterator_type>::difference_type difference_type; 11950b57cec5SDimitry Andric typedef iterator_type pointer; 11960b57cec5SDimitry Andric#ifndef _LIBCPP_CXX03_LANG 11970b57cec5SDimitry Andric typedef typename iterator_traits<iterator_type>::reference __reference; 11980b57cec5SDimitry Andric typedef typename conditional< 11990b57cec5SDimitry Andric is_reference<__reference>::value, 12000b57cec5SDimitry Andric typename remove_reference<__reference>::type&&, 12010b57cec5SDimitry Andric __reference 12020b57cec5SDimitry Andric >::type reference; 12030b57cec5SDimitry Andric#else 12040b57cec5SDimitry Andric typedef typename iterator_traits<iterator_type>::reference reference; 12050b57cec5SDimitry Andric#endif 12060b57cec5SDimitry Andric 12070b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 12080b57cec5SDimitry Andric move_iterator() : __i() {} 12090b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 12100b57cec5SDimitry Andric explicit move_iterator(_Iter __x) : __i(__x) {} 12110b57cec5SDimitry Andric template <class _Up> 12120b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 12130b57cec5SDimitry Andric move_iterator(const move_iterator<_Up>& __u) : __i(__u.base()) {} 12140b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 _Iter base() const {return __i;} 12150b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 12160b57cec5SDimitry Andric reference operator*() const { return static_cast<reference>(*__i); } 12170b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 12180b57cec5SDimitry Andric pointer operator->() const { return __i;} 12190b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 12200b57cec5SDimitry Andric move_iterator& operator++() {++__i; return *this;} 12210b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 12220b57cec5SDimitry Andric move_iterator operator++(int) {move_iterator __tmp(*this); ++__i; return __tmp;} 12230b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 12240b57cec5SDimitry Andric move_iterator& operator--() {--__i; return *this;} 12250b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 12260b57cec5SDimitry Andric move_iterator operator--(int) {move_iterator __tmp(*this); --__i; return __tmp;} 12270b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 12280b57cec5SDimitry Andric move_iterator operator+ (difference_type __n) const {return move_iterator(__i + __n);} 12290b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 12300b57cec5SDimitry Andric move_iterator& operator+=(difference_type __n) {__i += __n; return *this;} 12310b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 12320b57cec5SDimitry Andric move_iterator operator- (difference_type __n) const {return move_iterator(__i - __n);} 12330b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 12340b57cec5SDimitry Andric move_iterator& operator-=(difference_type __n) {__i -= __n; return *this;} 12350b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 12360b57cec5SDimitry Andric reference operator[](difference_type __n) const { return static_cast<reference>(__i[__n]); } 12370b57cec5SDimitry Andric}; 12380b57cec5SDimitry Andric 12390b57cec5SDimitry Andrictemplate <class _Iter1, class _Iter2> 12400b57cec5SDimitry Andricinline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 12410b57cec5SDimitry Andricbool 12420b57cec5SDimitry Andricoperator==(const move_iterator<_Iter1>& __x, const move_iterator<_Iter2>& __y) 12430b57cec5SDimitry Andric{ 12440b57cec5SDimitry Andric return __x.base() == __y.base(); 12450b57cec5SDimitry Andric} 12460b57cec5SDimitry Andric 12470b57cec5SDimitry Andrictemplate <class _Iter1, class _Iter2> 12480b57cec5SDimitry Andricinline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 12490b57cec5SDimitry Andricbool 12500b57cec5SDimitry Andricoperator<(const move_iterator<_Iter1>& __x, const move_iterator<_Iter2>& __y) 12510b57cec5SDimitry Andric{ 12520b57cec5SDimitry Andric return __x.base() < __y.base(); 12530b57cec5SDimitry Andric} 12540b57cec5SDimitry Andric 12550b57cec5SDimitry Andrictemplate <class _Iter1, class _Iter2> 12560b57cec5SDimitry Andricinline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 12570b57cec5SDimitry Andricbool 12580b57cec5SDimitry Andricoperator!=(const move_iterator<_Iter1>& __x, const move_iterator<_Iter2>& __y) 12590b57cec5SDimitry Andric{ 12600b57cec5SDimitry Andric return __x.base() != __y.base(); 12610b57cec5SDimitry Andric} 12620b57cec5SDimitry Andric 12630b57cec5SDimitry Andrictemplate <class _Iter1, class _Iter2> 12640b57cec5SDimitry Andricinline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 12650b57cec5SDimitry Andricbool 12660b57cec5SDimitry Andricoperator>(const move_iterator<_Iter1>& __x, const move_iterator<_Iter2>& __y) 12670b57cec5SDimitry Andric{ 12680b57cec5SDimitry Andric return __x.base() > __y.base(); 12690b57cec5SDimitry Andric} 12700b57cec5SDimitry Andric 12710b57cec5SDimitry Andrictemplate <class _Iter1, class _Iter2> 12720b57cec5SDimitry Andricinline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 12730b57cec5SDimitry Andricbool 12740b57cec5SDimitry Andricoperator>=(const move_iterator<_Iter1>& __x, const move_iterator<_Iter2>& __y) 12750b57cec5SDimitry Andric{ 12760b57cec5SDimitry Andric return __x.base() >= __y.base(); 12770b57cec5SDimitry Andric} 12780b57cec5SDimitry Andric 12790b57cec5SDimitry Andrictemplate <class _Iter1, class _Iter2> 12800b57cec5SDimitry Andricinline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 12810b57cec5SDimitry Andricbool 12820b57cec5SDimitry Andricoperator<=(const move_iterator<_Iter1>& __x, const move_iterator<_Iter2>& __y) 12830b57cec5SDimitry Andric{ 12840b57cec5SDimitry Andric return __x.base() <= __y.base(); 12850b57cec5SDimitry Andric} 12860b57cec5SDimitry Andric 12870b57cec5SDimitry Andric#ifndef _LIBCPP_CXX03_LANG 12880b57cec5SDimitry Andrictemplate <class _Iter1, class _Iter2> 12890b57cec5SDimitry Andricinline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 12900b57cec5SDimitry Andricauto 12910b57cec5SDimitry Andricoperator-(const move_iterator<_Iter1>& __x, const move_iterator<_Iter2>& __y) 12920b57cec5SDimitry Andric-> decltype(__x.base() - __y.base()) 12930b57cec5SDimitry Andric{ 12940b57cec5SDimitry Andric return __x.base() - __y.base(); 12950b57cec5SDimitry Andric} 12960b57cec5SDimitry Andric#else 12970b57cec5SDimitry Andrictemplate <class _Iter1, class _Iter2> 12980b57cec5SDimitry Andricinline _LIBCPP_INLINE_VISIBILITY 12990b57cec5SDimitry Andrictypename move_iterator<_Iter1>::difference_type 13000b57cec5SDimitry Andricoperator-(const move_iterator<_Iter1>& __x, const move_iterator<_Iter2>& __y) 13010b57cec5SDimitry Andric{ 13020b57cec5SDimitry Andric return __x.base() - __y.base(); 13030b57cec5SDimitry Andric} 13040b57cec5SDimitry Andric#endif 13050b57cec5SDimitry Andric 13060b57cec5SDimitry Andrictemplate <class _Iter> 13070b57cec5SDimitry Andricinline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 13080b57cec5SDimitry Andricmove_iterator<_Iter> 13090b57cec5SDimitry Andricoperator+(typename move_iterator<_Iter>::difference_type __n, const move_iterator<_Iter>& __x) 13100b57cec5SDimitry Andric{ 13110b57cec5SDimitry Andric return move_iterator<_Iter>(__x.base() + __n); 13120b57cec5SDimitry Andric} 13130b57cec5SDimitry Andric 13140b57cec5SDimitry Andrictemplate <class _Iter> 13150b57cec5SDimitry Andricinline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 13160b57cec5SDimitry Andricmove_iterator<_Iter> 13170b57cec5SDimitry Andricmake_move_iterator(_Iter __i) 13180b57cec5SDimitry Andric{ 13190b57cec5SDimitry Andric return move_iterator<_Iter>(__i); 13200b57cec5SDimitry Andric} 13210b57cec5SDimitry Andric 13220b57cec5SDimitry Andric// __wrap_iter 13230b57cec5SDimitry Andric 13240b57cec5SDimitry Andrictemplate <class _Iter> class __wrap_iter; 13250b57cec5SDimitry Andric 13260b57cec5SDimitry Andrictemplate <class _Iter1, class _Iter2> 13270b57cec5SDimitry Andric_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG 13280b57cec5SDimitry Andricbool 13290b57cec5SDimitry Andricoperator==(const __wrap_iter<_Iter1>&, const __wrap_iter<_Iter2>&) _NOEXCEPT; 13300b57cec5SDimitry Andric 13310b57cec5SDimitry Andrictemplate <class _Iter1, class _Iter2> 13320b57cec5SDimitry Andric_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG 13330b57cec5SDimitry Andricbool 13340b57cec5SDimitry Andricoperator<(const __wrap_iter<_Iter1>&, const __wrap_iter<_Iter2>&) _NOEXCEPT; 13350b57cec5SDimitry Andric 13360b57cec5SDimitry Andrictemplate <class _Iter1, class _Iter2> 13370b57cec5SDimitry Andric_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG 13380b57cec5SDimitry Andricbool 13390b57cec5SDimitry Andricoperator!=(const __wrap_iter<_Iter1>&, const __wrap_iter<_Iter2>&) _NOEXCEPT; 13400b57cec5SDimitry Andric 13410b57cec5SDimitry Andrictemplate <class _Iter1, class _Iter2> 13420b57cec5SDimitry Andric_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG 13430b57cec5SDimitry Andricbool 13440b57cec5SDimitry Andricoperator>(const __wrap_iter<_Iter1>&, const __wrap_iter<_Iter2>&) _NOEXCEPT; 13450b57cec5SDimitry Andric 13460b57cec5SDimitry Andrictemplate <class _Iter1, class _Iter2> 13470b57cec5SDimitry Andric_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG 13480b57cec5SDimitry Andricbool 13490b57cec5SDimitry Andricoperator>=(const __wrap_iter<_Iter1>&, const __wrap_iter<_Iter2>&) _NOEXCEPT; 13500b57cec5SDimitry Andric 13510b57cec5SDimitry Andrictemplate <class _Iter1, class _Iter2> 13520b57cec5SDimitry Andric_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG 13530b57cec5SDimitry Andricbool 13540b57cec5SDimitry Andricoperator<=(const __wrap_iter<_Iter1>&, const __wrap_iter<_Iter2>&) _NOEXCEPT; 13550b57cec5SDimitry Andric 13560b57cec5SDimitry Andric#ifndef _LIBCPP_CXX03_LANG 13570b57cec5SDimitry Andrictemplate <class _Iter1, class _Iter2> 13580b57cec5SDimitry Andric_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG 13590b57cec5SDimitry Andricauto 13600b57cec5SDimitry Andricoperator-(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter2>& __y) _NOEXCEPT 13610b57cec5SDimitry Andric-> decltype(__x.base() - __y.base()); 13620b57cec5SDimitry Andric#else 13630b57cec5SDimitry Andrictemplate <class _Iter1, class _Iter2> 13640b57cec5SDimitry Andric_LIBCPP_INLINE_VISIBILITY 13650b57cec5SDimitry Andrictypename __wrap_iter<_Iter1>::difference_type 13660b57cec5SDimitry Andricoperator-(const __wrap_iter<_Iter1>&, const __wrap_iter<_Iter2>&) _NOEXCEPT; 13670b57cec5SDimitry Andric#endif 13680b57cec5SDimitry Andric 13690b57cec5SDimitry Andrictemplate <class _Iter> 13700b57cec5SDimitry Andric_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG 13710b57cec5SDimitry Andric__wrap_iter<_Iter> 13720b57cec5SDimitry Andricoperator+(typename __wrap_iter<_Iter>::difference_type, __wrap_iter<_Iter>) _NOEXCEPT; 13730b57cec5SDimitry Andric 1374480093f4SDimitry Andrictemplate <class _Ip, class _Op> _Op _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 copy(_Ip, _Ip, _Op); 1375480093f4SDimitry Andrictemplate <class _B1, class _B2> _B2 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 copy_backward(_B1, _B1, _B2); 13760b57cec5SDimitry Andrictemplate <class _Ip, class _Op> _Op _LIBCPP_INLINE_VISIBILITY move(_Ip, _Ip, _Op); 13770b57cec5SDimitry Andrictemplate <class _B1, class _B2> _B2 _LIBCPP_INLINE_VISIBILITY move_backward(_B1, _B1, _B2); 13780b57cec5SDimitry Andric 13790b57cec5SDimitry Andric#if _LIBCPP_DEBUG_LEVEL < 2 13800b57cec5SDimitry Andric 13810b57cec5SDimitry Andrictemplate <class _Tp> 13820b57cec5SDimitry Andric_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG 13830b57cec5SDimitry Andrictypename enable_if 13840b57cec5SDimitry Andric< 13850b57cec5SDimitry Andric is_trivially_copy_assignable<_Tp>::value, 13860b57cec5SDimitry Andric _Tp* 13870b57cec5SDimitry Andric>::type 13880b57cec5SDimitry Andric__unwrap_iter(__wrap_iter<_Tp*>); 13890b57cec5SDimitry Andric 13900b57cec5SDimitry Andric#else 13910b57cec5SDimitry Andric 13920b57cec5SDimitry Andrictemplate <class _Tp> 13930b57cec5SDimitry Andricinline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG 13940b57cec5SDimitry Andrictypename enable_if 13950b57cec5SDimitry Andric< 13960b57cec5SDimitry Andric is_trivially_copy_assignable<_Tp>::value, 13970b57cec5SDimitry Andric __wrap_iter<_Tp*> 13980b57cec5SDimitry Andric>::type 13990b57cec5SDimitry Andric__unwrap_iter(__wrap_iter<_Tp*> __i); 14000b57cec5SDimitry Andric 14010b57cec5SDimitry Andric#endif 14020b57cec5SDimitry Andric 14030b57cec5SDimitry Andrictemplate <class _Iter> 14040b57cec5SDimitry Andricclass __wrap_iter 14050b57cec5SDimitry Andric{ 14060b57cec5SDimitry Andricpublic: 14070b57cec5SDimitry Andric typedef _Iter iterator_type; 14080b57cec5SDimitry Andric typedef typename iterator_traits<iterator_type>::iterator_category iterator_category; 14090b57cec5SDimitry Andric typedef typename iterator_traits<iterator_type>::value_type value_type; 14100b57cec5SDimitry Andric typedef typename iterator_traits<iterator_type>::difference_type difference_type; 14110b57cec5SDimitry Andric typedef typename iterator_traits<iterator_type>::pointer pointer; 14120b57cec5SDimitry Andric typedef typename iterator_traits<iterator_type>::reference reference; 14130b57cec5SDimitry Andricprivate: 14140b57cec5SDimitry Andric iterator_type __i; 14150b57cec5SDimitry Andricpublic: 14160b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG __wrap_iter() _NOEXCEPT 14170b57cec5SDimitry Andric#if _LIBCPP_STD_VER > 11 14180b57cec5SDimitry Andric : __i{} 14190b57cec5SDimitry Andric#endif 14200b57cec5SDimitry Andric { 14210b57cec5SDimitry Andric#if _LIBCPP_DEBUG_LEVEL >= 2 14220b57cec5SDimitry Andric __get_db()->__insert_i(this); 14230b57cec5SDimitry Andric#endif 14240b57cec5SDimitry Andric } 14250b57cec5SDimitry Andric template <class _Up> _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG 14260b57cec5SDimitry Andric __wrap_iter(const __wrap_iter<_Up>& __u, 14270b57cec5SDimitry Andric typename enable_if<is_convertible<_Up, iterator_type>::value>::type* = 0) _NOEXCEPT 14280b57cec5SDimitry Andric : __i(__u.base()) 14290b57cec5SDimitry Andric { 14300b57cec5SDimitry Andric#if _LIBCPP_DEBUG_LEVEL >= 2 14310b57cec5SDimitry Andric __get_db()->__iterator_copy(this, &__u); 14320b57cec5SDimitry Andric#endif 14330b57cec5SDimitry Andric } 14340b57cec5SDimitry Andric#if _LIBCPP_DEBUG_LEVEL >= 2 14350b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG 14360b57cec5SDimitry Andric __wrap_iter(const __wrap_iter& __x) 14370b57cec5SDimitry Andric : __i(__x.base()) 14380b57cec5SDimitry Andric { 14390b57cec5SDimitry Andric __get_db()->__iterator_copy(this, &__x); 14400b57cec5SDimitry Andric } 14410b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG 14420b57cec5SDimitry Andric __wrap_iter& operator=(const __wrap_iter& __x) 14430b57cec5SDimitry Andric { 14440b57cec5SDimitry Andric if (this != &__x) 14450b57cec5SDimitry Andric { 14460b57cec5SDimitry Andric __get_db()->__iterator_copy(this, &__x); 14470b57cec5SDimitry Andric __i = __x.__i; 14480b57cec5SDimitry Andric } 14490b57cec5SDimitry Andric return *this; 14500b57cec5SDimitry Andric } 14510b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG 14520b57cec5SDimitry Andric ~__wrap_iter() 14530b57cec5SDimitry Andric { 14540b57cec5SDimitry Andric __get_db()->__erase_i(this); 14550b57cec5SDimitry Andric } 14560b57cec5SDimitry Andric#endif 14570b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG reference operator*() const _NOEXCEPT 14580b57cec5SDimitry Andric { 14590b57cec5SDimitry Andric#if _LIBCPP_DEBUG_LEVEL >= 2 14600b57cec5SDimitry Andric _LIBCPP_ASSERT(__get_const_db()->__dereferenceable(this), 14610b57cec5SDimitry Andric "Attempted to dereference a non-dereferenceable iterator"); 14620b57cec5SDimitry Andric#endif 14630b57cec5SDimitry Andric return *__i; 14640b57cec5SDimitry Andric } 14650b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG pointer operator->() const _NOEXCEPT 14660b57cec5SDimitry Andric { 14670b57cec5SDimitry Andric#if _LIBCPP_DEBUG_LEVEL >= 2 14680b57cec5SDimitry Andric _LIBCPP_ASSERT(__get_const_db()->__dereferenceable(this), 14690b57cec5SDimitry Andric "Attempted to dereference a non-dereferenceable iterator"); 14700b57cec5SDimitry Andric#endif 14710b57cec5SDimitry Andric return (pointer)_VSTD::addressof(*__i); 14720b57cec5SDimitry Andric } 14730b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG __wrap_iter& operator++() _NOEXCEPT 14740b57cec5SDimitry Andric { 14750b57cec5SDimitry Andric#if _LIBCPP_DEBUG_LEVEL >= 2 14760b57cec5SDimitry Andric _LIBCPP_ASSERT(__get_const_db()->__dereferenceable(this), 14770b57cec5SDimitry Andric "Attempted to increment non-incrementable iterator"); 14780b57cec5SDimitry Andric#endif 14790b57cec5SDimitry Andric ++__i; 14800b57cec5SDimitry Andric return *this; 14810b57cec5SDimitry Andric } 14820b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG __wrap_iter operator++(int) _NOEXCEPT 14830b57cec5SDimitry Andric {__wrap_iter __tmp(*this); ++(*this); return __tmp;} 14840b57cec5SDimitry Andric 14850b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG __wrap_iter& operator--() _NOEXCEPT 14860b57cec5SDimitry Andric { 14870b57cec5SDimitry Andric#if _LIBCPP_DEBUG_LEVEL >= 2 14880b57cec5SDimitry Andric _LIBCPP_ASSERT(__get_const_db()->__decrementable(this), 14890b57cec5SDimitry Andric "Attempted to decrement non-decrementable iterator"); 14900b57cec5SDimitry Andric#endif 14910b57cec5SDimitry Andric --__i; 14920b57cec5SDimitry Andric return *this; 14930b57cec5SDimitry Andric } 14940b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG __wrap_iter operator--(int) _NOEXCEPT 14950b57cec5SDimitry Andric {__wrap_iter __tmp(*this); --(*this); return __tmp;} 14960b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG __wrap_iter operator+ (difference_type __n) const _NOEXCEPT 14970b57cec5SDimitry Andric {__wrap_iter __w(*this); __w += __n; return __w;} 14980b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG __wrap_iter& operator+=(difference_type __n) _NOEXCEPT 14990b57cec5SDimitry Andric { 15000b57cec5SDimitry Andric#if _LIBCPP_DEBUG_LEVEL >= 2 15010b57cec5SDimitry Andric _LIBCPP_ASSERT(__get_const_db()->__addable(this, __n), 15020b57cec5SDimitry Andric "Attempted to add/subtract iterator outside of valid range"); 15030b57cec5SDimitry Andric#endif 15040b57cec5SDimitry Andric __i += __n; 15050b57cec5SDimitry Andric return *this; 15060b57cec5SDimitry Andric } 15070b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG __wrap_iter operator- (difference_type __n) const _NOEXCEPT 15080b57cec5SDimitry Andric {return *this + (-__n);} 15090b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG __wrap_iter& operator-=(difference_type __n) _NOEXCEPT 15100b57cec5SDimitry Andric {*this += -__n; return *this;} 15110b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG reference operator[](difference_type __n) const _NOEXCEPT 15120b57cec5SDimitry Andric { 15130b57cec5SDimitry Andric#if _LIBCPP_DEBUG_LEVEL >= 2 15140b57cec5SDimitry Andric _LIBCPP_ASSERT(__get_const_db()->__subscriptable(this, __n), 15150b57cec5SDimitry Andric "Attempted to subscript iterator outside of valid range"); 15160b57cec5SDimitry Andric#endif 15170b57cec5SDimitry Andric return __i[__n]; 15180b57cec5SDimitry Andric } 15190b57cec5SDimitry Andric 15200b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG iterator_type base() const _NOEXCEPT {return __i;} 15210b57cec5SDimitry Andric 15220b57cec5SDimitry Andricprivate: 15230b57cec5SDimitry Andric#if _LIBCPP_DEBUG_LEVEL >= 2 15240b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG __wrap_iter(const void* __p, iterator_type __x) : __i(__x) 15250b57cec5SDimitry Andric { 15260b57cec5SDimitry Andric __get_db()->__insert_ic(this, __p); 15270b57cec5SDimitry Andric } 15280b57cec5SDimitry Andric#else 15290b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG __wrap_iter(iterator_type __x) _NOEXCEPT : __i(__x) {} 15300b57cec5SDimitry Andric#endif 15310b57cec5SDimitry Andric 15320b57cec5SDimitry Andric template <class _Up> friend class __wrap_iter; 15330b57cec5SDimitry Andric template <class _CharT, class _Traits, class _Alloc> friend class basic_string; 15340b57cec5SDimitry Andric template <class _Tp, class _Alloc> friend class _LIBCPP_TEMPLATE_VIS vector; 15350b57cec5SDimitry Andric template <class _Tp, size_t> friend class _LIBCPP_TEMPLATE_VIS span; 15360b57cec5SDimitry Andric 15370b57cec5SDimitry Andric template <class _Iter1, class _Iter2> 15380b57cec5SDimitry Andric _LIBCPP_CONSTEXPR_IF_NODEBUG friend 15390b57cec5SDimitry Andric bool 15400b57cec5SDimitry Andric operator==(const __wrap_iter<_Iter1>&, const __wrap_iter<_Iter2>&) _NOEXCEPT; 15410b57cec5SDimitry Andric 15420b57cec5SDimitry Andric template <class _Iter1, class _Iter2> 15430b57cec5SDimitry Andric _LIBCPP_CONSTEXPR_IF_NODEBUG friend 15440b57cec5SDimitry Andric bool 15450b57cec5SDimitry Andric operator<(const __wrap_iter<_Iter1>&, const __wrap_iter<_Iter2>&) _NOEXCEPT; 15460b57cec5SDimitry Andric 15470b57cec5SDimitry Andric template <class _Iter1, class _Iter2> 15480b57cec5SDimitry Andric _LIBCPP_CONSTEXPR_IF_NODEBUG friend 15490b57cec5SDimitry Andric bool 15500b57cec5SDimitry Andric operator!=(const __wrap_iter<_Iter1>&, const __wrap_iter<_Iter2>&) _NOEXCEPT; 15510b57cec5SDimitry Andric 15520b57cec5SDimitry Andric template <class _Iter1, class _Iter2> 15530b57cec5SDimitry Andric _LIBCPP_CONSTEXPR_IF_NODEBUG friend 15540b57cec5SDimitry Andric bool 15550b57cec5SDimitry Andric operator>(const __wrap_iter<_Iter1>&, const __wrap_iter<_Iter2>&) _NOEXCEPT; 15560b57cec5SDimitry Andric 15570b57cec5SDimitry Andric template <class _Iter1, class _Iter2> 15580b57cec5SDimitry Andric _LIBCPP_CONSTEXPR_IF_NODEBUG friend 15590b57cec5SDimitry Andric bool 15600b57cec5SDimitry Andric operator>=(const __wrap_iter<_Iter1>&, const __wrap_iter<_Iter2>&) _NOEXCEPT; 15610b57cec5SDimitry Andric 15620b57cec5SDimitry Andric template <class _Iter1, class _Iter2> 15630b57cec5SDimitry Andric _LIBCPP_CONSTEXPR_IF_NODEBUG friend 15640b57cec5SDimitry Andric bool 15650b57cec5SDimitry Andric operator<=(const __wrap_iter<_Iter1>&, const __wrap_iter<_Iter2>&) _NOEXCEPT; 15660b57cec5SDimitry Andric 15670b57cec5SDimitry Andric#ifndef _LIBCPP_CXX03_LANG 15680b57cec5SDimitry Andric template <class _Iter1, class _Iter2> 15690b57cec5SDimitry Andric _LIBCPP_CONSTEXPR_IF_NODEBUG friend 15700b57cec5SDimitry Andric auto 15710b57cec5SDimitry Andric operator-(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter2>& __y) _NOEXCEPT 15720b57cec5SDimitry Andric -> decltype(__x.base() - __y.base()); 15730b57cec5SDimitry Andric#else 15740b57cec5SDimitry Andric template <class _Iter1, class _Iter2> 15750b57cec5SDimitry Andric _LIBCPP_CONSTEXPR_IF_NODEBUG friend 15760b57cec5SDimitry Andric typename __wrap_iter<_Iter1>::difference_type 15770b57cec5SDimitry Andric operator-(const __wrap_iter<_Iter1>&, const __wrap_iter<_Iter2>&) _NOEXCEPT; 15780b57cec5SDimitry Andric#endif 15790b57cec5SDimitry Andric 15800b57cec5SDimitry Andric template <class _Iter1> 15810b57cec5SDimitry Andric _LIBCPP_CONSTEXPR_IF_NODEBUG friend 15820b57cec5SDimitry Andric __wrap_iter<_Iter1> 15830b57cec5SDimitry Andric operator+(typename __wrap_iter<_Iter1>::difference_type, __wrap_iter<_Iter1>) _NOEXCEPT; 15840b57cec5SDimitry Andric 1585480093f4SDimitry Andric template <class _Ip, class _Op> friend _LIBCPP_CONSTEXPR_AFTER_CXX17 _Op copy(_Ip, _Ip, _Op); 1586480093f4SDimitry Andric template <class _B1, class _B2> friend _LIBCPP_CONSTEXPR_AFTER_CXX17 _B2 copy_backward(_B1, _B1, _B2); 15870b57cec5SDimitry Andric template <class _Ip, class _Op> friend _Op move(_Ip, _Ip, _Op); 15880b57cec5SDimitry Andric template <class _B1, class _B2> friend _B2 move_backward(_B1, _B1, _B2); 15890b57cec5SDimitry Andric 15900b57cec5SDimitry Andric#if _LIBCPP_DEBUG_LEVEL < 2 15910b57cec5SDimitry Andric template <class _Tp> 15920b57cec5SDimitry Andric _LIBCPP_CONSTEXPR_IF_NODEBUG friend 15930b57cec5SDimitry Andric typename enable_if 15940b57cec5SDimitry Andric < 15950b57cec5SDimitry Andric is_trivially_copy_assignable<_Tp>::value, 15960b57cec5SDimitry Andric _Tp* 15970b57cec5SDimitry Andric >::type 15980b57cec5SDimitry Andric __unwrap_iter(__wrap_iter<_Tp*>); 15990b57cec5SDimitry Andric#else 16000b57cec5SDimitry Andric template <class _Tp> 16010b57cec5SDimitry Andric inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG 16020b57cec5SDimitry Andric typename enable_if 16030b57cec5SDimitry Andric < 16040b57cec5SDimitry Andric is_trivially_copy_assignable<_Tp>::value, 16050b57cec5SDimitry Andric __wrap_iter<_Tp*> 16060b57cec5SDimitry Andric >::type 16070b57cec5SDimitry Andric __unwrap_iter(__wrap_iter<_Tp*> __i); 16080b57cec5SDimitry Andric#endif 16090b57cec5SDimitry Andric}; 16100b57cec5SDimitry Andric 16110b57cec5SDimitry Andrictemplate <class _Iter1, class _Iter2> 16120b57cec5SDimitry Andricinline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG 16130b57cec5SDimitry Andricbool 16140b57cec5SDimitry Andricoperator==(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter2>& __y) _NOEXCEPT 16150b57cec5SDimitry Andric{ 16160b57cec5SDimitry Andric return __x.base() == __y.base(); 16170b57cec5SDimitry Andric} 16180b57cec5SDimitry Andric 16190b57cec5SDimitry Andrictemplate <class _Iter1, class _Iter2> 16200b57cec5SDimitry Andricinline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG 16210b57cec5SDimitry Andricbool 16220b57cec5SDimitry Andricoperator<(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter2>& __y) _NOEXCEPT 16230b57cec5SDimitry Andric{ 16240b57cec5SDimitry Andric#if _LIBCPP_DEBUG_LEVEL >= 2 16250b57cec5SDimitry Andric _LIBCPP_ASSERT(__get_const_db()->__less_than_comparable(&__x, &__y), 16260b57cec5SDimitry Andric "Attempted to compare incomparable iterators"); 16270b57cec5SDimitry Andric#endif 16280b57cec5SDimitry Andric return __x.base() < __y.base(); 16290b57cec5SDimitry Andric} 16300b57cec5SDimitry Andric 16310b57cec5SDimitry Andrictemplate <class _Iter1, class _Iter2> 16320b57cec5SDimitry Andricinline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG 16330b57cec5SDimitry Andricbool 16340b57cec5SDimitry Andricoperator!=(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter2>& __y) _NOEXCEPT 16350b57cec5SDimitry Andric{ 16360b57cec5SDimitry Andric return !(__x == __y); 16370b57cec5SDimitry Andric} 16380b57cec5SDimitry Andric 16390b57cec5SDimitry Andrictemplate <class _Iter1, class _Iter2> 16400b57cec5SDimitry Andricinline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG 16410b57cec5SDimitry Andricbool 16420b57cec5SDimitry Andricoperator>(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter2>& __y) _NOEXCEPT 16430b57cec5SDimitry Andric{ 16440b57cec5SDimitry Andric return __y < __x; 16450b57cec5SDimitry Andric} 16460b57cec5SDimitry Andric 16470b57cec5SDimitry Andrictemplate <class _Iter1, class _Iter2> 16480b57cec5SDimitry Andricinline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG 16490b57cec5SDimitry Andricbool 16500b57cec5SDimitry Andricoperator>=(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter2>& __y) _NOEXCEPT 16510b57cec5SDimitry Andric{ 16520b57cec5SDimitry Andric return !(__x < __y); 16530b57cec5SDimitry Andric} 16540b57cec5SDimitry Andric 16550b57cec5SDimitry Andrictemplate <class _Iter1, class _Iter2> 16560b57cec5SDimitry Andricinline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG 16570b57cec5SDimitry Andricbool 16580b57cec5SDimitry Andricoperator<=(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter2>& __y) _NOEXCEPT 16590b57cec5SDimitry Andric{ 16600b57cec5SDimitry Andric return !(__y < __x); 16610b57cec5SDimitry Andric} 16620b57cec5SDimitry Andric 16630b57cec5SDimitry Andrictemplate <class _Iter1> 16640b57cec5SDimitry Andricinline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG 16650b57cec5SDimitry Andricbool 16660b57cec5SDimitry Andricoperator!=(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter1>& __y) _NOEXCEPT 16670b57cec5SDimitry Andric{ 16680b57cec5SDimitry Andric return !(__x == __y); 16690b57cec5SDimitry Andric} 16700b57cec5SDimitry Andric 16710b57cec5SDimitry Andrictemplate <class _Iter1> 16720b57cec5SDimitry Andricinline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG 16730b57cec5SDimitry Andricbool 16740b57cec5SDimitry Andricoperator>(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter1>& __y) _NOEXCEPT 16750b57cec5SDimitry Andric{ 16760b57cec5SDimitry Andric return __y < __x; 16770b57cec5SDimitry Andric} 16780b57cec5SDimitry Andric 16790b57cec5SDimitry Andrictemplate <class _Iter1> 16800b57cec5SDimitry Andricinline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG 16810b57cec5SDimitry Andricbool 16820b57cec5SDimitry Andricoperator>=(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter1>& __y) _NOEXCEPT 16830b57cec5SDimitry Andric{ 16840b57cec5SDimitry Andric return !(__x < __y); 16850b57cec5SDimitry Andric} 16860b57cec5SDimitry Andric 16870b57cec5SDimitry Andrictemplate <class _Iter1> 16880b57cec5SDimitry Andricinline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG 16890b57cec5SDimitry Andricbool 16900b57cec5SDimitry Andricoperator<=(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter1>& __y) _NOEXCEPT 16910b57cec5SDimitry Andric{ 16920b57cec5SDimitry Andric return !(__y < __x); 16930b57cec5SDimitry Andric} 16940b57cec5SDimitry Andric 16950b57cec5SDimitry Andric#ifndef _LIBCPP_CXX03_LANG 16960b57cec5SDimitry Andrictemplate <class _Iter1, class _Iter2> 16970b57cec5SDimitry Andricinline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG 16980b57cec5SDimitry Andricauto 16990b57cec5SDimitry Andricoperator-(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter2>& __y) _NOEXCEPT 17000b57cec5SDimitry Andric-> decltype(__x.base() - __y.base()) 17010b57cec5SDimitry Andric{ 17020b57cec5SDimitry Andric#if _LIBCPP_DEBUG_LEVEL >= 2 17030b57cec5SDimitry Andric _LIBCPP_ASSERT(__get_const_db()->__less_than_comparable(&__x, &__y), 17040b57cec5SDimitry Andric "Attempted to subtract incompatible iterators"); 17050b57cec5SDimitry Andric#endif 17060b57cec5SDimitry Andric return __x.base() - __y.base(); 17070b57cec5SDimitry Andric} 17080b57cec5SDimitry Andric#else 17090b57cec5SDimitry Andrictemplate <class _Iter1, class _Iter2> 17100b57cec5SDimitry Andricinline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG 17110b57cec5SDimitry Andrictypename __wrap_iter<_Iter1>::difference_type 17120b57cec5SDimitry Andricoperator-(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter2>& __y) _NOEXCEPT 17130b57cec5SDimitry Andric{ 17140b57cec5SDimitry Andric#if _LIBCPP_DEBUG_LEVEL >= 2 17150b57cec5SDimitry Andric _LIBCPP_ASSERT(__get_const_db()->__less_than_comparable(&__x, &__y), 17160b57cec5SDimitry Andric "Attempted to subtract incompatible iterators"); 17170b57cec5SDimitry Andric#endif 17180b57cec5SDimitry Andric return __x.base() - __y.base(); 17190b57cec5SDimitry Andric} 17200b57cec5SDimitry Andric#endif 17210b57cec5SDimitry Andric 17220b57cec5SDimitry Andrictemplate <class _Iter> 17230b57cec5SDimitry Andricinline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG 17240b57cec5SDimitry Andric__wrap_iter<_Iter> 17250b57cec5SDimitry Andricoperator+(typename __wrap_iter<_Iter>::difference_type __n, 17260b57cec5SDimitry Andric __wrap_iter<_Iter> __x) _NOEXCEPT 17270b57cec5SDimitry Andric{ 17280b57cec5SDimitry Andric __x += __n; 17290b57cec5SDimitry Andric return __x; 17300b57cec5SDimitry Andric} 17310b57cec5SDimitry Andric 17320b57cec5SDimitry Andrictemplate <class _Iter> 17330b57cec5SDimitry Andricstruct __libcpp_is_trivial_iterator 17340b57cec5SDimitry Andric : public _LIBCPP_BOOL_CONSTANT(is_pointer<_Iter>::value) {}; 17350b57cec5SDimitry Andric 17360b57cec5SDimitry Andrictemplate <class _Iter> 17370b57cec5SDimitry Andricstruct __libcpp_is_trivial_iterator<move_iterator<_Iter> > 17380b57cec5SDimitry Andric : public _LIBCPP_BOOL_CONSTANT(__libcpp_is_trivial_iterator<_Iter>::value) {}; 17390b57cec5SDimitry Andric 17400b57cec5SDimitry Andrictemplate <class _Iter> 17410b57cec5SDimitry Andricstruct __libcpp_is_trivial_iterator<reverse_iterator<_Iter> > 17420b57cec5SDimitry Andric : public _LIBCPP_BOOL_CONSTANT(__libcpp_is_trivial_iterator<_Iter>::value) {}; 17430b57cec5SDimitry Andric 17440b57cec5SDimitry Andrictemplate <class _Iter> 17450b57cec5SDimitry Andricstruct __libcpp_is_trivial_iterator<__wrap_iter<_Iter> > 17460b57cec5SDimitry Andric : public _LIBCPP_BOOL_CONSTANT(__libcpp_is_trivial_iterator<_Iter>::value) {}; 17470b57cec5SDimitry Andric 17480b57cec5SDimitry Andric 17490b57cec5SDimitry Andrictemplate <class _Tp, size_t _Np> 17500b57cec5SDimitry Andric_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 17510b57cec5SDimitry Andric_Tp* 17520b57cec5SDimitry Andricbegin(_Tp (&__array)[_Np]) 17530b57cec5SDimitry Andric{ 17540b57cec5SDimitry Andric return __array; 17550b57cec5SDimitry Andric} 17560b57cec5SDimitry Andric 17570b57cec5SDimitry Andrictemplate <class _Tp, size_t _Np> 17580b57cec5SDimitry Andric_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 17590b57cec5SDimitry Andric_Tp* 17600b57cec5SDimitry Andricend(_Tp (&__array)[_Np]) 17610b57cec5SDimitry Andric{ 17620b57cec5SDimitry Andric return __array + _Np; 17630b57cec5SDimitry Andric} 17640b57cec5SDimitry Andric 17650b57cec5SDimitry Andric#if !defined(_LIBCPP_CXX03_LANG) 17660b57cec5SDimitry Andric 17670b57cec5SDimitry Andrictemplate <class _Cp> 17680b57cec5SDimitry Andric_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 17690b57cec5SDimitry Andricauto 17700b57cec5SDimitry Andricbegin(_Cp& __c) -> decltype(__c.begin()) 17710b57cec5SDimitry Andric{ 17720b57cec5SDimitry Andric return __c.begin(); 17730b57cec5SDimitry Andric} 17740b57cec5SDimitry Andric 17750b57cec5SDimitry Andrictemplate <class _Cp> 17760b57cec5SDimitry Andric_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 17770b57cec5SDimitry Andricauto 17780b57cec5SDimitry Andricbegin(const _Cp& __c) -> decltype(__c.begin()) 17790b57cec5SDimitry Andric{ 17800b57cec5SDimitry Andric return __c.begin(); 17810b57cec5SDimitry Andric} 17820b57cec5SDimitry Andric 17830b57cec5SDimitry Andrictemplate <class _Cp> 17840b57cec5SDimitry Andric_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 17850b57cec5SDimitry Andricauto 17860b57cec5SDimitry Andricend(_Cp& __c) -> decltype(__c.end()) 17870b57cec5SDimitry Andric{ 17880b57cec5SDimitry Andric return __c.end(); 17890b57cec5SDimitry Andric} 17900b57cec5SDimitry Andric 17910b57cec5SDimitry Andrictemplate <class _Cp> 17920b57cec5SDimitry Andric_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 17930b57cec5SDimitry Andricauto 17940b57cec5SDimitry Andricend(const _Cp& __c) -> decltype(__c.end()) 17950b57cec5SDimitry Andric{ 17960b57cec5SDimitry Andric return __c.end(); 17970b57cec5SDimitry Andric} 17980b57cec5SDimitry Andric 17990b57cec5SDimitry Andric#if _LIBCPP_STD_VER > 11 18000b57cec5SDimitry Andric 18010b57cec5SDimitry Andrictemplate <class _Tp, size_t _Np> 18020b57cec5SDimitry Andric_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 18030b57cec5SDimitry Andricreverse_iterator<_Tp*> rbegin(_Tp (&__array)[_Np]) 18040b57cec5SDimitry Andric{ 18050b57cec5SDimitry Andric return reverse_iterator<_Tp*>(__array + _Np); 18060b57cec5SDimitry Andric} 18070b57cec5SDimitry Andric 18080b57cec5SDimitry Andrictemplate <class _Tp, size_t _Np> 18090b57cec5SDimitry Andric_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 18100b57cec5SDimitry Andricreverse_iterator<_Tp*> rend(_Tp (&__array)[_Np]) 18110b57cec5SDimitry Andric{ 18120b57cec5SDimitry Andric return reverse_iterator<_Tp*>(__array); 18130b57cec5SDimitry Andric} 18140b57cec5SDimitry Andric 18150b57cec5SDimitry Andrictemplate <class _Ep> 18160b57cec5SDimitry Andric_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 18170b57cec5SDimitry Andricreverse_iterator<const _Ep*> rbegin(initializer_list<_Ep> __il) 18180b57cec5SDimitry Andric{ 18190b57cec5SDimitry Andric return reverse_iterator<const _Ep*>(__il.end()); 18200b57cec5SDimitry Andric} 18210b57cec5SDimitry Andric 18220b57cec5SDimitry Andrictemplate <class _Ep> 18230b57cec5SDimitry Andric_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 18240b57cec5SDimitry Andricreverse_iterator<const _Ep*> rend(initializer_list<_Ep> __il) 18250b57cec5SDimitry Andric{ 18260b57cec5SDimitry Andric return reverse_iterator<const _Ep*>(__il.begin()); 18270b57cec5SDimitry Andric} 18280b57cec5SDimitry Andric 18290b57cec5SDimitry Andrictemplate <class _Cp> 18300b57cec5SDimitry Andric_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 18310b57cec5SDimitry Andricauto cbegin(const _Cp& __c) -> decltype(_VSTD::begin(__c)) 18320b57cec5SDimitry Andric{ 18330b57cec5SDimitry Andric return _VSTD::begin(__c); 18340b57cec5SDimitry Andric} 18350b57cec5SDimitry Andric 18360b57cec5SDimitry Andrictemplate <class _Cp> 18370b57cec5SDimitry Andric_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 18380b57cec5SDimitry Andricauto cend(const _Cp& __c) -> decltype(_VSTD::end(__c)) 18390b57cec5SDimitry Andric{ 18400b57cec5SDimitry Andric return _VSTD::end(__c); 18410b57cec5SDimitry Andric} 18420b57cec5SDimitry Andric 18430b57cec5SDimitry Andrictemplate <class _Cp> 18440b57cec5SDimitry Andric_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 18450b57cec5SDimitry Andricauto rbegin(_Cp& __c) -> decltype(__c.rbegin()) 18460b57cec5SDimitry Andric{ 18470b57cec5SDimitry Andric return __c.rbegin(); 18480b57cec5SDimitry Andric} 18490b57cec5SDimitry Andric 18500b57cec5SDimitry Andrictemplate <class _Cp> 18510b57cec5SDimitry Andric_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 18520b57cec5SDimitry Andricauto rbegin(const _Cp& __c) -> decltype(__c.rbegin()) 18530b57cec5SDimitry Andric{ 18540b57cec5SDimitry Andric return __c.rbegin(); 18550b57cec5SDimitry Andric} 18560b57cec5SDimitry Andric 18570b57cec5SDimitry Andrictemplate <class _Cp> 18580b57cec5SDimitry Andric_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 18590b57cec5SDimitry Andricauto rend(_Cp& __c) -> decltype(__c.rend()) 18600b57cec5SDimitry Andric{ 18610b57cec5SDimitry Andric return __c.rend(); 18620b57cec5SDimitry Andric} 18630b57cec5SDimitry Andric 18640b57cec5SDimitry Andrictemplate <class _Cp> 18650b57cec5SDimitry Andric_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 18660b57cec5SDimitry Andricauto rend(const _Cp& __c) -> decltype(__c.rend()) 18670b57cec5SDimitry Andric{ 18680b57cec5SDimitry Andric return __c.rend(); 18690b57cec5SDimitry Andric} 18700b57cec5SDimitry Andric 18710b57cec5SDimitry Andrictemplate <class _Cp> 18720b57cec5SDimitry Andric_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 18730b57cec5SDimitry Andricauto crbegin(const _Cp& __c) -> decltype(_VSTD::rbegin(__c)) 18740b57cec5SDimitry Andric{ 18750b57cec5SDimitry Andric return _VSTD::rbegin(__c); 18760b57cec5SDimitry Andric} 18770b57cec5SDimitry Andric 18780b57cec5SDimitry Andrictemplate <class _Cp> 18790b57cec5SDimitry Andric_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 18800b57cec5SDimitry Andricauto crend(const _Cp& __c) -> decltype(_VSTD::rend(__c)) 18810b57cec5SDimitry Andric{ 18820b57cec5SDimitry Andric return _VSTD::rend(__c); 18830b57cec5SDimitry Andric} 18840b57cec5SDimitry Andric 18850b57cec5SDimitry Andric#endif 18860b57cec5SDimitry Andric 18870b57cec5SDimitry Andric 18880b57cec5SDimitry Andric#else // defined(_LIBCPP_CXX03_LANG) 18890b57cec5SDimitry Andric 18900b57cec5SDimitry Andrictemplate <class _Cp> 18910b57cec5SDimitry Andric_LIBCPP_INLINE_VISIBILITY 18920b57cec5SDimitry Andrictypename _Cp::iterator 18930b57cec5SDimitry Andricbegin(_Cp& __c) 18940b57cec5SDimitry Andric{ 18950b57cec5SDimitry Andric return __c.begin(); 18960b57cec5SDimitry Andric} 18970b57cec5SDimitry Andric 18980b57cec5SDimitry Andrictemplate <class _Cp> 18990b57cec5SDimitry Andric_LIBCPP_INLINE_VISIBILITY 19000b57cec5SDimitry Andrictypename _Cp::const_iterator 19010b57cec5SDimitry Andricbegin(const _Cp& __c) 19020b57cec5SDimitry Andric{ 19030b57cec5SDimitry Andric return __c.begin(); 19040b57cec5SDimitry Andric} 19050b57cec5SDimitry Andric 19060b57cec5SDimitry Andrictemplate <class _Cp> 19070b57cec5SDimitry Andric_LIBCPP_INLINE_VISIBILITY 19080b57cec5SDimitry Andrictypename _Cp::iterator 19090b57cec5SDimitry Andricend(_Cp& __c) 19100b57cec5SDimitry Andric{ 19110b57cec5SDimitry Andric return __c.end(); 19120b57cec5SDimitry Andric} 19130b57cec5SDimitry Andric 19140b57cec5SDimitry Andrictemplate <class _Cp> 19150b57cec5SDimitry Andric_LIBCPP_INLINE_VISIBILITY 19160b57cec5SDimitry Andrictypename _Cp::const_iterator 19170b57cec5SDimitry Andricend(const _Cp& __c) 19180b57cec5SDimitry Andric{ 19190b57cec5SDimitry Andric return __c.end(); 19200b57cec5SDimitry Andric} 19210b57cec5SDimitry Andric 19220b57cec5SDimitry Andric#endif // !defined(_LIBCPP_CXX03_LANG) 19230b57cec5SDimitry Andric 19240b57cec5SDimitry Andric#if _LIBCPP_STD_VER > 14 19250b57cec5SDimitry Andric 19260b57cec5SDimitry Andric// #if _LIBCPP_STD_VER > 11 19270b57cec5SDimitry Andric// template <> 19280b57cec5SDimitry Andric// struct _LIBCPP_TEMPLATE_VIS plus<void> 19290b57cec5SDimitry Andric// { 19300b57cec5SDimitry Andric// template <class _T1, class _T2> 19310b57cec5SDimitry Andric// _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY 19320b57cec5SDimitry Andric// auto operator()(_T1&& __t, _T2&& __u) const 19330b57cec5SDimitry Andric// _NOEXCEPT_(noexcept(_VSTD::forward<_T1>(__t) + _VSTD::forward<_T2>(__u))) 19340b57cec5SDimitry Andric// -> decltype (_VSTD::forward<_T1>(__t) + _VSTD::forward<_T2>(__u)) 19350b57cec5SDimitry Andric// { return _VSTD::forward<_T1>(__t) + _VSTD::forward<_T2>(__u); } 19360b57cec5SDimitry Andric// typedef void is_transparent; 19370b57cec5SDimitry Andric// }; 19380b57cec5SDimitry Andric// #endif 19390b57cec5SDimitry Andric 19400b57cec5SDimitry Andrictemplate <class _Cont> 19410b57cec5SDimitry Andric_LIBCPP_INLINE_VISIBILITY 19420b57cec5SDimitry Andricconstexpr auto size(const _Cont& __c) 19430b57cec5SDimitry Andric_NOEXCEPT_(noexcept(__c.size())) 19440b57cec5SDimitry Andric-> decltype (__c.size()) 19450b57cec5SDimitry Andric{ return __c.size(); } 19460b57cec5SDimitry Andric 19470b57cec5SDimitry Andrictemplate <class _Tp, size_t _Sz> 19480b57cec5SDimitry Andric_LIBCPP_INLINE_VISIBILITY 19490b57cec5SDimitry Andricconstexpr size_t size(const _Tp (&)[_Sz]) noexcept { return _Sz; } 19500b57cec5SDimitry Andric 19510b57cec5SDimitry Andric#if _LIBCPP_STD_VER > 17 19520b57cec5SDimitry Andrictemplate <class _Cont> 19530b57cec5SDimitry Andric_LIBCPP_INLINE_VISIBILITY 19540b57cec5SDimitry Andricconstexpr auto ssize(const _Cont& __c) 19550b57cec5SDimitry Andric_NOEXCEPT_(noexcept(static_cast<common_type_t<ptrdiff_t, make_signed_t<decltype(__c.size())>>>(__c.size()))) 19560b57cec5SDimitry Andric-> common_type_t<ptrdiff_t, make_signed_t<decltype(__c.size())>> 19570b57cec5SDimitry Andric{ return static_cast<common_type_t<ptrdiff_t, make_signed_t<decltype(__c.size())>>>(__c.size()); } 19580b57cec5SDimitry Andric 19590b57cec5SDimitry Andrictemplate <class _Tp, ptrdiff_t _Sz> 19600b57cec5SDimitry Andric_LIBCPP_INLINE_VISIBILITY 19610b57cec5SDimitry Andricconstexpr ptrdiff_t ssize(const _Tp (&)[_Sz]) noexcept { return _Sz; } 19620b57cec5SDimitry Andric#endif 19630b57cec5SDimitry Andric 19640b57cec5SDimitry Andrictemplate <class _Cont> 19650b57cec5SDimitry Andric_LIBCPP_NODISCARD_AFTER_CXX17 _LIBCPP_INLINE_VISIBILITY 19660b57cec5SDimitry Andricconstexpr auto empty(const _Cont& __c) 19670b57cec5SDimitry Andric_NOEXCEPT_(noexcept(__c.empty())) 19680b57cec5SDimitry Andric-> decltype (__c.empty()) 19690b57cec5SDimitry Andric{ return __c.empty(); } 19700b57cec5SDimitry Andric 19710b57cec5SDimitry Andrictemplate <class _Tp, size_t _Sz> 19720b57cec5SDimitry Andric_LIBCPP_NODISCARD_AFTER_CXX17 _LIBCPP_INLINE_VISIBILITY 19730b57cec5SDimitry Andricconstexpr bool empty(const _Tp (&)[_Sz]) noexcept { return false; } 19740b57cec5SDimitry Andric 19750b57cec5SDimitry Andrictemplate <class _Ep> 19760b57cec5SDimitry Andric_LIBCPP_NODISCARD_AFTER_CXX17 _LIBCPP_INLINE_VISIBILITY 19770b57cec5SDimitry Andricconstexpr bool empty(initializer_list<_Ep> __il) noexcept { return __il.size() == 0; } 19780b57cec5SDimitry Andric 19790b57cec5SDimitry Andrictemplate <class _Cont> constexpr 19800b57cec5SDimitry Andric_LIBCPP_INLINE_VISIBILITY 19810b57cec5SDimitry Andricauto data(_Cont& __c) 19820b57cec5SDimitry Andric_NOEXCEPT_(noexcept(__c.data())) 19830b57cec5SDimitry Andric-> decltype (__c.data()) 19840b57cec5SDimitry Andric{ return __c.data(); } 19850b57cec5SDimitry Andric 19860b57cec5SDimitry Andrictemplate <class _Cont> constexpr 19870b57cec5SDimitry Andric_LIBCPP_INLINE_VISIBILITY 19880b57cec5SDimitry Andricauto data(const _Cont& __c) 19890b57cec5SDimitry Andric_NOEXCEPT_(noexcept(__c.data())) 19900b57cec5SDimitry Andric-> decltype (__c.data()) 19910b57cec5SDimitry Andric{ return __c.data(); } 19920b57cec5SDimitry Andric 19930b57cec5SDimitry Andrictemplate <class _Tp, size_t _Sz> 19940b57cec5SDimitry Andric_LIBCPP_INLINE_VISIBILITY 19950b57cec5SDimitry Andricconstexpr _Tp* data(_Tp (&__array)[_Sz]) noexcept { return __array; } 19960b57cec5SDimitry Andric 19970b57cec5SDimitry Andrictemplate <class _Ep> 19980b57cec5SDimitry Andric_LIBCPP_INLINE_VISIBILITY 19990b57cec5SDimitry Andricconstexpr const _Ep* data(initializer_list<_Ep> __il) noexcept { return __il.begin(); } 20000b57cec5SDimitry Andric#endif 20010b57cec5SDimitry Andric 20020b57cec5SDimitry Andric 20030b57cec5SDimitry Andric_LIBCPP_END_NAMESPACE_STD 20040b57cec5SDimitry Andric 20050b57cec5SDimitry Andric#endif // _LIBCPP_ITERATOR 2006