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