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