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