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