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