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 | |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 92 | reverse_iterator(); |
| 93 | explicit reverse_iterator(Iterator x); |
| 94 | template <class U> reverse_iterator(const reverse_iterator<U>& u); |
| 95 | Iterator base() const; |
| 96 | reference operator*() const; |
| 97 | pointer operator->() const; |
| 98 | reverse_iterator& operator++(); |
| 99 | reverse_iterator operator++(int); |
| 100 | reverse_iterator& operator--(); |
| 101 | reverse_iterator operator--(int); |
| 102 | reverse_iterator operator+ (difference_type n) const; |
| 103 | reverse_iterator& operator+=(difference_type n); |
| 104 | reverse_iterator operator- (difference_type n) const; |
| 105 | reverse_iterator& operator-=(difference_type n); |
| 106 | reference operator[](difference_type n) const; |
| 107 | }; |
| 108 | |
| 109 | template <class Iterator1, class Iterator2> |
| 110 | bool |
| 111 | operator==(const reverse_iterator<Iterator1>& x, const reverse_iterator<Iterator2>& y); |
| 112 | |
| 113 | template <class Iterator1, class Iterator2> |
| 114 | bool |
| 115 | operator<(const reverse_iterator<Iterator1>& x, const reverse_iterator<Iterator2>& y); |
| 116 | |
| 117 | template <class Iterator1, class Iterator2> |
| 118 | bool |
| 119 | operator!=(const reverse_iterator<Iterator1>& x, const reverse_iterator<Iterator2>& y); |
| 120 | |
| 121 | template <class Iterator1, class Iterator2> |
| 122 | bool |
| 123 | operator>(const reverse_iterator<Iterator1>& x, const reverse_iterator<Iterator2>& y); |
| 124 | |
| 125 | template <class Iterator1, class Iterator2> |
| 126 | bool |
| 127 | operator>=(const reverse_iterator<Iterator1>& x, const reverse_iterator<Iterator2>& y); |
| 128 | |
| 129 | template <class Iterator1, class Iterator2> |
| 130 | bool |
| 131 | operator<=(const reverse_iterator<Iterator1>& x, const reverse_iterator<Iterator2>& y); |
| 132 | |
| 133 | template <class Iterator1, class Iterator2> |
| 134 | typename reverse_iterator<Iterator1>::difference_type |
| 135 | operator-(const reverse_iterator<Iterator1>& x, const reverse_iterator<Iterator2>& y); |
| 136 | |
| 137 | template <class Iterator> |
| 138 | reverse_iterator<Iterator> |
| 139 | operator+(typename reverse_iterator<Iterator>::difference_type n, const reverse_iterator<Iterator>& x); |
| 140 | |
| 141 | template <class Container> |
| 142 | class back_insert_iterator |
| 143 | { |
| 144 | protected: |
| 145 | Container* container; |
| 146 | public: |
| 147 | typedef Container container_type; |
| 148 | typedef void value_type; |
| 149 | typedef void difference_type; |
| 150 | typedef back_insert_iterator<Cont>& reference; |
| 151 | typedef void pointer; |
| 152 | |
| 153 | explicit back_insert_iterator(Container& x); |
Howard Hinnant | 45f5717 | 2010-09-14 20:26:27 +0000 | [diff] [blame] | 154 | back_insert_iterator& operator=(const typename Container::value_type& value); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 155 | back_insert_iterator& operator*(); |
| 156 | back_insert_iterator& operator++(); |
| 157 | back_insert_iterator operator++(int); |
| 158 | }; |
| 159 | |
| 160 | template <class Container> back_insert_iterator<Container> back_inserter(Container& x); |
| 161 | |
| 162 | template <class Container> |
| 163 | class front_insert_iterator |
| 164 | { |
| 165 | protected: |
| 166 | Container* container; |
| 167 | public: |
| 168 | typedef Container container_type; |
| 169 | typedef void value_type; |
| 170 | typedef void difference_type; |
| 171 | typedef front_insert_iterator<Cont>& reference; |
| 172 | typedef void pointer; |
| 173 | |
| 174 | explicit front_insert_iterator(Container& x); |
Howard Hinnant | 45f5717 | 2010-09-14 20:26:27 +0000 | [diff] [blame] | 175 | front_insert_iterator& operator=(const typename Container::value_type& value); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 176 | front_insert_iterator& operator*(); |
| 177 | front_insert_iterator& operator++(); |
| 178 | front_insert_iterator operator++(int); |
| 179 | }; |
| 180 | |
| 181 | template <class Container> front_insert_iterator<Container> front_inserter(Container& x); |
| 182 | |
| 183 | template <class Container> |
| 184 | class insert_iterator |
| 185 | { |
| 186 | protected: |
| 187 | Container* container; |
| 188 | typename Container::iterator iter; |
| 189 | public: |
| 190 | typedef Container container_type; |
| 191 | typedef void value_type; |
| 192 | typedef void difference_type; |
| 193 | typedef insert_iterator<Cont>& reference; |
| 194 | typedef void pointer; |
| 195 | |
| 196 | insert_iterator(Container& x, typename Container::iterator i); |
Howard Hinnant | 45f5717 | 2010-09-14 20:26:27 +0000 | [diff] [blame] | 197 | insert_iterator& operator=(const typename Container::value_type& value); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 198 | insert_iterator& operator*(); |
| 199 | insert_iterator& operator++(); |
| 200 | insert_iterator& operator++(int); |
| 201 | }; |
| 202 | |
| 203 | template <class Container, class Iterator> |
| 204 | insert_iterator<Container> inserter(Container& x, Iterator i); |
| 205 | |
| 206 | template <class T, class charT = char, class traits = char_traits<charT>, class Distance = ptrdiff_t> |
| 207 | class istream_iterator |
| 208 | : public iterator<input_iterator_tag, T, Distance, const T*, const T&> |
| 209 | { |
| 210 | public: |
| 211 | typedef charT char_type; |
| 212 | typedef traits traits_type; |
| 213 | typedef basic_istream<charT,traits> istream_type; |
| 214 | |
| 215 | istream_iterator(); |
| 216 | istream_iterator(istream_type& s); |
| 217 | istream_iterator(const istream_iterator& x); |
| 218 | ~istream_iterator(); |
| 219 | |
| 220 | const T& operator*() const; |
| 221 | const T* operator->() const; |
| 222 | istream_iterator& operator++(); |
| 223 | istream_iterator operator++(int); |
| 224 | }; |
| 225 | |
| 226 | template <class T, class charT, class traits, class Distance> |
| 227 | bool operator==(const istream_iterator<T,charT,traits,Distance>& x, |
| 228 | const istream_iterator<T,charT,traits,Distance>& y); |
| 229 | template <class T, class charT, class traits, class Distance> |
| 230 | bool operator!=(const istream_iterator<T,charT,traits,Distance>& x, |
| 231 | const istream_iterator<T,charT,traits,Distance>& y); |
| 232 | |
| 233 | template <class T, class charT = char, class traits = char_traits<charT> > |
| 234 | class ostream_iterator |
| 235 | : public iterator<output_iterator_tag, void, void, void ,void> |
| 236 | { |
| 237 | public: |
| 238 | typedef charT char_type; |
| 239 | typedef traits traits_type; |
| 240 | typedef basic_ostream<charT,traits> ostream_type; |
| 241 | |
| 242 | ostream_iterator(ostream_type& s); |
| 243 | ostream_iterator(ostream_type& s, const charT* delimiter); |
| 244 | ostream_iterator(const ostream_iterator& x); |
| 245 | ~ostream_iterator(); |
| 246 | ostream_iterator& operator=(const T& value); |
| 247 | |
| 248 | ostream_iterator& operator*(); |
| 249 | ostream_iterator& operator++(); |
| 250 | ostream_iterator& operator++(int); |
| 251 | }; |
| 252 | |
| 253 | template<class charT, class traits = char_traits<charT> > |
| 254 | class istreambuf_iterator |
| 255 | : public iterator<input_iterator_tag, charT, |
| 256 | typename traits::off_type, unspecified, |
| 257 | charT> |
| 258 | { |
| 259 | public: |
| 260 | typedef charT char_type; |
| 261 | typedef traits traits_type; |
| 262 | typedef typename traits::int_type int_type; |
| 263 | typedef basic_streambuf<charT,traits> streambuf_type; |
| 264 | typedef basic_istream<charT,traits> istream_type; |
| 265 | |
Howard Hinnant | d06a640 | 2012-07-20 19:36:34 +0000 | [diff] [blame] | 266 | istreambuf_iterator() noexcept; |
| 267 | istreambuf_iterator(istream_type& s) noexcept; |
| 268 | istreambuf_iterator(streambuf_type* s) noexcept; |
| 269 | istreambuf_iterator(a-private-type) noexcept; |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 270 | |
| 271 | charT operator*() const; |
| 272 | pointer operator->() const; |
| 273 | istreambuf_iterator& operator++(); |
| 274 | a-private-type operator++(int); |
| 275 | |
| 276 | bool equal(const istreambuf_iterator& b) const; |
| 277 | }; |
| 278 | |
| 279 | template <class charT, class traits> |
| 280 | bool operator==(const istreambuf_iterator<charT,traits>& a, |
| 281 | const istreambuf_iterator<charT,traits>& b); |
| 282 | template <class charT, class traits> |
| 283 | bool operator!=(const istreambuf_iterator<charT,traits>& a, |
| 284 | const istreambuf_iterator<charT,traits>& b); |
| 285 | |
| 286 | template <class charT, class traits = char_traits<charT> > |
| 287 | class ostreambuf_iterator |
| 288 | : public iterator<output_iterator_tag, void, void, void, void> |
| 289 | { |
| 290 | public: |
| 291 | typedef charT char_type; |
| 292 | typedef traits traits_type; |
| 293 | typedef basic_streambuf<charT,traits> streambuf_type; |
| 294 | typedef basic_ostream<charT,traits> ostream_type; |
| 295 | |
Howard Hinnant | d06a640 | 2012-07-20 19:36:34 +0000 | [diff] [blame] | 296 | ostreambuf_iterator(ostream_type& s) noexcept; |
| 297 | ostreambuf_iterator(streambuf_type* s) noexcept; |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 298 | ostreambuf_iterator& operator=(charT c); |
| 299 | ostreambuf_iterator& operator*(); |
| 300 | ostreambuf_iterator& operator++(); |
| 301 | ostreambuf_iterator& operator++(int); |
Howard Hinnant | d06a640 | 2012-07-20 19:36:34 +0000 | [diff] [blame] | 302 | bool failed() const noexcept; |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 303 | }; |
| 304 | |
| 305 | template <class C> auto begin(C& c) -> decltype(c.begin()); |
| 306 | template <class C> auto begin(const C& c) -> decltype(c.begin()); |
| 307 | template <class C> auto end(C& c) -> decltype(c.end()); |
| 308 | template <class C> auto end(const C& c) -> decltype(c.end()); |
| 309 | template <class T, size_t N> T* begin(T (&array)[N]); |
| 310 | template <class T, size_t N> T* end(T (&array)[N]); |
| 311 | |
| 312 | } // std |
| 313 | |
| 314 | */ |
| 315 | |
| 316 | #include <__config> |
| 317 | #include <type_traits> |
| 318 | #include <cstddef> |
| 319 | #include <iosfwd> |
Marshall Clow | dece7fe | 2013-03-18 17:45:34 +0000 | [diff] [blame] | 320 | #ifdef __APPLE__ |
Howard Hinnant | 537b2fa | 2012-11-14 21:17:15 +0000 | [diff] [blame] | 321 | #include <Availability.h> |
| 322 | #endif |
| 323 | |
Howard Hinnant | 5e57142 | 2013-08-23 20:10:18 +0000 | [diff] [blame] | 324 | #ifdef _LIBCPP_DEBUG |
Howard Hinnant | 8b00e6c | 2013-08-02 00:26:35 +0000 | [diff] [blame] | 325 | # include <__debug> |
| 326 | #else |
| 327 | # define _LIBCPP_ASSERT(x, m) ((void)0) |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 328 | #endif |
| 329 | |
Howard Hinnant | 08e1747 | 2011-10-17 20:05:10 +0000 | [diff] [blame] | 330 | #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 331 | #pragma GCC system_header |
Howard Hinnant | 08e1747 | 2011-10-17 20:05:10 +0000 | [diff] [blame] | 332 | #endif |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 333 | |
| 334 | _LIBCPP_BEGIN_NAMESPACE_STD |
| 335 | |
Howard Hinnant | 0f678bd | 2013-08-12 18:38:34 +0000 | [diff] [blame] | 336 | struct _LIBCPP_TYPE_VIS_ONLY input_iterator_tag {}; |
| 337 | struct _LIBCPP_TYPE_VIS_ONLY output_iterator_tag {}; |
| 338 | struct _LIBCPP_TYPE_VIS_ONLY forward_iterator_tag : public input_iterator_tag {}; |
| 339 | struct _LIBCPP_TYPE_VIS_ONLY bidirectional_iterator_tag : public forward_iterator_tag {}; |
| 340 | 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] | 341 | |
| 342 | template <class _Tp> |
| 343 | struct __has_iterator_category |
| 344 | { |
| 345 | private: |
Howard Hinnant | 9c0df14 | 2012-10-30 19:06:59 +0000 | [diff] [blame] | 346 | struct __two {char __lx; char __lxx;}; |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 347 | template <class _Up> static __two __test(...); |
| 348 | template <class _Up> static char __test(typename _Up::iterator_category* = 0); |
| 349 | public: |
| 350 | static const bool value = sizeof(__test<_Tp>(0)) == 1; |
| 351 | }; |
| 352 | |
| 353 | template <class _Iter, bool> struct ____iterator_traits {}; |
| 354 | |
| 355 | template <class _Iter> |
| 356 | struct ____iterator_traits<_Iter, true> |
| 357 | { |
| 358 | typedef typename _Iter::difference_type difference_type; |
| 359 | typedef typename _Iter::value_type value_type; |
| 360 | typedef typename _Iter::pointer pointer; |
| 361 | typedef typename _Iter::reference reference; |
| 362 | typedef typename _Iter::iterator_category iterator_category; |
| 363 | }; |
| 364 | |
| 365 | template <class _Iter, bool> struct __iterator_traits {}; |
| 366 | |
| 367 | template <class _Iter> |
| 368 | struct __iterator_traits<_Iter, true> |
| 369 | : ____iterator_traits |
| 370 | < |
| 371 | _Iter, |
| 372 | is_convertible<typename _Iter::iterator_category, input_iterator_tag>::value || |
| 373 | is_convertible<typename _Iter::iterator_category, output_iterator_tag>::value |
| 374 | > |
| 375 | {}; |
| 376 | |
| 377 | // iterator_traits<Iterator> will only have the nested types if Iterator::iterator_category |
| 378 | // exists. Else iterator_traits<Iterator> will be an empty class. This is a |
| 379 | // conforming extension which allows some programs to compile and behave as |
| 380 | // the client expects instead of failing at compile time. |
| 381 | |
| 382 | template <class _Iter> |
Howard Hinnant | 0f678bd | 2013-08-12 18:38:34 +0000 | [diff] [blame] | 383 | struct _LIBCPP_TYPE_VIS_ONLY iterator_traits |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 384 | : __iterator_traits<_Iter, __has_iterator_category<_Iter>::value> {}; |
| 385 | |
| 386 | template<class _Tp> |
Howard Hinnant | 0f678bd | 2013-08-12 18:38:34 +0000 | [diff] [blame] | 387 | struct _LIBCPP_TYPE_VIS_ONLY iterator_traits<_Tp*> |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 388 | { |
| 389 | typedef ptrdiff_t difference_type; |
| 390 | typedef typename remove_const<_Tp>::type value_type; |
| 391 | typedef _Tp* pointer; |
| 392 | typedef _Tp& reference; |
| 393 | typedef random_access_iterator_tag iterator_category; |
| 394 | }; |
| 395 | |
| 396 | template <class _Tp, class _Up, bool = __has_iterator_category<iterator_traits<_Tp> >::value> |
| 397 | struct __has_iterator_category_convertible_to |
| 398 | : public integral_constant<bool, is_convertible<typename iterator_traits<_Tp>::iterator_category, _Up>::value> |
| 399 | {}; |
| 400 | |
| 401 | template <class _Tp, class _Up> |
| 402 | struct __has_iterator_category_convertible_to<_Tp, _Up, false> : public false_type {}; |
| 403 | |
| 404 | template <class _Tp> |
| 405 | struct __is_input_iterator : public __has_iterator_category_convertible_to<_Tp, input_iterator_tag> {}; |
| 406 | |
| 407 | template <class _Tp> |
| 408 | struct __is_forward_iterator : public __has_iterator_category_convertible_to<_Tp, forward_iterator_tag> {}; |
| 409 | |
| 410 | template <class _Tp> |
| 411 | struct __is_bidirectional_iterator : public __has_iterator_category_convertible_to<_Tp, bidirectional_iterator_tag> {}; |
| 412 | |
| 413 | template <class _Tp> |
| 414 | struct __is_random_access_iterator : public __has_iterator_category_convertible_to<_Tp, random_access_iterator_tag> {}; |
| 415 | |
| 416 | template<class _Category, class _Tp, class _Distance = ptrdiff_t, |
| 417 | class _Pointer = _Tp*, class _Reference = _Tp&> |
Howard Hinnant | 0f678bd | 2013-08-12 18:38:34 +0000 | [diff] [blame] | 418 | struct _LIBCPP_TYPE_VIS_ONLY iterator |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 419 | { |
| 420 | typedef _Tp value_type; |
| 421 | typedef _Distance difference_type; |
| 422 | typedef _Pointer pointer; |
| 423 | typedef _Reference reference; |
| 424 | typedef _Category iterator_category; |
| 425 | }; |
| 426 | |
| 427 | template <class _InputIter> |
| 428 | inline _LIBCPP_INLINE_VISIBILITY |
| 429 | void __advance(_InputIter& __i, |
| 430 | typename iterator_traits<_InputIter>::difference_type __n, input_iterator_tag) |
| 431 | { |
| 432 | for (; __n > 0; --__n) |
| 433 | ++__i; |
| 434 | } |
| 435 | |
| 436 | template <class _BiDirIter> |
| 437 | inline _LIBCPP_INLINE_VISIBILITY |
| 438 | void __advance(_BiDirIter& __i, |
| 439 | typename iterator_traits<_BiDirIter>::difference_type __n, bidirectional_iterator_tag) |
| 440 | { |
| 441 | if (__n >= 0) |
| 442 | for (; __n > 0; --__n) |
| 443 | ++__i; |
| 444 | else |
| 445 | for (; __n < 0; ++__n) |
| 446 | --__i; |
| 447 | } |
| 448 | |
| 449 | template <class _RandIter> |
| 450 | inline _LIBCPP_INLINE_VISIBILITY |
| 451 | void __advance(_RandIter& __i, |
| 452 | typename iterator_traits<_RandIter>::difference_type __n, random_access_iterator_tag) |
| 453 | { |
| 454 | __i += __n; |
| 455 | } |
| 456 | |
| 457 | template <class _InputIter> |
| 458 | inline _LIBCPP_INLINE_VISIBILITY |
| 459 | void advance(_InputIter& __i, |
| 460 | typename iterator_traits<_InputIter>::difference_type __n) |
| 461 | { |
| 462 | __advance(__i, __n, typename iterator_traits<_InputIter>::iterator_category()); |
| 463 | } |
| 464 | |
| 465 | template <class _InputIter> |
| 466 | inline _LIBCPP_INLINE_VISIBILITY |
| 467 | typename iterator_traits<_InputIter>::difference_type |
| 468 | __distance(_InputIter __first, _InputIter __last, input_iterator_tag) |
| 469 | { |
| 470 | typename iterator_traits<_InputIter>::difference_type __r(0); |
| 471 | for (; __first != __last; ++__first) |
| 472 | ++__r; |
| 473 | return __r; |
| 474 | } |
| 475 | |
| 476 | template <class _RandIter> |
| 477 | inline _LIBCPP_INLINE_VISIBILITY |
| 478 | typename iterator_traits<_RandIter>::difference_type |
| 479 | __distance(_RandIter __first, _RandIter __last, random_access_iterator_tag) |
| 480 | { |
| 481 | return __last - __first; |
| 482 | } |
| 483 | |
| 484 | template <class _InputIter> |
| 485 | inline _LIBCPP_INLINE_VISIBILITY |
| 486 | typename iterator_traits<_InputIter>::difference_type |
| 487 | distance(_InputIter __first, _InputIter __last) |
| 488 | { |
| 489 | return __distance(__first, __last, typename iterator_traits<_InputIter>::iterator_category()); |
| 490 | } |
| 491 | |
| 492 | template <class _ForwardIter> |
Howard Hinnant | 8289481 | 2010-09-22 16:48:34 +0000 | [diff] [blame] | 493 | inline _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 494 | _ForwardIter |
| 495 | next(_ForwardIter __x, |
| 496 | typename iterator_traits<_ForwardIter>::difference_type __n = 1, |
| 497 | typename enable_if<__is_forward_iterator<_ForwardIter>::value>::type* = 0) |
| 498 | { |
Howard Hinnant | 0949eed | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 499 | _VSTD::advance(__x, __n); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 500 | return __x; |
| 501 | } |
| 502 | |
| 503 | template <class _BidiretionalIter> |
Howard Hinnant | 8289481 | 2010-09-22 16:48:34 +0000 | [diff] [blame] | 504 | inline _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 505 | _BidiretionalIter |
| 506 | prev(_BidiretionalIter __x, |
| 507 | typename iterator_traits<_BidiretionalIter>::difference_type __n = 1, |
| 508 | typename enable_if<__is_bidirectional_iterator<_BidiretionalIter>::value>::type* = 0) |
| 509 | { |
Howard Hinnant | 0949eed | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 510 | _VSTD::advance(__x, -__n); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 511 | return __x; |
| 512 | } |
| 513 | |
| 514 | template <class _Iter> |
Howard Hinnant | 0f678bd | 2013-08-12 18:38:34 +0000 | [diff] [blame] | 515 | class _LIBCPP_TYPE_VIS_ONLY reverse_iterator |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 516 | : public iterator<typename iterator_traits<_Iter>::iterator_category, |
| 517 | typename iterator_traits<_Iter>::value_type, |
| 518 | typename iterator_traits<_Iter>::difference_type, |
| 519 | typename iterator_traits<_Iter>::pointer, |
| 520 | typename iterator_traits<_Iter>::reference> |
| 521 | { |
| 522 | private: |
| 523 | mutable _Iter __t; |
| 524 | protected: |
| 525 | _Iter current; |
| 526 | public: |
| 527 | typedef _Iter iterator_type; |
| 528 | typedef typename iterator_traits<_Iter>::difference_type difference_type; |
| 529 | typedef typename iterator_traits<_Iter>::reference reference; |
| 530 | typedef typename iterator_traits<_Iter>::pointer pointer; |
Howard Hinnant | 324bb03 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 531 | |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 532 | _LIBCPP_INLINE_VISIBILITY reverse_iterator() : current() {} |
| 533 | _LIBCPP_INLINE_VISIBILITY explicit reverse_iterator(_Iter __x) : __t(__x), current(__x) {} |
| 534 | template <class _Up> _LIBCPP_INLINE_VISIBILITY reverse_iterator(const reverse_iterator<_Up>& __u) |
| 535 | : __t(__u.base()), current(__u.base()) {} |
| 536 | _LIBCPP_INLINE_VISIBILITY _Iter base() const {return current;} |
| 537 | _LIBCPP_INLINE_VISIBILITY reference operator*() const {__t = current; return *--__t;} |
| 538 | _LIBCPP_INLINE_VISIBILITY pointer operator->() const {return &(operator*());} |
| 539 | _LIBCPP_INLINE_VISIBILITY reverse_iterator& operator++() {--current; return *this;} |
| 540 | _LIBCPP_INLINE_VISIBILITY reverse_iterator operator++(int) |
| 541 | {reverse_iterator __tmp(*this); --current; return __tmp;} |
| 542 | _LIBCPP_INLINE_VISIBILITY reverse_iterator& operator--() {++current; return *this;} |
| 543 | _LIBCPP_INLINE_VISIBILITY reverse_iterator operator--(int) |
| 544 | {reverse_iterator __tmp(*this); ++current; return __tmp;} |
| 545 | _LIBCPP_INLINE_VISIBILITY reverse_iterator operator+ (difference_type __n) const |
| 546 | {return reverse_iterator(current - __n);} |
| 547 | _LIBCPP_INLINE_VISIBILITY reverse_iterator& operator+=(difference_type __n) |
| 548 | {current -= __n; return *this;} |
| 549 | _LIBCPP_INLINE_VISIBILITY reverse_iterator operator- (difference_type __n) const |
| 550 | {return reverse_iterator(current + __n);} |
| 551 | _LIBCPP_INLINE_VISIBILITY reverse_iterator& operator-=(difference_type __n) |
| 552 | {current += __n; return *this;} |
| 553 | _LIBCPP_INLINE_VISIBILITY reference operator[](difference_type __n) const |
| 554 | {return current[-__n-1];} |
| 555 | }; |
| 556 | |
| 557 | template <class _Iter1, class _Iter2> |
| 558 | inline _LIBCPP_INLINE_VISIBILITY |
| 559 | bool |
| 560 | operator==(const reverse_iterator<_Iter1>& __x, const reverse_iterator<_Iter2>& __y) |
| 561 | { |
| 562 | return __x.base() == __y.base(); |
| 563 | } |
| 564 | |
| 565 | template <class _Iter1, class _Iter2> |
| 566 | inline _LIBCPP_INLINE_VISIBILITY |
| 567 | bool |
| 568 | operator<(const reverse_iterator<_Iter1>& __x, const reverse_iterator<_Iter2>& __y) |
| 569 | { |
| 570 | return __x.base() > __y.base(); |
| 571 | } |
| 572 | |
| 573 | template <class _Iter1, class _Iter2> |
| 574 | inline _LIBCPP_INLINE_VISIBILITY |
| 575 | bool |
| 576 | operator!=(const reverse_iterator<_Iter1>& __x, const reverse_iterator<_Iter2>& __y) |
| 577 | { |
| 578 | return __x.base() != __y.base(); |
| 579 | } |
| 580 | |
| 581 | template <class _Iter1, class _Iter2> |
| 582 | inline _LIBCPP_INLINE_VISIBILITY |
| 583 | bool |
| 584 | operator>(const reverse_iterator<_Iter1>& __x, const reverse_iterator<_Iter2>& __y) |
| 585 | { |
| 586 | return __x.base() < __y.base(); |
| 587 | } |
| 588 | |
| 589 | template <class _Iter1, class _Iter2> |
| 590 | inline _LIBCPP_INLINE_VISIBILITY |
| 591 | bool |
| 592 | operator>=(const reverse_iterator<_Iter1>& __x, const reverse_iterator<_Iter2>& __y) |
| 593 | { |
| 594 | return __x.base() <= __y.base(); |
| 595 | } |
| 596 | |
| 597 | template <class _Iter1, class _Iter2> |
| 598 | inline _LIBCPP_INLINE_VISIBILITY |
| 599 | bool |
| 600 | operator<=(const reverse_iterator<_Iter1>& __x, const reverse_iterator<_Iter2>& __y) |
| 601 | { |
| 602 | return __x.base() >= __y.base(); |
| 603 | } |
| 604 | |
| 605 | template <class _Iter1, class _Iter2> |
| 606 | inline _LIBCPP_INLINE_VISIBILITY |
| 607 | typename reverse_iterator<_Iter1>::difference_type |
| 608 | operator-(const reverse_iterator<_Iter1>& __x, const reverse_iterator<_Iter2>& __y) |
| 609 | { |
| 610 | return __y.base() - __x.base(); |
| 611 | } |
| 612 | |
| 613 | template <class _Iter> |
| 614 | inline _LIBCPP_INLINE_VISIBILITY |
| 615 | reverse_iterator<_Iter> |
| 616 | operator+(typename reverse_iterator<_Iter>::difference_type __n, const reverse_iterator<_Iter>& __x) |
| 617 | { |
| 618 | return reverse_iterator<_Iter>(__x.base() - __n); |
| 619 | } |
| 620 | |
| 621 | template <class _Container> |
Howard Hinnant | 0f678bd | 2013-08-12 18:38:34 +0000 | [diff] [blame] | 622 | class _LIBCPP_TYPE_VIS_ONLY back_insert_iterator |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 623 | : public iterator<output_iterator_tag, |
| 624 | void, |
| 625 | void, |
| 626 | void, |
| 627 | back_insert_iterator<_Container>&> |
| 628 | { |
| 629 | protected: |
| 630 | _Container* container; |
| 631 | public: |
| 632 | typedef _Container container_type; |
| 633 | |
| 634 | _LIBCPP_INLINE_VISIBILITY explicit back_insert_iterator(_Container& __x) : container(&__x) {} |
Howard Hinnant | 78b6828 | 2011-10-22 20:59:45 +0000 | [diff] [blame] | 635 | _LIBCPP_INLINE_VISIBILITY back_insert_iterator& operator=(const typename _Container::value_type& __value_) |
| 636 | {container->push_back(__value_); return *this;} |
Howard Hinnant | 73d21a4 | 2010-09-04 23:28:19 +0000 | [diff] [blame] | 637 | #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES |
Howard Hinnant | 78b6828 | 2011-10-22 20:59:45 +0000 | [diff] [blame] | 638 | _LIBCPP_INLINE_VISIBILITY back_insert_iterator& operator=(typename _Container::value_type&& __value_) |
| 639 | {container->push_back(_VSTD::move(__value_)); return *this;} |
Howard Hinnant | 73d21a4 | 2010-09-04 23:28:19 +0000 | [diff] [blame] | 640 | #endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 641 | _LIBCPP_INLINE_VISIBILITY back_insert_iterator& operator*() {return *this;} |
| 642 | _LIBCPP_INLINE_VISIBILITY back_insert_iterator& operator++() {return *this;} |
| 643 | _LIBCPP_INLINE_VISIBILITY back_insert_iterator operator++(int) {return *this;} |
| 644 | }; |
| 645 | |
| 646 | template <class _Container> |
| 647 | inline _LIBCPP_INLINE_VISIBILITY |
| 648 | back_insert_iterator<_Container> |
| 649 | back_inserter(_Container& __x) |
| 650 | { |
| 651 | return back_insert_iterator<_Container>(__x); |
| 652 | } |
| 653 | |
| 654 | template <class _Container> |
Howard Hinnant | 0f678bd | 2013-08-12 18:38:34 +0000 | [diff] [blame] | 655 | class _LIBCPP_TYPE_VIS_ONLY front_insert_iterator |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 656 | : public iterator<output_iterator_tag, |
| 657 | void, |
| 658 | void, |
| 659 | void, |
| 660 | front_insert_iterator<_Container>&> |
| 661 | { |
| 662 | protected: |
| 663 | _Container* container; |
| 664 | public: |
| 665 | typedef _Container container_type; |
| 666 | |
| 667 | _LIBCPP_INLINE_VISIBILITY explicit front_insert_iterator(_Container& __x) : container(&__x) {} |
Howard Hinnant | 78b6828 | 2011-10-22 20:59:45 +0000 | [diff] [blame] | 668 | _LIBCPP_INLINE_VISIBILITY front_insert_iterator& operator=(const typename _Container::value_type& __value_) |
| 669 | {container->push_front(__value_); return *this;} |
Howard Hinnant | 73d21a4 | 2010-09-04 23:28:19 +0000 | [diff] [blame] | 670 | #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES |
Howard Hinnant | 78b6828 | 2011-10-22 20:59:45 +0000 | [diff] [blame] | 671 | _LIBCPP_INLINE_VISIBILITY front_insert_iterator& operator=(typename _Container::value_type&& __value_) |
| 672 | {container->push_front(_VSTD::move(__value_)); return *this;} |
Howard Hinnant | 73d21a4 | 2010-09-04 23:28:19 +0000 | [diff] [blame] | 673 | #endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 674 | _LIBCPP_INLINE_VISIBILITY front_insert_iterator& operator*() {return *this;} |
| 675 | _LIBCPP_INLINE_VISIBILITY front_insert_iterator& operator++() {return *this;} |
| 676 | _LIBCPP_INLINE_VISIBILITY front_insert_iterator operator++(int) {return *this;} |
| 677 | }; |
| 678 | |
| 679 | template <class _Container> |
| 680 | inline _LIBCPP_INLINE_VISIBILITY |
| 681 | front_insert_iterator<_Container> |
| 682 | front_inserter(_Container& __x) |
| 683 | { |
| 684 | return front_insert_iterator<_Container>(__x); |
| 685 | } |
| 686 | |
| 687 | template <class _Container> |
Howard Hinnant | 0f678bd | 2013-08-12 18:38:34 +0000 | [diff] [blame] | 688 | class _LIBCPP_TYPE_VIS_ONLY insert_iterator |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 689 | : public iterator<output_iterator_tag, |
| 690 | void, |
| 691 | void, |
| 692 | void, |
| 693 | insert_iterator<_Container>&> |
| 694 | { |
| 695 | protected: |
| 696 | _Container* container; |
| 697 | typename _Container::iterator iter; |
| 698 | public: |
| 699 | typedef _Container container_type; |
| 700 | |
| 701 | _LIBCPP_INLINE_VISIBILITY insert_iterator(_Container& __x, typename _Container::iterator __i) |
| 702 | : container(&__x), iter(__i) {} |
Howard Hinnant | 78b6828 | 2011-10-22 20:59:45 +0000 | [diff] [blame] | 703 | _LIBCPP_INLINE_VISIBILITY insert_iterator& operator=(const typename _Container::value_type& __value_) |
| 704 | {iter = container->insert(iter, __value_); ++iter; return *this;} |
Howard Hinnant | 73d21a4 | 2010-09-04 23:28:19 +0000 | [diff] [blame] | 705 | #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES |
Howard Hinnant | 78b6828 | 2011-10-22 20:59:45 +0000 | [diff] [blame] | 706 | _LIBCPP_INLINE_VISIBILITY insert_iterator& operator=(typename _Container::value_type&& __value_) |
| 707 | {iter = container->insert(iter, _VSTD::move(__value_)); ++iter; return *this;} |
Howard Hinnant | 73d21a4 | 2010-09-04 23:28:19 +0000 | [diff] [blame] | 708 | #endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 709 | _LIBCPP_INLINE_VISIBILITY insert_iterator& operator*() {return *this;} |
| 710 | _LIBCPP_INLINE_VISIBILITY insert_iterator& operator++() {return *this;} |
| 711 | _LIBCPP_INLINE_VISIBILITY insert_iterator& operator++(int) {return *this;} |
| 712 | }; |
| 713 | |
| 714 | template <class _Container> |
| 715 | inline _LIBCPP_INLINE_VISIBILITY |
| 716 | insert_iterator<_Container> |
| 717 | inserter(_Container& __x, typename _Container::iterator __i) |
| 718 | { |
| 719 | return insert_iterator<_Container>(__x, __i); |
| 720 | } |
| 721 | |
| 722 | template <class _Tp, class _CharT = char, |
| 723 | class _Traits = char_traits<_CharT>, class _Distance = ptrdiff_t> |
Howard Hinnant | 0f678bd | 2013-08-12 18:38:34 +0000 | [diff] [blame] | 724 | class _LIBCPP_TYPE_VIS_ONLY istream_iterator |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 725 | : public iterator<input_iterator_tag, _Tp, _Distance, const _Tp*, const _Tp&> |
| 726 | { |
| 727 | public: |
| 728 | typedef _CharT char_type; |
| 729 | typedef _Traits traits_type; |
| 730 | typedef basic_istream<_CharT,_Traits> istream_type; |
| 731 | private: |
| 732 | istream_type* __in_stream_; |
| 733 | _Tp __value_; |
| 734 | public: |
| 735 | _LIBCPP_INLINE_VISIBILITY istream_iterator() : __in_stream_(0) {} |
| 736 | _LIBCPP_INLINE_VISIBILITY istream_iterator(istream_type& __s) : __in_stream_(&__s) |
| 737 | { |
| 738 | if (!(*__in_stream_ >> __value_)) |
| 739 | __in_stream_ = 0; |
| 740 | } |
| 741 | |
| 742 | _LIBCPP_INLINE_VISIBILITY const _Tp& operator*() const {return __value_;} |
| 743 | _LIBCPP_INLINE_VISIBILITY const _Tp* operator->() const {return &(operator*());} |
| 744 | _LIBCPP_INLINE_VISIBILITY istream_iterator& operator++() |
| 745 | { |
| 746 | if (!(*__in_stream_ >> __value_)) |
| 747 | __in_stream_ = 0; |
| 748 | return *this; |
| 749 | } |
| 750 | _LIBCPP_INLINE_VISIBILITY istream_iterator operator++(int) |
| 751 | {istream_iterator __t(*this); ++(*this); return __t;} |
| 752 | |
| 753 | friend _LIBCPP_INLINE_VISIBILITY |
| 754 | bool operator==(const istream_iterator& __x, const istream_iterator& __y) |
| 755 | {return __x.__in_stream_ == __y.__in_stream_;} |
| 756 | |
| 757 | friend _LIBCPP_INLINE_VISIBILITY |
| 758 | bool operator!=(const istream_iterator& __x, const istream_iterator& __y) |
| 759 | {return !(__x == __y);} |
| 760 | }; |
| 761 | |
| 762 | template <class _Tp, class _CharT = char, class _Traits = char_traits<_CharT> > |
Howard Hinnant | 0f678bd | 2013-08-12 18:38:34 +0000 | [diff] [blame] | 763 | class _LIBCPP_TYPE_VIS_ONLY ostream_iterator |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 764 | : public iterator<output_iterator_tag, void, void, void, void> |
| 765 | { |
| 766 | public: |
| 767 | typedef _CharT char_type; |
| 768 | typedef _Traits traits_type; |
| 769 | typedef basic_ostream<_CharT,_Traits> ostream_type; |
| 770 | private: |
| 771 | ostream_type* __out_stream_; |
| 772 | const char_type* __delim_; |
| 773 | public: |
| 774 | _LIBCPP_INLINE_VISIBILITY ostream_iterator(ostream_type& __s) |
| 775 | : __out_stream_(&__s), __delim_(0) {} |
| 776 | _LIBCPP_INLINE_VISIBILITY ostream_iterator(ostream_type& __s, const _CharT* __delimiter) |
| 777 | : __out_stream_(&__s), __delim_(__delimiter) {} |
Howard Hinnant | 78b6828 | 2011-10-22 20:59:45 +0000 | [diff] [blame] | 778 | _LIBCPP_INLINE_VISIBILITY ostream_iterator& operator=(const _Tp& __value_) |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 779 | { |
Howard Hinnant | 78b6828 | 2011-10-22 20:59:45 +0000 | [diff] [blame] | 780 | *__out_stream_ << __value_; |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 781 | if (__delim_) |
| 782 | *__out_stream_ << __delim_; |
| 783 | return *this; |
| 784 | } |
| 785 | |
| 786 | _LIBCPP_INLINE_VISIBILITY ostream_iterator& operator*() {return *this;} |
| 787 | _LIBCPP_INLINE_VISIBILITY ostream_iterator& operator++() {return *this;} |
| 788 | _LIBCPP_INLINE_VISIBILITY ostream_iterator& operator++(int) {return *this;} |
| 789 | }; |
| 790 | |
| 791 | template<class _CharT, class _Traits> |
Howard Hinnant | 0f678bd | 2013-08-12 18:38:34 +0000 | [diff] [blame] | 792 | class _LIBCPP_TYPE_VIS_ONLY istreambuf_iterator |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 793 | : public iterator<input_iterator_tag, _CharT, |
| 794 | typename _Traits::off_type, _CharT*, |
| 795 | _CharT> |
| 796 | { |
| 797 | public: |
| 798 | typedef _CharT char_type; |
| 799 | typedef _Traits traits_type; |
| 800 | typedef typename _Traits::int_type int_type; |
| 801 | typedef basic_streambuf<_CharT,_Traits> streambuf_type; |
| 802 | typedef basic_istream<_CharT,_Traits> istream_type; |
| 803 | private: |
Howard Hinnant | 984f10f | 2012-11-16 22:17:23 +0000 | [diff] [blame] | 804 | mutable streambuf_type* __sbuf_; |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 805 | |
| 806 | class __proxy |
| 807 | { |
| 808 | char_type __keep_; |
| 809 | streambuf_type* __sbuf_; |
| 810 | _LIBCPP_INLINE_VISIBILITY __proxy(char_type __c, streambuf_type* __s) |
| 811 | : __keep_(__c), __sbuf_(__s) {} |
| 812 | friend class istreambuf_iterator; |
| 813 | public: |
| 814 | _LIBCPP_INLINE_VISIBILITY char_type operator*() const {return __keep_;} |
| 815 | }; |
| 816 | |
Howard Hinnant | 8289481 | 2010-09-22 16:48:34 +0000 | [diff] [blame] | 817 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 984f10f | 2012-11-16 22:17:23 +0000 | [diff] [blame] | 818 | bool __test_for_eof() const |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 819 | { |
| 820 | if (__sbuf_ && traits_type::eq_int_type(__sbuf_->sgetc(), traits_type::eof())) |
| 821 | __sbuf_ = 0; |
Howard Hinnant | 984f10f | 2012-11-16 22:17:23 +0000 | [diff] [blame] | 822 | return __sbuf_ == 0; |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 823 | } |
| 824 | public: |
Howard Hinnant | 984f10f | 2012-11-16 22:17:23 +0000 | [diff] [blame] | 825 | _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR istreambuf_iterator() _NOEXCEPT : __sbuf_(0) {} |
Howard Hinnant | d06a640 | 2012-07-20 19:36:34 +0000 | [diff] [blame] | 826 | _LIBCPP_INLINE_VISIBILITY istreambuf_iterator(istream_type& __s) _NOEXCEPT |
Howard Hinnant | d1a7479 | 2012-12-29 17:45:42 +0000 | [diff] [blame] | 827 | : __sbuf_(__s.rdbuf()) {} |
Howard Hinnant | d06a640 | 2012-07-20 19:36:34 +0000 | [diff] [blame] | 828 | _LIBCPP_INLINE_VISIBILITY istreambuf_iterator(streambuf_type* __s) _NOEXCEPT |
Howard Hinnant | d1a7479 | 2012-12-29 17:45:42 +0000 | [diff] [blame] | 829 | : __sbuf_(__s) {} |
Howard Hinnant | d06a640 | 2012-07-20 19:36:34 +0000 | [diff] [blame] | 830 | _LIBCPP_INLINE_VISIBILITY istreambuf_iterator(const __proxy& __p) _NOEXCEPT |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 831 | : __sbuf_(__p.__sbuf_) {} |
| 832 | |
Howard Hinnant | ec3773c | 2011-12-01 20:21:04 +0000 | [diff] [blame] | 833 | _LIBCPP_INLINE_VISIBILITY char_type operator*() const |
| 834 | {return static_cast<char_type>(__sbuf_->sgetc());} |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 835 | _LIBCPP_INLINE_VISIBILITY char_type* operator->() const {return nullptr;} |
| 836 | _LIBCPP_INLINE_VISIBILITY istreambuf_iterator& operator++() |
| 837 | { |
Howard Hinnant | 984f10f | 2012-11-16 22:17:23 +0000 | [diff] [blame] | 838 | __sbuf_->sbumpc(); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 839 | return *this; |
| 840 | } |
| 841 | _LIBCPP_INLINE_VISIBILITY __proxy operator++(int) |
| 842 | { |
Howard Hinnant | 984f10f | 2012-11-16 22:17:23 +0000 | [diff] [blame] | 843 | return __proxy(__sbuf_->sbumpc(), __sbuf_); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 844 | } |
| 845 | |
| 846 | _LIBCPP_INLINE_VISIBILITY bool equal(const istreambuf_iterator& __b) const |
Howard Hinnant | 984f10f | 2012-11-16 22:17:23 +0000 | [diff] [blame] | 847 | {return __test_for_eof() == __b.__test_for_eof();} |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 848 | }; |
| 849 | |
| 850 | template <class _CharT, class _Traits> |
| 851 | inline _LIBCPP_INLINE_VISIBILITY |
| 852 | bool operator==(const istreambuf_iterator<_CharT,_Traits>& __a, |
| 853 | const istreambuf_iterator<_CharT,_Traits>& __b) |
| 854 | {return __a.equal(__b);} |
| 855 | |
| 856 | template <class _CharT, class _Traits> |
| 857 | inline _LIBCPP_INLINE_VISIBILITY |
| 858 | bool operator!=(const istreambuf_iterator<_CharT,_Traits>& __a, |
| 859 | const istreambuf_iterator<_CharT,_Traits>& __b) |
| 860 | {return !__a.equal(__b);} |
| 861 | |
| 862 | template <class _CharT, class _Traits> |
Howard Hinnant | 0f678bd | 2013-08-12 18:38:34 +0000 | [diff] [blame] | 863 | class _LIBCPP_TYPE_VIS_ONLY ostreambuf_iterator |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 864 | : public iterator<output_iterator_tag, void, void, void, void> |
| 865 | { |
| 866 | public: |
| 867 | typedef _CharT char_type; |
| 868 | typedef _Traits traits_type; |
| 869 | typedef basic_streambuf<_CharT,_Traits> streambuf_type; |
| 870 | typedef basic_ostream<_CharT,_Traits> ostream_type; |
| 871 | private: |
| 872 | streambuf_type* __sbuf_; |
| 873 | public: |
Howard Hinnant | d06a640 | 2012-07-20 19:36:34 +0000 | [diff] [blame] | 874 | _LIBCPP_INLINE_VISIBILITY ostreambuf_iterator(ostream_type& __s) _NOEXCEPT |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 875 | : __sbuf_(__s.rdbuf()) {} |
Howard Hinnant | d06a640 | 2012-07-20 19:36:34 +0000 | [diff] [blame] | 876 | _LIBCPP_INLINE_VISIBILITY ostreambuf_iterator(streambuf_type* __s) _NOEXCEPT |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 877 | : __sbuf_(__s) {} |
| 878 | _LIBCPP_INLINE_VISIBILITY ostreambuf_iterator& operator=(_CharT __c) |
| 879 | { |
| 880 | if (__sbuf_ && traits_type::eq_int_type(__sbuf_->sputc(__c), traits_type::eof())) |
| 881 | __sbuf_ = 0; |
| 882 | return *this; |
| 883 | } |
| 884 | _LIBCPP_INLINE_VISIBILITY ostreambuf_iterator& operator*() {return *this;} |
| 885 | _LIBCPP_INLINE_VISIBILITY ostreambuf_iterator& operator++() {return *this;} |
| 886 | _LIBCPP_INLINE_VISIBILITY ostreambuf_iterator& operator++(int) {return *this;} |
Howard Hinnant | d06a640 | 2012-07-20 19:36:34 +0000 | [diff] [blame] | 887 | _LIBCPP_INLINE_VISIBILITY bool failed() const _NOEXCEPT {return __sbuf_ == 0;} |
Howard Hinnant | a585de6 | 2012-09-19 19:14:15 +0000 | [diff] [blame] | 888 | |
Howard Hinnant | 537b2fa | 2012-11-14 21:17:15 +0000 | [diff] [blame] | 889 | #if !defined(__APPLE__) || \ |
| 890 | (defined(__MAC_OS_X_VERSION_MIN_REQUIRED) && __MAC_OS_X_VERSION_MIN_REQUIRED > __MAC_10_8) || \ |
| 891 | (defined(__IPHONE_OS_VERSION_MIN_REQUIRED) && __IPHONE_OS_VERSION_MIN_REQUIRED > __IPHONE_6_0) |
| 892 | |
Howard Hinnant | a585de6 | 2012-09-19 19:14:15 +0000 | [diff] [blame] | 893 | template <class _Ch, class _Tr> |
| 894 | friend |
| 895 | _LIBCPP_HIDDEN |
| 896 | ostreambuf_iterator<_Ch, _Tr> |
| 897 | __pad_and_output(ostreambuf_iterator<_Ch, _Tr> __s, |
| 898 | const _Ch* __ob, const _Ch* __op, const _Ch* __oe, |
| 899 | ios_base& __iob, _Ch __fl); |
Howard Hinnant | 537b2fa | 2012-11-14 21:17:15 +0000 | [diff] [blame] | 900 | #endif |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 901 | }; |
| 902 | |
| 903 | template <class _Iter> |
Howard Hinnant | 0f678bd | 2013-08-12 18:38:34 +0000 | [diff] [blame] | 904 | class _LIBCPP_TYPE_VIS_ONLY move_iterator |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 905 | { |
| 906 | private: |
| 907 | _Iter __i; |
| 908 | public: |
| 909 | typedef _Iter iterator_type; |
| 910 | typedef typename iterator_traits<iterator_type>::iterator_category iterator_category; |
| 911 | typedef typename iterator_traits<iterator_type>::value_type value_type; |
| 912 | typedef typename iterator_traits<iterator_type>::difference_type difference_type; |
| 913 | typedef typename iterator_traits<iterator_type>::pointer pointer; |
Howard Hinnant | 73d21a4 | 2010-09-04 23:28:19 +0000 | [diff] [blame] | 914 | #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 915 | typedef value_type&& reference; |
| 916 | #else |
| 917 | typedef typename iterator_traits<iterator_type>::reference reference; |
| 918 | #endif |
Howard Hinnant | 324bb03 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 919 | |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 920 | _LIBCPP_INLINE_VISIBILITY move_iterator() : __i() {} |
| 921 | _LIBCPP_INLINE_VISIBILITY explicit move_iterator(_Iter __x) : __i(__x) {} |
| 922 | template <class _Up> _LIBCPP_INLINE_VISIBILITY move_iterator(const move_iterator<_Up>& __u) |
| 923 | : __i(__u.base()) {} |
| 924 | _LIBCPP_INLINE_VISIBILITY _Iter base() const {return __i;} |
Douglas Gregor | aab015a | 2011-01-26 00:12:48 +0000 | [diff] [blame] | 925 | _LIBCPP_INLINE_VISIBILITY reference operator*() const { |
| 926 | return static_cast<reference>(*__i); |
| 927 | } |
| 928 | _LIBCPP_INLINE_VISIBILITY pointer operator->() const { |
| 929 | typename iterator_traits<iterator_type>::reference __ref = *__i; |
| 930 | return &__ref; |
| 931 | } |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 932 | _LIBCPP_INLINE_VISIBILITY move_iterator& operator++() {++__i; return *this;} |
| 933 | _LIBCPP_INLINE_VISIBILITY move_iterator operator++(int) |
| 934 | {move_iterator __tmp(*this); ++__i; return __tmp;} |
| 935 | _LIBCPP_INLINE_VISIBILITY move_iterator& operator--() {--__i; return *this;} |
| 936 | _LIBCPP_INLINE_VISIBILITY move_iterator operator--(int) |
| 937 | {move_iterator __tmp(*this); --__i; return __tmp;} |
| 938 | _LIBCPP_INLINE_VISIBILITY move_iterator operator+ (difference_type __n) const |
| 939 | {return move_iterator(__i + __n);} |
| 940 | _LIBCPP_INLINE_VISIBILITY move_iterator& operator+=(difference_type __n) |
| 941 | {__i += __n; return *this;} |
| 942 | _LIBCPP_INLINE_VISIBILITY move_iterator operator- (difference_type __n) const |
| 943 | {return move_iterator(__i - __n);} |
| 944 | _LIBCPP_INLINE_VISIBILITY move_iterator& operator-=(difference_type __n) |
| 945 | {__i -= __n; return *this;} |
| 946 | _LIBCPP_INLINE_VISIBILITY reference operator[](difference_type __n) const |
Douglas Gregor | aab015a | 2011-01-26 00:12:48 +0000 | [diff] [blame] | 947 | { |
| 948 | return static_cast<reference>(__i[__n]); |
| 949 | } |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 950 | }; |
| 951 | |
| 952 | template <class _Iter1, class _Iter2> |
| 953 | inline _LIBCPP_INLINE_VISIBILITY |
| 954 | bool |
| 955 | operator==(const move_iterator<_Iter1>& __x, const move_iterator<_Iter2>& __y) |
| 956 | { |
| 957 | return __x.base() == __y.base(); |
| 958 | } |
| 959 | |
| 960 | template <class _Iter1, class _Iter2> |
| 961 | inline _LIBCPP_INLINE_VISIBILITY |
| 962 | bool |
| 963 | operator<(const move_iterator<_Iter1>& __x, const move_iterator<_Iter2>& __y) |
| 964 | { |
| 965 | return __x.base() < __y.base(); |
| 966 | } |
| 967 | |
| 968 | template <class _Iter1, class _Iter2> |
| 969 | inline _LIBCPP_INLINE_VISIBILITY |
| 970 | bool |
| 971 | operator!=(const move_iterator<_Iter1>& __x, const move_iterator<_Iter2>& __y) |
| 972 | { |
| 973 | return __x.base() != __y.base(); |
| 974 | } |
| 975 | |
| 976 | template <class _Iter1, class _Iter2> |
| 977 | inline _LIBCPP_INLINE_VISIBILITY |
| 978 | bool |
| 979 | operator>(const move_iterator<_Iter1>& __x, const move_iterator<_Iter2>& __y) |
| 980 | { |
| 981 | return __x.base() > __y.base(); |
| 982 | } |
| 983 | |
| 984 | template <class _Iter1, class _Iter2> |
| 985 | inline _LIBCPP_INLINE_VISIBILITY |
| 986 | bool |
| 987 | operator>=(const move_iterator<_Iter1>& __x, const move_iterator<_Iter2>& __y) |
| 988 | { |
| 989 | return __x.base() >= __y.base(); |
| 990 | } |
| 991 | |
| 992 | template <class _Iter1, class _Iter2> |
| 993 | inline _LIBCPP_INLINE_VISIBILITY |
| 994 | bool |
| 995 | operator<=(const move_iterator<_Iter1>& __x, const move_iterator<_Iter2>& __y) |
| 996 | { |
| 997 | return __x.base() <= __y.base(); |
| 998 | } |
| 999 | |
| 1000 | template <class _Iter1, class _Iter2> |
| 1001 | inline _LIBCPP_INLINE_VISIBILITY |
| 1002 | typename move_iterator<_Iter1>::difference_type |
| 1003 | operator-(const move_iterator<_Iter1>& __x, const move_iterator<_Iter2>& __y) |
| 1004 | { |
| 1005 | return __x.base() - __y.base(); |
| 1006 | } |
| 1007 | |
| 1008 | template <class _Iter> |
| 1009 | inline _LIBCPP_INLINE_VISIBILITY |
| 1010 | move_iterator<_Iter> |
| 1011 | operator+(typename move_iterator<_Iter>::difference_type __n, const move_iterator<_Iter>& __x) |
| 1012 | { |
| 1013 | return move_iterator<_Iter>(__x.base() + __n); |
| 1014 | } |
| 1015 | |
| 1016 | template <class _Iter> |
| 1017 | inline _LIBCPP_INLINE_VISIBILITY |
| 1018 | move_iterator<_Iter> |
Marshall Clow | af74651 | 2013-08-27 13:03:03 +0000 | [diff] [blame] | 1019 | make_move_iterator(_Iter __i) |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1020 | { |
| 1021 | return move_iterator<_Iter>(__i); |
| 1022 | } |
| 1023 | |
| 1024 | // __wrap_iter |
| 1025 | |
| 1026 | template <class _Iter> class __wrap_iter; |
| 1027 | |
| 1028 | template <class _Iter1, class _Iter2> |
Howard Hinnant | 33be35e | 2012-09-14 00:39:16 +0000 | [diff] [blame] | 1029 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1030 | bool |
Howard Hinnant | a6119a8 | 2011-05-29 19:57:12 +0000 | [diff] [blame] | 1031 | operator==(const __wrap_iter<_Iter1>&, const __wrap_iter<_Iter2>&) _NOEXCEPT; |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1032 | |
| 1033 | template <class _Iter1, class _Iter2> |
Howard Hinnant | 33be35e | 2012-09-14 00:39:16 +0000 | [diff] [blame] | 1034 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1035 | bool |
Howard Hinnant | a6119a8 | 2011-05-29 19:57:12 +0000 | [diff] [blame] | 1036 | operator<(const __wrap_iter<_Iter1>&, const __wrap_iter<_Iter2>&) _NOEXCEPT; |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1037 | |
| 1038 | template <class _Iter1, class _Iter2> |
Howard Hinnant | 33be35e | 2012-09-14 00:39:16 +0000 | [diff] [blame] | 1039 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1040 | bool |
Howard Hinnant | a6119a8 | 2011-05-29 19:57:12 +0000 | [diff] [blame] | 1041 | operator!=(const __wrap_iter<_Iter1>&, const __wrap_iter<_Iter2>&) _NOEXCEPT; |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1042 | |
| 1043 | template <class _Iter1, class _Iter2> |
Howard Hinnant | 33be35e | 2012-09-14 00:39:16 +0000 | [diff] [blame] | 1044 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1045 | bool |
Howard Hinnant | a6119a8 | 2011-05-29 19:57:12 +0000 | [diff] [blame] | 1046 | operator>(const __wrap_iter<_Iter1>&, const __wrap_iter<_Iter2>&) _NOEXCEPT; |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1047 | |
| 1048 | template <class _Iter1, class _Iter2> |
Howard Hinnant | 33be35e | 2012-09-14 00:39:16 +0000 | [diff] [blame] | 1049 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1050 | bool |
Howard Hinnant | a6119a8 | 2011-05-29 19:57:12 +0000 | [diff] [blame] | 1051 | operator>=(const __wrap_iter<_Iter1>&, const __wrap_iter<_Iter2>&) _NOEXCEPT; |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1052 | |
| 1053 | template <class _Iter1, class _Iter2> |
Howard Hinnant | 33be35e | 2012-09-14 00:39:16 +0000 | [diff] [blame] | 1054 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1055 | bool |
Howard Hinnant | a6119a8 | 2011-05-29 19:57:12 +0000 | [diff] [blame] | 1056 | operator<=(const __wrap_iter<_Iter1>&, const __wrap_iter<_Iter2>&) _NOEXCEPT; |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1057 | |
| 1058 | template <class _Iter1, class _Iter2> |
Howard Hinnant | 33be35e | 2012-09-14 00:39:16 +0000 | [diff] [blame] | 1059 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1060 | typename __wrap_iter<_Iter1>::difference_type |
Howard Hinnant | a6119a8 | 2011-05-29 19:57:12 +0000 | [diff] [blame] | 1061 | operator-(const __wrap_iter<_Iter1>&, const __wrap_iter<_Iter2>&) _NOEXCEPT; |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1062 | |
| 1063 | template <class _Iter> |
Howard Hinnant | 33be35e | 2012-09-14 00:39:16 +0000 | [diff] [blame] | 1064 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1065 | __wrap_iter<_Iter> |
Howard Hinnant | 2baccd8 | 2011-10-11 21:28:38 +0000 | [diff] [blame] | 1066 | operator+(typename __wrap_iter<_Iter>::difference_type, __wrap_iter<_Iter>) _NOEXCEPT; |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1067 | |
Howard Hinnant | 33be35e | 2012-09-14 00:39:16 +0000 | [diff] [blame] | 1068 | template <class _Ip, class _Op> _Op _LIBCPP_INLINE_VISIBILITY copy(_Ip, _Ip, _Op); |
| 1069 | template <class _B1, class _B2> _B2 _LIBCPP_INLINE_VISIBILITY copy_backward(_B1, _B1, _B2); |
| 1070 | template <class _Ip, class _Op> _Op _LIBCPP_INLINE_VISIBILITY move(_Ip, _Ip, _Op); |
| 1071 | 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] | 1072 | |
| 1073 | template <class _Tp> |
Howard Hinnant | 33be35e | 2012-09-14 00:39:16 +0000 | [diff] [blame] | 1074 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1075 | typename enable_if |
| 1076 | < |
Howard Hinnant | 1468b66 | 2010-11-19 22:17:28 +0000 | [diff] [blame] | 1077 | is_trivially_copy_assignable<_Tp>::value, |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1078 | _Tp* |
| 1079 | >::type |
| 1080 | __unwrap_iter(__wrap_iter<_Tp*>); |
| 1081 | |
| 1082 | template <class _Iter> |
| 1083 | class __wrap_iter |
| 1084 | { |
| 1085 | public: |
| 1086 | typedef _Iter iterator_type; |
| 1087 | typedef typename iterator_traits<iterator_type>::iterator_category iterator_category; |
| 1088 | typedef typename iterator_traits<iterator_type>::value_type value_type; |
| 1089 | typedef typename iterator_traits<iterator_type>::difference_type difference_type; |
| 1090 | typedef typename iterator_traits<iterator_type>::pointer pointer; |
| 1091 | typedef typename iterator_traits<iterator_type>::reference reference; |
| 1092 | private: |
| 1093 | iterator_type __i; |
| 1094 | public: |
Howard Hinnant | 7608b4a | 2011-09-16 19:52:23 +0000 | [diff] [blame] | 1095 | _LIBCPP_INLINE_VISIBILITY __wrap_iter() _NOEXCEPT |
Marshall Clow | 0f164c9 | 2013-08-07 20:48:48 +0000 | [diff] [blame] | 1096 | #if _LIBCPP_STD_VER > 11 |
| 1097 | : __i{} |
| 1098 | #endif |
Howard Hinnant | 7608b4a | 2011-09-16 19:52:23 +0000 | [diff] [blame] | 1099 | { |
| 1100 | #if _LIBCPP_DEBUG_LEVEL >= 2 |
| 1101 | __get_db()->__insert_i(this); |
| 1102 | #endif |
| 1103 | } |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1104 | 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] | 1105 | typename enable_if<is_convertible<_Up, iterator_type>::value>::type* = 0) _NOEXCEPT |
Howard Hinnant | 7a563db | 2011-09-14 18:33:51 +0000 | [diff] [blame] | 1106 | : __i(__u.base()) |
| 1107 | { |
Howard Hinnant | abe2628 | 2011-09-16 17:29:17 +0000 | [diff] [blame] | 1108 | #if _LIBCPP_DEBUG_LEVEL >= 2 |
Howard Hinnant | 7a563db | 2011-09-14 18:33:51 +0000 | [diff] [blame] | 1109 | __get_db()->__iterator_copy(this, &__u); |
| 1110 | #endif |
| 1111 | } |
Howard Hinnant | abe2628 | 2011-09-16 17:29:17 +0000 | [diff] [blame] | 1112 | #if _LIBCPP_DEBUG_LEVEL >= 2 |
Howard Hinnant | 7a563db | 2011-09-14 18:33:51 +0000 | [diff] [blame] | 1113 | _LIBCPP_INLINE_VISIBILITY |
| 1114 | __wrap_iter(const __wrap_iter& __x) |
| 1115 | : __i(__x.base()) |
| 1116 | { |
| 1117 | __get_db()->__iterator_copy(this, &__x); |
| 1118 | } |
| 1119 | _LIBCPP_INLINE_VISIBILITY |
| 1120 | __wrap_iter& operator=(const __wrap_iter& __x) |
| 1121 | { |
| 1122 | if (this != &__x) |
| 1123 | { |
| 1124 | __get_db()->__iterator_copy(this, &__x); |
| 1125 | __i = __x.__i; |
| 1126 | } |
| 1127 | return *this; |
| 1128 | } |
| 1129 | _LIBCPP_INLINE_VISIBILITY |
| 1130 | ~__wrap_iter() |
| 1131 | { |
| 1132 | __get_db()->__erase_i(this); |
| 1133 | } |
| 1134 | #endif |
| 1135 | _LIBCPP_INLINE_VISIBILITY reference operator*() const _NOEXCEPT |
| 1136 | { |
Howard Hinnant | abe2628 | 2011-09-16 17:29:17 +0000 | [diff] [blame] | 1137 | #if _LIBCPP_DEBUG_LEVEL >= 2 |
Howard Hinnant | 7a563db | 2011-09-14 18:33:51 +0000 | [diff] [blame] | 1138 | _LIBCPP_ASSERT(__get_const_db()->__dereferenceable(this), |
| 1139 | "Attempted to dereference a non-dereferenceable iterator"); |
Howard Hinnant | abe2628 | 2011-09-16 17:29:17 +0000 | [diff] [blame] | 1140 | #endif |
Howard Hinnant | 7a563db | 2011-09-14 18:33:51 +0000 | [diff] [blame] | 1141 | return *__i; |
| 1142 | } |
Howard Hinnant | 2c39cbe | 2013-06-27 19:35:32 +0000 | [diff] [blame] | 1143 | _LIBCPP_INLINE_VISIBILITY pointer operator->() const _NOEXCEPT |
| 1144 | { |
| 1145 | #if _LIBCPP_DEBUG_LEVEL >= 2 |
| 1146 | _LIBCPP_ASSERT(__get_const_db()->__dereferenceable(this), |
| 1147 | "Attempted to dereference a non-dereferenceable iterator"); |
| 1148 | #endif |
| 1149 | return (pointer)&reinterpret_cast<const volatile char&>(*__i); |
| 1150 | } |
Howard Hinnant | 7a563db | 2011-09-14 18:33:51 +0000 | [diff] [blame] | 1151 | _LIBCPP_INLINE_VISIBILITY __wrap_iter& operator++() _NOEXCEPT |
| 1152 | { |
Howard Hinnant | abe2628 | 2011-09-16 17:29:17 +0000 | [diff] [blame] | 1153 | #if _LIBCPP_DEBUG_LEVEL >= 2 |
Howard Hinnant | 7a563db | 2011-09-14 18:33:51 +0000 | [diff] [blame] | 1154 | _LIBCPP_ASSERT(__get_const_db()->__dereferenceable(this), |
| 1155 | "Attempted to increment non-incrementable iterator"); |
Howard Hinnant | abe2628 | 2011-09-16 17:29:17 +0000 | [diff] [blame] | 1156 | #endif |
Howard Hinnant | 7a563db | 2011-09-14 18:33:51 +0000 | [diff] [blame] | 1157 | ++__i; |
| 1158 | return *this; |
| 1159 | } |
Howard Hinnant | a6119a8 | 2011-05-29 19:57:12 +0000 | [diff] [blame] | 1160 | _LIBCPP_INLINE_VISIBILITY __wrap_iter operator++(int) _NOEXCEPT |
Howard Hinnant | 7a563db | 2011-09-14 18:33:51 +0000 | [diff] [blame] | 1161 | {__wrap_iter __tmp(*this); ++(*this); return __tmp;} |
| 1162 | _LIBCPP_INLINE_VISIBILITY __wrap_iter& operator--() _NOEXCEPT |
| 1163 | { |
Howard Hinnant | abe2628 | 2011-09-16 17:29:17 +0000 | [diff] [blame] | 1164 | #if _LIBCPP_DEBUG_LEVEL >= 2 |
Howard Hinnant | 7a563db | 2011-09-14 18:33:51 +0000 | [diff] [blame] | 1165 | _LIBCPP_ASSERT(__get_const_db()->__decrementable(this), |
| 1166 | "Attempted to decrement non-decrementable iterator"); |
Howard Hinnant | abe2628 | 2011-09-16 17:29:17 +0000 | [diff] [blame] | 1167 | #endif |
Howard Hinnant | 7a563db | 2011-09-14 18:33:51 +0000 | [diff] [blame] | 1168 | --__i; |
| 1169 | return *this; |
| 1170 | } |
Howard Hinnant | a6119a8 | 2011-05-29 19:57:12 +0000 | [diff] [blame] | 1171 | _LIBCPP_INLINE_VISIBILITY __wrap_iter operator--(int) _NOEXCEPT |
Howard Hinnant | 7a563db | 2011-09-14 18:33:51 +0000 | [diff] [blame] | 1172 | {__wrap_iter __tmp(*this); --(*this); return __tmp;} |
Howard Hinnant | a6119a8 | 2011-05-29 19:57:12 +0000 | [diff] [blame] | 1173 | _LIBCPP_INLINE_VISIBILITY __wrap_iter operator+ (difference_type __n) const _NOEXCEPT |
Howard Hinnant | 7a563db | 2011-09-14 18:33:51 +0000 | [diff] [blame] | 1174 | {__wrap_iter __w(*this); __w += __n; return __w;} |
Howard Hinnant | a6119a8 | 2011-05-29 19:57:12 +0000 | [diff] [blame] | 1175 | _LIBCPP_INLINE_VISIBILITY __wrap_iter& operator+=(difference_type __n) _NOEXCEPT |
Howard Hinnant | 7a563db | 2011-09-14 18:33:51 +0000 | [diff] [blame] | 1176 | { |
Howard Hinnant | abe2628 | 2011-09-16 17:29:17 +0000 | [diff] [blame] | 1177 | #if _LIBCPP_DEBUG_LEVEL >= 2 |
Howard Hinnant | 7a563db | 2011-09-14 18:33:51 +0000 | [diff] [blame] | 1178 | _LIBCPP_ASSERT(__get_const_db()->__addable(this, __n), |
| 1179 | "Attempted to add/subtract iterator outside of valid range"); |
Howard Hinnant | abe2628 | 2011-09-16 17:29:17 +0000 | [diff] [blame] | 1180 | #endif |
Howard Hinnant | 7a563db | 2011-09-14 18:33:51 +0000 | [diff] [blame] | 1181 | __i += __n; |
| 1182 | return *this; |
| 1183 | } |
Howard Hinnant | a6119a8 | 2011-05-29 19:57:12 +0000 | [diff] [blame] | 1184 | _LIBCPP_INLINE_VISIBILITY __wrap_iter operator- (difference_type __n) const _NOEXCEPT |
Howard Hinnant | 7a563db | 2011-09-14 18:33:51 +0000 | [diff] [blame] | 1185 | {return *this + (-__n);} |
Howard Hinnant | a6119a8 | 2011-05-29 19:57:12 +0000 | [diff] [blame] | 1186 | _LIBCPP_INLINE_VISIBILITY __wrap_iter& operator-=(difference_type __n) _NOEXCEPT |
Howard Hinnant | 7a563db | 2011-09-14 18:33:51 +0000 | [diff] [blame] | 1187 | {*this += -__n; return *this;} |
Howard Hinnant | a6119a8 | 2011-05-29 19:57:12 +0000 | [diff] [blame] | 1188 | _LIBCPP_INLINE_VISIBILITY reference operator[](difference_type __n) const _NOEXCEPT |
Howard Hinnant | 7a563db | 2011-09-14 18:33:51 +0000 | [diff] [blame] | 1189 | { |
Howard Hinnant | abe2628 | 2011-09-16 17:29:17 +0000 | [diff] [blame] | 1190 | #if _LIBCPP_DEBUG_LEVEL >= 2 |
Howard Hinnant | 7a563db | 2011-09-14 18:33:51 +0000 | [diff] [blame] | 1191 | _LIBCPP_ASSERT(__get_const_db()->__subscriptable(this, __n), |
| 1192 | "Attempted to subscript iterator outside of valid range"); |
Howard Hinnant | abe2628 | 2011-09-16 17:29:17 +0000 | [diff] [blame] | 1193 | #endif |
Howard Hinnant | 7a563db | 2011-09-14 18:33:51 +0000 | [diff] [blame] | 1194 | return __i[__n]; |
| 1195 | } |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1196 | |
Howard Hinnant | a6119a8 | 2011-05-29 19:57:12 +0000 | [diff] [blame] | 1197 | _LIBCPP_INLINE_VISIBILITY iterator_type base() const _NOEXCEPT {return __i;} |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1198 | |
| 1199 | private: |
Howard Hinnant | abe2628 | 2011-09-16 17:29:17 +0000 | [diff] [blame] | 1200 | #if _LIBCPP_DEBUG_LEVEL >= 2 |
Howard Hinnant | 7a563db | 2011-09-14 18:33:51 +0000 | [diff] [blame] | 1201 | _LIBCPP_INLINE_VISIBILITY __wrap_iter(const void* __p, iterator_type __x) : __i(__x) |
| 1202 | { |
| 1203 | __get_db()->__insert_ic(this, __p); |
| 1204 | } |
Howard Hinnant | 499cea1 | 2013-08-23 17:37:05 +0000 | [diff] [blame] | 1205 | #else |
| 1206 | _LIBCPP_INLINE_VISIBILITY __wrap_iter(iterator_type __x) _NOEXCEPT : __i(__x) {} |
Howard Hinnant | 7a563db | 2011-09-14 18:33:51 +0000 | [diff] [blame] | 1207 | #endif |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1208 | |
| 1209 | template <class _Up> friend class __wrap_iter; |
| 1210 | template <class _CharT, class _Traits, class _Alloc> friend class basic_string; |
| 1211 | template <class _Tp, class _Alloc> friend class vector; |
| 1212 | |
| 1213 | template <class _Iter1, class _Iter2> |
| 1214 | friend |
| 1215 | bool |
Howard Hinnant | a6119a8 | 2011-05-29 19:57:12 +0000 | [diff] [blame] | 1216 | operator==(const __wrap_iter<_Iter1>&, const __wrap_iter<_Iter2>&) _NOEXCEPT; |
Howard Hinnant | 324bb03 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 1217 | |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1218 | template <class _Iter1, class _Iter2> |
| 1219 | friend |
| 1220 | bool |
Howard Hinnant | a6119a8 | 2011-05-29 19:57:12 +0000 | [diff] [blame] | 1221 | operator<(const __wrap_iter<_Iter1>&, const __wrap_iter<_Iter2>&) _NOEXCEPT; |
Howard Hinnant | 324bb03 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 1222 | |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1223 | template <class _Iter1, class _Iter2> |
| 1224 | friend |
| 1225 | bool |
Howard Hinnant | a6119a8 | 2011-05-29 19:57:12 +0000 | [diff] [blame] | 1226 | operator!=(const __wrap_iter<_Iter1>&, const __wrap_iter<_Iter2>&) _NOEXCEPT; |
Howard Hinnant | 324bb03 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 1227 | |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1228 | template <class _Iter1, class _Iter2> |
| 1229 | friend |
| 1230 | bool |
Howard Hinnant | a6119a8 | 2011-05-29 19:57:12 +0000 | [diff] [blame] | 1231 | operator>(const __wrap_iter<_Iter1>&, const __wrap_iter<_Iter2>&) _NOEXCEPT; |
Howard Hinnant | 324bb03 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 1232 | |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1233 | template <class _Iter1, class _Iter2> |
| 1234 | friend |
| 1235 | bool |
Howard Hinnant | a6119a8 | 2011-05-29 19:57:12 +0000 | [diff] [blame] | 1236 | operator>=(const __wrap_iter<_Iter1>&, const __wrap_iter<_Iter2>&) _NOEXCEPT; |
Howard Hinnant | 324bb03 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 1237 | |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1238 | template <class _Iter1, class _Iter2> |
| 1239 | friend |
| 1240 | bool |
Howard Hinnant | a6119a8 | 2011-05-29 19:57:12 +0000 | [diff] [blame] | 1241 | operator<=(const __wrap_iter<_Iter1>&, const __wrap_iter<_Iter2>&) _NOEXCEPT; |
Howard Hinnant | 324bb03 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 1242 | |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1243 | template <class _Iter1, class _Iter2> |
| 1244 | friend |
| 1245 | typename __wrap_iter<_Iter1>::difference_type |
Howard Hinnant | a6119a8 | 2011-05-29 19:57:12 +0000 | [diff] [blame] | 1246 | operator-(const __wrap_iter<_Iter1>&, const __wrap_iter<_Iter2>&) _NOEXCEPT; |
Howard Hinnant | 324bb03 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 1247 | |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1248 | template <class _Iter1> |
| 1249 | friend |
| 1250 | __wrap_iter<_Iter1> |
Howard Hinnant | 2baccd8 | 2011-10-11 21:28:38 +0000 | [diff] [blame] | 1251 | operator+(typename __wrap_iter<_Iter1>::difference_type, __wrap_iter<_Iter1>) _NOEXCEPT; |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1252 | |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 1253 | template <class _Ip, class _Op> friend _Op copy(_Ip, _Ip, _Op); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1254 | template <class _B1, class _B2> friend _B2 copy_backward(_B1, _B1, _B2); |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 1255 | template <class _Ip, class _Op> friend _Op move(_Ip, _Ip, _Op); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1256 | template <class _B1, class _B2> friend _B2 move_backward(_B1, _B1, _B2); |
| 1257 | |
| 1258 | template <class _Tp> |
| 1259 | friend |
| 1260 | typename enable_if |
| 1261 | < |
Howard Hinnant | 1468b66 | 2010-11-19 22:17:28 +0000 | [diff] [blame] | 1262 | is_trivially_copy_assignable<_Tp>::value, |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1263 | _Tp* |
| 1264 | >::type |
| 1265 | __unwrap_iter(__wrap_iter<_Tp*>); |
| 1266 | }; |
| 1267 | |
| 1268 | template <class _Iter1, class _Iter2> |
| 1269 | inline _LIBCPP_INLINE_VISIBILITY |
| 1270 | bool |
Howard Hinnant | a6119a8 | 2011-05-29 19:57:12 +0000 | [diff] [blame] | 1271 | operator==(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter2>& __y) _NOEXCEPT |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1272 | { |
| 1273 | return __x.base() == __y.base(); |
| 1274 | } |
| 1275 | |
| 1276 | template <class _Iter1, class _Iter2> |
| 1277 | inline _LIBCPP_INLINE_VISIBILITY |
| 1278 | bool |
Howard Hinnant | a6119a8 | 2011-05-29 19:57:12 +0000 | [diff] [blame] | 1279 | operator<(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter2>& __y) _NOEXCEPT |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1280 | { |
Howard Hinnant | abe2628 | 2011-09-16 17:29:17 +0000 | [diff] [blame] | 1281 | #if _LIBCPP_DEBUG_LEVEL >= 2 |
Howard Hinnant | 8b00e6c | 2013-08-02 00:26:35 +0000 | [diff] [blame] | 1282 | _LIBCPP_ASSERT(__get_const_db()->__less_than_comparable(&__x, &__y), |
Howard Hinnant | 7a563db | 2011-09-14 18:33:51 +0000 | [diff] [blame] | 1283 | "Attempted to compare incomparable iterators"); |
Howard Hinnant | abe2628 | 2011-09-16 17:29:17 +0000 | [diff] [blame] | 1284 | #endif |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1285 | return __x.base() < __y.base(); |
| 1286 | } |
| 1287 | |
| 1288 | template <class _Iter1, class _Iter2> |
| 1289 | inline _LIBCPP_INLINE_VISIBILITY |
| 1290 | bool |
Howard Hinnant | a6119a8 | 2011-05-29 19:57:12 +0000 | [diff] [blame] | 1291 | operator!=(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter2>& __y) _NOEXCEPT |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1292 | { |
Howard Hinnant | 7a563db | 2011-09-14 18:33:51 +0000 | [diff] [blame] | 1293 | return !(__x == __y); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1294 | } |
| 1295 | |
| 1296 | template <class _Iter1, class _Iter2> |
| 1297 | inline _LIBCPP_INLINE_VISIBILITY |
| 1298 | bool |
Howard Hinnant | a6119a8 | 2011-05-29 19:57:12 +0000 | [diff] [blame] | 1299 | operator>(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter2>& __y) _NOEXCEPT |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1300 | { |
Howard Hinnant | 7a563db | 2011-09-14 18:33:51 +0000 | [diff] [blame] | 1301 | return __y < __x; |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1302 | } |
| 1303 | |
| 1304 | template <class _Iter1, class _Iter2> |
| 1305 | inline _LIBCPP_INLINE_VISIBILITY |
| 1306 | bool |
Howard Hinnant | a6119a8 | 2011-05-29 19:57:12 +0000 | [diff] [blame] | 1307 | operator>=(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter2>& __y) _NOEXCEPT |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1308 | { |
Howard Hinnant | 7a563db | 2011-09-14 18:33:51 +0000 | [diff] [blame] | 1309 | return !(__x < __y); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1310 | } |
| 1311 | |
| 1312 | template <class _Iter1, class _Iter2> |
| 1313 | inline _LIBCPP_INLINE_VISIBILITY |
| 1314 | bool |
Howard Hinnant | a6119a8 | 2011-05-29 19:57:12 +0000 | [diff] [blame] | 1315 | operator<=(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter2>& __y) _NOEXCEPT |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1316 | { |
Howard Hinnant | 7a563db | 2011-09-14 18:33:51 +0000 | [diff] [blame] | 1317 | return !(__y < __x); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1318 | } |
| 1319 | |
Howard Hinnant | 95c0e9f | 2012-10-02 19:45:42 +0000 | [diff] [blame] | 1320 | template <class _Iter1> |
| 1321 | inline _LIBCPP_INLINE_VISIBILITY |
| 1322 | bool |
| 1323 | operator!=(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter1>& __y) _NOEXCEPT |
| 1324 | { |
| 1325 | return !(__x == __y); |
| 1326 | } |
| 1327 | |
| 1328 | template <class _Iter1> |
| 1329 | inline _LIBCPP_INLINE_VISIBILITY |
| 1330 | bool |
| 1331 | operator>(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter1>& __y) _NOEXCEPT |
| 1332 | { |
| 1333 | return __y < __x; |
| 1334 | } |
| 1335 | |
| 1336 | template <class _Iter1> |
| 1337 | inline _LIBCPP_INLINE_VISIBILITY |
| 1338 | bool |
| 1339 | operator>=(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter1>& __y) _NOEXCEPT |
| 1340 | { |
| 1341 | return !(__x < __y); |
| 1342 | } |
| 1343 | |
| 1344 | template <class _Iter1> |
| 1345 | inline _LIBCPP_INLINE_VISIBILITY |
| 1346 | bool |
| 1347 | operator<=(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter1>& __y) _NOEXCEPT |
| 1348 | { |
| 1349 | return !(__y < __x); |
| 1350 | } |
| 1351 | |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1352 | template <class _Iter1, class _Iter2> |
| 1353 | inline _LIBCPP_INLINE_VISIBILITY |
| 1354 | typename __wrap_iter<_Iter1>::difference_type |
Howard Hinnant | a6119a8 | 2011-05-29 19:57:12 +0000 | [diff] [blame] | 1355 | operator-(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter2>& __y) _NOEXCEPT |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1356 | { |
Howard Hinnant | abe2628 | 2011-09-16 17:29:17 +0000 | [diff] [blame] | 1357 | #if _LIBCPP_DEBUG_LEVEL >= 2 |
Howard Hinnant | 8b00e6c | 2013-08-02 00:26:35 +0000 | [diff] [blame] | 1358 | _LIBCPP_ASSERT(__get_const_db()->__less_than_comparable(&__x, &__y), |
Howard Hinnant | 7a563db | 2011-09-14 18:33:51 +0000 | [diff] [blame] | 1359 | "Attempted to subtract incompatible iterators"); |
Howard Hinnant | abe2628 | 2011-09-16 17:29:17 +0000 | [diff] [blame] | 1360 | #endif |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1361 | return __x.base() - __y.base(); |
| 1362 | } |
| 1363 | |
| 1364 | template <class _Iter> |
| 1365 | inline _LIBCPP_INLINE_VISIBILITY |
| 1366 | __wrap_iter<_Iter> |
| 1367 | operator+(typename __wrap_iter<_Iter>::difference_type __n, |
Howard Hinnant | 7a563db | 2011-09-14 18:33:51 +0000 | [diff] [blame] | 1368 | __wrap_iter<_Iter> __x) _NOEXCEPT |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1369 | { |
Howard Hinnant | 7a563db | 2011-09-14 18:33:51 +0000 | [diff] [blame] | 1370 | __x += __n; |
| 1371 | return __x; |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1372 | } |
| 1373 | |
Howard Hinnant | 726a76f | 2010-11-16 21:10:23 +0000 | [diff] [blame] | 1374 | #if !defined(_LIBCPP_HAS_NO_RVALUE_REFERENCES) && !defined(_LIBCPP_HAS_NO_TRAILING_RETURN) |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1375 | |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 1376 | template <class _Cp> |
Howard Hinnant | 8289481 | 2010-09-22 16:48:34 +0000 | [diff] [blame] | 1377 | inline _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1378 | auto |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 1379 | begin(_Cp& __c) -> decltype(__c.begin()) |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1380 | { |
| 1381 | return __c.begin(); |
| 1382 | } |
| 1383 | |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 1384 | template <class _Cp> |
Howard Hinnant | 8289481 | 2010-09-22 16:48:34 +0000 | [diff] [blame] | 1385 | inline _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1386 | auto |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 1387 | begin(const _Cp& __c) -> decltype(__c.begin()) |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1388 | { |
| 1389 | return __c.begin(); |
| 1390 | } |
| 1391 | |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 1392 | template <class _Cp> |
Howard Hinnant | 8289481 | 2010-09-22 16:48:34 +0000 | [diff] [blame] | 1393 | inline _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1394 | auto |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 1395 | end(_Cp& __c) -> decltype(__c.end()) |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1396 | { |
| 1397 | return __c.end(); |
| 1398 | } |
| 1399 | |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 1400 | template <class _Cp> |
Howard Hinnant | 8289481 | 2010-09-22 16:48:34 +0000 | [diff] [blame] | 1401 | inline _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1402 | auto |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 1403 | end(const _Cp& __c) -> decltype(__c.end()) |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1404 | { |
| 1405 | return __c.end(); |
| 1406 | } |
| 1407 | |
Howard Hinnant | 726a76f | 2010-11-16 21:10:23 +0000 | [diff] [blame] | 1408 | #else // !defined(_LIBCPP_HAS_NO_RVALUE_REFERENCES) && !defined(_LIBCPP_HAS_NO_TRAILING_RETURN) |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1409 | |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 1410 | template <class _Cp> |
Howard Hinnant | 8289481 | 2010-09-22 16:48:34 +0000 | [diff] [blame] | 1411 | inline _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 1412 | typename _Cp::iterator |
| 1413 | begin(_Cp& __c) |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1414 | { |
| 1415 | return __c.begin(); |
| 1416 | } |
| 1417 | |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 1418 | template <class _Cp> |
Howard Hinnant | 8289481 | 2010-09-22 16:48:34 +0000 | [diff] [blame] | 1419 | inline _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 1420 | typename _Cp::const_iterator |
| 1421 | begin(const _Cp& __c) |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1422 | { |
| 1423 | return __c.begin(); |
| 1424 | } |
| 1425 | |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 1426 | template <class _Cp> |
Howard Hinnant | 8289481 | 2010-09-22 16:48:34 +0000 | [diff] [blame] | 1427 | inline _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 1428 | typename _Cp::iterator |
| 1429 | end(_Cp& __c) |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1430 | { |
| 1431 | return __c.end(); |
| 1432 | } |
| 1433 | |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 1434 | template <class _Cp> |
Howard Hinnant | 8289481 | 2010-09-22 16:48:34 +0000 | [diff] [blame] | 1435 | inline _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 1436 | typename _Cp::const_iterator |
| 1437 | end(const _Cp& __c) |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1438 | { |
| 1439 | return __c.end(); |
| 1440 | } |
| 1441 | |
Howard Hinnant | 726a76f | 2010-11-16 21:10:23 +0000 | [diff] [blame] | 1442 | #endif // !defined(_LIBCPP_HAS_NO_RVALUE_REFERENCES) && !defined(_LIBCPP_HAS_NO_TRAILING_RETURN) |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1443 | |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 1444 | template <class _Tp, size_t _Np> |
Howard Hinnant | 8289481 | 2010-09-22 16:48:34 +0000 | [diff] [blame] | 1445 | inline _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 1446 | _Tp* |
| 1447 | begin(_Tp (&__array)[_Np]) |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1448 | { |
| 1449 | return __array; |
| 1450 | } |
| 1451 | |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 1452 | template <class _Tp, size_t _Np> |
Howard Hinnant | 8289481 | 2010-09-22 16:48:34 +0000 | [diff] [blame] | 1453 | inline _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 1454 | _Tp* |
| 1455 | end(_Tp (&__array)[_Np]) |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1456 | { |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 1457 | return __array + _Np; |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1458 | } |
| 1459 | |
| 1460 | _LIBCPP_END_NAMESPACE_STD |
| 1461 | |
| 1462 | #endif // _LIBCPP_ITERATOR |