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