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 | 0a1e750 | 2018-09-12 19:41:40 +0000 | [diff] [blame^] | 421 | #include <version> |
Marshall Clow | dde4bfe | 2013-03-18 17:45:34 +0000 | [diff] [blame] | 422 | #ifdef __APPLE__ |
Howard Hinnant | 48fd5d5 | 2012-11-14 21:17:15 +0000 | [diff] [blame] | 423 | #include <Availability.h> |
| 424 | #endif |
| 425 | |
Eric Fiselier | 14b6de9 | 2014-08-10 23:53:08 +0000 | [diff] [blame] | 426 | #include <__debug> |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 427 | |
Howard Hinnant | aaaa52b | 2011-10-17 20:05:10 +0000 | [diff] [blame] | 428 | #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 429 | #pragma GCC system_header |
Howard Hinnant | aaaa52b | 2011-10-17 20:05:10 +0000 | [diff] [blame] | 430 | #endif |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 431 | |
| 432 | _LIBCPP_BEGIN_NAMESPACE_STD |
| 433 | |
Eric Fiselier | b5eb1bf | 2017-01-04 23:56:00 +0000 | [diff] [blame] | 434 | struct _LIBCPP_TEMPLATE_VIS input_iterator_tag {}; |
| 435 | struct _LIBCPP_TEMPLATE_VIS output_iterator_tag {}; |
| 436 | struct _LIBCPP_TEMPLATE_VIS forward_iterator_tag : public input_iterator_tag {}; |
| 437 | struct _LIBCPP_TEMPLATE_VIS bidirectional_iterator_tag : public forward_iterator_tag {}; |
| 438 | struct _LIBCPP_TEMPLATE_VIS random_access_iterator_tag : public bidirectional_iterator_tag {}; |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 439 | |
| 440 | template <class _Tp> |
| 441 | struct __has_iterator_category |
| 442 | { |
| 443 | private: |
Howard Hinnant | 49e145e | 2012-10-30 19:06:59 +0000 | [diff] [blame] | 444 | struct __two {char __lx; char __lxx;}; |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 445 | template <class _Up> static __two __test(...); |
| 446 | template <class _Up> static char __test(typename _Up::iterator_category* = 0); |
| 447 | public: |
| 448 | static const bool value = sizeof(__test<_Tp>(0)) == 1; |
| 449 | }; |
| 450 | |
Marshall Clow | 75533b0 | 2014-01-03 22:55:49 +0000 | [diff] [blame] | 451 | template <class _Iter, bool> struct __iterator_traits_impl {}; |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 452 | |
| 453 | template <class _Iter> |
Marshall Clow | 75533b0 | 2014-01-03 22:55:49 +0000 | [diff] [blame] | 454 | struct __iterator_traits_impl<_Iter, true> |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 455 | { |
| 456 | typedef typename _Iter::difference_type difference_type; |
| 457 | typedef typename _Iter::value_type value_type; |
| 458 | typedef typename _Iter::pointer pointer; |
| 459 | typedef typename _Iter::reference reference; |
| 460 | typedef typename _Iter::iterator_category iterator_category; |
| 461 | }; |
| 462 | |
| 463 | template <class _Iter, bool> struct __iterator_traits {}; |
| 464 | |
| 465 | template <class _Iter> |
| 466 | struct __iterator_traits<_Iter, true> |
Marshall Clow | 75533b0 | 2014-01-03 22:55:49 +0000 | [diff] [blame] | 467 | : __iterator_traits_impl |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 468 | < |
| 469 | _Iter, |
| 470 | is_convertible<typename _Iter::iterator_category, input_iterator_tag>::value || |
| 471 | is_convertible<typename _Iter::iterator_category, output_iterator_tag>::value |
| 472 | > |
| 473 | {}; |
| 474 | |
| 475 | // iterator_traits<Iterator> will only have the nested types if Iterator::iterator_category |
| 476 | // exists. Else iterator_traits<Iterator> will be an empty class. This is a |
| 477 | // conforming extension which allows some programs to compile and behave as |
| 478 | // the client expects instead of failing at compile time. |
| 479 | |
| 480 | template <class _Iter> |
Eric Fiselier | b5eb1bf | 2017-01-04 23:56:00 +0000 | [diff] [blame] | 481 | struct _LIBCPP_TEMPLATE_VIS iterator_traits |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 482 | : __iterator_traits<_Iter, __has_iterator_category<_Iter>::value> {}; |
| 483 | |
| 484 | template<class _Tp> |
Eric Fiselier | b5eb1bf | 2017-01-04 23:56:00 +0000 | [diff] [blame] | 485 | struct _LIBCPP_TEMPLATE_VIS iterator_traits<_Tp*> |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 486 | { |
| 487 | typedef ptrdiff_t difference_type; |
Marshall Clow | 56d5352 | 2017-11-14 00:03:10 +0000 | [diff] [blame] | 488 | typedef typename remove_cv<_Tp>::type value_type; |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 489 | typedef _Tp* pointer; |
| 490 | typedef _Tp& reference; |
| 491 | typedef random_access_iterator_tag iterator_category; |
| 492 | }; |
| 493 | |
| 494 | template <class _Tp, class _Up, bool = __has_iterator_category<iterator_traits<_Tp> >::value> |
| 495 | struct __has_iterator_category_convertible_to |
| 496 | : public integral_constant<bool, is_convertible<typename iterator_traits<_Tp>::iterator_category, _Up>::value> |
| 497 | {}; |
| 498 | |
| 499 | template <class _Tp, class _Up> |
| 500 | struct __has_iterator_category_convertible_to<_Tp, _Up, false> : public false_type {}; |
| 501 | |
| 502 | template <class _Tp> |
| 503 | struct __is_input_iterator : public __has_iterator_category_convertible_to<_Tp, input_iterator_tag> {}; |
| 504 | |
| 505 | template <class _Tp> |
| 506 | struct __is_forward_iterator : public __has_iterator_category_convertible_to<_Tp, forward_iterator_tag> {}; |
| 507 | |
| 508 | template <class _Tp> |
| 509 | struct __is_bidirectional_iterator : public __has_iterator_category_convertible_to<_Tp, bidirectional_iterator_tag> {}; |
| 510 | |
| 511 | template <class _Tp> |
| 512 | struct __is_random_access_iterator : public __has_iterator_category_convertible_to<_Tp, random_access_iterator_tag> {}; |
| 513 | |
Marshall Clow | 039b2f0 | 2016-01-13 21:54:34 +0000 | [diff] [blame] | 514 | template <class _Tp> |
| 515 | struct __is_exactly_input_iterator |
| 516 | : public integral_constant<bool, |
Marshall Clow | b5f9912 | 2016-11-02 15:30:26 +0000 | [diff] [blame] | 517 | __has_iterator_category_convertible_to<_Tp, input_iterator_tag>::value && |
| 518 | !__has_iterator_category_convertible_to<_Tp, forward_iterator_tag>::value> {}; |
Marshall Clow | 039b2f0 | 2016-01-13 21:54:34 +0000 | [diff] [blame] | 519 | |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 520 | template<class _Category, class _Tp, class _Distance = ptrdiff_t, |
| 521 | class _Pointer = _Tp*, class _Reference = _Tp&> |
Eric Fiselier | b5eb1bf | 2017-01-04 23:56:00 +0000 | [diff] [blame] | 522 | struct _LIBCPP_TEMPLATE_VIS iterator |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 523 | { |
| 524 | typedef _Tp value_type; |
| 525 | typedef _Distance difference_type; |
| 526 | typedef _Pointer pointer; |
| 527 | typedef _Reference reference; |
| 528 | typedef _Category iterator_category; |
| 529 | }; |
| 530 | |
| 531 | template <class _InputIter> |
Marshall Clow | 75468e7 | 2017-05-17 18:51:36 +0000 | [diff] [blame] | 532 | inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 533 | void __advance(_InputIter& __i, |
| 534 | typename iterator_traits<_InputIter>::difference_type __n, input_iterator_tag) |
| 535 | { |
| 536 | for (; __n > 0; --__n) |
| 537 | ++__i; |
| 538 | } |
| 539 | |
| 540 | template <class _BiDirIter> |
Marshall Clow | 75468e7 | 2017-05-17 18:51:36 +0000 | [diff] [blame] | 541 | inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 542 | void __advance(_BiDirIter& __i, |
| 543 | typename iterator_traits<_BiDirIter>::difference_type __n, bidirectional_iterator_tag) |
| 544 | { |
| 545 | if (__n >= 0) |
| 546 | for (; __n > 0; --__n) |
| 547 | ++__i; |
| 548 | else |
| 549 | for (; __n < 0; ++__n) |
| 550 | --__i; |
| 551 | } |
| 552 | |
| 553 | template <class _RandIter> |
Marshall Clow | 75468e7 | 2017-05-17 18:51:36 +0000 | [diff] [blame] | 554 | inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 555 | void __advance(_RandIter& __i, |
| 556 | typename iterator_traits<_RandIter>::difference_type __n, random_access_iterator_tag) |
| 557 | { |
| 558 | __i += __n; |
| 559 | } |
| 560 | |
| 561 | template <class _InputIter> |
Marshall Clow | 75468e7 | 2017-05-17 18:51:36 +0000 | [diff] [blame] | 562 | inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 563 | void advance(_InputIter& __i, |
| 564 | typename iterator_traits<_InputIter>::difference_type __n) |
| 565 | { |
| 566 | __advance(__i, __n, typename iterator_traits<_InputIter>::iterator_category()); |
| 567 | } |
| 568 | |
| 569 | template <class _InputIter> |
Marshall Clow | 75468e7 | 2017-05-17 18:51:36 +0000 | [diff] [blame] | 570 | inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 571 | typename iterator_traits<_InputIter>::difference_type |
| 572 | __distance(_InputIter __first, _InputIter __last, input_iterator_tag) |
| 573 | { |
| 574 | typename iterator_traits<_InputIter>::difference_type __r(0); |
| 575 | for (; __first != __last; ++__first) |
| 576 | ++__r; |
| 577 | return __r; |
| 578 | } |
| 579 | |
| 580 | template <class _RandIter> |
Marshall Clow | 75468e7 | 2017-05-17 18:51:36 +0000 | [diff] [blame] | 581 | inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 582 | typename iterator_traits<_RandIter>::difference_type |
| 583 | __distance(_RandIter __first, _RandIter __last, random_access_iterator_tag) |
| 584 | { |
| 585 | return __last - __first; |
| 586 | } |
| 587 | |
| 588 | template <class _InputIter> |
Marshall Clow | 75468e7 | 2017-05-17 18:51:36 +0000 | [diff] [blame] | 589 | inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 590 | typename iterator_traits<_InputIter>::difference_type |
| 591 | distance(_InputIter __first, _InputIter __last) |
| 592 | { |
| 593 | return __distance(__first, __last, typename iterator_traits<_InputIter>::iterator_category()); |
| 594 | } |
| 595 | |
Marshall Clow | 990c70d | 2015-11-07 17:48:49 +0000 | [diff] [blame] | 596 | template <class _InputIter> |
Marshall Clow | 75468e7 | 2017-05-17 18:51:36 +0000 | [diff] [blame] | 597 | inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 |
Rachel Craik | 2048d82 | 2017-07-24 22:17:05 +0000 | [diff] [blame] | 598 | typename enable_if |
| 599 | < |
| 600 | __is_input_iterator<_InputIter>::value, |
| 601 | _InputIter |
| 602 | >::type |
Marshall Clow | 990c70d | 2015-11-07 17:48:49 +0000 | [diff] [blame] | 603 | next(_InputIter __x, |
Rachel Craik | 2048d82 | 2017-07-24 22:17:05 +0000 | [diff] [blame] | 604 | typename iterator_traits<_InputIter>::difference_type __n = 1) |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 605 | { |
Howard Hinnant | b1ad5a8 | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 606 | _VSTD::advance(__x, __n); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 607 | return __x; |
| 608 | } |
| 609 | |
Rachel Craik | 2048d82 | 2017-07-24 22:17:05 +0000 | [diff] [blame] | 610 | template <class _BidirectionalIter> |
Marshall Clow | 75468e7 | 2017-05-17 18:51:36 +0000 | [diff] [blame] | 611 | inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 |
Rachel Craik | 2048d82 | 2017-07-24 22:17:05 +0000 | [diff] [blame] | 612 | typename enable_if |
| 613 | < |
| 614 | __is_bidirectional_iterator<_BidirectionalIter>::value, |
| 615 | _BidirectionalIter |
| 616 | >::type |
| 617 | prev(_BidirectionalIter __x, |
| 618 | typename iterator_traits<_BidirectionalIter>::difference_type __n = 1) |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 619 | { |
Howard Hinnant | b1ad5a8 | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 620 | _VSTD::advance(__x, -__n); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 621 | return __x; |
| 622 | } |
| 623 | |
Eric Fiselier | 883af11 | 2017-04-13 02:54:13 +0000 | [diff] [blame] | 624 | |
| 625 | template <class _Tp, class = void> |
| 626 | struct __is_stashing_iterator : false_type {}; |
| 627 | |
| 628 | template <class _Tp> |
| 629 | struct __is_stashing_iterator<_Tp, typename __void_t<typename _Tp::__stashing_iterator_tag>::type> |
| 630 | : true_type {}; |
| 631 | |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 632 | template <class _Iter> |
Eric Fiselier | b5eb1bf | 2017-01-04 23:56:00 +0000 | [diff] [blame] | 633 | class _LIBCPP_TEMPLATE_VIS reverse_iterator |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 634 | : public iterator<typename iterator_traits<_Iter>::iterator_category, |
| 635 | typename iterator_traits<_Iter>::value_type, |
| 636 | typename iterator_traits<_Iter>::difference_type, |
| 637 | typename iterator_traits<_Iter>::pointer, |
| 638 | typename iterator_traits<_Iter>::reference> |
| 639 | { |
Marshall Clow | 0ad029e | 2014-03-11 22:05:31 +0000 | [diff] [blame] | 640 | private: |
Marshall Clow | 5ace554 | 2016-10-19 15:12:50 +0000 | [diff] [blame] | 641 | /*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] | 642 | |
| 643 | static_assert(!__is_stashing_iterator<_Iter>::value, |
| 644 | "The specified iterator type cannot be used with reverse_iterator; " |
| 645 | "Using stashing iterators with reverse_iterator causes undefined behavior"); |
| 646 | |
Marshall Clow | 1f61f0a | 2014-03-12 01:19:36 +0000 | [diff] [blame] | 647 | protected: |
| 648 | _Iter current; |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 649 | public: |
| 650 | typedef _Iter iterator_type; |
| 651 | typedef typename iterator_traits<_Iter>::difference_type difference_type; |
| 652 | typedef typename iterator_traits<_Iter>::reference reference; |
| 653 | typedef typename iterator_traits<_Iter>::pointer pointer; |
Howard Hinnant | 3b6579a | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 654 | |
Marshall Clow | 5ace554 | 2016-10-19 15:12:50 +0000 | [diff] [blame] | 655 | _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 |
| 656 | reverse_iterator() : __t(), current() {} |
| 657 | _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 |
| 658 | explicit reverse_iterator(_Iter __x) : __t(__x), current(__x) {} |
| 659 | template <class _Up> |
| 660 | _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 |
| 661 | reverse_iterator(const reverse_iterator<_Up>& __u) : __t(__u.base()), current(__u.base()) {} |
| 662 | template <class _Up> |
| 663 | _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 |
| 664 | reverse_iterator& operator=(const reverse_iterator<_Up>& __u) |
| 665 | { __t = current = __u.base(); return *this; } |
| 666 | _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 |
| 667 | _Iter base() const {return current;} |
| 668 | _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 |
| 669 | reference operator*() const {_Iter __tmp = current; return *--__tmp;} |
| 670 | _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 |
| 671 | pointer operator->() const {return _VSTD::addressof(operator*());} |
| 672 | _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 |
| 673 | reverse_iterator& operator++() {--current; return *this;} |
| 674 | _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 |
| 675 | reverse_iterator operator++(int) {reverse_iterator __tmp(*this); --current; return __tmp;} |
| 676 | _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 |
| 677 | reverse_iterator& operator--() {++current; return *this;} |
| 678 | _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 |
| 679 | reverse_iterator operator--(int) {reverse_iterator __tmp(*this); ++current; return __tmp;} |
| 680 | _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 |
| 681 | reverse_iterator operator+ (difference_type __n) const {return reverse_iterator(current - __n);} |
| 682 | _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 |
| 683 | reverse_iterator& operator+=(difference_type __n) {current -= __n; return *this;} |
| 684 | _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 |
| 685 | reverse_iterator operator- (difference_type __n) const {return reverse_iterator(current + __n);} |
| 686 | _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 |
| 687 | reverse_iterator& operator-=(difference_type __n) {current += __n; return *this;} |
| 688 | _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 |
| 689 | reference operator[](difference_type __n) const {return *(*this + __n);} |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 690 | }; |
| 691 | |
| 692 | template <class _Iter1, class _Iter2> |
Marshall Clow | 5ace554 | 2016-10-19 15:12:50 +0000 | [diff] [blame] | 693 | inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 694 | bool |
| 695 | operator==(const reverse_iterator<_Iter1>& __x, const reverse_iterator<_Iter2>& __y) |
| 696 | { |
| 697 | return __x.base() == __y.base(); |
| 698 | } |
| 699 | |
| 700 | template <class _Iter1, class _Iter2> |
Marshall Clow | 5ace554 | 2016-10-19 15:12:50 +0000 | [diff] [blame] | 701 | inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 702 | bool |
| 703 | operator<(const reverse_iterator<_Iter1>& __x, const reverse_iterator<_Iter2>& __y) |
| 704 | { |
| 705 | return __x.base() > __y.base(); |
| 706 | } |
| 707 | |
| 708 | template <class _Iter1, class _Iter2> |
Marshall Clow | 5ace554 | 2016-10-19 15:12:50 +0000 | [diff] [blame] | 709 | inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 710 | bool |
| 711 | operator!=(const reverse_iterator<_Iter1>& __x, const reverse_iterator<_Iter2>& __y) |
| 712 | { |
| 713 | return __x.base() != __y.base(); |
| 714 | } |
| 715 | |
| 716 | template <class _Iter1, class _Iter2> |
Marshall Clow | 5ace554 | 2016-10-19 15:12:50 +0000 | [diff] [blame] | 717 | inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 718 | bool |
| 719 | operator>(const reverse_iterator<_Iter1>& __x, const reverse_iterator<_Iter2>& __y) |
| 720 | { |
| 721 | return __x.base() < __y.base(); |
| 722 | } |
| 723 | |
| 724 | template <class _Iter1, class _Iter2> |
Marshall Clow | 5ace554 | 2016-10-19 15:12:50 +0000 | [diff] [blame] | 725 | inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 726 | bool |
| 727 | operator>=(const reverse_iterator<_Iter1>& __x, const reverse_iterator<_Iter2>& __y) |
| 728 | { |
| 729 | return __x.base() <= __y.base(); |
| 730 | } |
| 731 | |
| 732 | template <class _Iter1, class _Iter2> |
Marshall Clow | 5ace554 | 2016-10-19 15:12:50 +0000 | [diff] [blame] | 733 | inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 734 | bool |
| 735 | operator<=(const reverse_iterator<_Iter1>& __x, const reverse_iterator<_Iter2>& __y) |
| 736 | { |
| 737 | return __x.base() >= __y.base(); |
| 738 | } |
| 739 | |
Marshall Clow | 476d3f4 | 2016-07-18 13:19:00 +0000 | [diff] [blame] | 740 | #ifndef _LIBCPP_CXX03_LANG |
Marshall Clow | f8fec4e | 2016-07-08 16:54:47 +0000 | [diff] [blame] | 741 | template <class _Iter1, class _Iter2> |
Marshall Clow | 5ace554 | 2016-10-19 15:12:50 +0000 | [diff] [blame] | 742 | inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 |
Marshall Clow | f8fec4e | 2016-07-08 16:54:47 +0000 | [diff] [blame] | 743 | auto |
| 744 | operator-(const reverse_iterator<_Iter1>& __x, const reverse_iterator<_Iter2>& __y) |
| 745 | -> decltype(__y.base() - __x.base()) |
| 746 | { |
| 747 | return __y.base() - __x.base(); |
| 748 | } |
| 749 | #else |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 750 | template <class _Iter1, class _Iter2> |
| 751 | inline _LIBCPP_INLINE_VISIBILITY |
| 752 | typename reverse_iterator<_Iter1>::difference_type |
| 753 | operator-(const reverse_iterator<_Iter1>& __x, const reverse_iterator<_Iter2>& __y) |
| 754 | { |
| 755 | return __y.base() - __x.base(); |
| 756 | } |
Marshall Clow | f8fec4e | 2016-07-08 16:54:47 +0000 | [diff] [blame] | 757 | #endif |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 758 | |
| 759 | template <class _Iter> |
Marshall Clow | 5ace554 | 2016-10-19 15:12:50 +0000 | [diff] [blame] | 760 | inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 761 | reverse_iterator<_Iter> |
| 762 | operator+(typename reverse_iterator<_Iter>::difference_type __n, const reverse_iterator<_Iter>& __x) |
| 763 | { |
| 764 | return reverse_iterator<_Iter>(__x.base() - __n); |
| 765 | } |
| 766 | |
Marshall Clow | 6dbbdc9 | 2014-03-03 01:24:04 +0000 | [diff] [blame] | 767 | #if _LIBCPP_STD_VER > 11 |
| 768 | template <class _Iter> |
Marshall Clow | 5ace554 | 2016-10-19 15:12:50 +0000 | [diff] [blame] | 769 | inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 |
Marshall Clow | 6dbbdc9 | 2014-03-03 01:24:04 +0000 | [diff] [blame] | 770 | reverse_iterator<_Iter> make_reverse_iterator(_Iter __i) |
| 771 | { |
| 772 | return reverse_iterator<_Iter>(__i); |
| 773 | } |
| 774 | #endif |
| 775 | |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 776 | template <class _Container> |
Eric Fiselier | b5eb1bf | 2017-01-04 23:56:00 +0000 | [diff] [blame] | 777 | class _LIBCPP_TEMPLATE_VIS back_insert_iterator |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 778 | : public iterator<output_iterator_tag, |
| 779 | void, |
| 780 | void, |
| 781 | void, |
Eric Fiselier | 9aeea87 | 2016-06-30 04:40:50 +0000 | [diff] [blame] | 782 | void> |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 783 | { |
| 784 | protected: |
| 785 | _Container* container; |
| 786 | public: |
| 787 | typedef _Container container_type; |
| 788 | |
Marshall Clow | cef3168 | 2014-03-03 19:20:40 +0000 | [diff] [blame] | 789 | _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] | 790 | _LIBCPP_INLINE_VISIBILITY back_insert_iterator& operator=(const typename _Container::value_type& __value_) |
| 791 | {container->push_back(__value_); return *this;} |
Eric Fiselier | f07d88c | 2017-04-19 01:34:08 +0000 | [diff] [blame] | 792 | #ifndef _LIBCPP_CXX03_LANG |
Howard Hinnant | bf07402 | 2011-10-22 20:59:45 +0000 | [diff] [blame] | 793 | _LIBCPP_INLINE_VISIBILITY back_insert_iterator& operator=(typename _Container::value_type&& __value_) |
| 794 | {container->push_back(_VSTD::move(__value_)); return *this;} |
Eric Fiselier | f07d88c | 2017-04-19 01:34:08 +0000 | [diff] [blame] | 795 | #endif // _LIBCPP_CXX03_LANG |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 796 | _LIBCPP_INLINE_VISIBILITY back_insert_iterator& operator*() {return *this;} |
| 797 | _LIBCPP_INLINE_VISIBILITY back_insert_iterator& operator++() {return *this;} |
| 798 | _LIBCPP_INLINE_VISIBILITY back_insert_iterator operator++(int) {return *this;} |
| 799 | }; |
| 800 | |
| 801 | template <class _Container> |
| 802 | inline _LIBCPP_INLINE_VISIBILITY |
| 803 | back_insert_iterator<_Container> |
| 804 | back_inserter(_Container& __x) |
| 805 | { |
| 806 | return back_insert_iterator<_Container>(__x); |
| 807 | } |
| 808 | |
| 809 | template <class _Container> |
Eric Fiselier | b5eb1bf | 2017-01-04 23:56:00 +0000 | [diff] [blame] | 810 | class _LIBCPP_TEMPLATE_VIS front_insert_iterator |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 811 | : public iterator<output_iterator_tag, |
| 812 | void, |
| 813 | void, |
| 814 | void, |
Eric Fiselier | 9aeea87 | 2016-06-30 04:40:50 +0000 | [diff] [blame] | 815 | void> |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 816 | { |
| 817 | protected: |
| 818 | _Container* container; |
| 819 | public: |
| 820 | typedef _Container container_type; |
| 821 | |
Marshall Clow | cef3168 | 2014-03-03 19:20:40 +0000 | [diff] [blame] | 822 | _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] | 823 | _LIBCPP_INLINE_VISIBILITY front_insert_iterator& operator=(const typename _Container::value_type& __value_) |
| 824 | {container->push_front(__value_); return *this;} |
Eric Fiselier | f07d88c | 2017-04-19 01:34:08 +0000 | [diff] [blame] | 825 | #ifndef _LIBCPP_CXX03_LANG |
Howard Hinnant | bf07402 | 2011-10-22 20:59:45 +0000 | [diff] [blame] | 826 | _LIBCPP_INLINE_VISIBILITY front_insert_iterator& operator=(typename _Container::value_type&& __value_) |
| 827 | {container->push_front(_VSTD::move(__value_)); return *this;} |
Eric Fiselier | f07d88c | 2017-04-19 01:34:08 +0000 | [diff] [blame] | 828 | #endif // _LIBCPP_CXX03_LANG |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 829 | _LIBCPP_INLINE_VISIBILITY front_insert_iterator& operator*() {return *this;} |
| 830 | _LIBCPP_INLINE_VISIBILITY front_insert_iterator& operator++() {return *this;} |
| 831 | _LIBCPP_INLINE_VISIBILITY front_insert_iterator operator++(int) {return *this;} |
| 832 | }; |
| 833 | |
| 834 | template <class _Container> |
| 835 | inline _LIBCPP_INLINE_VISIBILITY |
| 836 | front_insert_iterator<_Container> |
| 837 | front_inserter(_Container& __x) |
| 838 | { |
| 839 | return front_insert_iterator<_Container>(__x); |
| 840 | } |
| 841 | |
| 842 | template <class _Container> |
Eric Fiselier | b5eb1bf | 2017-01-04 23:56:00 +0000 | [diff] [blame] | 843 | class _LIBCPP_TEMPLATE_VIS insert_iterator |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 844 | : public iterator<output_iterator_tag, |
| 845 | void, |
| 846 | void, |
| 847 | void, |
Eric Fiselier | 9aeea87 | 2016-06-30 04:40:50 +0000 | [diff] [blame] | 848 | void> |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 849 | { |
| 850 | protected: |
| 851 | _Container* container; |
| 852 | typename _Container::iterator iter; |
| 853 | public: |
| 854 | typedef _Container container_type; |
| 855 | |
| 856 | _LIBCPP_INLINE_VISIBILITY insert_iterator(_Container& __x, typename _Container::iterator __i) |
Marshall Clow | cef3168 | 2014-03-03 19:20:40 +0000 | [diff] [blame] | 857 | : container(_VSTD::addressof(__x)), iter(__i) {} |
Howard Hinnant | bf07402 | 2011-10-22 20:59:45 +0000 | [diff] [blame] | 858 | _LIBCPP_INLINE_VISIBILITY insert_iterator& operator=(const typename _Container::value_type& __value_) |
| 859 | {iter = container->insert(iter, __value_); ++iter; return *this;} |
Eric Fiselier | f07d88c | 2017-04-19 01:34:08 +0000 | [diff] [blame] | 860 | #ifndef _LIBCPP_CXX03_LANG |
Howard Hinnant | bf07402 | 2011-10-22 20:59:45 +0000 | [diff] [blame] | 861 | _LIBCPP_INLINE_VISIBILITY insert_iterator& operator=(typename _Container::value_type&& __value_) |
| 862 | {iter = container->insert(iter, _VSTD::move(__value_)); ++iter; return *this;} |
Eric Fiselier | f07d88c | 2017-04-19 01:34:08 +0000 | [diff] [blame] | 863 | #endif // _LIBCPP_CXX03_LANG |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 864 | _LIBCPP_INLINE_VISIBILITY insert_iterator& operator*() {return *this;} |
| 865 | _LIBCPP_INLINE_VISIBILITY insert_iterator& operator++() {return *this;} |
| 866 | _LIBCPP_INLINE_VISIBILITY insert_iterator& operator++(int) {return *this;} |
| 867 | }; |
| 868 | |
| 869 | template <class _Container> |
| 870 | inline _LIBCPP_INLINE_VISIBILITY |
| 871 | insert_iterator<_Container> |
| 872 | inserter(_Container& __x, typename _Container::iterator __i) |
| 873 | { |
| 874 | return insert_iterator<_Container>(__x, __i); |
| 875 | } |
| 876 | |
| 877 | template <class _Tp, class _CharT = char, |
| 878 | class _Traits = char_traits<_CharT>, class _Distance = ptrdiff_t> |
Eric Fiselier | b5eb1bf | 2017-01-04 23:56:00 +0000 | [diff] [blame] | 879 | class _LIBCPP_TEMPLATE_VIS istream_iterator |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 880 | : public iterator<input_iterator_tag, _Tp, _Distance, const _Tp*, const _Tp&> |
| 881 | { |
| 882 | public: |
| 883 | typedef _CharT char_type; |
| 884 | typedef _Traits traits_type; |
| 885 | typedef basic_istream<_CharT,_Traits> istream_type; |
| 886 | private: |
| 887 | istream_type* __in_stream_; |
| 888 | _Tp __value_; |
| 889 | public: |
Marshall Clow | 0735e4e | 2015-04-16 21:36:54 +0000 | [diff] [blame] | 890 | _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR istream_iterator() : __in_stream_(0), __value_() {} |
Marshall Clow | b774270 | 2016-05-17 17:44:40 +0000 | [diff] [blame] | 891 | _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] | 892 | { |
| 893 | if (!(*__in_stream_ >> __value_)) |
| 894 | __in_stream_ = 0; |
| 895 | } |
| 896 | |
| 897 | _LIBCPP_INLINE_VISIBILITY const _Tp& operator*() const {return __value_;} |
Marshall Clow | b774270 | 2016-05-17 17:44:40 +0000 | [diff] [blame] | 898 | _LIBCPP_INLINE_VISIBILITY const _Tp* operator->() const {return _VSTD::addressof((operator*()));} |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 899 | _LIBCPP_INLINE_VISIBILITY istream_iterator& operator++() |
| 900 | { |
| 901 | if (!(*__in_stream_ >> __value_)) |
| 902 | __in_stream_ = 0; |
| 903 | return *this; |
| 904 | } |
| 905 | _LIBCPP_INLINE_VISIBILITY istream_iterator operator++(int) |
| 906 | {istream_iterator __t(*this); ++(*this); return __t;} |
| 907 | |
Roger Ferrer Ibanez | d16858b | 2017-12-11 13:54:58 +0000 | [diff] [blame] | 908 | template <class _Up, class _CharU, class _TraitsU, class _DistanceU> |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 909 | friend _LIBCPP_INLINE_VISIBILITY |
Roger Ferrer Ibanez | d16858b | 2017-12-11 13:54:58 +0000 | [diff] [blame] | 910 | bool |
| 911 | operator==(const istream_iterator<_Up, _CharU, _TraitsU, _DistanceU>& __x, |
| 912 | const istream_iterator<_Up, _CharU, _TraitsU, _DistanceU>& __y); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 913 | |
Roger Ferrer Ibanez | d16858b | 2017-12-11 13:54:58 +0000 | [diff] [blame] | 914 | template <class _Up, class _CharU, class _TraitsU, class _DistanceU> |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 915 | friend _LIBCPP_INLINE_VISIBILITY |
Roger Ferrer Ibanez | d16858b | 2017-12-11 13:54:58 +0000 | [diff] [blame] | 916 | bool |
| 917 | operator==(const istream_iterator<_Up, _CharU, _TraitsU, _DistanceU>& __x, |
| 918 | const istream_iterator<_Up, _CharU, _TraitsU, _DistanceU>& __y); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 919 | }; |
| 920 | |
Roger Ferrer Ibanez | d16858b | 2017-12-11 13:54:58 +0000 | [diff] [blame] | 921 | template <class _Tp, class _CharT, class _Traits, class _Distance> |
| 922 | inline _LIBCPP_INLINE_VISIBILITY |
| 923 | bool |
| 924 | operator==(const istream_iterator<_Tp, _CharT, _Traits, _Distance>& __x, |
| 925 | const istream_iterator<_Tp, _CharT, _Traits, _Distance>& __y) |
| 926 | { |
| 927 | return __x.__in_stream_ == __y.__in_stream_; |
| 928 | } |
| 929 | |
| 930 | template <class _Tp, class _CharT, class _Traits, class _Distance> |
| 931 | inline _LIBCPP_INLINE_VISIBILITY |
| 932 | bool |
| 933 | operator!=(const istream_iterator<_Tp, _CharT, _Traits, _Distance>& __x, |
| 934 | const istream_iterator<_Tp, _CharT, _Traits, _Distance>& __y) |
| 935 | { |
| 936 | return !(__x == __y); |
| 937 | } |
| 938 | |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 939 | template <class _Tp, class _CharT = char, class _Traits = char_traits<_CharT> > |
Eric Fiselier | b5eb1bf | 2017-01-04 23:56:00 +0000 | [diff] [blame] | 940 | class _LIBCPP_TEMPLATE_VIS ostream_iterator |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 941 | : public iterator<output_iterator_tag, void, void, void, void> |
| 942 | { |
| 943 | public: |
| 944 | typedef _CharT char_type; |
| 945 | typedef _Traits traits_type; |
| 946 | typedef basic_ostream<_CharT,_Traits> ostream_type; |
| 947 | private: |
| 948 | ostream_type* __out_stream_; |
| 949 | const char_type* __delim_; |
| 950 | public: |
Marshall Clow | 27a8951 | 2016-10-12 16:13:48 +0000 | [diff] [blame] | 951 | _LIBCPP_INLINE_VISIBILITY ostream_iterator(ostream_type& __s) _NOEXCEPT |
Marshall Clow | b774270 | 2016-05-17 17:44:40 +0000 | [diff] [blame] | 952 | : __out_stream_(_VSTD::addressof(__s)), __delim_(0) {} |
Marshall Clow | 27a8951 | 2016-10-12 16:13:48 +0000 | [diff] [blame] | 953 | _LIBCPP_INLINE_VISIBILITY ostream_iterator(ostream_type& __s, const _CharT* __delimiter) _NOEXCEPT |
Marshall Clow | b774270 | 2016-05-17 17:44:40 +0000 | [diff] [blame] | 954 | : __out_stream_(_VSTD::addressof(__s)), __delim_(__delimiter) {} |
Howard Hinnant | bf07402 | 2011-10-22 20:59:45 +0000 | [diff] [blame] | 955 | _LIBCPP_INLINE_VISIBILITY ostream_iterator& operator=(const _Tp& __value_) |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 956 | { |
Howard Hinnant | bf07402 | 2011-10-22 20:59:45 +0000 | [diff] [blame] | 957 | *__out_stream_ << __value_; |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 958 | if (__delim_) |
| 959 | *__out_stream_ << __delim_; |
| 960 | return *this; |
| 961 | } |
| 962 | |
| 963 | _LIBCPP_INLINE_VISIBILITY ostream_iterator& operator*() {return *this;} |
| 964 | _LIBCPP_INLINE_VISIBILITY ostream_iterator& operator++() {return *this;} |
| 965 | _LIBCPP_INLINE_VISIBILITY ostream_iterator& operator++(int) {return *this;} |
| 966 | }; |
| 967 | |
| 968 | template<class _CharT, class _Traits> |
Eric Fiselier | b5eb1bf | 2017-01-04 23:56:00 +0000 | [diff] [blame] | 969 | class _LIBCPP_TEMPLATE_VIS istreambuf_iterator |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 970 | : public iterator<input_iterator_tag, _CharT, |
| 971 | typename _Traits::off_type, _CharT*, |
| 972 | _CharT> |
| 973 | { |
| 974 | public: |
| 975 | typedef _CharT char_type; |
| 976 | typedef _Traits traits_type; |
| 977 | typedef typename _Traits::int_type int_type; |
| 978 | typedef basic_streambuf<_CharT,_Traits> streambuf_type; |
| 979 | typedef basic_istream<_CharT,_Traits> istream_type; |
| 980 | private: |
Howard Hinnant | 3e57b27 | 2012-11-16 22:17:23 +0000 | [diff] [blame] | 981 | mutable streambuf_type* __sbuf_; |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 982 | |
| 983 | class __proxy |
| 984 | { |
| 985 | char_type __keep_; |
| 986 | streambuf_type* __sbuf_; |
| 987 | _LIBCPP_INLINE_VISIBILITY __proxy(char_type __c, streambuf_type* __s) |
| 988 | : __keep_(__c), __sbuf_(__s) {} |
| 989 | friend class istreambuf_iterator; |
| 990 | public: |
| 991 | _LIBCPP_INLINE_VISIBILITY char_type operator*() const {return __keep_;} |
| 992 | }; |
| 993 | |
Howard Hinnant | 756c69b | 2010-09-22 16:48:34 +0000 | [diff] [blame] | 994 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 3e57b27 | 2012-11-16 22:17:23 +0000 | [diff] [blame] | 995 | bool __test_for_eof() const |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 996 | { |
| 997 | if (__sbuf_ && traits_type::eq_int_type(__sbuf_->sgetc(), traits_type::eof())) |
| 998 | __sbuf_ = 0; |
Howard Hinnant | 3e57b27 | 2012-11-16 22:17:23 +0000 | [diff] [blame] | 999 | return __sbuf_ == 0; |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1000 | } |
| 1001 | public: |
Howard Hinnant | 3e57b27 | 2012-11-16 22:17:23 +0000 | [diff] [blame] | 1002 | _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR istreambuf_iterator() _NOEXCEPT : __sbuf_(0) {} |
Howard Hinnant | 011138d | 2012-07-20 19:36:34 +0000 | [diff] [blame] | 1003 | _LIBCPP_INLINE_VISIBILITY istreambuf_iterator(istream_type& __s) _NOEXCEPT |
Howard Hinnant | b9af8d8 | 2012-12-29 17:45:42 +0000 | [diff] [blame] | 1004 | : __sbuf_(__s.rdbuf()) {} |
Howard Hinnant | 011138d | 2012-07-20 19:36:34 +0000 | [diff] [blame] | 1005 | _LIBCPP_INLINE_VISIBILITY istreambuf_iterator(streambuf_type* __s) _NOEXCEPT |
Howard Hinnant | b9af8d8 | 2012-12-29 17:45:42 +0000 | [diff] [blame] | 1006 | : __sbuf_(__s) {} |
Howard Hinnant | 011138d | 2012-07-20 19:36:34 +0000 | [diff] [blame] | 1007 | _LIBCPP_INLINE_VISIBILITY istreambuf_iterator(const __proxy& __p) _NOEXCEPT |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1008 | : __sbuf_(__p.__sbuf_) {} |
| 1009 | |
Howard Hinnant | 28b2488 | 2011-12-01 20:21:04 +0000 | [diff] [blame] | 1010 | _LIBCPP_INLINE_VISIBILITY char_type operator*() const |
| 1011 | {return static_cast<char_type>(__sbuf_->sgetc());} |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1012 | _LIBCPP_INLINE_VISIBILITY istreambuf_iterator& operator++() |
| 1013 | { |
Howard Hinnant | 3e57b27 | 2012-11-16 22:17:23 +0000 | [diff] [blame] | 1014 | __sbuf_->sbumpc(); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1015 | return *this; |
| 1016 | } |
| 1017 | _LIBCPP_INLINE_VISIBILITY __proxy operator++(int) |
| 1018 | { |
Howard Hinnant | 3e57b27 | 2012-11-16 22:17:23 +0000 | [diff] [blame] | 1019 | return __proxy(__sbuf_->sbumpc(), __sbuf_); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1020 | } |
| 1021 | |
| 1022 | _LIBCPP_INLINE_VISIBILITY bool equal(const istreambuf_iterator& __b) const |
Howard Hinnant | 3e57b27 | 2012-11-16 22:17:23 +0000 | [diff] [blame] | 1023 | {return __test_for_eof() == __b.__test_for_eof();} |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1024 | }; |
| 1025 | |
| 1026 | template <class _CharT, class _Traits> |
| 1027 | inline _LIBCPP_INLINE_VISIBILITY |
| 1028 | bool operator==(const istreambuf_iterator<_CharT,_Traits>& __a, |
| 1029 | const istreambuf_iterator<_CharT,_Traits>& __b) |
| 1030 | {return __a.equal(__b);} |
| 1031 | |
| 1032 | template <class _CharT, class _Traits> |
| 1033 | inline _LIBCPP_INLINE_VISIBILITY |
| 1034 | bool operator!=(const istreambuf_iterator<_CharT,_Traits>& __a, |
| 1035 | const istreambuf_iterator<_CharT,_Traits>& __b) |
| 1036 | {return !__a.equal(__b);} |
| 1037 | |
| 1038 | template <class _CharT, class _Traits> |
Eric Fiselier | b5eb1bf | 2017-01-04 23:56:00 +0000 | [diff] [blame] | 1039 | class _LIBCPP_TEMPLATE_VIS ostreambuf_iterator |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1040 | : public iterator<output_iterator_tag, void, void, void, void> |
| 1041 | { |
| 1042 | public: |
| 1043 | typedef _CharT char_type; |
| 1044 | typedef _Traits traits_type; |
| 1045 | typedef basic_streambuf<_CharT,_Traits> streambuf_type; |
| 1046 | typedef basic_ostream<_CharT,_Traits> ostream_type; |
| 1047 | private: |
| 1048 | streambuf_type* __sbuf_; |
| 1049 | public: |
Howard Hinnant | 011138d | 2012-07-20 19:36:34 +0000 | [diff] [blame] | 1050 | _LIBCPP_INLINE_VISIBILITY ostreambuf_iterator(ostream_type& __s) _NOEXCEPT |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1051 | : __sbuf_(__s.rdbuf()) {} |
Howard Hinnant | 011138d | 2012-07-20 19:36:34 +0000 | [diff] [blame] | 1052 | _LIBCPP_INLINE_VISIBILITY ostreambuf_iterator(streambuf_type* __s) _NOEXCEPT |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1053 | : __sbuf_(__s) {} |
| 1054 | _LIBCPP_INLINE_VISIBILITY ostreambuf_iterator& operator=(_CharT __c) |
| 1055 | { |
| 1056 | if (__sbuf_ && traits_type::eq_int_type(__sbuf_->sputc(__c), traits_type::eof())) |
| 1057 | __sbuf_ = 0; |
| 1058 | return *this; |
| 1059 | } |
| 1060 | _LIBCPP_INLINE_VISIBILITY ostreambuf_iterator& operator*() {return *this;} |
| 1061 | _LIBCPP_INLINE_VISIBILITY ostreambuf_iterator& operator++() {return *this;} |
| 1062 | _LIBCPP_INLINE_VISIBILITY ostreambuf_iterator& operator++(int) {return *this;} |
Howard Hinnant | 011138d | 2012-07-20 19:36:34 +0000 | [diff] [blame] | 1063 | _LIBCPP_INLINE_VISIBILITY bool failed() const _NOEXCEPT {return __sbuf_ == 0;} |
Howard Hinnant | 9795517 | 2012-09-19 19:14:15 +0000 | [diff] [blame] | 1064 | |
Howard Hinnant | 48fd5d5 | 2012-11-14 21:17:15 +0000 | [diff] [blame] | 1065 | #if !defined(__APPLE__) || \ |
| 1066 | (defined(__MAC_OS_X_VERSION_MIN_REQUIRED) && __MAC_OS_X_VERSION_MIN_REQUIRED > __MAC_10_8) || \ |
| 1067 | (defined(__IPHONE_OS_VERSION_MIN_REQUIRED) && __IPHONE_OS_VERSION_MIN_REQUIRED > __IPHONE_6_0) |
| 1068 | |
Howard Hinnant | 9795517 | 2012-09-19 19:14:15 +0000 | [diff] [blame] | 1069 | template <class _Ch, class _Tr> |
| 1070 | friend |
| 1071 | _LIBCPP_HIDDEN |
| 1072 | ostreambuf_iterator<_Ch, _Tr> |
| 1073 | __pad_and_output(ostreambuf_iterator<_Ch, _Tr> __s, |
| 1074 | const _Ch* __ob, const _Ch* __op, const _Ch* __oe, |
| 1075 | ios_base& __iob, _Ch __fl); |
Howard Hinnant | 48fd5d5 | 2012-11-14 21:17:15 +0000 | [diff] [blame] | 1076 | #endif |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1077 | }; |
| 1078 | |
| 1079 | template <class _Iter> |
Eric Fiselier | b5eb1bf | 2017-01-04 23:56:00 +0000 | [diff] [blame] | 1080 | class _LIBCPP_TEMPLATE_VIS move_iterator |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1081 | { |
| 1082 | private: |
| 1083 | _Iter __i; |
| 1084 | public: |
| 1085 | typedef _Iter iterator_type; |
| 1086 | typedef typename iterator_traits<iterator_type>::iterator_category iterator_category; |
| 1087 | typedef typename iterator_traits<iterator_type>::value_type value_type; |
| 1088 | typedef typename iterator_traits<iterator_type>::difference_type difference_type; |
Marshall Clow | d85a056 | 2016-04-11 03:54:53 +0000 | [diff] [blame] | 1089 | typedef iterator_type pointer; |
Eric Fiselier | f07d88c | 2017-04-19 01:34:08 +0000 | [diff] [blame] | 1090 | #ifndef _LIBCPP_CXX03_LANG |
Eric Fiselier | 57b8e0e | 2016-04-22 00:49:12 +0000 | [diff] [blame] | 1091 | typedef typename iterator_traits<iterator_type>::reference __reference; |
| 1092 | typedef typename conditional< |
| 1093 | is_reference<__reference>::value, |
| 1094 | typename remove_reference<__reference>::type&&, |
| 1095 | __reference |
| 1096 | >::type reference; |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1097 | #else |
| 1098 | typedef typename iterator_traits<iterator_type>::reference reference; |
| 1099 | #endif |
Howard Hinnant | 3b6579a | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 1100 | |
Marshall Clow | b5f9912 | 2016-11-02 15:30:26 +0000 | [diff] [blame] | 1101 | _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 |
| 1102 | move_iterator() : __i() {} |
| 1103 | _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 |
| 1104 | explicit move_iterator(_Iter __x) : __i(__x) {} |
| 1105 | template <class _Up> |
| 1106 | _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 |
| 1107 | move_iterator(const move_iterator<_Up>& __u) : __i(__u.base()) {} |
| 1108 | _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 _Iter base() const {return __i;} |
| 1109 | _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 |
| 1110 | reference operator*() const { return static_cast<reference>(*__i); } |
| 1111 | _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 |
| 1112 | pointer operator->() const { return __i;} |
| 1113 | _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 |
| 1114 | move_iterator& operator++() {++__i; return *this;} |
| 1115 | _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 |
| 1116 | move_iterator operator++(int) {move_iterator __tmp(*this); ++__i; return __tmp;} |
| 1117 | _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 |
| 1118 | move_iterator& operator--() {--__i; return *this;} |
| 1119 | _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 |
| 1120 | move_iterator operator--(int) {move_iterator __tmp(*this); --__i; return __tmp;} |
| 1121 | _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 |
| 1122 | move_iterator operator+ (difference_type __n) const {return move_iterator(__i + __n);} |
| 1123 | _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 |
| 1124 | move_iterator& operator+=(difference_type __n) {__i += __n; return *this;} |
| 1125 | _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 |
| 1126 | move_iterator operator- (difference_type __n) const {return move_iterator(__i - __n);} |
| 1127 | _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 |
| 1128 | move_iterator& operator-=(difference_type __n) {__i -= __n; return *this;} |
| 1129 | _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 |
| 1130 | reference operator[](difference_type __n) const { return static_cast<reference>(__i[__n]); } |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1131 | }; |
| 1132 | |
| 1133 | template <class _Iter1, class _Iter2> |
Marshall Clow | b5f9912 | 2016-11-02 15:30:26 +0000 | [diff] [blame] | 1134 | inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1135 | bool |
| 1136 | operator==(const move_iterator<_Iter1>& __x, const move_iterator<_Iter2>& __y) |
| 1137 | { |
| 1138 | return __x.base() == __y.base(); |
| 1139 | } |
| 1140 | |
| 1141 | template <class _Iter1, class _Iter2> |
Marshall Clow | b5f9912 | 2016-11-02 15:30:26 +0000 | [diff] [blame] | 1142 | inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1143 | bool |
| 1144 | operator<(const move_iterator<_Iter1>& __x, const move_iterator<_Iter2>& __y) |
| 1145 | { |
| 1146 | return __x.base() < __y.base(); |
| 1147 | } |
| 1148 | |
| 1149 | template <class _Iter1, class _Iter2> |
Marshall Clow | b5f9912 | 2016-11-02 15:30:26 +0000 | [diff] [blame] | 1150 | inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1151 | bool |
| 1152 | operator!=(const move_iterator<_Iter1>& __x, const move_iterator<_Iter2>& __y) |
| 1153 | { |
| 1154 | return __x.base() != __y.base(); |
| 1155 | } |
| 1156 | |
| 1157 | template <class _Iter1, class _Iter2> |
Marshall Clow | b5f9912 | 2016-11-02 15:30:26 +0000 | [diff] [blame] | 1158 | inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1159 | bool |
| 1160 | operator>(const move_iterator<_Iter1>& __x, const move_iterator<_Iter2>& __y) |
| 1161 | { |
| 1162 | return __x.base() > __y.base(); |
| 1163 | } |
| 1164 | |
| 1165 | template <class _Iter1, class _Iter2> |
Marshall Clow | b5f9912 | 2016-11-02 15:30:26 +0000 | [diff] [blame] | 1166 | inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1167 | bool |
| 1168 | operator>=(const move_iterator<_Iter1>& __x, const move_iterator<_Iter2>& __y) |
| 1169 | { |
| 1170 | return __x.base() >= __y.base(); |
| 1171 | } |
| 1172 | |
| 1173 | template <class _Iter1, class _Iter2> |
Marshall Clow | b5f9912 | 2016-11-02 15:30:26 +0000 | [diff] [blame] | 1174 | inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1175 | bool |
| 1176 | operator<=(const move_iterator<_Iter1>& __x, const move_iterator<_Iter2>& __y) |
| 1177 | { |
| 1178 | return __x.base() <= __y.base(); |
| 1179 | } |
| 1180 | |
Marshall Clow | 476d3f4 | 2016-07-18 13:19:00 +0000 | [diff] [blame] | 1181 | #ifndef _LIBCPP_CXX03_LANG |
Marshall Clow | f8fec4e | 2016-07-08 16:54:47 +0000 | [diff] [blame] | 1182 | template <class _Iter1, class _Iter2> |
Marshall Clow | b5f9912 | 2016-11-02 15:30:26 +0000 | [diff] [blame] | 1183 | inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 |
Marshall Clow | f8fec4e | 2016-07-08 16:54:47 +0000 | [diff] [blame] | 1184 | auto |
| 1185 | operator-(const move_iterator<_Iter1>& __x, const move_iterator<_Iter2>& __y) |
| 1186 | -> decltype(__x.base() - __y.base()) |
| 1187 | { |
| 1188 | return __x.base() - __y.base(); |
| 1189 | } |
| 1190 | #else |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1191 | template <class _Iter1, class _Iter2> |
| 1192 | inline _LIBCPP_INLINE_VISIBILITY |
| 1193 | typename move_iterator<_Iter1>::difference_type |
| 1194 | operator-(const move_iterator<_Iter1>& __x, const move_iterator<_Iter2>& __y) |
| 1195 | { |
| 1196 | return __x.base() - __y.base(); |
| 1197 | } |
Marshall Clow | f8fec4e | 2016-07-08 16:54:47 +0000 | [diff] [blame] | 1198 | #endif |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1199 | |
| 1200 | template <class _Iter> |
Marshall Clow | b5f9912 | 2016-11-02 15:30:26 +0000 | [diff] [blame] | 1201 | inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1202 | move_iterator<_Iter> |
| 1203 | operator+(typename move_iterator<_Iter>::difference_type __n, const move_iterator<_Iter>& __x) |
| 1204 | { |
| 1205 | return move_iterator<_Iter>(__x.base() + __n); |
| 1206 | } |
| 1207 | |
| 1208 | template <class _Iter> |
Marshall Clow | b5f9912 | 2016-11-02 15:30:26 +0000 | [diff] [blame] | 1209 | inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1210 | move_iterator<_Iter> |
Marshall Clow | 84f90cf | 2013-08-27 13:03:03 +0000 | [diff] [blame] | 1211 | make_move_iterator(_Iter __i) |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1212 | { |
| 1213 | return move_iterator<_Iter>(__i); |
| 1214 | } |
| 1215 | |
| 1216 | // __wrap_iter |
| 1217 | |
| 1218 | template <class _Iter> class __wrap_iter; |
| 1219 | |
| 1220 | template <class _Iter1, class _Iter2> |
Marshall Clow | ae4f831 | 2018-07-13 16:35:26 +0000 | [diff] [blame] | 1221 | _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1222 | bool |
Eric Fiselier | 38badb8 | 2016-12-28 05:35:32 +0000 | [diff] [blame] | 1223 | operator==(const __wrap_iter<_Iter1>&, const __wrap_iter<_Iter2>&) _NOEXCEPT_DEBUG; |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1224 | |
| 1225 | template <class _Iter1, class _Iter2> |
Marshall Clow | ae4f831 | 2018-07-13 16:35:26 +0000 | [diff] [blame] | 1226 | _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1227 | bool |
Eric Fiselier | 38badb8 | 2016-12-28 05:35:32 +0000 | [diff] [blame] | 1228 | operator<(const __wrap_iter<_Iter1>&, const __wrap_iter<_Iter2>&) _NOEXCEPT_DEBUG; |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1229 | |
| 1230 | template <class _Iter1, class _Iter2> |
Marshall Clow | ae4f831 | 2018-07-13 16:35:26 +0000 | [diff] [blame] | 1231 | _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1232 | bool |
Eric Fiselier | 38badb8 | 2016-12-28 05:35:32 +0000 | [diff] [blame] | 1233 | operator!=(const __wrap_iter<_Iter1>&, const __wrap_iter<_Iter2>&) _NOEXCEPT_DEBUG; |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1234 | |
| 1235 | template <class _Iter1, class _Iter2> |
Marshall Clow | ae4f831 | 2018-07-13 16:35:26 +0000 | [diff] [blame] | 1236 | _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1237 | bool |
Eric Fiselier | 38badb8 | 2016-12-28 05:35:32 +0000 | [diff] [blame] | 1238 | operator>(const __wrap_iter<_Iter1>&, const __wrap_iter<_Iter2>&) _NOEXCEPT_DEBUG; |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1239 | |
| 1240 | template <class _Iter1, class _Iter2> |
Marshall Clow | ae4f831 | 2018-07-13 16:35:26 +0000 | [diff] [blame] | 1241 | _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1242 | bool |
Eric Fiselier | 38badb8 | 2016-12-28 05:35:32 +0000 | [diff] [blame] | 1243 | operator>=(const __wrap_iter<_Iter1>&, const __wrap_iter<_Iter2>&) _NOEXCEPT_DEBUG; |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1244 | |
| 1245 | template <class _Iter1, class _Iter2> |
Marshall Clow | ae4f831 | 2018-07-13 16:35:26 +0000 | [diff] [blame] | 1246 | _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1247 | bool |
Eric Fiselier | 38badb8 | 2016-12-28 05:35:32 +0000 | [diff] [blame] | 1248 | operator<=(const __wrap_iter<_Iter1>&, const __wrap_iter<_Iter2>&) _NOEXCEPT_DEBUG; |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1249 | |
Marshall Clow | 476d3f4 | 2016-07-18 13:19:00 +0000 | [diff] [blame] | 1250 | #ifndef _LIBCPP_CXX03_LANG |
Marshall Clow | f8fec4e | 2016-07-08 16:54:47 +0000 | [diff] [blame] | 1251 | template <class _Iter1, class _Iter2> |
Marshall Clow | ae4f831 | 2018-07-13 16:35:26 +0000 | [diff] [blame] | 1252 | _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG |
Marshall Clow | f8fec4e | 2016-07-08 16:54:47 +0000 | [diff] [blame] | 1253 | auto |
Eric Fiselier | 38badb8 | 2016-12-28 05:35:32 +0000 | [diff] [blame] | 1254 | 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] | 1255 | -> decltype(__x.base() - __y.base()); |
| 1256 | #else |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1257 | template <class _Iter1, class _Iter2> |
Howard Hinnant | a54386e | 2012-09-14 00:39:16 +0000 | [diff] [blame] | 1258 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1259 | typename __wrap_iter<_Iter1>::difference_type |
Eric Fiselier | 38badb8 | 2016-12-28 05:35:32 +0000 | [diff] [blame] | 1260 | operator-(const __wrap_iter<_Iter1>&, const __wrap_iter<_Iter2>&) _NOEXCEPT_DEBUG; |
Marshall Clow | f8fec4e | 2016-07-08 16:54:47 +0000 | [diff] [blame] | 1261 | #endif |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1262 | |
| 1263 | template <class _Iter> |
Marshall Clow | ae4f831 | 2018-07-13 16:35:26 +0000 | [diff] [blame] | 1264 | _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1265 | __wrap_iter<_Iter> |
Eric Fiselier | 38badb8 | 2016-12-28 05:35:32 +0000 | [diff] [blame] | 1266 | operator+(typename __wrap_iter<_Iter>::difference_type, __wrap_iter<_Iter>) _NOEXCEPT_DEBUG; |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1267 | |
Howard Hinnant | a54386e | 2012-09-14 00:39:16 +0000 | [diff] [blame] | 1268 | template <class _Ip, class _Op> _Op _LIBCPP_INLINE_VISIBILITY copy(_Ip, _Ip, _Op); |
| 1269 | template <class _B1, class _B2> _B2 _LIBCPP_INLINE_VISIBILITY copy_backward(_B1, _B1, _B2); |
| 1270 | template <class _Ip, class _Op> _Op _LIBCPP_INLINE_VISIBILITY move(_Ip, _Ip, _Op); |
| 1271 | 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] | 1272 | |
Eric Fiselier | 38badb8 | 2016-12-28 05:35:32 +0000 | [diff] [blame] | 1273 | #if _LIBCPP_DEBUG_LEVEL < 2 |
| 1274 | |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1275 | template <class _Tp> |
Marshall Clow | ae4f831 | 2018-07-13 16:35:26 +0000 | [diff] [blame] | 1276 | _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1277 | typename enable_if |
| 1278 | < |
Howard Hinnant | a9a897e | 2010-11-19 22:17:28 +0000 | [diff] [blame] | 1279 | is_trivially_copy_assignable<_Tp>::value, |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1280 | _Tp* |
| 1281 | >::type |
| 1282 | __unwrap_iter(__wrap_iter<_Tp*>); |
| 1283 | |
Eric Fiselier | 38badb8 | 2016-12-28 05:35:32 +0000 | [diff] [blame] | 1284 | #else |
| 1285 | |
| 1286 | template <class _Tp> |
Marshall Clow | ae4f831 | 2018-07-13 16:35:26 +0000 | [diff] [blame] | 1287 | inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG |
Eric Fiselier | 38badb8 | 2016-12-28 05:35:32 +0000 | [diff] [blame] | 1288 | typename enable_if |
| 1289 | < |
| 1290 | is_trivially_copy_assignable<_Tp>::value, |
| 1291 | __wrap_iter<_Tp*> |
| 1292 | >::type |
| 1293 | __unwrap_iter(__wrap_iter<_Tp*> __i); |
| 1294 | |
| 1295 | #endif |
| 1296 | |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1297 | template <class _Iter> |
| 1298 | class __wrap_iter |
| 1299 | { |
| 1300 | public: |
| 1301 | typedef _Iter iterator_type; |
| 1302 | typedef typename iterator_traits<iterator_type>::iterator_category iterator_category; |
| 1303 | typedef typename iterator_traits<iterator_type>::value_type value_type; |
| 1304 | typedef typename iterator_traits<iterator_type>::difference_type difference_type; |
| 1305 | typedef typename iterator_traits<iterator_type>::pointer pointer; |
| 1306 | typedef typename iterator_traits<iterator_type>::reference reference; |
| 1307 | private: |
| 1308 | iterator_type __i; |
| 1309 | public: |
Marshall Clow | ae4f831 | 2018-07-13 16:35:26 +0000 | [diff] [blame] | 1310 | _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG __wrap_iter() _NOEXCEPT_DEBUG |
Marshall Clow | 4e7b35b | 2013-08-07 20:48:48 +0000 | [diff] [blame] | 1311 | #if _LIBCPP_STD_VER > 11 |
| 1312 | : __i{} |
| 1313 | #endif |
Howard Hinnant | c90aa63 | 2011-09-16 19:52:23 +0000 | [diff] [blame] | 1314 | { |
| 1315 | #if _LIBCPP_DEBUG_LEVEL >= 2 |
| 1316 | __get_db()->__insert_i(this); |
| 1317 | #endif |
| 1318 | } |
Marshall Clow | ae4f831 | 2018-07-13 16:35:26 +0000 | [diff] [blame] | 1319 | template <class _Up> _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG |
| 1320 | __wrap_iter(const __wrap_iter<_Up>& __u, |
| 1321 | typename enable_if<is_convertible<_Up, iterator_type>::value>::type* = 0) _NOEXCEPT_DEBUG |
| 1322 | : __i(__u.base()) |
Howard Hinnant | 27e0e77 | 2011-09-14 18:33:51 +0000 | [diff] [blame] | 1323 | { |
Howard Hinnant | a47c6d5 | 2011-09-16 17:29:17 +0000 | [diff] [blame] | 1324 | #if _LIBCPP_DEBUG_LEVEL >= 2 |
Howard Hinnant | 27e0e77 | 2011-09-14 18:33:51 +0000 | [diff] [blame] | 1325 | __get_db()->__iterator_copy(this, &__u); |
| 1326 | #endif |
| 1327 | } |
Howard Hinnant | a47c6d5 | 2011-09-16 17:29:17 +0000 | [diff] [blame] | 1328 | #if _LIBCPP_DEBUG_LEVEL >= 2 |
Marshall Clow | ae4f831 | 2018-07-13 16:35:26 +0000 | [diff] [blame] | 1329 | _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG |
Howard Hinnant | 27e0e77 | 2011-09-14 18:33:51 +0000 | [diff] [blame] | 1330 | __wrap_iter(const __wrap_iter& __x) |
| 1331 | : __i(__x.base()) |
| 1332 | { |
| 1333 | __get_db()->__iterator_copy(this, &__x); |
| 1334 | } |
Marshall Clow | ae4f831 | 2018-07-13 16:35:26 +0000 | [diff] [blame] | 1335 | _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG |
Howard Hinnant | 27e0e77 | 2011-09-14 18:33:51 +0000 | [diff] [blame] | 1336 | __wrap_iter& operator=(const __wrap_iter& __x) |
| 1337 | { |
| 1338 | if (this != &__x) |
| 1339 | { |
| 1340 | __get_db()->__iterator_copy(this, &__x); |
| 1341 | __i = __x.__i; |
| 1342 | } |
| 1343 | return *this; |
| 1344 | } |
Marshall Clow | ae4f831 | 2018-07-13 16:35:26 +0000 | [diff] [blame] | 1345 | _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG |
Howard Hinnant | 27e0e77 | 2011-09-14 18:33:51 +0000 | [diff] [blame] | 1346 | ~__wrap_iter() |
| 1347 | { |
| 1348 | __get_db()->__erase_i(this); |
| 1349 | } |
| 1350 | #endif |
Marshall Clow | ae4f831 | 2018-07-13 16:35:26 +0000 | [diff] [blame] | 1351 | _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG reference operator*() const _NOEXCEPT_DEBUG |
Howard Hinnant | 27e0e77 | 2011-09-14 18:33:51 +0000 | [diff] [blame] | 1352 | { |
Howard Hinnant | a47c6d5 | 2011-09-16 17:29:17 +0000 | [diff] [blame] | 1353 | #if _LIBCPP_DEBUG_LEVEL >= 2 |
Howard Hinnant | 27e0e77 | 2011-09-14 18:33:51 +0000 | [diff] [blame] | 1354 | _LIBCPP_ASSERT(__get_const_db()->__dereferenceable(this), |
| 1355 | "Attempted to dereference a non-dereferenceable iterator"); |
Howard Hinnant | a47c6d5 | 2011-09-16 17:29:17 +0000 | [diff] [blame] | 1356 | #endif |
Howard Hinnant | 27e0e77 | 2011-09-14 18:33:51 +0000 | [diff] [blame] | 1357 | return *__i; |
| 1358 | } |
Marshall Clow | ae4f831 | 2018-07-13 16:35:26 +0000 | [diff] [blame] | 1359 | _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG pointer operator->() const _NOEXCEPT_DEBUG |
Howard Hinnant | 76053d7 | 2013-06-27 19:35:32 +0000 | [diff] [blame] | 1360 | { |
| 1361 | #if _LIBCPP_DEBUG_LEVEL >= 2 |
| 1362 | _LIBCPP_ASSERT(__get_const_db()->__dereferenceable(this), |
| 1363 | "Attempted to dereference a non-dereferenceable iterator"); |
| 1364 | #endif |
Marshall Clow | d85a056 | 2016-04-11 03:54:53 +0000 | [diff] [blame] | 1365 | return (pointer)_VSTD::addressof(*__i); |
Howard Hinnant | 76053d7 | 2013-06-27 19:35:32 +0000 | [diff] [blame] | 1366 | } |
Marshall Clow | ae4f831 | 2018-07-13 16:35:26 +0000 | [diff] [blame] | 1367 | _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG __wrap_iter& operator++() _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()->__dereferenceable(this), |
| 1371 | "Attempted to increment non-incrementable iterator"); |
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; |
| 1374 | return *this; |
| 1375 | } |
Marshall Clow | ae4f831 | 2018-07-13 16:35:26 +0000 | [diff] [blame] | 1376 | _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG __wrap_iter operator++(int) _NOEXCEPT_DEBUG |
Howard Hinnant | 27e0e77 | 2011-09-14 18:33:51 +0000 | [diff] [blame] | 1377 | {__wrap_iter __tmp(*this); ++(*this); return __tmp;} |
Marshall Clow | 6d553a5 | 2018-07-14 03:06:11 +0000 | [diff] [blame] | 1378 | |
| 1379 | _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG __wrap_iter& operator--() _NOEXCEPT_DEBUG |
Howard Hinnant | 27e0e77 | 2011-09-14 18:33:51 +0000 | [diff] [blame] | 1380 | { |
Howard Hinnant | a47c6d5 | 2011-09-16 17:29:17 +0000 | [diff] [blame] | 1381 | #if _LIBCPP_DEBUG_LEVEL >= 2 |
Howard Hinnant | 27e0e77 | 2011-09-14 18:33:51 +0000 | [diff] [blame] | 1382 | _LIBCPP_ASSERT(__get_const_db()->__decrementable(this), |
| 1383 | "Attempted to decrement non-decrementable iterator"); |
Howard Hinnant | a47c6d5 | 2011-09-16 17:29:17 +0000 | [diff] [blame] | 1384 | #endif |
Howard Hinnant | 27e0e77 | 2011-09-14 18:33:51 +0000 | [diff] [blame] | 1385 | --__i; |
| 1386 | return *this; |
| 1387 | } |
Marshall Clow | ae4f831 | 2018-07-13 16:35:26 +0000 | [diff] [blame] | 1388 | _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG __wrap_iter operator--(int) _NOEXCEPT_DEBUG |
Howard Hinnant | 27e0e77 | 2011-09-14 18:33:51 +0000 | [diff] [blame] | 1389 | {__wrap_iter __tmp(*this); --(*this); return __tmp;} |
Marshall Clow | ae4f831 | 2018-07-13 16:35:26 +0000 | [diff] [blame] | 1390 | _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG __wrap_iter operator+ (difference_type __n) const _NOEXCEPT_DEBUG |
Howard Hinnant | 27e0e77 | 2011-09-14 18:33:51 +0000 | [diff] [blame] | 1391 | {__wrap_iter __w(*this); __w += __n; return __w;} |
Marshall Clow | ae4f831 | 2018-07-13 16:35:26 +0000 | [diff] [blame] | 1392 | _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG __wrap_iter& operator+=(difference_type __n) _NOEXCEPT_DEBUG |
Howard Hinnant | 27e0e77 | 2011-09-14 18:33:51 +0000 | [diff] [blame] | 1393 | { |
Howard Hinnant | a47c6d5 | 2011-09-16 17:29:17 +0000 | [diff] [blame] | 1394 | #if _LIBCPP_DEBUG_LEVEL >= 2 |
Howard Hinnant | 27e0e77 | 2011-09-14 18:33:51 +0000 | [diff] [blame] | 1395 | _LIBCPP_ASSERT(__get_const_db()->__addable(this, __n), |
| 1396 | "Attempted to add/subtract iterator outside of valid range"); |
Howard Hinnant | a47c6d5 | 2011-09-16 17:29:17 +0000 | [diff] [blame] | 1397 | #endif |
Howard Hinnant | 27e0e77 | 2011-09-14 18:33:51 +0000 | [diff] [blame] | 1398 | __i += __n; |
| 1399 | return *this; |
| 1400 | } |
Marshall Clow | ae4f831 | 2018-07-13 16:35:26 +0000 | [diff] [blame] | 1401 | _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG __wrap_iter operator- (difference_type __n) const _NOEXCEPT_DEBUG |
Howard Hinnant | 27e0e77 | 2011-09-14 18:33:51 +0000 | [diff] [blame] | 1402 | {return *this + (-__n);} |
Marshall Clow | ae4f831 | 2018-07-13 16:35:26 +0000 | [diff] [blame] | 1403 | _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG __wrap_iter& operator-=(difference_type __n) _NOEXCEPT_DEBUG |
Howard Hinnant | 27e0e77 | 2011-09-14 18:33:51 +0000 | [diff] [blame] | 1404 | {*this += -__n; return *this;} |
Marshall Clow | ae4f831 | 2018-07-13 16:35:26 +0000 | [diff] [blame] | 1405 | _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG reference operator[](difference_type __n) const _NOEXCEPT_DEBUG |
Howard Hinnant | 27e0e77 | 2011-09-14 18:33:51 +0000 | [diff] [blame] | 1406 | { |
Howard Hinnant | a47c6d5 | 2011-09-16 17:29:17 +0000 | [diff] [blame] | 1407 | #if _LIBCPP_DEBUG_LEVEL >= 2 |
Howard Hinnant | 27e0e77 | 2011-09-14 18:33:51 +0000 | [diff] [blame] | 1408 | _LIBCPP_ASSERT(__get_const_db()->__subscriptable(this, __n), |
| 1409 | "Attempted to subscript iterator outside of valid range"); |
Howard Hinnant | a47c6d5 | 2011-09-16 17:29:17 +0000 | [diff] [blame] | 1410 | #endif |
Howard Hinnant | 27e0e77 | 2011-09-14 18:33:51 +0000 | [diff] [blame] | 1411 | return __i[__n]; |
| 1412 | } |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1413 | |
Marshall Clow | ae4f831 | 2018-07-13 16:35:26 +0000 | [diff] [blame] | 1414 | _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG iterator_type base() const _NOEXCEPT_DEBUG {return __i;} |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1415 | |
| 1416 | private: |
Howard Hinnant | a47c6d5 | 2011-09-16 17:29:17 +0000 | [diff] [blame] | 1417 | #if _LIBCPP_DEBUG_LEVEL >= 2 |
Marshall Clow | ae4f831 | 2018-07-13 16:35:26 +0000 | [diff] [blame] | 1418 | _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG __wrap_iter(const void* __p, iterator_type __x) : __i(__x) |
Howard Hinnant | 27e0e77 | 2011-09-14 18:33:51 +0000 | [diff] [blame] | 1419 | { |
| 1420 | __get_db()->__insert_ic(this, __p); |
| 1421 | } |
Howard Hinnant | 8ea9824 | 2013-08-23 17:37:05 +0000 | [diff] [blame] | 1422 | #else |
Marshall Clow | ae4f831 | 2018-07-13 16:35:26 +0000 | [diff] [blame] | 1423 | _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG __wrap_iter(iterator_type __x) _NOEXCEPT_DEBUG : __i(__x) {} |
Howard Hinnant | 27e0e77 | 2011-09-14 18:33:51 +0000 | [diff] [blame] | 1424 | #endif |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1425 | |
| 1426 | template <class _Up> friend class __wrap_iter; |
| 1427 | template <class _CharT, class _Traits, class _Alloc> friend class basic_string; |
Eric Fiselier | b5eb1bf | 2017-01-04 23:56:00 +0000 | [diff] [blame] | 1428 | template <class _Tp, class _Alloc> friend class _LIBCPP_TEMPLATE_VIS vector; |
Marshall Clow | ae4f831 | 2018-07-13 16:35:26 +0000 | [diff] [blame] | 1429 | template <class _Tp, ptrdiff_t> friend class _LIBCPP_TEMPLATE_VIS span; |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1430 | |
| 1431 | template <class _Iter1, class _Iter2> |
Marshall Clow | ae4f831 | 2018-07-13 16:35:26 +0000 | [diff] [blame] | 1432 | _LIBCPP_CONSTEXPR_IF_NODEBUG friend |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1433 | bool |
Eric Fiselier | 38badb8 | 2016-12-28 05:35:32 +0000 | [diff] [blame] | 1434 | operator==(const __wrap_iter<_Iter1>&, const __wrap_iter<_Iter2>&) _NOEXCEPT_DEBUG; |
Howard Hinnant | 3b6579a | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 1435 | |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1436 | template <class _Iter1, class _Iter2> |
Marshall Clow | ae4f831 | 2018-07-13 16:35:26 +0000 | [diff] [blame] | 1437 | _LIBCPP_CONSTEXPR_IF_NODEBUG friend |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1438 | bool |
Eric Fiselier | 38badb8 | 2016-12-28 05:35:32 +0000 | [diff] [blame] | 1439 | operator<(const __wrap_iter<_Iter1>&, const __wrap_iter<_Iter2>&) _NOEXCEPT_DEBUG; |
Howard Hinnant | 3b6579a | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 1440 | |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1441 | template <class _Iter1, class _Iter2> |
Marshall Clow | ae4f831 | 2018-07-13 16:35:26 +0000 | [diff] [blame] | 1442 | _LIBCPP_CONSTEXPR_IF_NODEBUG friend |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1443 | bool |
Eric Fiselier | 38badb8 | 2016-12-28 05:35:32 +0000 | [diff] [blame] | 1444 | operator!=(const __wrap_iter<_Iter1>&, const __wrap_iter<_Iter2>&) _NOEXCEPT_DEBUG; |
Howard Hinnant | 3b6579a | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 1445 | |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1446 | template <class _Iter1, class _Iter2> |
Marshall Clow | ae4f831 | 2018-07-13 16:35:26 +0000 | [diff] [blame] | 1447 | _LIBCPP_CONSTEXPR_IF_NODEBUG friend |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1448 | bool |
Eric Fiselier | 38badb8 | 2016-12-28 05:35:32 +0000 | [diff] [blame] | 1449 | operator>(const __wrap_iter<_Iter1>&, const __wrap_iter<_Iter2>&) _NOEXCEPT_DEBUG; |
Howard Hinnant | 3b6579a | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 1450 | |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1451 | template <class _Iter1, class _Iter2> |
Marshall Clow | ae4f831 | 2018-07-13 16:35:26 +0000 | [diff] [blame] | 1452 | _LIBCPP_CONSTEXPR_IF_NODEBUG friend |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1453 | bool |
Eric Fiselier | 38badb8 | 2016-12-28 05:35:32 +0000 | [diff] [blame] | 1454 | operator>=(const __wrap_iter<_Iter1>&, const __wrap_iter<_Iter2>&) _NOEXCEPT_DEBUG; |
Howard Hinnant | 3b6579a | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 1455 | |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1456 | template <class _Iter1, class _Iter2> |
Marshall Clow | ae4f831 | 2018-07-13 16:35:26 +0000 | [diff] [blame] | 1457 | _LIBCPP_CONSTEXPR_IF_NODEBUG friend |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1458 | bool |
Eric Fiselier | 38badb8 | 2016-12-28 05:35:32 +0000 | [diff] [blame] | 1459 | operator<=(const __wrap_iter<_Iter1>&, const __wrap_iter<_Iter2>&) _NOEXCEPT_DEBUG; |
Howard Hinnant | 3b6579a | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 1460 | |
Marshall Clow | 476d3f4 | 2016-07-18 13:19:00 +0000 | [diff] [blame] | 1461 | #ifndef _LIBCPP_CXX03_LANG |
Marshall Clow | f8fec4e | 2016-07-08 16:54:47 +0000 | [diff] [blame] | 1462 | template <class _Iter1, class _Iter2> |
Marshall Clow | ae4f831 | 2018-07-13 16:35:26 +0000 | [diff] [blame] | 1463 | _LIBCPP_CONSTEXPR_IF_NODEBUG friend |
Marshall Clow | f8fec4e | 2016-07-08 16:54:47 +0000 | [diff] [blame] | 1464 | auto |
Eric Fiselier | 38badb8 | 2016-12-28 05:35:32 +0000 | [diff] [blame] | 1465 | 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] | 1466 | -> decltype(__x.base() - __y.base()); |
| 1467 | #else |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1468 | template <class _Iter1, class _Iter2> |
Marshall Clow | ae4f831 | 2018-07-13 16:35:26 +0000 | [diff] [blame] | 1469 | _LIBCPP_CONSTEXPR_IF_NODEBUG friend |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1470 | typename __wrap_iter<_Iter1>::difference_type |
Eric Fiselier | 38badb8 | 2016-12-28 05:35:32 +0000 | [diff] [blame] | 1471 | operator-(const __wrap_iter<_Iter1>&, const __wrap_iter<_Iter2>&) _NOEXCEPT_DEBUG; |
Marshall Clow | f8fec4e | 2016-07-08 16:54:47 +0000 | [diff] [blame] | 1472 | #endif |
Howard Hinnant | 3b6579a | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 1473 | |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1474 | template <class _Iter1> |
Marshall Clow | ae4f831 | 2018-07-13 16:35:26 +0000 | [diff] [blame] | 1475 | _LIBCPP_CONSTEXPR_IF_NODEBUG friend |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1476 | __wrap_iter<_Iter1> |
Eric Fiselier | 38badb8 | 2016-12-28 05:35:32 +0000 | [diff] [blame] | 1477 | operator+(typename __wrap_iter<_Iter1>::difference_type, __wrap_iter<_Iter1>) _NOEXCEPT_DEBUG; |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1478 | |
Howard Hinnant | c834c51 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 1479 | template <class _Ip, class _Op> friend _Op copy(_Ip, _Ip, _Op); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1480 | template <class _B1, class _B2> friend _B2 copy_backward(_B1, _B1, _B2); |
Howard Hinnant | c834c51 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 1481 | template <class _Ip, class _Op> friend _Op move(_Ip, _Ip, _Op); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1482 | template <class _B1, class _B2> friend _B2 move_backward(_B1, _B1, _B2); |
| 1483 | |
Eric Fiselier | 38badb8 | 2016-12-28 05:35:32 +0000 | [diff] [blame] | 1484 | #if _LIBCPP_DEBUG_LEVEL < 2 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1485 | template <class _Tp> |
Marshall Clow | ae4f831 | 2018-07-13 16:35:26 +0000 | [diff] [blame] | 1486 | _LIBCPP_CONSTEXPR_IF_NODEBUG friend |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1487 | typename enable_if |
| 1488 | < |
Howard Hinnant | a9a897e | 2010-11-19 22:17:28 +0000 | [diff] [blame] | 1489 | is_trivially_copy_assignable<_Tp>::value, |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1490 | _Tp* |
| 1491 | >::type |
| 1492 | __unwrap_iter(__wrap_iter<_Tp*>); |
Eric Fiselier | 38badb8 | 2016-12-28 05:35:32 +0000 | [diff] [blame] | 1493 | #else |
| 1494 | template <class _Tp> |
Marshall Clow | ae4f831 | 2018-07-13 16:35:26 +0000 | [diff] [blame] | 1495 | inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG |
Eric Fiselier | 38badb8 | 2016-12-28 05:35:32 +0000 | [diff] [blame] | 1496 | typename enable_if |
| 1497 | < |
| 1498 | is_trivially_copy_assignable<_Tp>::value, |
| 1499 | __wrap_iter<_Tp*> |
| 1500 | >::type |
| 1501 | __unwrap_iter(__wrap_iter<_Tp*> __i); |
| 1502 | #endif |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1503 | }; |
| 1504 | |
| 1505 | template <class _Iter1, class _Iter2> |
Marshall Clow | ae4f831 | 2018-07-13 16:35:26 +0000 | [diff] [blame] | 1506 | inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1507 | bool |
Eric Fiselier | 38badb8 | 2016-12-28 05:35:32 +0000 | [diff] [blame] | 1508 | 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] | 1509 | { |
| 1510 | return __x.base() == __y.base(); |
| 1511 | } |
| 1512 | |
| 1513 | template <class _Iter1, class _Iter2> |
Marshall Clow | ae4f831 | 2018-07-13 16:35:26 +0000 | [diff] [blame] | 1514 | inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1515 | bool |
Eric Fiselier | 38badb8 | 2016-12-28 05:35:32 +0000 | [diff] [blame] | 1516 | 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] | 1517 | { |
Howard Hinnant | a47c6d5 | 2011-09-16 17:29:17 +0000 | [diff] [blame] | 1518 | #if _LIBCPP_DEBUG_LEVEL >= 2 |
Howard Hinnant | e6ff0b6 | 2013-08-02 00:26:35 +0000 | [diff] [blame] | 1519 | _LIBCPP_ASSERT(__get_const_db()->__less_than_comparable(&__x, &__y), |
Howard Hinnant | 27e0e77 | 2011-09-14 18:33:51 +0000 | [diff] [blame] | 1520 | "Attempted to compare incomparable iterators"); |
Howard Hinnant | a47c6d5 | 2011-09-16 17:29:17 +0000 | [diff] [blame] | 1521 | #endif |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1522 | return __x.base() < __y.base(); |
| 1523 | } |
| 1524 | |
| 1525 | template <class _Iter1, class _Iter2> |
Marshall Clow | ae4f831 | 2018-07-13 16:35:26 +0000 | [diff] [blame] | 1526 | inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1527 | bool |
Eric Fiselier | 38badb8 | 2016-12-28 05:35:32 +0000 | [diff] [blame] | 1528 | operator!=(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter2>& __y) _NOEXCEPT_DEBUG |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1529 | { |
Howard Hinnant | 27e0e77 | 2011-09-14 18:33:51 +0000 | [diff] [blame] | 1530 | return !(__x == __y); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1531 | } |
| 1532 | |
| 1533 | template <class _Iter1, class _Iter2> |
Marshall Clow | ae4f831 | 2018-07-13 16:35:26 +0000 | [diff] [blame] | 1534 | inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1535 | bool |
Eric Fiselier | 38badb8 | 2016-12-28 05:35:32 +0000 | [diff] [blame] | 1536 | operator>(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter2>& __y) _NOEXCEPT_DEBUG |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1537 | { |
Howard Hinnant | 27e0e77 | 2011-09-14 18:33:51 +0000 | [diff] [blame] | 1538 | return __y < __x; |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1539 | } |
| 1540 | |
| 1541 | template <class _Iter1, class _Iter2> |
Marshall Clow | ae4f831 | 2018-07-13 16:35:26 +0000 | [diff] [blame] | 1542 | inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1543 | bool |
Eric Fiselier | 38badb8 | 2016-12-28 05:35:32 +0000 | [diff] [blame] | 1544 | 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] | 1545 | { |
Howard Hinnant | 27e0e77 | 2011-09-14 18:33:51 +0000 | [diff] [blame] | 1546 | return !(__x < __y); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1547 | } |
| 1548 | |
| 1549 | template <class _Iter1, class _Iter2> |
Marshall Clow | ae4f831 | 2018-07-13 16:35:26 +0000 | [diff] [blame] | 1550 | inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1551 | bool |
Eric Fiselier | 38badb8 | 2016-12-28 05:35:32 +0000 | [diff] [blame] | 1552 | 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] | 1553 | { |
Howard Hinnant | 27e0e77 | 2011-09-14 18:33:51 +0000 | [diff] [blame] | 1554 | return !(__y < __x); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1555 | } |
| 1556 | |
Howard Hinnant | f78e32c | 2012-10-02 19:45:42 +0000 | [diff] [blame] | 1557 | template <class _Iter1> |
Marshall Clow | ae4f831 | 2018-07-13 16:35:26 +0000 | [diff] [blame] | 1558 | inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG |
Howard Hinnant | f78e32c | 2012-10-02 19:45:42 +0000 | [diff] [blame] | 1559 | bool |
Eric Fiselier | 38badb8 | 2016-12-28 05:35:32 +0000 | [diff] [blame] | 1560 | operator!=(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter1>& __y) _NOEXCEPT_DEBUG |
Howard Hinnant | f78e32c | 2012-10-02 19:45:42 +0000 | [diff] [blame] | 1561 | { |
| 1562 | return !(__x == __y); |
| 1563 | } |
| 1564 | |
| 1565 | template <class _Iter1> |
Marshall Clow | ae4f831 | 2018-07-13 16:35:26 +0000 | [diff] [blame] | 1566 | inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG |
Howard Hinnant | f78e32c | 2012-10-02 19:45:42 +0000 | [diff] [blame] | 1567 | bool |
Eric Fiselier | 38badb8 | 2016-12-28 05:35:32 +0000 | [diff] [blame] | 1568 | operator>(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter1>& __y) _NOEXCEPT_DEBUG |
Howard Hinnant | f78e32c | 2012-10-02 19:45:42 +0000 | [diff] [blame] | 1569 | { |
| 1570 | return __y < __x; |
| 1571 | } |
| 1572 | |
| 1573 | template <class _Iter1> |
Marshall Clow | ae4f831 | 2018-07-13 16:35:26 +0000 | [diff] [blame] | 1574 | inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG |
Howard Hinnant | f78e32c | 2012-10-02 19:45:42 +0000 | [diff] [blame] | 1575 | bool |
Eric Fiselier | 38badb8 | 2016-12-28 05:35:32 +0000 | [diff] [blame] | 1576 | 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] | 1577 | { |
| 1578 | return !(__x < __y); |
| 1579 | } |
| 1580 | |
| 1581 | template <class _Iter1> |
Marshall Clow | ae4f831 | 2018-07-13 16:35:26 +0000 | [diff] [blame] | 1582 | inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG |
Howard Hinnant | f78e32c | 2012-10-02 19:45:42 +0000 | [diff] [blame] | 1583 | bool |
Eric Fiselier | 38badb8 | 2016-12-28 05:35:32 +0000 | [diff] [blame] | 1584 | 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] | 1585 | { |
| 1586 | return !(__y < __x); |
| 1587 | } |
| 1588 | |
Marshall Clow | 476d3f4 | 2016-07-18 13:19:00 +0000 | [diff] [blame] | 1589 | #ifndef _LIBCPP_CXX03_LANG |
Marshall Clow | f8fec4e | 2016-07-08 16:54:47 +0000 | [diff] [blame] | 1590 | template <class _Iter1, class _Iter2> |
Marshall Clow | ae4f831 | 2018-07-13 16:35:26 +0000 | [diff] [blame] | 1591 | inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG |
Marshall Clow | f8fec4e | 2016-07-08 16:54:47 +0000 | [diff] [blame] | 1592 | auto |
Eric Fiselier | 38badb8 | 2016-12-28 05:35:32 +0000 | [diff] [blame] | 1593 | 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] | 1594 | -> decltype(__x.base() - __y.base()) |
| 1595 | { |
| 1596 | #if _LIBCPP_DEBUG_LEVEL >= 2 |
| 1597 | _LIBCPP_ASSERT(__get_const_db()->__less_than_comparable(&__x, &__y), |
| 1598 | "Attempted to subtract incompatible iterators"); |
| 1599 | #endif |
| 1600 | return __x.base() - __y.base(); |
| 1601 | } |
| 1602 | #else |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1603 | template <class _Iter1, class _Iter2> |
Marshall Clow | ae4f831 | 2018-07-13 16:35:26 +0000 | [diff] [blame] | 1604 | inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1605 | typename __wrap_iter<_Iter1>::difference_type |
Eric Fiselier | 38badb8 | 2016-12-28 05:35:32 +0000 | [diff] [blame] | 1606 | 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] | 1607 | { |
Howard Hinnant | a47c6d5 | 2011-09-16 17:29:17 +0000 | [diff] [blame] | 1608 | #if _LIBCPP_DEBUG_LEVEL >= 2 |
Howard Hinnant | e6ff0b6 | 2013-08-02 00:26:35 +0000 | [diff] [blame] | 1609 | _LIBCPP_ASSERT(__get_const_db()->__less_than_comparable(&__x, &__y), |
Howard Hinnant | 27e0e77 | 2011-09-14 18:33:51 +0000 | [diff] [blame] | 1610 | "Attempted to subtract incompatible iterators"); |
Howard Hinnant | a47c6d5 | 2011-09-16 17:29:17 +0000 | [diff] [blame] | 1611 | #endif |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1612 | return __x.base() - __y.base(); |
| 1613 | } |
Marshall Clow | f8fec4e | 2016-07-08 16:54:47 +0000 | [diff] [blame] | 1614 | #endif |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1615 | |
| 1616 | template <class _Iter> |
Marshall Clow | ae4f831 | 2018-07-13 16:35:26 +0000 | [diff] [blame] | 1617 | inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1618 | __wrap_iter<_Iter> |
| 1619 | operator+(typename __wrap_iter<_Iter>::difference_type __n, |
Eric Fiselier | 38badb8 | 2016-12-28 05:35:32 +0000 | [diff] [blame] | 1620 | __wrap_iter<_Iter> __x) _NOEXCEPT_DEBUG |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1621 | { |
Howard Hinnant | 27e0e77 | 2011-09-14 18:33:51 +0000 | [diff] [blame] | 1622 | __x += __n; |
| 1623 | return __x; |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1624 | } |
| 1625 | |
Marshall Clow | 039b2f0 | 2016-01-13 21:54:34 +0000 | [diff] [blame] | 1626 | template <class _Iter> |
| 1627 | struct __libcpp_is_trivial_iterator |
Marshall Clow | b5f9912 | 2016-11-02 15:30:26 +0000 | [diff] [blame] | 1628 | : public _LIBCPP_BOOL_CONSTANT(is_pointer<_Iter>::value) {}; |
| 1629 | |
Marshall Clow | 039b2f0 | 2016-01-13 21:54:34 +0000 | [diff] [blame] | 1630 | template <class _Iter> |
| 1631 | struct __libcpp_is_trivial_iterator<move_iterator<_Iter> > |
Marshall Clow | b5f9912 | 2016-11-02 15:30:26 +0000 | [diff] [blame] | 1632 | : public _LIBCPP_BOOL_CONSTANT(__libcpp_is_trivial_iterator<_Iter>::value) {}; |
Marshall Clow | 039b2f0 | 2016-01-13 21:54:34 +0000 | [diff] [blame] | 1633 | |
| 1634 | template <class _Iter> |
| 1635 | struct __libcpp_is_trivial_iterator<reverse_iterator<_Iter> > |
Marshall Clow | b5f9912 | 2016-11-02 15:30:26 +0000 | [diff] [blame] | 1636 | : public _LIBCPP_BOOL_CONSTANT(__libcpp_is_trivial_iterator<_Iter>::value) {}; |
Marshall Clow | 039b2f0 | 2016-01-13 21:54:34 +0000 | [diff] [blame] | 1637 | |
| 1638 | template <class _Iter> |
| 1639 | struct __libcpp_is_trivial_iterator<__wrap_iter<_Iter> > |
Marshall Clow | b5f9912 | 2016-11-02 15:30:26 +0000 | [diff] [blame] | 1640 | : public _LIBCPP_BOOL_CONSTANT(__libcpp_is_trivial_iterator<_Iter>::value) {}; |
Marshall Clow | 039b2f0 | 2016-01-13 21:54:34 +0000 | [diff] [blame] | 1641 | |
| 1642 | |
Marshall Clow | 8411ebf | 2013-12-02 03:24:33 +0000 | [diff] [blame] | 1643 | template <class _Tp, size_t _Np> |
Marshall Clow | e0ba886 | 2014-02-19 17:53:30 +0000 | [diff] [blame] | 1644 | inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 |
Marshall Clow | 8411ebf | 2013-12-02 03:24:33 +0000 | [diff] [blame] | 1645 | _Tp* |
| 1646 | begin(_Tp (&__array)[_Np]) |
| 1647 | { |
| 1648 | return __array; |
| 1649 | } |
| 1650 | |
| 1651 | template <class _Tp, size_t _Np> |
Marshall Clow | e0ba886 | 2014-02-19 17:53:30 +0000 | [diff] [blame] | 1652 | inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 |
Marshall Clow | 8411ebf | 2013-12-02 03:24:33 +0000 | [diff] [blame] | 1653 | _Tp* |
| 1654 | end(_Tp (&__array)[_Np]) |
| 1655 | { |
| 1656 | return __array + _Np; |
| 1657 | } |
| 1658 | |
Eric Fiselier | c6f17cc | 2016-09-25 03:34:28 +0000 | [diff] [blame] | 1659 | #if !defined(_LIBCPP_CXX03_LANG) |
Marshall Clow | 037fcb7 | 2013-12-11 19:32:32 +0000 | [diff] [blame] | 1660 | |
Howard Hinnant | c834c51 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 1661 | template <class _Cp> |
Marshall Clow | 99ba002 | 2017-01-04 17:58:17 +0000 | [diff] [blame] | 1662 | inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1663 | auto |
Howard Hinnant | c834c51 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 1664 | begin(_Cp& __c) -> decltype(__c.begin()) |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1665 | { |
| 1666 | return __c.begin(); |
| 1667 | } |
| 1668 | |
Howard Hinnant | c834c51 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 1669 | template <class _Cp> |
Marshall Clow | 99ba002 | 2017-01-04 17:58:17 +0000 | [diff] [blame] | 1670 | inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1671 | auto |
Howard Hinnant | c834c51 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 1672 | begin(const _Cp& __c) -> decltype(__c.begin()) |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1673 | { |
| 1674 | return __c.begin(); |
| 1675 | } |
| 1676 | |
Howard Hinnant | c834c51 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 1677 | template <class _Cp> |
Marshall Clow | 99ba002 | 2017-01-04 17:58:17 +0000 | [diff] [blame] | 1678 | inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1679 | auto |
Howard Hinnant | c834c51 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 1680 | end(_Cp& __c) -> decltype(__c.end()) |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1681 | { |
| 1682 | return __c.end(); |
| 1683 | } |
| 1684 | |
Howard Hinnant | c834c51 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 1685 | template <class _Cp> |
Marshall Clow | 99ba002 | 2017-01-04 17:58:17 +0000 | [diff] [blame] | 1686 | inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1687 | auto |
Howard Hinnant | c834c51 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 1688 | end(const _Cp& __c) -> decltype(__c.end()) |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1689 | { |
| 1690 | return __c.end(); |
| 1691 | } |
| 1692 | |
Marshall Clow | b278e9c | 2013-08-30 01:17:07 +0000 | [diff] [blame] | 1693 | #if _LIBCPP_STD_VER > 11 |
| 1694 | |
Marshall Clow | 8411ebf | 2013-12-02 03:24:33 +0000 | [diff] [blame] | 1695 | template <class _Tp, size_t _Np> |
Marshall Clow | 99ba002 | 2017-01-04 17:58:17 +0000 | [diff] [blame] | 1696 | inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 |
Marshall Clow | 8411ebf | 2013-12-02 03:24:33 +0000 | [diff] [blame] | 1697 | reverse_iterator<_Tp*> rbegin(_Tp (&__array)[_Np]) |
| 1698 | { |
| 1699 | return reverse_iterator<_Tp*>(__array + _Np); |
| 1700 | } |
| 1701 | |
| 1702 | template <class _Tp, size_t _Np> |
Marshall Clow | 99ba002 | 2017-01-04 17:58:17 +0000 | [diff] [blame] | 1703 | inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 |
Marshall Clow | 8411ebf | 2013-12-02 03:24:33 +0000 | [diff] [blame] | 1704 | reverse_iterator<_Tp*> rend(_Tp (&__array)[_Np]) |
| 1705 | { |
| 1706 | return reverse_iterator<_Tp*>(__array); |
| 1707 | } |
| 1708 | |
| 1709 | template <class _Ep> |
Marshall Clow | 99ba002 | 2017-01-04 17:58:17 +0000 | [diff] [blame] | 1710 | inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 |
Marshall Clow | 8411ebf | 2013-12-02 03:24:33 +0000 | [diff] [blame] | 1711 | reverse_iterator<const _Ep*> rbegin(initializer_list<_Ep> __il) |
| 1712 | { |
| 1713 | return reverse_iterator<const _Ep*>(__il.end()); |
| 1714 | } |
| 1715 | |
| 1716 | template <class _Ep> |
Marshall Clow | 99ba002 | 2017-01-04 17:58:17 +0000 | [diff] [blame] | 1717 | inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 |
Marshall Clow | 8411ebf | 2013-12-02 03:24:33 +0000 | [diff] [blame] | 1718 | reverse_iterator<const _Ep*> rend(initializer_list<_Ep> __il) |
| 1719 | { |
| 1720 | return reverse_iterator<const _Ep*>(__il.begin()); |
| 1721 | } |
| 1722 | |
Marshall Clow | b278e9c | 2013-08-30 01:17:07 +0000 | [diff] [blame] | 1723 | template <class _Cp> |
Marshall Clow | e0ba886 | 2014-02-19 17:53:30 +0000 | [diff] [blame] | 1724 | inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 |
Marshall Clow | 3862f53 | 2016-08-10 20:04:46 +0000 | [diff] [blame] | 1725 | auto cbegin(const _Cp& __c) -> decltype(_VSTD::begin(__c)) |
Marshall Clow | b278e9c | 2013-08-30 01:17:07 +0000 | [diff] [blame] | 1726 | { |
Marshall Clow | 3862f53 | 2016-08-10 20:04:46 +0000 | [diff] [blame] | 1727 | return _VSTD::begin(__c); |
Marshall Clow | b278e9c | 2013-08-30 01:17:07 +0000 | [diff] [blame] | 1728 | } |
| 1729 | |
| 1730 | template <class _Cp> |
Marshall Clow | e0ba886 | 2014-02-19 17:53:30 +0000 | [diff] [blame] | 1731 | inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 |
Marshall Clow | 3862f53 | 2016-08-10 20:04:46 +0000 | [diff] [blame] | 1732 | auto cend(const _Cp& __c) -> decltype(_VSTD::end(__c)) |
Marshall Clow | b278e9c | 2013-08-30 01:17:07 +0000 | [diff] [blame] | 1733 | { |
Marshall Clow | 3862f53 | 2016-08-10 20:04:46 +0000 | [diff] [blame] | 1734 | return _VSTD::end(__c); |
Marshall Clow | b278e9c | 2013-08-30 01:17:07 +0000 | [diff] [blame] | 1735 | } |
| 1736 | |
| 1737 | template <class _Cp> |
Marshall Clow | 99ba002 | 2017-01-04 17:58:17 +0000 | [diff] [blame] | 1738 | inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 |
Marshall Clow | b278e9c | 2013-08-30 01:17:07 +0000 | [diff] [blame] | 1739 | auto rbegin(_Cp& __c) -> decltype(__c.rbegin()) |
| 1740 | { |
| 1741 | return __c.rbegin(); |
| 1742 | } |
| 1743 | |
| 1744 | template <class _Cp> |
Marshall Clow | 99ba002 | 2017-01-04 17:58:17 +0000 | [diff] [blame] | 1745 | inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 |
Marshall Clow | b278e9c | 2013-08-30 01:17:07 +0000 | [diff] [blame] | 1746 | auto rbegin(const _Cp& __c) -> decltype(__c.rbegin()) |
| 1747 | { |
| 1748 | return __c.rbegin(); |
| 1749 | } |
| 1750 | |
| 1751 | template <class _Cp> |
Marshall Clow | 99ba002 | 2017-01-04 17:58:17 +0000 | [diff] [blame] | 1752 | inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 |
Marshall Clow | b278e9c | 2013-08-30 01:17:07 +0000 | [diff] [blame] | 1753 | auto rend(_Cp& __c) -> decltype(__c.rend()) |
| 1754 | { |
| 1755 | return __c.rend(); |
| 1756 | } |
| 1757 | |
| 1758 | template <class _Cp> |
Marshall Clow | 99ba002 | 2017-01-04 17:58:17 +0000 | [diff] [blame] | 1759 | inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 |
Marshall Clow | b278e9c | 2013-08-30 01:17:07 +0000 | [diff] [blame] | 1760 | auto rend(const _Cp& __c) -> decltype(__c.rend()) |
| 1761 | { |
| 1762 | return __c.rend(); |
| 1763 | } |
| 1764 | |
| 1765 | template <class _Cp> |
Marshall Clow | 99ba002 | 2017-01-04 17:58:17 +0000 | [diff] [blame] | 1766 | inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 |
Marshall Clow | 3862f53 | 2016-08-10 20:04:46 +0000 | [diff] [blame] | 1767 | auto crbegin(const _Cp& __c) -> decltype(_VSTD::rbegin(__c)) |
Marshall Clow | b278e9c | 2013-08-30 01:17:07 +0000 | [diff] [blame] | 1768 | { |
Marshall Clow | 3862f53 | 2016-08-10 20:04:46 +0000 | [diff] [blame] | 1769 | return _VSTD::rbegin(__c); |
Marshall Clow | b278e9c | 2013-08-30 01:17:07 +0000 | [diff] [blame] | 1770 | } |
| 1771 | |
| 1772 | template <class _Cp> |
Marshall Clow | 99ba002 | 2017-01-04 17:58:17 +0000 | [diff] [blame] | 1773 | inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 |
Marshall Clow | 3862f53 | 2016-08-10 20:04:46 +0000 | [diff] [blame] | 1774 | auto crend(const _Cp& __c) -> decltype(_VSTD::rend(__c)) |
Marshall Clow | b278e9c | 2013-08-30 01:17:07 +0000 | [diff] [blame] | 1775 | { |
Marshall Clow | 3862f53 | 2016-08-10 20:04:46 +0000 | [diff] [blame] | 1776 | return _VSTD::rend(__c); |
Marshall Clow | b278e9c | 2013-08-30 01:17:07 +0000 | [diff] [blame] | 1777 | } |
| 1778 | |
| 1779 | #endif |
| 1780 | |
| 1781 | |
Eric Fiselier | c6f17cc | 2016-09-25 03:34:28 +0000 | [diff] [blame] | 1782 | #else // defined(_LIBCPP_CXX03_LANG) |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1783 | |
Howard Hinnant | c834c51 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 1784 | template <class _Cp> |
Howard Hinnant | 756c69b | 2010-09-22 16:48:34 +0000 | [diff] [blame] | 1785 | inline _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | c834c51 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 1786 | typename _Cp::iterator |
| 1787 | begin(_Cp& __c) |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1788 | { |
| 1789 | return __c.begin(); |
| 1790 | } |
| 1791 | |
Howard Hinnant | c834c51 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 1792 | template <class _Cp> |
Howard Hinnant | 756c69b | 2010-09-22 16:48:34 +0000 | [diff] [blame] | 1793 | inline _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | c834c51 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 1794 | typename _Cp::const_iterator |
| 1795 | begin(const _Cp& __c) |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1796 | { |
| 1797 | return __c.begin(); |
| 1798 | } |
| 1799 | |
Howard Hinnant | c834c51 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 1800 | template <class _Cp> |
Howard Hinnant | 756c69b | 2010-09-22 16:48:34 +0000 | [diff] [blame] | 1801 | inline _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | c834c51 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 1802 | typename _Cp::iterator |
| 1803 | end(_Cp& __c) |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1804 | { |
| 1805 | return __c.end(); |
| 1806 | } |
| 1807 | |
Howard Hinnant | c834c51 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 1808 | template <class _Cp> |
Howard Hinnant | 756c69b | 2010-09-22 16:48:34 +0000 | [diff] [blame] | 1809 | inline _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | c834c51 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 1810 | typename _Cp::const_iterator |
| 1811 | end(const _Cp& __c) |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1812 | { |
| 1813 | return __c.end(); |
| 1814 | } |
| 1815 | |
Eric Fiselier | c6f17cc | 2016-09-25 03:34:28 +0000 | [diff] [blame] | 1816 | #endif // !defined(_LIBCPP_CXX03_LANG) |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1817 | |
Marshall Clow | ef35727 | 2014-11-19 19:43:23 +0000 | [diff] [blame] | 1818 | #if _LIBCPP_STD_VER > 14 |
Marshall Clow | 344c41d | 2017-11-16 17:55:41 +0000 | [diff] [blame] | 1819 | |
| 1820 | // #if _LIBCPP_STD_VER > 11 |
| 1821 | // template <> |
| 1822 | // struct _LIBCPP_TEMPLATE_VIS plus<void> |
| 1823 | // { |
| 1824 | // template <class _T1, class _T2> |
| 1825 | // _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY |
| 1826 | // auto operator()(_T1&& __t, _T2&& __u) const |
| 1827 | // _NOEXCEPT_(noexcept(_VSTD::forward<_T1>(__t) + _VSTD::forward<_T2>(__u))) |
| 1828 | // -> decltype (_VSTD::forward<_T1>(__t) + _VSTD::forward<_T2>(__u)) |
| 1829 | // { return _VSTD::forward<_T1>(__t) + _VSTD::forward<_T2>(__u); } |
| 1830 | // typedef void is_transparent; |
| 1831 | // }; |
| 1832 | // #endif |
| 1833 | |
Marshall Clow | c4b4a34 | 2015-02-11 16:14:01 +0000 | [diff] [blame] | 1834 | template <class _Cont> |
Marshall Clow | b7db497 | 2017-11-15 20:02:27 +0000 | [diff] [blame] | 1835 | inline _LIBCPP_INLINE_VISIBILITY |
Marshall Clow | 344c41d | 2017-11-16 17:55:41 +0000 | [diff] [blame] | 1836 | constexpr auto size(const _Cont& __c) |
| 1837 | _NOEXCEPT_(noexcept(__c.size())) |
| 1838 | -> decltype (__c.size()) |
| 1839 | { return __c.size(); } |
Marshall Clow | ef35727 | 2014-11-19 19:43:23 +0000 | [diff] [blame] | 1840 | |
Marshall Clow | c4b4a34 | 2015-02-11 16:14:01 +0000 | [diff] [blame] | 1841 | template <class _Tp, size_t _Sz> |
Marshall Clow | b7db497 | 2017-11-15 20:02:27 +0000 | [diff] [blame] | 1842 | inline _LIBCPP_INLINE_VISIBILITY |
Eric Fiselier | 6003c77 | 2016-12-23 23:37:52 +0000 | [diff] [blame] | 1843 | constexpr size_t size(const _Tp (&)[_Sz]) noexcept { return _Sz; } |
Marshall Clow | ef35727 | 2014-11-19 19:43:23 +0000 | [diff] [blame] | 1844 | |
Marshall Clow | c4b4a34 | 2015-02-11 16:14:01 +0000 | [diff] [blame] | 1845 | template <class _Cont> |
Marshall Clow | b7db497 | 2017-11-15 20:02:27 +0000 | [diff] [blame] | 1846 | _LIBCPP_NODISCARD_AFTER_CXX17 inline _LIBCPP_INLINE_VISIBILITY |
Marshall Clow | 344c41d | 2017-11-16 17:55:41 +0000 | [diff] [blame] | 1847 | constexpr auto empty(const _Cont& __c) |
| 1848 | _NOEXCEPT_(noexcept(__c.empty())) |
| 1849 | -> decltype (__c.empty()) |
| 1850 | { return __c.empty(); } |
Marshall Clow | ef35727 | 2014-11-19 19:43:23 +0000 | [diff] [blame] | 1851 | |
Marshall Clow | c4b4a34 | 2015-02-11 16:14:01 +0000 | [diff] [blame] | 1852 | template <class _Tp, size_t _Sz> |
Marshall Clow | b7db497 | 2017-11-15 20:02:27 +0000 | [diff] [blame] | 1853 | _LIBCPP_NODISCARD_AFTER_CXX17 inline _LIBCPP_INLINE_VISIBILITY |
Eric Fiselier | 6003c77 | 2016-12-23 23:37:52 +0000 | [diff] [blame] | 1854 | constexpr bool empty(const _Tp (&)[_Sz]) noexcept { return false; } |
Marshall Clow | ef35727 | 2014-11-19 19:43:23 +0000 | [diff] [blame] | 1855 | |
| 1856 | template <class _Ep> |
Marshall Clow | b7db497 | 2017-11-15 20:02:27 +0000 | [diff] [blame] | 1857 | _LIBCPP_NODISCARD_AFTER_CXX17 inline _LIBCPP_INLINE_VISIBILITY |
Marshall Clow | ef35727 | 2014-11-19 19:43:23 +0000 | [diff] [blame] | 1858 | constexpr bool empty(initializer_list<_Ep> __il) noexcept { return __il.size() == 0; } |
| 1859 | |
Marshall Clow | c4b4a34 | 2015-02-11 16:14:01 +0000 | [diff] [blame] | 1860 | template <class _Cont> constexpr |
Marshall Clow | b7db497 | 2017-11-15 20:02:27 +0000 | [diff] [blame] | 1861 | inline _LIBCPP_INLINE_VISIBILITY |
Marshall Clow | 344c41d | 2017-11-16 17:55:41 +0000 | [diff] [blame] | 1862 | auto data(_Cont& __c) |
| 1863 | _NOEXCEPT_(noexcept(__c.data())) |
| 1864 | -> decltype (__c.data()) |
| 1865 | { return __c.data(); } |
Marshall Clow | ef35727 | 2014-11-19 19:43:23 +0000 | [diff] [blame] | 1866 | |
Marshall Clow | c4b4a34 | 2015-02-11 16:14:01 +0000 | [diff] [blame] | 1867 | template <class _Cont> constexpr |
Marshall Clow | b7db497 | 2017-11-15 20:02:27 +0000 | [diff] [blame] | 1868 | inline _LIBCPP_INLINE_VISIBILITY |
Marshall Clow | 344c41d | 2017-11-16 17:55:41 +0000 | [diff] [blame] | 1869 | auto data(const _Cont& __c) |
| 1870 | _NOEXCEPT_(noexcept(__c.data())) |
| 1871 | -> decltype (__c.data()) |
| 1872 | { return __c.data(); } |
Marshall Clow | ef35727 | 2014-11-19 19:43:23 +0000 | [diff] [blame] | 1873 | |
Marshall Clow | c4b4a34 | 2015-02-11 16:14:01 +0000 | [diff] [blame] | 1874 | template <class _Tp, size_t _Sz> |
Marshall Clow | b7db497 | 2017-11-15 20:02:27 +0000 | [diff] [blame] | 1875 | inline _LIBCPP_INLINE_VISIBILITY |
Marshall Clow | c4b4a34 | 2015-02-11 16:14:01 +0000 | [diff] [blame] | 1876 | constexpr _Tp* data(_Tp (&__array)[_Sz]) noexcept { return __array; } |
Marshall Clow | ef35727 | 2014-11-19 19:43:23 +0000 | [diff] [blame] | 1877 | |
| 1878 | template <class _Ep> |
Marshall Clow | b7db497 | 2017-11-15 20:02:27 +0000 | [diff] [blame] | 1879 | inline _LIBCPP_INLINE_VISIBILITY |
Marshall Clow | ef35727 | 2014-11-19 19:43:23 +0000 | [diff] [blame] | 1880 | constexpr const _Ep* data(initializer_list<_Ep> __il) noexcept { return __il.begin(); } |
| 1881 | #endif |
| 1882 | |
| 1883 | |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1884 | _LIBCPP_END_NAMESPACE_STD |
| 1885 | |
| 1886 | #endif // _LIBCPP_ITERATOR |