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