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 | { |
| 539 | private: |
| 540 | mutable _Iter __t; |
| 541 | protected: |
| 542 | _Iter current; |
| 543 | public: |
| 544 | typedef _Iter iterator_type; |
| 545 | typedef typename iterator_traits<_Iter>::difference_type difference_type; |
| 546 | typedef typename iterator_traits<_Iter>::reference reference; |
| 547 | typedef typename iterator_traits<_Iter>::pointer pointer; |
Howard Hinnant | 324bb03 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 548 | |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 549 | _LIBCPP_INLINE_VISIBILITY reverse_iterator() : current() {} |
| 550 | _LIBCPP_INLINE_VISIBILITY explicit reverse_iterator(_Iter __x) : __t(__x), current(__x) {} |
| 551 | template <class _Up> _LIBCPP_INLINE_VISIBILITY reverse_iterator(const reverse_iterator<_Up>& __u) |
| 552 | : __t(__u.base()), current(__u.base()) {} |
| 553 | _LIBCPP_INLINE_VISIBILITY _Iter base() const {return current;} |
| 554 | _LIBCPP_INLINE_VISIBILITY reference operator*() const {__t = current; return *--__t;} |
Marshall Clow | 02ca8af | 2014-02-27 02:11:50 +0000 | [diff] [blame] | 555 | _LIBCPP_INLINE_VISIBILITY pointer operator->() const {return _VSTD::addressof(operator*());} |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 556 | _LIBCPP_INLINE_VISIBILITY reverse_iterator& operator++() {--current; return *this;} |
| 557 | _LIBCPP_INLINE_VISIBILITY reverse_iterator operator++(int) |
| 558 | {reverse_iterator __tmp(*this); --current; return __tmp;} |
| 559 | _LIBCPP_INLINE_VISIBILITY reverse_iterator& operator--() {++current; return *this;} |
| 560 | _LIBCPP_INLINE_VISIBILITY reverse_iterator operator--(int) |
| 561 | {reverse_iterator __tmp(*this); ++current; return __tmp;} |
| 562 | _LIBCPP_INLINE_VISIBILITY reverse_iterator operator+ (difference_type __n) const |
| 563 | {return reverse_iterator(current - __n);} |
| 564 | _LIBCPP_INLINE_VISIBILITY reverse_iterator& operator+=(difference_type __n) |
| 565 | {current -= __n; return *this;} |
| 566 | _LIBCPP_INLINE_VISIBILITY reverse_iterator operator- (difference_type __n) const |
| 567 | {return reverse_iterator(current + __n);} |
| 568 | _LIBCPP_INLINE_VISIBILITY reverse_iterator& operator-=(difference_type __n) |
| 569 | {current += __n; return *this;} |
| 570 | _LIBCPP_INLINE_VISIBILITY reference operator[](difference_type __n) const |
| 571 | {return current[-__n-1];} |
| 572 | }; |
| 573 | |
| 574 | template <class _Iter1, class _Iter2> |
| 575 | inline _LIBCPP_INLINE_VISIBILITY |
| 576 | bool |
| 577 | operator==(const reverse_iterator<_Iter1>& __x, const reverse_iterator<_Iter2>& __y) |
| 578 | { |
| 579 | return __x.base() == __y.base(); |
| 580 | } |
| 581 | |
| 582 | template <class _Iter1, class _Iter2> |
| 583 | inline _LIBCPP_INLINE_VISIBILITY |
| 584 | bool |
| 585 | operator<(const reverse_iterator<_Iter1>& __x, const reverse_iterator<_Iter2>& __y) |
| 586 | { |
| 587 | return __x.base() > __y.base(); |
| 588 | } |
| 589 | |
| 590 | template <class _Iter1, class _Iter2> |
| 591 | inline _LIBCPP_INLINE_VISIBILITY |
| 592 | bool |
| 593 | operator!=(const reverse_iterator<_Iter1>& __x, const reverse_iterator<_Iter2>& __y) |
| 594 | { |
| 595 | return __x.base() != __y.base(); |
| 596 | } |
| 597 | |
| 598 | template <class _Iter1, class _Iter2> |
| 599 | inline _LIBCPP_INLINE_VISIBILITY |
| 600 | bool |
| 601 | operator>(const reverse_iterator<_Iter1>& __x, const reverse_iterator<_Iter2>& __y) |
| 602 | { |
| 603 | return __x.base() < __y.base(); |
| 604 | } |
| 605 | |
| 606 | template <class _Iter1, class _Iter2> |
| 607 | inline _LIBCPP_INLINE_VISIBILITY |
| 608 | bool |
| 609 | operator>=(const reverse_iterator<_Iter1>& __x, const reverse_iterator<_Iter2>& __y) |
| 610 | { |
| 611 | return __x.base() <= __y.base(); |
| 612 | } |
| 613 | |
| 614 | template <class _Iter1, class _Iter2> |
| 615 | inline _LIBCPP_INLINE_VISIBILITY |
| 616 | bool |
| 617 | operator<=(const reverse_iterator<_Iter1>& __x, const reverse_iterator<_Iter2>& __y) |
| 618 | { |
| 619 | return __x.base() >= __y.base(); |
| 620 | } |
| 621 | |
| 622 | template <class _Iter1, class _Iter2> |
| 623 | inline _LIBCPP_INLINE_VISIBILITY |
| 624 | typename reverse_iterator<_Iter1>::difference_type |
| 625 | operator-(const reverse_iterator<_Iter1>& __x, const reverse_iterator<_Iter2>& __y) |
| 626 | { |
| 627 | return __y.base() - __x.base(); |
| 628 | } |
| 629 | |
| 630 | template <class _Iter> |
| 631 | inline _LIBCPP_INLINE_VISIBILITY |
| 632 | reverse_iterator<_Iter> |
| 633 | operator+(typename reverse_iterator<_Iter>::difference_type __n, const reverse_iterator<_Iter>& __x) |
| 634 | { |
| 635 | return reverse_iterator<_Iter>(__x.base() - __n); |
| 636 | } |
| 637 | |
Marshall Clow | ff137e9 | 2014-03-03 01:24:04 +0000 | [diff] [blame] | 638 | #if _LIBCPP_STD_VER > 11 |
| 639 | template <class _Iter> |
| 640 | inline _LIBCPP_INLINE_VISIBILITY |
| 641 | reverse_iterator<_Iter> make_reverse_iterator(_Iter __i) |
| 642 | { |
| 643 | return reverse_iterator<_Iter>(__i); |
| 644 | } |
| 645 | #endif |
| 646 | |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 647 | template <class _Container> |
Howard Hinnant | 0f678bd | 2013-08-12 18:38:34 +0000 | [diff] [blame] | 648 | class _LIBCPP_TYPE_VIS_ONLY back_insert_iterator |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 649 | : public iterator<output_iterator_tag, |
| 650 | void, |
| 651 | void, |
| 652 | void, |
| 653 | back_insert_iterator<_Container>&> |
| 654 | { |
| 655 | protected: |
| 656 | _Container* container; |
| 657 | public: |
| 658 | typedef _Container container_type; |
| 659 | |
Marshall Clow | 53c0e72 | 2014-03-03 19:20:40 +0000 | [diff] [blame^] | 660 | _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] | 661 | _LIBCPP_INLINE_VISIBILITY back_insert_iterator& operator=(const typename _Container::value_type& __value_) |
| 662 | {container->push_back(__value_); return *this;} |
Howard Hinnant | 73d21a4 | 2010-09-04 23:28:19 +0000 | [diff] [blame] | 663 | #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES |
Howard Hinnant | 78b6828 | 2011-10-22 20:59:45 +0000 | [diff] [blame] | 664 | _LIBCPP_INLINE_VISIBILITY back_insert_iterator& operator=(typename _Container::value_type&& __value_) |
| 665 | {container->push_back(_VSTD::move(__value_)); return *this;} |
Howard Hinnant | 73d21a4 | 2010-09-04 23:28:19 +0000 | [diff] [blame] | 666 | #endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 667 | _LIBCPP_INLINE_VISIBILITY back_insert_iterator& operator*() {return *this;} |
| 668 | _LIBCPP_INLINE_VISIBILITY back_insert_iterator& operator++() {return *this;} |
| 669 | _LIBCPP_INLINE_VISIBILITY back_insert_iterator operator++(int) {return *this;} |
| 670 | }; |
| 671 | |
| 672 | template <class _Container> |
| 673 | inline _LIBCPP_INLINE_VISIBILITY |
| 674 | back_insert_iterator<_Container> |
| 675 | back_inserter(_Container& __x) |
| 676 | { |
| 677 | return back_insert_iterator<_Container>(__x); |
| 678 | } |
| 679 | |
| 680 | template <class _Container> |
Howard Hinnant | 0f678bd | 2013-08-12 18:38:34 +0000 | [diff] [blame] | 681 | class _LIBCPP_TYPE_VIS_ONLY front_insert_iterator |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 682 | : public iterator<output_iterator_tag, |
| 683 | void, |
| 684 | void, |
| 685 | void, |
| 686 | front_insert_iterator<_Container>&> |
| 687 | { |
| 688 | protected: |
| 689 | _Container* container; |
| 690 | public: |
| 691 | typedef _Container container_type; |
| 692 | |
Marshall Clow | 53c0e72 | 2014-03-03 19:20:40 +0000 | [diff] [blame^] | 693 | _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] | 694 | _LIBCPP_INLINE_VISIBILITY front_insert_iterator& operator=(const typename _Container::value_type& __value_) |
| 695 | {container->push_front(__value_); return *this;} |
Howard Hinnant | 73d21a4 | 2010-09-04 23:28:19 +0000 | [diff] [blame] | 696 | #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES |
Howard Hinnant | 78b6828 | 2011-10-22 20:59:45 +0000 | [diff] [blame] | 697 | _LIBCPP_INLINE_VISIBILITY front_insert_iterator& operator=(typename _Container::value_type&& __value_) |
| 698 | {container->push_front(_VSTD::move(__value_)); return *this;} |
Howard Hinnant | 73d21a4 | 2010-09-04 23:28:19 +0000 | [diff] [blame] | 699 | #endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 700 | _LIBCPP_INLINE_VISIBILITY front_insert_iterator& operator*() {return *this;} |
| 701 | _LIBCPP_INLINE_VISIBILITY front_insert_iterator& operator++() {return *this;} |
| 702 | _LIBCPP_INLINE_VISIBILITY front_insert_iterator operator++(int) {return *this;} |
| 703 | }; |
| 704 | |
| 705 | template <class _Container> |
| 706 | inline _LIBCPP_INLINE_VISIBILITY |
| 707 | front_insert_iterator<_Container> |
| 708 | front_inserter(_Container& __x) |
| 709 | { |
| 710 | return front_insert_iterator<_Container>(__x); |
| 711 | } |
| 712 | |
| 713 | template <class _Container> |
Howard Hinnant | 0f678bd | 2013-08-12 18:38:34 +0000 | [diff] [blame] | 714 | class _LIBCPP_TYPE_VIS_ONLY insert_iterator |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 715 | : public iterator<output_iterator_tag, |
| 716 | void, |
| 717 | void, |
| 718 | void, |
| 719 | insert_iterator<_Container>&> |
| 720 | { |
| 721 | protected: |
| 722 | _Container* container; |
| 723 | typename _Container::iterator iter; |
| 724 | public: |
| 725 | typedef _Container container_type; |
| 726 | |
| 727 | _LIBCPP_INLINE_VISIBILITY insert_iterator(_Container& __x, typename _Container::iterator __i) |
Marshall Clow | 53c0e72 | 2014-03-03 19:20:40 +0000 | [diff] [blame^] | 728 | : container(_VSTD::addressof(__x)), iter(__i) {} |
Howard Hinnant | 78b6828 | 2011-10-22 20:59:45 +0000 | [diff] [blame] | 729 | _LIBCPP_INLINE_VISIBILITY insert_iterator& operator=(const typename _Container::value_type& __value_) |
| 730 | {iter = container->insert(iter, __value_); ++iter; return *this;} |
Howard Hinnant | 73d21a4 | 2010-09-04 23:28:19 +0000 | [diff] [blame] | 731 | #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES |
Howard Hinnant | 78b6828 | 2011-10-22 20:59:45 +0000 | [diff] [blame] | 732 | _LIBCPP_INLINE_VISIBILITY insert_iterator& operator=(typename _Container::value_type&& __value_) |
| 733 | {iter = container->insert(iter, _VSTD::move(__value_)); ++iter; return *this;} |
Howard Hinnant | 73d21a4 | 2010-09-04 23:28:19 +0000 | [diff] [blame] | 734 | #endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 735 | _LIBCPP_INLINE_VISIBILITY insert_iterator& operator*() {return *this;} |
| 736 | _LIBCPP_INLINE_VISIBILITY insert_iterator& operator++() {return *this;} |
| 737 | _LIBCPP_INLINE_VISIBILITY insert_iterator& operator++(int) {return *this;} |
| 738 | }; |
| 739 | |
| 740 | template <class _Container> |
| 741 | inline _LIBCPP_INLINE_VISIBILITY |
| 742 | insert_iterator<_Container> |
| 743 | inserter(_Container& __x, typename _Container::iterator __i) |
| 744 | { |
| 745 | return insert_iterator<_Container>(__x, __i); |
| 746 | } |
| 747 | |
| 748 | template <class _Tp, class _CharT = char, |
| 749 | class _Traits = char_traits<_CharT>, class _Distance = ptrdiff_t> |
Howard Hinnant | 0f678bd | 2013-08-12 18:38:34 +0000 | [diff] [blame] | 750 | class _LIBCPP_TYPE_VIS_ONLY istream_iterator |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 751 | : public iterator<input_iterator_tag, _Tp, _Distance, const _Tp*, const _Tp&> |
| 752 | { |
| 753 | public: |
| 754 | typedef _CharT char_type; |
| 755 | typedef _Traits traits_type; |
| 756 | typedef basic_istream<_CharT,_Traits> istream_type; |
| 757 | private: |
| 758 | istream_type* __in_stream_; |
| 759 | _Tp __value_; |
| 760 | public: |
| 761 | _LIBCPP_INLINE_VISIBILITY istream_iterator() : __in_stream_(0) {} |
| 762 | _LIBCPP_INLINE_VISIBILITY istream_iterator(istream_type& __s) : __in_stream_(&__s) |
| 763 | { |
| 764 | if (!(*__in_stream_ >> __value_)) |
| 765 | __in_stream_ = 0; |
| 766 | } |
| 767 | |
| 768 | _LIBCPP_INLINE_VISIBILITY const _Tp& operator*() const {return __value_;} |
| 769 | _LIBCPP_INLINE_VISIBILITY const _Tp* operator->() const {return &(operator*());} |
| 770 | _LIBCPP_INLINE_VISIBILITY istream_iterator& operator++() |
| 771 | { |
| 772 | if (!(*__in_stream_ >> __value_)) |
| 773 | __in_stream_ = 0; |
| 774 | return *this; |
| 775 | } |
| 776 | _LIBCPP_INLINE_VISIBILITY istream_iterator operator++(int) |
| 777 | {istream_iterator __t(*this); ++(*this); return __t;} |
| 778 | |
| 779 | friend _LIBCPP_INLINE_VISIBILITY |
| 780 | bool operator==(const istream_iterator& __x, const istream_iterator& __y) |
| 781 | {return __x.__in_stream_ == __y.__in_stream_;} |
| 782 | |
| 783 | friend _LIBCPP_INLINE_VISIBILITY |
| 784 | bool operator!=(const istream_iterator& __x, const istream_iterator& __y) |
| 785 | {return !(__x == __y);} |
| 786 | }; |
| 787 | |
| 788 | template <class _Tp, class _CharT = char, class _Traits = char_traits<_CharT> > |
Howard Hinnant | 0f678bd | 2013-08-12 18:38:34 +0000 | [diff] [blame] | 789 | class _LIBCPP_TYPE_VIS_ONLY ostream_iterator |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 790 | : public iterator<output_iterator_tag, void, void, void, void> |
| 791 | { |
| 792 | public: |
| 793 | typedef _CharT char_type; |
| 794 | typedef _Traits traits_type; |
| 795 | typedef basic_ostream<_CharT,_Traits> ostream_type; |
| 796 | private: |
| 797 | ostream_type* __out_stream_; |
| 798 | const char_type* __delim_; |
| 799 | public: |
| 800 | _LIBCPP_INLINE_VISIBILITY ostream_iterator(ostream_type& __s) |
| 801 | : __out_stream_(&__s), __delim_(0) {} |
| 802 | _LIBCPP_INLINE_VISIBILITY ostream_iterator(ostream_type& __s, const _CharT* __delimiter) |
| 803 | : __out_stream_(&__s), __delim_(__delimiter) {} |
Howard Hinnant | 78b6828 | 2011-10-22 20:59:45 +0000 | [diff] [blame] | 804 | _LIBCPP_INLINE_VISIBILITY ostream_iterator& operator=(const _Tp& __value_) |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 805 | { |
Howard Hinnant | 78b6828 | 2011-10-22 20:59:45 +0000 | [diff] [blame] | 806 | *__out_stream_ << __value_; |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 807 | if (__delim_) |
| 808 | *__out_stream_ << __delim_; |
| 809 | return *this; |
| 810 | } |
| 811 | |
| 812 | _LIBCPP_INLINE_VISIBILITY ostream_iterator& operator*() {return *this;} |
| 813 | _LIBCPP_INLINE_VISIBILITY ostream_iterator& operator++() {return *this;} |
| 814 | _LIBCPP_INLINE_VISIBILITY ostream_iterator& operator++(int) {return *this;} |
| 815 | }; |
| 816 | |
| 817 | template<class _CharT, class _Traits> |
Howard Hinnant | 0f678bd | 2013-08-12 18:38:34 +0000 | [diff] [blame] | 818 | class _LIBCPP_TYPE_VIS_ONLY istreambuf_iterator |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 819 | : public iterator<input_iterator_tag, _CharT, |
| 820 | typename _Traits::off_type, _CharT*, |
| 821 | _CharT> |
| 822 | { |
| 823 | public: |
| 824 | typedef _CharT char_type; |
| 825 | typedef _Traits traits_type; |
| 826 | typedef typename _Traits::int_type int_type; |
| 827 | typedef basic_streambuf<_CharT,_Traits> streambuf_type; |
| 828 | typedef basic_istream<_CharT,_Traits> istream_type; |
| 829 | private: |
Howard Hinnant | 984f10f | 2012-11-16 22:17:23 +0000 | [diff] [blame] | 830 | mutable streambuf_type* __sbuf_; |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 831 | |
| 832 | class __proxy |
| 833 | { |
| 834 | char_type __keep_; |
| 835 | streambuf_type* __sbuf_; |
| 836 | _LIBCPP_INLINE_VISIBILITY __proxy(char_type __c, streambuf_type* __s) |
| 837 | : __keep_(__c), __sbuf_(__s) {} |
| 838 | friend class istreambuf_iterator; |
| 839 | public: |
| 840 | _LIBCPP_INLINE_VISIBILITY char_type operator*() const {return __keep_;} |
| 841 | }; |
| 842 | |
Howard Hinnant | 8289481 | 2010-09-22 16:48:34 +0000 | [diff] [blame] | 843 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 984f10f | 2012-11-16 22:17:23 +0000 | [diff] [blame] | 844 | bool __test_for_eof() const |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 845 | { |
| 846 | if (__sbuf_ && traits_type::eq_int_type(__sbuf_->sgetc(), traits_type::eof())) |
| 847 | __sbuf_ = 0; |
Howard Hinnant | 984f10f | 2012-11-16 22:17:23 +0000 | [diff] [blame] | 848 | return __sbuf_ == 0; |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 849 | } |
| 850 | public: |
Howard Hinnant | 984f10f | 2012-11-16 22:17:23 +0000 | [diff] [blame] | 851 | _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR istreambuf_iterator() _NOEXCEPT : __sbuf_(0) {} |
Howard Hinnant | d06a640 | 2012-07-20 19:36:34 +0000 | [diff] [blame] | 852 | _LIBCPP_INLINE_VISIBILITY istreambuf_iterator(istream_type& __s) _NOEXCEPT |
Howard Hinnant | d1a7479 | 2012-12-29 17:45:42 +0000 | [diff] [blame] | 853 | : __sbuf_(__s.rdbuf()) {} |
Howard Hinnant | d06a640 | 2012-07-20 19:36:34 +0000 | [diff] [blame] | 854 | _LIBCPP_INLINE_VISIBILITY istreambuf_iterator(streambuf_type* __s) _NOEXCEPT |
Howard Hinnant | d1a7479 | 2012-12-29 17:45:42 +0000 | [diff] [blame] | 855 | : __sbuf_(__s) {} |
Howard Hinnant | d06a640 | 2012-07-20 19:36:34 +0000 | [diff] [blame] | 856 | _LIBCPP_INLINE_VISIBILITY istreambuf_iterator(const __proxy& __p) _NOEXCEPT |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 857 | : __sbuf_(__p.__sbuf_) {} |
| 858 | |
Howard Hinnant | ec3773c | 2011-12-01 20:21:04 +0000 | [diff] [blame] | 859 | _LIBCPP_INLINE_VISIBILITY char_type operator*() const |
| 860 | {return static_cast<char_type>(__sbuf_->sgetc());} |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 861 | _LIBCPP_INLINE_VISIBILITY char_type* operator->() const {return nullptr;} |
| 862 | _LIBCPP_INLINE_VISIBILITY istreambuf_iterator& operator++() |
| 863 | { |
Howard Hinnant | 984f10f | 2012-11-16 22:17:23 +0000 | [diff] [blame] | 864 | __sbuf_->sbumpc(); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 865 | return *this; |
| 866 | } |
| 867 | _LIBCPP_INLINE_VISIBILITY __proxy operator++(int) |
| 868 | { |
Howard Hinnant | 984f10f | 2012-11-16 22:17:23 +0000 | [diff] [blame] | 869 | return __proxy(__sbuf_->sbumpc(), __sbuf_); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 870 | } |
| 871 | |
| 872 | _LIBCPP_INLINE_VISIBILITY bool equal(const istreambuf_iterator& __b) const |
Howard Hinnant | 984f10f | 2012-11-16 22:17:23 +0000 | [diff] [blame] | 873 | {return __test_for_eof() == __b.__test_for_eof();} |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 874 | }; |
| 875 | |
| 876 | template <class _CharT, class _Traits> |
| 877 | inline _LIBCPP_INLINE_VISIBILITY |
| 878 | bool operator==(const istreambuf_iterator<_CharT,_Traits>& __a, |
| 879 | const istreambuf_iterator<_CharT,_Traits>& __b) |
| 880 | {return __a.equal(__b);} |
| 881 | |
| 882 | template <class _CharT, class _Traits> |
| 883 | inline _LIBCPP_INLINE_VISIBILITY |
| 884 | bool operator!=(const istreambuf_iterator<_CharT,_Traits>& __a, |
| 885 | const istreambuf_iterator<_CharT,_Traits>& __b) |
| 886 | {return !__a.equal(__b);} |
| 887 | |
| 888 | template <class _CharT, class _Traits> |
Howard Hinnant | 0f678bd | 2013-08-12 18:38:34 +0000 | [diff] [blame] | 889 | class _LIBCPP_TYPE_VIS_ONLY ostreambuf_iterator |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 890 | : public iterator<output_iterator_tag, void, void, void, void> |
| 891 | { |
| 892 | public: |
| 893 | typedef _CharT char_type; |
| 894 | typedef _Traits traits_type; |
| 895 | typedef basic_streambuf<_CharT,_Traits> streambuf_type; |
| 896 | typedef basic_ostream<_CharT,_Traits> ostream_type; |
| 897 | private: |
| 898 | streambuf_type* __sbuf_; |
| 899 | public: |
Howard Hinnant | d06a640 | 2012-07-20 19:36:34 +0000 | [diff] [blame] | 900 | _LIBCPP_INLINE_VISIBILITY ostreambuf_iterator(ostream_type& __s) _NOEXCEPT |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 901 | : __sbuf_(__s.rdbuf()) {} |
Howard Hinnant | d06a640 | 2012-07-20 19:36:34 +0000 | [diff] [blame] | 902 | _LIBCPP_INLINE_VISIBILITY ostreambuf_iterator(streambuf_type* __s) _NOEXCEPT |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 903 | : __sbuf_(__s) {} |
| 904 | _LIBCPP_INLINE_VISIBILITY ostreambuf_iterator& operator=(_CharT __c) |
| 905 | { |
| 906 | if (__sbuf_ && traits_type::eq_int_type(__sbuf_->sputc(__c), traits_type::eof())) |
| 907 | __sbuf_ = 0; |
| 908 | return *this; |
| 909 | } |
| 910 | _LIBCPP_INLINE_VISIBILITY ostreambuf_iterator& operator*() {return *this;} |
| 911 | _LIBCPP_INLINE_VISIBILITY ostreambuf_iterator& operator++() {return *this;} |
| 912 | _LIBCPP_INLINE_VISIBILITY ostreambuf_iterator& operator++(int) {return *this;} |
Howard Hinnant | d06a640 | 2012-07-20 19:36:34 +0000 | [diff] [blame] | 913 | _LIBCPP_INLINE_VISIBILITY bool failed() const _NOEXCEPT {return __sbuf_ == 0;} |
Howard Hinnant | a585de6 | 2012-09-19 19:14:15 +0000 | [diff] [blame] | 914 | |
Howard Hinnant | 537b2fa | 2012-11-14 21:17:15 +0000 | [diff] [blame] | 915 | #if !defined(__APPLE__) || \ |
| 916 | (defined(__MAC_OS_X_VERSION_MIN_REQUIRED) && __MAC_OS_X_VERSION_MIN_REQUIRED > __MAC_10_8) || \ |
| 917 | (defined(__IPHONE_OS_VERSION_MIN_REQUIRED) && __IPHONE_OS_VERSION_MIN_REQUIRED > __IPHONE_6_0) |
| 918 | |
Howard Hinnant | a585de6 | 2012-09-19 19:14:15 +0000 | [diff] [blame] | 919 | template <class _Ch, class _Tr> |
| 920 | friend |
| 921 | _LIBCPP_HIDDEN |
| 922 | ostreambuf_iterator<_Ch, _Tr> |
| 923 | __pad_and_output(ostreambuf_iterator<_Ch, _Tr> __s, |
| 924 | const _Ch* __ob, const _Ch* __op, const _Ch* __oe, |
| 925 | ios_base& __iob, _Ch __fl); |
Howard Hinnant | 537b2fa | 2012-11-14 21:17:15 +0000 | [diff] [blame] | 926 | #endif |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 927 | }; |
| 928 | |
| 929 | template <class _Iter> |
Howard Hinnant | 0f678bd | 2013-08-12 18:38:34 +0000 | [diff] [blame] | 930 | class _LIBCPP_TYPE_VIS_ONLY move_iterator |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 931 | { |
| 932 | private: |
| 933 | _Iter __i; |
| 934 | public: |
| 935 | typedef _Iter iterator_type; |
| 936 | typedef typename iterator_traits<iterator_type>::iterator_category iterator_category; |
| 937 | typedef typename iterator_traits<iterator_type>::value_type value_type; |
| 938 | typedef typename iterator_traits<iterator_type>::difference_type difference_type; |
| 939 | typedef typename iterator_traits<iterator_type>::pointer pointer; |
Howard Hinnant | 73d21a4 | 2010-09-04 23:28:19 +0000 | [diff] [blame] | 940 | #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 941 | typedef value_type&& reference; |
| 942 | #else |
| 943 | typedef typename iterator_traits<iterator_type>::reference reference; |
| 944 | #endif |
Howard Hinnant | 324bb03 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 945 | |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 946 | _LIBCPP_INLINE_VISIBILITY move_iterator() : __i() {} |
| 947 | _LIBCPP_INLINE_VISIBILITY explicit move_iterator(_Iter __x) : __i(__x) {} |
| 948 | template <class _Up> _LIBCPP_INLINE_VISIBILITY move_iterator(const move_iterator<_Up>& __u) |
| 949 | : __i(__u.base()) {} |
| 950 | _LIBCPP_INLINE_VISIBILITY _Iter base() const {return __i;} |
Douglas Gregor | aab015a | 2011-01-26 00:12:48 +0000 | [diff] [blame] | 951 | _LIBCPP_INLINE_VISIBILITY reference operator*() const { |
| 952 | return static_cast<reference>(*__i); |
| 953 | } |
| 954 | _LIBCPP_INLINE_VISIBILITY pointer operator->() const { |
| 955 | typename iterator_traits<iterator_type>::reference __ref = *__i; |
| 956 | return &__ref; |
| 957 | } |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 958 | _LIBCPP_INLINE_VISIBILITY move_iterator& operator++() {++__i; return *this;} |
| 959 | _LIBCPP_INLINE_VISIBILITY move_iterator operator++(int) |
| 960 | {move_iterator __tmp(*this); ++__i; return __tmp;} |
| 961 | _LIBCPP_INLINE_VISIBILITY move_iterator& operator--() {--__i; return *this;} |
| 962 | _LIBCPP_INLINE_VISIBILITY move_iterator operator--(int) |
| 963 | {move_iterator __tmp(*this); --__i; return __tmp;} |
| 964 | _LIBCPP_INLINE_VISIBILITY move_iterator operator+ (difference_type __n) const |
| 965 | {return move_iterator(__i + __n);} |
| 966 | _LIBCPP_INLINE_VISIBILITY move_iterator& operator+=(difference_type __n) |
| 967 | {__i += __n; return *this;} |
| 968 | _LIBCPP_INLINE_VISIBILITY move_iterator operator- (difference_type __n) const |
| 969 | {return move_iterator(__i - __n);} |
| 970 | _LIBCPP_INLINE_VISIBILITY move_iterator& operator-=(difference_type __n) |
| 971 | {__i -= __n; return *this;} |
| 972 | _LIBCPP_INLINE_VISIBILITY reference operator[](difference_type __n) const |
Douglas Gregor | aab015a | 2011-01-26 00:12:48 +0000 | [diff] [blame] | 973 | { |
| 974 | return static_cast<reference>(__i[__n]); |
| 975 | } |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 976 | }; |
| 977 | |
| 978 | template <class _Iter1, class _Iter2> |
| 979 | inline _LIBCPP_INLINE_VISIBILITY |
| 980 | bool |
| 981 | operator==(const move_iterator<_Iter1>& __x, const move_iterator<_Iter2>& __y) |
| 982 | { |
| 983 | return __x.base() == __y.base(); |
| 984 | } |
| 985 | |
| 986 | template <class _Iter1, class _Iter2> |
| 987 | inline _LIBCPP_INLINE_VISIBILITY |
| 988 | bool |
| 989 | operator<(const move_iterator<_Iter1>& __x, const move_iterator<_Iter2>& __y) |
| 990 | { |
| 991 | return __x.base() < __y.base(); |
| 992 | } |
| 993 | |
| 994 | template <class _Iter1, class _Iter2> |
| 995 | inline _LIBCPP_INLINE_VISIBILITY |
| 996 | bool |
| 997 | operator!=(const move_iterator<_Iter1>& __x, const move_iterator<_Iter2>& __y) |
| 998 | { |
| 999 | return __x.base() != __y.base(); |
| 1000 | } |
| 1001 | |
| 1002 | template <class _Iter1, class _Iter2> |
| 1003 | inline _LIBCPP_INLINE_VISIBILITY |
| 1004 | bool |
| 1005 | operator>(const move_iterator<_Iter1>& __x, const move_iterator<_Iter2>& __y) |
| 1006 | { |
| 1007 | return __x.base() > __y.base(); |
| 1008 | } |
| 1009 | |
| 1010 | template <class _Iter1, class _Iter2> |
| 1011 | inline _LIBCPP_INLINE_VISIBILITY |
| 1012 | bool |
| 1013 | operator>=(const move_iterator<_Iter1>& __x, const move_iterator<_Iter2>& __y) |
| 1014 | { |
| 1015 | return __x.base() >= __y.base(); |
| 1016 | } |
| 1017 | |
| 1018 | template <class _Iter1, class _Iter2> |
| 1019 | inline _LIBCPP_INLINE_VISIBILITY |
| 1020 | bool |
| 1021 | operator<=(const move_iterator<_Iter1>& __x, const move_iterator<_Iter2>& __y) |
| 1022 | { |
| 1023 | return __x.base() <= __y.base(); |
| 1024 | } |
| 1025 | |
| 1026 | template <class _Iter1, class _Iter2> |
| 1027 | inline _LIBCPP_INLINE_VISIBILITY |
| 1028 | typename move_iterator<_Iter1>::difference_type |
| 1029 | operator-(const move_iterator<_Iter1>& __x, const move_iterator<_Iter2>& __y) |
| 1030 | { |
| 1031 | return __x.base() - __y.base(); |
| 1032 | } |
| 1033 | |
| 1034 | template <class _Iter> |
| 1035 | inline _LIBCPP_INLINE_VISIBILITY |
| 1036 | move_iterator<_Iter> |
| 1037 | operator+(typename move_iterator<_Iter>::difference_type __n, const move_iterator<_Iter>& __x) |
| 1038 | { |
| 1039 | return move_iterator<_Iter>(__x.base() + __n); |
| 1040 | } |
| 1041 | |
| 1042 | template <class _Iter> |
| 1043 | inline _LIBCPP_INLINE_VISIBILITY |
| 1044 | move_iterator<_Iter> |
Marshall Clow | af74651 | 2013-08-27 13:03:03 +0000 | [diff] [blame] | 1045 | make_move_iterator(_Iter __i) |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1046 | { |
| 1047 | return move_iterator<_Iter>(__i); |
| 1048 | } |
| 1049 | |
| 1050 | // __wrap_iter |
| 1051 | |
| 1052 | template <class _Iter> class __wrap_iter; |
| 1053 | |
| 1054 | template <class _Iter1, class _Iter2> |
Howard Hinnant | 33be35e | 2012-09-14 00:39:16 +0000 | [diff] [blame] | 1055 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1056 | bool |
Howard Hinnant | a6119a8 | 2011-05-29 19:57:12 +0000 | [diff] [blame] | 1057 | operator==(const __wrap_iter<_Iter1>&, const __wrap_iter<_Iter2>&) _NOEXCEPT; |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1058 | |
| 1059 | template <class _Iter1, class _Iter2> |
Howard Hinnant | 33be35e | 2012-09-14 00:39:16 +0000 | [diff] [blame] | 1060 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1061 | bool |
Howard Hinnant | a6119a8 | 2011-05-29 19:57:12 +0000 | [diff] [blame] | 1062 | operator<(const __wrap_iter<_Iter1>&, const __wrap_iter<_Iter2>&) _NOEXCEPT; |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1063 | |
| 1064 | template <class _Iter1, class _Iter2> |
Howard Hinnant | 33be35e | 2012-09-14 00:39:16 +0000 | [diff] [blame] | 1065 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1066 | bool |
Howard Hinnant | a6119a8 | 2011-05-29 19:57:12 +0000 | [diff] [blame] | 1067 | operator!=(const __wrap_iter<_Iter1>&, const __wrap_iter<_Iter2>&) _NOEXCEPT; |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1068 | |
| 1069 | template <class _Iter1, class _Iter2> |
Howard Hinnant | 33be35e | 2012-09-14 00:39:16 +0000 | [diff] [blame] | 1070 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1071 | bool |
Howard Hinnant | a6119a8 | 2011-05-29 19:57:12 +0000 | [diff] [blame] | 1072 | operator>(const __wrap_iter<_Iter1>&, const __wrap_iter<_Iter2>&) _NOEXCEPT; |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1073 | |
| 1074 | template <class _Iter1, class _Iter2> |
Howard Hinnant | 33be35e | 2012-09-14 00:39:16 +0000 | [diff] [blame] | 1075 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1076 | bool |
Howard Hinnant | a6119a8 | 2011-05-29 19:57:12 +0000 | [diff] [blame] | 1077 | operator>=(const __wrap_iter<_Iter1>&, const __wrap_iter<_Iter2>&) _NOEXCEPT; |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1078 | |
| 1079 | template <class _Iter1, class _Iter2> |
Howard Hinnant | 33be35e | 2012-09-14 00:39:16 +0000 | [diff] [blame] | 1080 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1081 | bool |
Howard Hinnant | a6119a8 | 2011-05-29 19:57:12 +0000 | [diff] [blame] | 1082 | operator<=(const __wrap_iter<_Iter1>&, const __wrap_iter<_Iter2>&) _NOEXCEPT; |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1083 | |
| 1084 | template <class _Iter1, class _Iter2> |
Howard Hinnant | 33be35e | 2012-09-14 00:39:16 +0000 | [diff] [blame] | 1085 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1086 | typename __wrap_iter<_Iter1>::difference_type |
Howard Hinnant | a6119a8 | 2011-05-29 19:57:12 +0000 | [diff] [blame] | 1087 | operator-(const __wrap_iter<_Iter1>&, const __wrap_iter<_Iter2>&) _NOEXCEPT; |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1088 | |
| 1089 | template <class _Iter> |
Howard Hinnant | 33be35e | 2012-09-14 00:39:16 +0000 | [diff] [blame] | 1090 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1091 | __wrap_iter<_Iter> |
Howard Hinnant | 2baccd8 | 2011-10-11 21:28:38 +0000 | [diff] [blame] | 1092 | operator+(typename __wrap_iter<_Iter>::difference_type, __wrap_iter<_Iter>) _NOEXCEPT; |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1093 | |
Howard Hinnant | 33be35e | 2012-09-14 00:39:16 +0000 | [diff] [blame] | 1094 | template <class _Ip, class _Op> _Op _LIBCPP_INLINE_VISIBILITY copy(_Ip, _Ip, _Op); |
| 1095 | template <class _B1, class _B2> _B2 _LIBCPP_INLINE_VISIBILITY copy_backward(_B1, _B1, _B2); |
| 1096 | template <class _Ip, class _Op> _Op _LIBCPP_INLINE_VISIBILITY move(_Ip, _Ip, _Op); |
| 1097 | 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] | 1098 | |
| 1099 | template <class _Tp> |
Howard Hinnant | 33be35e | 2012-09-14 00:39:16 +0000 | [diff] [blame] | 1100 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1101 | typename enable_if |
| 1102 | < |
Howard Hinnant | 1468b66 | 2010-11-19 22:17:28 +0000 | [diff] [blame] | 1103 | is_trivially_copy_assignable<_Tp>::value, |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1104 | _Tp* |
| 1105 | >::type |
| 1106 | __unwrap_iter(__wrap_iter<_Tp*>); |
| 1107 | |
| 1108 | template <class _Iter> |
| 1109 | class __wrap_iter |
| 1110 | { |
| 1111 | public: |
| 1112 | typedef _Iter iterator_type; |
| 1113 | typedef typename iterator_traits<iterator_type>::iterator_category iterator_category; |
| 1114 | typedef typename iterator_traits<iterator_type>::value_type value_type; |
| 1115 | typedef typename iterator_traits<iterator_type>::difference_type difference_type; |
| 1116 | typedef typename iterator_traits<iterator_type>::pointer pointer; |
| 1117 | typedef typename iterator_traits<iterator_type>::reference reference; |
| 1118 | private: |
| 1119 | iterator_type __i; |
| 1120 | public: |
Howard Hinnant | 7608b4a | 2011-09-16 19:52:23 +0000 | [diff] [blame] | 1121 | _LIBCPP_INLINE_VISIBILITY __wrap_iter() _NOEXCEPT |
Marshall Clow | 0f164c9 | 2013-08-07 20:48:48 +0000 | [diff] [blame] | 1122 | #if _LIBCPP_STD_VER > 11 |
| 1123 | : __i{} |
| 1124 | #endif |
Howard Hinnant | 7608b4a | 2011-09-16 19:52:23 +0000 | [diff] [blame] | 1125 | { |
| 1126 | #if _LIBCPP_DEBUG_LEVEL >= 2 |
| 1127 | __get_db()->__insert_i(this); |
| 1128 | #endif |
| 1129 | } |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1130 | 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] | 1131 | typename enable_if<is_convertible<_Up, iterator_type>::value>::type* = 0) _NOEXCEPT |
Howard Hinnant | 7a563db | 2011-09-14 18:33:51 +0000 | [diff] [blame] | 1132 | : __i(__u.base()) |
| 1133 | { |
Howard Hinnant | abe2628 | 2011-09-16 17:29:17 +0000 | [diff] [blame] | 1134 | #if _LIBCPP_DEBUG_LEVEL >= 2 |
Howard Hinnant | 7a563db | 2011-09-14 18:33:51 +0000 | [diff] [blame] | 1135 | __get_db()->__iterator_copy(this, &__u); |
| 1136 | #endif |
| 1137 | } |
Howard Hinnant | abe2628 | 2011-09-16 17:29:17 +0000 | [diff] [blame] | 1138 | #if _LIBCPP_DEBUG_LEVEL >= 2 |
Howard Hinnant | 7a563db | 2011-09-14 18:33:51 +0000 | [diff] [blame] | 1139 | _LIBCPP_INLINE_VISIBILITY |
| 1140 | __wrap_iter(const __wrap_iter& __x) |
| 1141 | : __i(__x.base()) |
| 1142 | { |
| 1143 | __get_db()->__iterator_copy(this, &__x); |
| 1144 | } |
| 1145 | _LIBCPP_INLINE_VISIBILITY |
| 1146 | __wrap_iter& operator=(const __wrap_iter& __x) |
| 1147 | { |
| 1148 | if (this != &__x) |
| 1149 | { |
| 1150 | __get_db()->__iterator_copy(this, &__x); |
| 1151 | __i = __x.__i; |
| 1152 | } |
| 1153 | return *this; |
| 1154 | } |
| 1155 | _LIBCPP_INLINE_VISIBILITY |
| 1156 | ~__wrap_iter() |
| 1157 | { |
| 1158 | __get_db()->__erase_i(this); |
| 1159 | } |
| 1160 | #endif |
| 1161 | _LIBCPP_INLINE_VISIBILITY reference operator*() const _NOEXCEPT |
| 1162 | { |
Howard Hinnant | abe2628 | 2011-09-16 17:29:17 +0000 | [diff] [blame] | 1163 | #if _LIBCPP_DEBUG_LEVEL >= 2 |
Howard Hinnant | 7a563db | 2011-09-14 18:33:51 +0000 | [diff] [blame] | 1164 | _LIBCPP_ASSERT(__get_const_db()->__dereferenceable(this), |
| 1165 | "Attempted to dereference a non-dereferenceable iterator"); |
Howard Hinnant | abe2628 | 2011-09-16 17:29:17 +0000 | [diff] [blame] | 1166 | #endif |
Howard Hinnant | 7a563db | 2011-09-14 18:33:51 +0000 | [diff] [blame] | 1167 | return *__i; |
| 1168 | } |
Howard Hinnant | 2c39cbe | 2013-06-27 19:35:32 +0000 | [diff] [blame] | 1169 | _LIBCPP_INLINE_VISIBILITY pointer operator->() const _NOEXCEPT |
| 1170 | { |
| 1171 | #if _LIBCPP_DEBUG_LEVEL >= 2 |
| 1172 | _LIBCPP_ASSERT(__get_const_db()->__dereferenceable(this), |
| 1173 | "Attempted to dereference a non-dereferenceable iterator"); |
| 1174 | #endif |
| 1175 | return (pointer)&reinterpret_cast<const volatile char&>(*__i); |
| 1176 | } |
Howard Hinnant | 7a563db | 2011-09-14 18:33:51 +0000 | [diff] [blame] | 1177 | _LIBCPP_INLINE_VISIBILITY __wrap_iter& operator++() _NOEXCEPT |
| 1178 | { |
Howard Hinnant | abe2628 | 2011-09-16 17:29:17 +0000 | [diff] [blame] | 1179 | #if _LIBCPP_DEBUG_LEVEL >= 2 |
Howard Hinnant | 7a563db | 2011-09-14 18:33:51 +0000 | [diff] [blame] | 1180 | _LIBCPP_ASSERT(__get_const_db()->__dereferenceable(this), |
| 1181 | "Attempted to increment non-incrementable iterator"); |
Howard Hinnant | abe2628 | 2011-09-16 17:29:17 +0000 | [diff] [blame] | 1182 | #endif |
Howard Hinnant | 7a563db | 2011-09-14 18:33:51 +0000 | [diff] [blame] | 1183 | ++__i; |
| 1184 | return *this; |
| 1185 | } |
Howard Hinnant | a6119a8 | 2011-05-29 19:57:12 +0000 | [diff] [blame] | 1186 | _LIBCPP_INLINE_VISIBILITY __wrap_iter operator++(int) _NOEXCEPT |
Howard Hinnant | 7a563db | 2011-09-14 18:33:51 +0000 | [diff] [blame] | 1187 | {__wrap_iter __tmp(*this); ++(*this); return __tmp;} |
| 1188 | _LIBCPP_INLINE_VISIBILITY __wrap_iter& operator--() _NOEXCEPT |
| 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()->__decrementable(this), |
| 1192 | "Attempted to decrement non-decrementable iterator"); |
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 | --__i; |
| 1195 | return *this; |
| 1196 | } |
Howard Hinnant | a6119a8 | 2011-05-29 19:57:12 +0000 | [diff] [blame] | 1197 | _LIBCPP_INLINE_VISIBILITY __wrap_iter operator--(int) _NOEXCEPT |
Howard Hinnant | 7a563db | 2011-09-14 18:33:51 +0000 | [diff] [blame] | 1198 | {__wrap_iter __tmp(*this); --(*this); return __tmp;} |
Howard Hinnant | a6119a8 | 2011-05-29 19:57:12 +0000 | [diff] [blame] | 1199 | _LIBCPP_INLINE_VISIBILITY __wrap_iter operator+ (difference_type __n) const _NOEXCEPT |
Howard Hinnant | 7a563db | 2011-09-14 18:33:51 +0000 | [diff] [blame] | 1200 | {__wrap_iter __w(*this); __w += __n; return __w;} |
Howard Hinnant | a6119a8 | 2011-05-29 19:57:12 +0000 | [diff] [blame] | 1201 | _LIBCPP_INLINE_VISIBILITY __wrap_iter& operator+=(difference_type __n) _NOEXCEPT |
Howard Hinnant | 7a563db | 2011-09-14 18:33:51 +0000 | [diff] [blame] | 1202 | { |
Howard Hinnant | abe2628 | 2011-09-16 17:29:17 +0000 | [diff] [blame] | 1203 | #if _LIBCPP_DEBUG_LEVEL >= 2 |
Howard Hinnant | 7a563db | 2011-09-14 18:33:51 +0000 | [diff] [blame] | 1204 | _LIBCPP_ASSERT(__get_const_db()->__addable(this, __n), |
| 1205 | "Attempted to add/subtract iterator outside of valid range"); |
Howard Hinnant | abe2628 | 2011-09-16 17:29:17 +0000 | [diff] [blame] | 1206 | #endif |
Howard Hinnant | 7a563db | 2011-09-14 18:33:51 +0000 | [diff] [blame] | 1207 | __i += __n; |
| 1208 | return *this; |
| 1209 | } |
Howard Hinnant | a6119a8 | 2011-05-29 19:57:12 +0000 | [diff] [blame] | 1210 | _LIBCPP_INLINE_VISIBILITY __wrap_iter operator- (difference_type __n) const _NOEXCEPT |
Howard Hinnant | 7a563db | 2011-09-14 18:33:51 +0000 | [diff] [blame] | 1211 | {return *this + (-__n);} |
Howard Hinnant | a6119a8 | 2011-05-29 19:57:12 +0000 | [diff] [blame] | 1212 | _LIBCPP_INLINE_VISIBILITY __wrap_iter& operator-=(difference_type __n) _NOEXCEPT |
Howard Hinnant | 7a563db | 2011-09-14 18:33:51 +0000 | [diff] [blame] | 1213 | {*this += -__n; return *this;} |
Howard Hinnant | a6119a8 | 2011-05-29 19:57:12 +0000 | [diff] [blame] | 1214 | _LIBCPP_INLINE_VISIBILITY reference operator[](difference_type __n) const _NOEXCEPT |
Howard Hinnant | 7a563db | 2011-09-14 18:33:51 +0000 | [diff] [blame] | 1215 | { |
Howard Hinnant | abe2628 | 2011-09-16 17:29:17 +0000 | [diff] [blame] | 1216 | #if _LIBCPP_DEBUG_LEVEL >= 2 |
Howard Hinnant | 7a563db | 2011-09-14 18:33:51 +0000 | [diff] [blame] | 1217 | _LIBCPP_ASSERT(__get_const_db()->__subscriptable(this, __n), |
| 1218 | "Attempted to subscript iterator outside of valid range"); |
Howard Hinnant | abe2628 | 2011-09-16 17:29:17 +0000 | [diff] [blame] | 1219 | #endif |
Howard Hinnant | 7a563db | 2011-09-14 18:33:51 +0000 | [diff] [blame] | 1220 | return __i[__n]; |
| 1221 | } |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1222 | |
Howard Hinnant | a6119a8 | 2011-05-29 19:57:12 +0000 | [diff] [blame] | 1223 | _LIBCPP_INLINE_VISIBILITY iterator_type base() const _NOEXCEPT {return __i;} |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1224 | |
| 1225 | private: |
Howard Hinnant | abe2628 | 2011-09-16 17:29:17 +0000 | [diff] [blame] | 1226 | #if _LIBCPP_DEBUG_LEVEL >= 2 |
Howard Hinnant | 7a563db | 2011-09-14 18:33:51 +0000 | [diff] [blame] | 1227 | _LIBCPP_INLINE_VISIBILITY __wrap_iter(const void* __p, iterator_type __x) : __i(__x) |
| 1228 | { |
| 1229 | __get_db()->__insert_ic(this, __p); |
| 1230 | } |
Howard Hinnant | 499cea1 | 2013-08-23 17:37:05 +0000 | [diff] [blame] | 1231 | #else |
| 1232 | _LIBCPP_INLINE_VISIBILITY __wrap_iter(iterator_type __x) _NOEXCEPT : __i(__x) {} |
Howard Hinnant | 7a563db | 2011-09-14 18:33:51 +0000 | [diff] [blame] | 1233 | #endif |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1234 | |
| 1235 | template <class _Up> friend class __wrap_iter; |
| 1236 | template <class _CharT, class _Traits, class _Alloc> friend class basic_string; |
| 1237 | template <class _Tp, class _Alloc> friend class vector; |
| 1238 | |
| 1239 | template <class _Iter1, class _Iter2> |
| 1240 | friend |
| 1241 | bool |
Howard Hinnant | a6119a8 | 2011-05-29 19:57:12 +0000 | [diff] [blame] | 1242 | operator==(const __wrap_iter<_Iter1>&, const __wrap_iter<_Iter2>&) _NOEXCEPT; |
Howard Hinnant | 324bb03 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 1243 | |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1244 | template <class _Iter1, class _Iter2> |
| 1245 | friend |
| 1246 | bool |
Howard Hinnant | a6119a8 | 2011-05-29 19:57:12 +0000 | [diff] [blame] | 1247 | operator<(const __wrap_iter<_Iter1>&, const __wrap_iter<_Iter2>&) _NOEXCEPT; |
Howard Hinnant | 324bb03 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 1248 | |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1249 | template <class _Iter1, class _Iter2> |
| 1250 | friend |
| 1251 | bool |
Howard Hinnant | a6119a8 | 2011-05-29 19:57:12 +0000 | [diff] [blame] | 1252 | operator!=(const __wrap_iter<_Iter1>&, const __wrap_iter<_Iter2>&) _NOEXCEPT; |
Howard Hinnant | 324bb03 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 1253 | |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1254 | template <class _Iter1, class _Iter2> |
| 1255 | friend |
| 1256 | bool |
Howard Hinnant | a6119a8 | 2011-05-29 19:57:12 +0000 | [diff] [blame] | 1257 | operator>(const __wrap_iter<_Iter1>&, const __wrap_iter<_Iter2>&) _NOEXCEPT; |
Howard Hinnant | 324bb03 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 1258 | |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1259 | template <class _Iter1, class _Iter2> |
| 1260 | friend |
| 1261 | bool |
Howard Hinnant | a6119a8 | 2011-05-29 19:57:12 +0000 | [diff] [blame] | 1262 | operator>=(const __wrap_iter<_Iter1>&, const __wrap_iter<_Iter2>&) _NOEXCEPT; |
Howard Hinnant | 324bb03 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 1263 | |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1264 | template <class _Iter1, class _Iter2> |
| 1265 | friend |
| 1266 | bool |
Howard Hinnant | a6119a8 | 2011-05-29 19:57:12 +0000 | [diff] [blame] | 1267 | operator<=(const __wrap_iter<_Iter1>&, const __wrap_iter<_Iter2>&) _NOEXCEPT; |
Howard Hinnant | 324bb03 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 1268 | |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1269 | template <class _Iter1, class _Iter2> |
| 1270 | friend |
| 1271 | typename __wrap_iter<_Iter1>::difference_type |
Howard Hinnant | a6119a8 | 2011-05-29 19:57:12 +0000 | [diff] [blame] | 1272 | operator-(const __wrap_iter<_Iter1>&, const __wrap_iter<_Iter2>&) _NOEXCEPT; |
Howard Hinnant | 324bb03 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 1273 | |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1274 | template <class _Iter1> |
| 1275 | friend |
| 1276 | __wrap_iter<_Iter1> |
Howard Hinnant | 2baccd8 | 2011-10-11 21:28:38 +0000 | [diff] [blame] | 1277 | operator+(typename __wrap_iter<_Iter1>::difference_type, __wrap_iter<_Iter1>) _NOEXCEPT; |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1278 | |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 1279 | template <class _Ip, class _Op> friend _Op copy(_Ip, _Ip, _Op); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1280 | template <class _B1, class _B2> friend _B2 copy_backward(_B1, _B1, _B2); |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 1281 | template <class _Ip, class _Op> friend _Op move(_Ip, _Ip, _Op); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1282 | template <class _B1, class _B2> friend _B2 move_backward(_B1, _B1, _B2); |
| 1283 | |
| 1284 | template <class _Tp> |
| 1285 | friend |
| 1286 | typename enable_if |
| 1287 | < |
Howard Hinnant | 1468b66 | 2010-11-19 22:17:28 +0000 | [diff] [blame] | 1288 | is_trivially_copy_assignable<_Tp>::value, |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1289 | _Tp* |
| 1290 | >::type |
| 1291 | __unwrap_iter(__wrap_iter<_Tp*>); |
| 1292 | }; |
| 1293 | |
| 1294 | template <class _Iter1, class _Iter2> |
| 1295 | inline _LIBCPP_INLINE_VISIBILITY |
| 1296 | bool |
Howard Hinnant | a6119a8 | 2011-05-29 19:57:12 +0000 | [diff] [blame] | 1297 | operator==(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter2>& __y) _NOEXCEPT |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1298 | { |
| 1299 | return __x.base() == __y.base(); |
| 1300 | } |
| 1301 | |
| 1302 | template <class _Iter1, class _Iter2> |
| 1303 | inline _LIBCPP_INLINE_VISIBILITY |
| 1304 | bool |
Howard Hinnant | a6119a8 | 2011-05-29 19:57:12 +0000 | [diff] [blame] | 1305 | operator<(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter2>& __y) _NOEXCEPT |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1306 | { |
Howard Hinnant | abe2628 | 2011-09-16 17:29:17 +0000 | [diff] [blame] | 1307 | #if _LIBCPP_DEBUG_LEVEL >= 2 |
Howard Hinnant | 8b00e6c | 2013-08-02 00:26:35 +0000 | [diff] [blame] | 1308 | _LIBCPP_ASSERT(__get_const_db()->__less_than_comparable(&__x, &__y), |
Howard Hinnant | 7a563db | 2011-09-14 18:33:51 +0000 | [diff] [blame] | 1309 | "Attempted to compare incomparable iterators"); |
Howard Hinnant | abe2628 | 2011-09-16 17:29:17 +0000 | [diff] [blame] | 1310 | #endif |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1311 | return __x.base() < __y.base(); |
| 1312 | } |
| 1313 | |
| 1314 | template <class _Iter1, class _Iter2> |
| 1315 | inline _LIBCPP_INLINE_VISIBILITY |
| 1316 | bool |
Howard Hinnant | a6119a8 | 2011-05-29 19:57:12 +0000 | [diff] [blame] | 1317 | operator!=(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter2>& __y) _NOEXCEPT |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1318 | { |
Howard Hinnant | 7a563db | 2011-09-14 18:33:51 +0000 | [diff] [blame] | 1319 | return !(__x == __y); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1320 | } |
| 1321 | |
| 1322 | template <class _Iter1, class _Iter2> |
| 1323 | inline _LIBCPP_INLINE_VISIBILITY |
| 1324 | bool |
Howard Hinnant | a6119a8 | 2011-05-29 19:57:12 +0000 | [diff] [blame] | 1325 | operator>(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter2>& __y) _NOEXCEPT |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1326 | { |
Howard Hinnant | 7a563db | 2011-09-14 18:33:51 +0000 | [diff] [blame] | 1327 | return __y < __x; |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1328 | } |
| 1329 | |
| 1330 | template <class _Iter1, class _Iter2> |
| 1331 | inline _LIBCPP_INLINE_VISIBILITY |
| 1332 | bool |
Howard Hinnant | a6119a8 | 2011-05-29 19:57:12 +0000 | [diff] [blame] | 1333 | operator>=(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter2>& __y) _NOEXCEPT |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1334 | { |
Howard Hinnant | 7a563db | 2011-09-14 18:33:51 +0000 | [diff] [blame] | 1335 | return !(__x < __y); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1336 | } |
| 1337 | |
| 1338 | template <class _Iter1, class _Iter2> |
| 1339 | inline _LIBCPP_INLINE_VISIBILITY |
| 1340 | bool |
Howard Hinnant | a6119a8 | 2011-05-29 19:57:12 +0000 | [diff] [blame] | 1341 | operator<=(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter2>& __y) _NOEXCEPT |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1342 | { |
Howard Hinnant | 7a563db | 2011-09-14 18:33:51 +0000 | [diff] [blame] | 1343 | return !(__y < __x); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1344 | } |
| 1345 | |
Howard Hinnant | 95c0e9f | 2012-10-02 19:45:42 +0000 | [diff] [blame] | 1346 | template <class _Iter1> |
| 1347 | inline _LIBCPP_INLINE_VISIBILITY |
| 1348 | bool |
| 1349 | operator!=(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter1>& __y) _NOEXCEPT |
| 1350 | { |
| 1351 | return !(__x == __y); |
| 1352 | } |
| 1353 | |
| 1354 | template <class _Iter1> |
| 1355 | inline _LIBCPP_INLINE_VISIBILITY |
| 1356 | bool |
| 1357 | operator>(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter1>& __y) _NOEXCEPT |
| 1358 | { |
| 1359 | return __y < __x; |
| 1360 | } |
| 1361 | |
| 1362 | template <class _Iter1> |
| 1363 | inline _LIBCPP_INLINE_VISIBILITY |
| 1364 | bool |
| 1365 | operator>=(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter1>& __y) _NOEXCEPT |
| 1366 | { |
| 1367 | return !(__x < __y); |
| 1368 | } |
| 1369 | |
| 1370 | template <class _Iter1> |
| 1371 | inline _LIBCPP_INLINE_VISIBILITY |
| 1372 | bool |
| 1373 | operator<=(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter1>& __y) _NOEXCEPT |
| 1374 | { |
| 1375 | return !(__y < __x); |
| 1376 | } |
| 1377 | |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1378 | template <class _Iter1, class _Iter2> |
| 1379 | inline _LIBCPP_INLINE_VISIBILITY |
| 1380 | typename __wrap_iter<_Iter1>::difference_type |
Howard Hinnant | a6119a8 | 2011-05-29 19:57:12 +0000 | [diff] [blame] | 1381 | operator-(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter2>& __y) _NOEXCEPT |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1382 | { |
Howard Hinnant | abe2628 | 2011-09-16 17:29:17 +0000 | [diff] [blame] | 1383 | #if _LIBCPP_DEBUG_LEVEL >= 2 |
Howard Hinnant | 8b00e6c | 2013-08-02 00:26:35 +0000 | [diff] [blame] | 1384 | _LIBCPP_ASSERT(__get_const_db()->__less_than_comparable(&__x, &__y), |
Howard Hinnant | 7a563db | 2011-09-14 18:33:51 +0000 | [diff] [blame] | 1385 | "Attempted to subtract incompatible iterators"); |
Howard Hinnant | abe2628 | 2011-09-16 17:29:17 +0000 | [diff] [blame] | 1386 | #endif |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1387 | return __x.base() - __y.base(); |
| 1388 | } |
| 1389 | |
| 1390 | template <class _Iter> |
| 1391 | inline _LIBCPP_INLINE_VISIBILITY |
| 1392 | __wrap_iter<_Iter> |
| 1393 | operator+(typename __wrap_iter<_Iter>::difference_type __n, |
Howard Hinnant | 7a563db | 2011-09-14 18:33:51 +0000 | [diff] [blame] | 1394 | __wrap_iter<_Iter> __x) _NOEXCEPT |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1395 | { |
Howard Hinnant | 7a563db | 2011-09-14 18:33:51 +0000 | [diff] [blame] | 1396 | __x += __n; |
| 1397 | return __x; |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1398 | } |
| 1399 | |
Marshall Clow | 6daf534 | 2013-12-02 03:24:33 +0000 | [diff] [blame] | 1400 | template <class _Tp, size_t _Np> |
Marshall Clow | 9dacb2f | 2014-02-19 17:53:30 +0000 | [diff] [blame] | 1401 | inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 |
Marshall Clow | 6daf534 | 2013-12-02 03:24:33 +0000 | [diff] [blame] | 1402 | _Tp* |
| 1403 | begin(_Tp (&__array)[_Np]) |
| 1404 | { |
| 1405 | return __array; |
| 1406 | } |
| 1407 | |
| 1408 | template <class _Tp, size_t _Np> |
Marshall Clow | 9dacb2f | 2014-02-19 17:53:30 +0000 | [diff] [blame] | 1409 | inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 |
Marshall Clow | 6daf534 | 2013-12-02 03:24:33 +0000 | [diff] [blame] | 1410 | _Tp* |
| 1411 | end(_Tp (&__array)[_Np]) |
| 1412 | { |
| 1413 | return __array + _Np; |
| 1414 | } |
| 1415 | |
Marshall Clow | 1c39869 | 2013-12-11 19:32:32 +0000 | [diff] [blame] | 1416 | #if !defined(_LIBCPP_HAS_NO_RVALUE_REFERENCES) && !defined(_LIBCPP_HAS_NO_TRAILING_RETURN) |
| 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 | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1420 | auto |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 1421 | begin(_Cp& __c) -> decltype(__c.begin()) |
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 | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1428 | auto |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 1429 | begin(const _Cp& __c) -> decltype(__c.begin()) |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1430 | { |
| 1431 | return __c.begin(); |
| 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 | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1436 | auto |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 1437 | end(_Cp& __c) -> decltype(__c.end()) |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1438 | { |
| 1439 | return __c.end(); |
| 1440 | } |
| 1441 | |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 1442 | template <class _Cp> |
Howard Hinnant | 8289481 | 2010-09-22 16:48:34 +0000 | [diff] [blame] | 1443 | inline _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1444 | auto |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 1445 | end(const _Cp& __c) -> decltype(__c.end()) |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1446 | { |
| 1447 | return __c.end(); |
| 1448 | } |
| 1449 | |
Marshall Clow | 09da3c0 | 2013-08-30 01:17:07 +0000 | [diff] [blame] | 1450 | #if _LIBCPP_STD_VER > 11 |
| 1451 | |
Marshall Clow | 6daf534 | 2013-12-02 03:24:33 +0000 | [diff] [blame] | 1452 | template <class _Tp, size_t _Np> |
| 1453 | inline _LIBCPP_INLINE_VISIBILITY |
| 1454 | reverse_iterator<_Tp*> rbegin(_Tp (&__array)[_Np]) |
| 1455 | { |
| 1456 | return reverse_iterator<_Tp*>(__array + _Np); |
| 1457 | } |
| 1458 | |
| 1459 | template <class _Tp, size_t _Np> |
| 1460 | inline _LIBCPP_INLINE_VISIBILITY |
| 1461 | reverse_iterator<_Tp*> rend(_Tp (&__array)[_Np]) |
| 1462 | { |
| 1463 | return reverse_iterator<_Tp*>(__array); |
| 1464 | } |
| 1465 | |
| 1466 | template <class _Ep> |
| 1467 | inline _LIBCPP_INLINE_VISIBILITY |
| 1468 | reverse_iterator<const _Ep*> rbegin(initializer_list<_Ep> __il) |
| 1469 | { |
| 1470 | return reverse_iterator<const _Ep*>(__il.end()); |
| 1471 | } |
| 1472 | |
| 1473 | template <class _Ep> |
| 1474 | inline _LIBCPP_INLINE_VISIBILITY |
| 1475 | reverse_iterator<const _Ep*> rend(initializer_list<_Ep> __il) |
| 1476 | { |
| 1477 | return reverse_iterator<const _Ep*>(__il.begin()); |
| 1478 | } |
| 1479 | |
Marshall Clow | 09da3c0 | 2013-08-30 01:17:07 +0000 | [diff] [blame] | 1480 | template <class _Cp> |
Marshall Clow | 9dacb2f | 2014-02-19 17:53:30 +0000 | [diff] [blame] | 1481 | inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 |
Marshall Clow | 09da3c0 | 2013-08-30 01:17:07 +0000 | [diff] [blame] | 1482 | auto cbegin(const _Cp& __c) -> decltype(begin(__c)) |
| 1483 | { |
Marshall Clow | 9dacb2f | 2014-02-19 17:53:30 +0000 | [diff] [blame] | 1484 | return begin(__c); |
Marshall Clow | 09da3c0 | 2013-08-30 01:17:07 +0000 | [diff] [blame] | 1485 | } |
| 1486 | |
| 1487 | template <class _Cp> |
Marshall Clow | 9dacb2f | 2014-02-19 17:53:30 +0000 | [diff] [blame] | 1488 | inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 |
Marshall Clow | 09da3c0 | 2013-08-30 01:17:07 +0000 | [diff] [blame] | 1489 | auto cend(const _Cp& __c) -> decltype(end(__c)) |
| 1490 | { |
Marshall Clow | 9dacb2f | 2014-02-19 17:53:30 +0000 | [diff] [blame] | 1491 | return end(__c); |
Marshall Clow | 09da3c0 | 2013-08-30 01:17:07 +0000 | [diff] [blame] | 1492 | } |
| 1493 | |
| 1494 | template <class _Cp> |
| 1495 | inline _LIBCPP_INLINE_VISIBILITY |
| 1496 | auto rbegin(_Cp& __c) -> decltype(__c.rbegin()) |
| 1497 | { |
| 1498 | return __c.rbegin(); |
| 1499 | } |
| 1500 | |
| 1501 | template <class _Cp> |
| 1502 | inline _LIBCPP_INLINE_VISIBILITY |
| 1503 | auto rbegin(const _Cp& __c) -> decltype(__c.rbegin()) |
| 1504 | { |
| 1505 | return __c.rbegin(); |
| 1506 | } |
| 1507 | |
| 1508 | template <class _Cp> |
| 1509 | inline _LIBCPP_INLINE_VISIBILITY |
| 1510 | auto rend(_Cp& __c) -> decltype(__c.rend()) |
| 1511 | { |
| 1512 | return __c.rend(); |
| 1513 | } |
| 1514 | |
| 1515 | template <class _Cp> |
| 1516 | inline _LIBCPP_INLINE_VISIBILITY |
| 1517 | auto rend(const _Cp& __c) -> decltype(__c.rend()) |
| 1518 | { |
| 1519 | return __c.rend(); |
| 1520 | } |
| 1521 | |
| 1522 | template <class _Cp> |
| 1523 | inline _LIBCPP_INLINE_VISIBILITY |
| 1524 | auto crbegin(const _Cp& __c) -> decltype(rbegin(__c)) |
| 1525 | { |
| 1526 | return rbegin(__c); |
| 1527 | } |
| 1528 | |
| 1529 | template <class _Cp> |
| 1530 | inline _LIBCPP_INLINE_VISIBILITY |
| 1531 | auto crend(const _Cp& __c) -> decltype(rend(__c)) |
| 1532 | { |
| 1533 | return rend(__c); |
| 1534 | } |
| 1535 | |
| 1536 | #endif |
| 1537 | |
| 1538 | |
Howard Hinnant | 726a76f | 2010-11-16 21:10:23 +0000 | [diff] [blame] | 1539 | #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] | 1540 | |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 1541 | template <class _Cp> |
Howard Hinnant | 8289481 | 2010-09-22 16:48:34 +0000 | [diff] [blame] | 1542 | inline _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 1543 | typename _Cp::iterator |
| 1544 | begin(_Cp& __c) |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1545 | { |
| 1546 | return __c.begin(); |
| 1547 | } |
| 1548 | |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 1549 | template <class _Cp> |
Howard Hinnant | 8289481 | 2010-09-22 16:48:34 +0000 | [diff] [blame] | 1550 | inline _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 1551 | typename _Cp::const_iterator |
| 1552 | begin(const _Cp& __c) |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1553 | { |
| 1554 | return __c.begin(); |
| 1555 | } |
| 1556 | |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 1557 | template <class _Cp> |
Howard Hinnant | 8289481 | 2010-09-22 16:48:34 +0000 | [diff] [blame] | 1558 | inline _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 1559 | typename _Cp::iterator |
| 1560 | end(_Cp& __c) |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1561 | { |
| 1562 | return __c.end(); |
| 1563 | } |
| 1564 | |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 1565 | template <class _Cp> |
Howard Hinnant | 8289481 | 2010-09-22 16:48:34 +0000 | [diff] [blame] | 1566 | inline _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 1567 | typename _Cp::const_iterator |
| 1568 | end(const _Cp& __c) |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1569 | { |
| 1570 | return __c.end(); |
| 1571 | } |
| 1572 | |
Howard Hinnant | 726a76f | 2010-11-16 21:10:23 +0000 | [diff] [blame] | 1573 | #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] | 1574 | |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1575 | _LIBCPP_END_NAMESPACE_STD |
| 1576 | |
| 1577 | #endif // _LIBCPP_ITERATOR |