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