Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1 | // -*- C++ -*- |
| 2 | //===-------------------------- iterator ----------------------------------===// |
| 3 | // |
Chandler Carruth | d201210 | 2019-01-19 10:56:40 +0000 | [diff] [blame] | 4 | // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. |
| 5 | // See https://llvm.org/LICENSE.txt for license information. |
| 6 | // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 7 | // |
| 8 | //===----------------------------------------------------------------------===// |
| 9 | |
| 10 | #ifndef _LIBCPP_ITERATOR |
| 11 | #define _LIBCPP_ITERATOR |
| 12 | |
| 13 | /* |
| 14 | iterator synopsis |
| 15 | |
Christopher Di Bella | 490fe40 | 2021-03-23 03:55:52 +0000 | [diff] [blame] | 16 | #include <concepts> |
| 17 | |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 18 | namespace std |
| 19 | { |
Christopher Di Bella | e00eebc | 2021-03-23 20:48:41 +0000 | [diff] [blame] | 20 | template<class> struct incrementable_traits; // since C++20 |
Christopher Di Bella | a3a1006 | 2021-04-20 18:56:08 +0000 | [diff] [blame] | 21 | template<class T> |
| 22 | using iter_difference_t = see below; // since C++20 |
| 23 | |
Christopher Di Bella | e00eebc | 2021-03-23 20:48:41 +0000 | [diff] [blame] | 24 | template<class> struct indirectly_readable_traits; // since C++20 |
Christopher Di Bella | a3a1006 | 2021-04-20 18:56:08 +0000 | [diff] [blame] | 25 | template<class T> |
| 26 | using iter_value_t = see below; // since C++20 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 27 | |
| 28 | template<class Iterator> |
zoecarver | 9f1e297 | 2021-04-20 08:50:11 -0400 | [diff] [blame] | 29 | struct iterator_traits; |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 30 | |
| 31 | template<class T> |
zoecarver | 9f1e297 | 2021-04-20 08:50:11 -0400 | [diff] [blame] | 32 | requires is_object_v<T> // since C++20 |
| 33 | struct iterator_traits<T*>; |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 34 | |
Christopher Di Bella | 875636f | 2021-04-04 05:12:46 +0000 | [diff] [blame] | 35 | template<dereferenceable T> |
| 36 | using iter_reference_t = decltype(*declval<T&>()); |
| 37 | |
Louis Dionne | ca989a5 | 2021-04-20 14:40:43 -0400 | [diff] [blame] | 38 | namespace ranges::inline unspecified { |
| 39 | inline constexpr unspecified iter_move = unspecified; // since C++20, nodiscard as an extension |
| 40 | }} |
| 41 | |
| 42 | template<dereferenceable T> |
| 43 | requires ... |
| 44 | using iter_rvalue_reference_t = decltype(ranges::iter_move(declval<T&>())); // since C++20 |
| 45 | |
Louis Dionne | 463afb8 | 2021-04-22 11:05:30 -0400 | [diff] [blame] | 46 | // [iterator.concepts], iterator concepts |
| 47 | // [iterator.concept.readable], concept indirectly_readable |
| 48 | template<class In> |
Louis Dionne | 170a03c | 2021-04-28 15:02:08 -0400 | [diff] [blame] | 49 | concept indirectly_readable = see below; // since C++20 |
| 50 | |
| 51 | template<indirectly_readable T> |
| 52 | using iter_common_reference_t = |
| 53 | common_reference_t<iter_reference_t<T>, iter_value_t<T>&>; // since C++20 |
Louis Dionne | 463afb8 | 2021-04-22 11:05:30 -0400 | [diff] [blame] | 54 | |
| 55 | // [iterator.concept.writable], concept indirectly_writable |
| 56 | template<class Out, class T> |
| 57 | concept indirectly_writable = see below; // since C++20 |
| 58 | |
Mark de Wever | 6639f42 | 2021-04-26 17:53:20 +0200 | [diff] [blame] | 59 | // [iterator.concept.winc], concept weakly_incrementable |
Christopher Di Bella | 54ffc18 | 2021-04-23 18:22:55 -0700 | [diff] [blame] | 60 | template<class I> |
| 61 | concept weakly_incrementable = see below; // since C++20 |
| 62 | |
| 63 | // [iterator.concept.inc], concept incrementable |
| 64 | template<class I> |
| 65 | concept incrementable = see below; // since C++20 |
| 66 | |
Mark de Wever | 6639f42 | 2021-04-26 17:53:20 +0200 | [diff] [blame] | 67 | // [iterator.concept.iterator], concept input_or_output_iterator |
Christopher Di Bella | 0ef5228 | 2021-04-09 02:10:32 +0000 | [diff] [blame] | 68 | template<class I> |
| 69 | concept input_or_output_iterator = see below; // since C++20 |
| 70 | |
Mark de Wever | 6639f42 | 2021-04-26 17:53:20 +0200 | [diff] [blame] | 71 | // [iterator.concept.sentinel], concept sentinel_for |
Christopher Di Bella | 0ef5228 | 2021-04-09 02:10:32 +0000 | [diff] [blame] | 72 | template<class S, class I> |
| 73 | concept sentinel_for = see below; // since C++20 |
| 74 | |
zoecarver | 11391bc | 2021-04-26 09:35:47 -0700 | [diff] [blame] | 75 | // [iterator.concept.sizedsentinel], concept sized_sentinel_for |
| 76 | template<class S, class I> |
| 77 | inline constexpr bool disable_sized_sentinel_for = false; |
| 78 | |
| 79 | template<class S, class I> |
| 80 | concept sized_sentinel_for = see below; |
| 81 | |
Christopher Di Bella | 8250c63 | 2021-04-11 19:04:52 +0000 | [diff] [blame] | 82 | // [iterator.concept.input], concept input_iterator |
| 83 | template<class I> |
| 84 | concept input_iterator = see below; // since C++20 |
| 85 | |
Christopher Di Bella | 8f1370d | 2021-04-11 22:11:03 +0000 | [diff] [blame] | 86 | // [iterator.concept.forward], concept forward_iterator |
| 87 | template<class I> |
| 88 | concept forward_iterator = see below; // since C++20 |
| 89 | |
Christopher Di Bella | 10a3147 | 2021-04-12 01:16:45 +0000 | [diff] [blame] | 90 | // [iterator.concept.bidir], concept bidirectional_iterator |
| 91 | template<class I> |
| 92 | concept bidirectional_iterator = see below; // since C++20 |
| 93 | |
zoecarver | 21da57e | 2021-04-23 17:11:44 -0700 | [diff] [blame] | 94 | // [iterator.concept.random.access], concept random_access_iterator |
| 95 | template<class I> |
| 96 | concept random_access_iterator = see below; // since C++20 |
| 97 | |
Louis Dionne | 170a03c | 2021-04-28 15:02:08 -0400 | [diff] [blame] | 98 | // [indirectcallable] |
| 99 | // [indirectcallable.indirectinvocable] |
| 100 | template<class F, class I> |
| 101 | concept indirectly_unary_invocable = see below; // since C++20 |
| 102 | |
| 103 | template<class F, class I> |
| 104 | concept indirectly_regular_unary_invocable = see below; // since C++20 |
| 105 | |
| 106 | template<class F, class I> |
| 107 | concept indirect_unary_predicate = see below; // since C++20 |
| 108 | |
| 109 | template<class F, class I1, class I2> |
| 110 | concept indirect_binary_predicate = see below; // since C++20 |
| 111 | |
| 112 | template<class F, class I1, class I2 = I1> |
| 113 | concept indirect_equivalence_relation = see below; // since C++20 |
| 114 | |
| 115 | template<class F, class I1, class I2 = I1> |
| 116 | concept indirect_strict_weak_order = see below; // since C++20 |
| 117 | |
| 118 | template<class F, class... Is> |
| 119 | using indirect_result_t = see below; // since C++20 |
| 120 | |
| 121 | // [projected], projected |
| 122 | template<indirectly_readable I, indirectly_regular_unary_invocable<I> Proj> |
| 123 | struct projected; // since C++20 |
| 124 | |
| 125 | template<weakly_incrementable I, indirectly_regular_unary_invocable<I> Proj> |
| 126 | struct incrementable_traits<projected<I, Proj>>; // since C++20 |
| 127 | |
zoecarver | 7e38f80 | 2021-05-17 10:30:12 -0700 | [diff] [blame] | 128 | // [alg.req.ind.move], concept indirectly_movable |
| 129 | template<class In, class Out> |
| 130 | concept indirectly_movable = see below; // since C++20 |
| 131 | |
| 132 | template<class In, class Out> |
| 133 | concept indirectly_movable_storable = see below; // since C++20 |
| 134 | |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 135 | template<class Category, class T, class Distance = ptrdiff_t, |
| 136 | class Pointer = T*, class Reference = T&> |
Louis Dionne | 8762e2b | 2021-05-25 18:15:58 -0400 | [diff] [blame] | 137 | struct iterator // deprecated in C++17 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 138 | { |
| 139 | typedef T value_type; |
| 140 | typedef Distance difference_type; |
| 141 | typedef Pointer pointer; |
| 142 | typedef Reference reference; |
| 143 | typedef Category iterator_category; |
| 144 | }; |
| 145 | |
| 146 | struct input_iterator_tag {}; |
| 147 | struct output_iterator_tag {}; |
| 148 | struct forward_iterator_tag : public input_iterator_tag {}; |
| 149 | struct bidirectional_iterator_tag : public forward_iterator_tag {}; |
| 150 | struct random_access_iterator_tag : public bidirectional_iterator_tag {}; |
| 151 | |
Marshall Clow | 75468e7 | 2017-05-17 18:51:36 +0000 | [diff] [blame] | 152 | // 27.4.3, iterator operations |
Louis Dionne | 4576866 | 2020-06-08 16:16:01 -0400 | [diff] [blame] | 153 | template <class InputIterator, class Distance> // constexpr in C++17 |
| 154 | constexpr void advance(InputIterator& i, Distance n); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 155 | |
Marshall Clow | 75468e7 | 2017-05-17 18:51:36 +0000 | [diff] [blame] | 156 | template <class InputIterator> // constexpr in C++17 |
| 157 | constexpr typename iterator_traits<InputIterator>::difference_type |
| 158 | distance(InputIterator first, InputIterator last); |
| 159 | |
| 160 | template <class InputIterator> // constexpr in C++17 |
| 161 | constexpr InputIterator next(InputIterator x, |
| 162 | typename iterator_traits<InputIterator>::difference_type n = 1); |
| 163 | |
| 164 | template <class BidirectionalIterator> // constexpr in C++17 |
| 165 | constexpr BidirectionalIterator prev(BidirectionalIterator x, |
Louis Dionne | 173f29e | 2019-05-29 16:01:36 +0000 | [diff] [blame] | 166 | typename iterator_traits<BidirectionalIterator>::difference_type n = 1); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 167 | |
Christopher Di Bella | c6ead65 | 2021-05-05 07:14:08 +0000 | [diff] [blame] | 168 | // [range.iter.ops], range iterator operations |
| 169 | namespace ranges { |
| 170 | // [range.iter.op.advance], ranges::advance |
| 171 | template<input_or_output_iterator I> |
| 172 | constexpr void advance(I& i, iter_difference_t<I> n); // since C++20 |
| 173 | template<input_or_output_iterator I, sentinel_for<I> S> |
| 174 | constexpr void advance(I& i, S bound); // since C++20 |
| 175 | template<input_or_output_iterator I, sentinel_for<I> S> |
| 176 | constexpr iter_difference_t<I> advance(I& i, iter_difference_t<I> n, S bound); // since C++20 |
| 177 | } |
| 178 | |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 179 | template <class Iterator> |
| 180 | class reverse_iterator |
Louis Dionne | 8762e2b | 2021-05-25 18:15:58 -0400 | [diff] [blame] | 181 | : public iterator<typename iterator_traits<Iterator>::iterator_category, // until C++17 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 182 | typename iterator_traits<Iterator>::value_type, |
| 183 | typename iterator_traits<Iterator>::difference_type, |
| 184 | typename iterator_traits<Iterator>::pointer, |
| 185 | typename iterator_traits<Iterator>::reference> |
| 186 | { |
| 187 | protected: |
| 188 | Iterator current; |
| 189 | public: |
| 190 | typedef Iterator iterator_type; |
| 191 | typedef typename iterator_traits<Iterator>::difference_type difference_type; |
| 192 | typedef typename iterator_traits<Iterator>::reference reference; |
| 193 | typedef typename iterator_traits<Iterator>::pointer pointer; |
Howard Hinnant | 3b6579a | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 194 | |
Marshall Clow | 5ace554 | 2016-10-19 15:12:50 +0000 | [diff] [blame] | 195 | constexpr reverse_iterator(); |
| 196 | constexpr explicit reverse_iterator(Iterator x); |
| 197 | template <class U> constexpr reverse_iterator(const reverse_iterator<U>& u); |
| 198 | template <class U> constexpr reverse_iterator& operator=(const reverse_iterator<U>& u); |
| 199 | constexpr Iterator base() const; |
| 200 | constexpr reference operator*() const; |
| 201 | constexpr pointer operator->() const; |
| 202 | constexpr reverse_iterator& operator++(); |
| 203 | constexpr reverse_iterator operator++(int); |
| 204 | constexpr reverse_iterator& operator--(); |
| 205 | constexpr reverse_iterator operator--(int); |
| 206 | constexpr reverse_iterator operator+ (difference_type n) const; |
| 207 | constexpr reverse_iterator& operator+=(difference_type n); |
| 208 | constexpr reverse_iterator operator- (difference_type n) const; |
| 209 | constexpr reverse_iterator& operator-=(difference_type n); |
| 210 | constexpr reference operator[](difference_type n) const; |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 211 | }; |
| 212 | |
| 213 | template <class Iterator1, class Iterator2> |
Marshall Clow | 5ace554 | 2016-10-19 15:12:50 +0000 | [diff] [blame] | 214 | constexpr bool // constexpr in C++17 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 215 | operator==(const reverse_iterator<Iterator1>& x, const reverse_iterator<Iterator2>& y); |
| 216 | |
| 217 | template <class Iterator1, class Iterator2> |
Marshall Clow | 5ace554 | 2016-10-19 15:12:50 +0000 | [diff] [blame] | 218 | constexpr bool // constexpr in C++17 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 219 | operator<(const reverse_iterator<Iterator1>& x, const reverse_iterator<Iterator2>& y); |
| 220 | |
| 221 | template <class Iterator1, class Iterator2> |
Marshall Clow | 5ace554 | 2016-10-19 15:12:50 +0000 | [diff] [blame] | 222 | constexpr bool // constexpr in C++17 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 223 | operator!=(const reverse_iterator<Iterator1>& x, const reverse_iterator<Iterator2>& y); |
| 224 | |
| 225 | template <class Iterator1, class Iterator2> |
Marshall Clow | 5ace554 | 2016-10-19 15:12:50 +0000 | [diff] [blame] | 226 | constexpr bool // constexpr in C++17 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 227 | operator>(const reverse_iterator<Iterator1>& x, const reverse_iterator<Iterator2>& y); |
| 228 | |
| 229 | template <class Iterator1, class Iterator2> |
Marshall Clow | 5ace554 | 2016-10-19 15:12:50 +0000 | [diff] [blame] | 230 | constexpr bool // constexpr in C++17 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 231 | operator>=(const reverse_iterator<Iterator1>& x, const reverse_iterator<Iterator2>& y); |
| 232 | |
| 233 | template <class Iterator1, class Iterator2> |
Marshall Clow | 5ace554 | 2016-10-19 15:12:50 +0000 | [diff] [blame] | 234 | constexpr bool // constexpr in C++17 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 235 | operator<=(const reverse_iterator<Iterator1>& x, const reverse_iterator<Iterator2>& y); |
| 236 | |
| 237 | template <class Iterator1, class Iterator2> |
Marshall Clow | 5ace554 | 2016-10-19 15:12:50 +0000 | [diff] [blame] | 238 | constexpr auto |
Marshall Clow | f8fec4e | 2016-07-08 16:54:47 +0000 | [diff] [blame] | 239 | operator-(const reverse_iterator<Iterator1>& x, const reverse_iterator<Iterator2>& y) |
Marshall Clow | 5ace554 | 2016-10-19 15:12:50 +0000 | [diff] [blame] | 240 | -> decltype(__y.base() - __x.base()); // constexpr in C++17 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 241 | |
| 242 | template <class Iterator> |
Marshall Clow | 5ace554 | 2016-10-19 15:12:50 +0000 | [diff] [blame] | 243 | constexpr reverse_iterator<Iterator> |
Louis Dionne | 173f29e | 2019-05-29 16:01:36 +0000 | [diff] [blame] | 244 | operator+(typename reverse_iterator<Iterator>::difference_type n, |
Marshall Clow | 5ace554 | 2016-10-19 15:12:50 +0000 | [diff] [blame] | 245 | const reverse_iterator<Iterator>& x); // constexpr in C++17 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 246 | |
Marshall Clow | 5ace554 | 2016-10-19 15:12:50 +0000 | [diff] [blame] | 247 | template <class Iterator> |
| 248 | 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] | 249 | |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 250 | template <class Container> |
| 251 | class back_insert_iterator |
Louis Dionne | 3402c3c | 2021-05-27 12:56:12 -0400 | [diff] [blame] | 252 | : public iterator<output_iterator_tag, void, void, void, void> // until C++17 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 253 | { |
| 254 | protected: |
| 255 | Container* container; |
| 256 | public: |
| 257 | typedef Container container_type; |
| 258 | typedef void value_type; |
Louis Dionne | 3402c3c | 2021-05-27 12:56:12 -0400 | [diff] [blame] | 259 | typedef void difference_type; // until C++20 |
| 260 | typedef ptrdiff_t difference_type; // since C++20 |
Eric Fiselier | 9aeea87 | 2016-06-30 04:40:50 +0000 | [diff] [blame] | 261 | typedef void reference; |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 262 | typedef void pointer; |
| 263 | |
Arthur O'Dwyer | 20638cc | 2021-02-09 19:12:16 -0500 | [diff] [blame] | 264 | explicit back_insert_iterator(Container& x); // constexpr in C++20 |
| 265 | back_insert_iterator& operator=(const typename Container::value_type& value); // constexpr in C++20 |
| 266 | back_insert_iterator& operator*(); // constexpr in C++20 |
| 267 | back_insert_iterator& operator++(); // constexpr in C++20 |
| 268 | back_insert_iterator operator++(int); // constexpr in C++20 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 269 | }; |
| 270 | |
Arthur O'Dwyer | 20638cc | 2021-02-09 19:12:16 -0500 | [diff] [blame] | 271 | template <class Container> back_insert_iterator<Container> back_inserter(Container& x); // constexpr in C++20 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 272 | |
| 273 | template <class Container> |
| 274 | class front_insert_iterator |
Louis Dionne | 3402c3c | 2021-05-27 12:56:12 -0400 | [diff] [blame] | 275 | : public iterator<output_iterator_tag, void, void, void, void> // until C++17 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 276 | { |
| 277 | protected: |
| 278 | Container* container; |
| 279 | public: |
| 280 | typedef Container container_type; |
| 281 | typedef void value_type; |
Louis Dionne | 3402c3c | 2021-05-27 12:56:12 -0400 | [diff] [blame] | 282 | typedef void difference_type; // until C++20 |
| 283 | typedef ptrdiff_t difference_type; // since C++20 |
Eric Fiselier | 9aeea87 | 2016-06-30 04:40:50 +0000 | [diff] [blame] | 284 | typedef void reference; |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 285 | typedef void pointer; |
| 286 | |
Arthur O'Dwyer | 20638cc | 2021-02-09 19:12:16 -0500 | [diff] [blame] | 287 | explicit front_insert_iterator(Container& x); // constexpr in C++20 |
| 288 | front_insert_iterator& operator=(const typename Container::value_type& value); // constexpr in C++20 |
| 289 | front_insert_iterator& operator*(); // constexpr in C++20 |
| 290 | front_insert_iterator& operator++(); // constexpr in C++20 |
| 291 | front_insert_iterator operator++(int); // constexpr in C++20 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 292 | }; |
| 293 | |
Arthur O'Dwyer | 20638cc | 2021-02-09 19:12:16 -0500 | [diff] [blame] | 294 | template <class Container> front_insert_iterator<Container> front_inserter(Container& x); // constexpr in C++20 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 295 | |
| 296 | template <class Container> |
| 297 | class insert_iterator |
Louis Dionne | 3402c3c | 2021-05-27 12:56:12 -0400 | [diff] [blame] | 298 | : public iterator<output_iterator_tag, void, void, void, void> // until C++17 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 299 | { |
| 300 | protected: |
| 301 | Container* container; |
| 302 | typename Container::iterator iter; |
| 303 | public: |
| 304 | typedef Container container_type; |
| 305 | typedef void value_type; |
Louis Dionne | 3402c3c | 2021-05-27 12:56:12 -0400 | [diff] [blame] | 306 | typedef void difference_type; // until C++20 |
| 307 | typedef ptrdiff_t difference_type; // since C++20 |
Eric Fiselier | 9aeea87 | 2016-06-30 04:40:50 +0000 | [diff] [blame] | 308 | typedef void reference; |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 309 | typedef void pointer; |
| 310 | |
Arthur O'Dwyer | 20638cc | 2021-02-09 19:12:16 -0500 | [diff] [blame] | 311 | insert_iterator(Container& x, typename Container::iterator i); // constexpr in C++20 |
| 312 | insert_iterator& operator=(const typename Container::value_type& value); // constexpr in C++20 |
| 313 | insert_iterator& operator*(); // constexpr in C++20 |
| 314 | insert_iterator& operator++(); // constexpr in C++20 |
| 315 | insert_iterator& operator++(int); // constexpr in C++20 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 316 | }; |
| 317 | |
| 318 | template <class Container, class Iterator> |
Arthur O'Dwyer | 20638cc | 2021-02-09 19:12:16 -0500 | [diff] [blame] | 319 | insert_iterator<Container> inserter(Container& x, Iterator i); // constexpr in C++20 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 320 | |
Marshall Clow | f8fec4e | 2016-07-08 16:54:47 +0000 | [diff] [blame] | 321 | template <class Iterator> |
| 322 | class move_iterator { |
| 323 | public: |
| 324 | typedef Iterator iterator_type; |
| 325 | typedef typename iterator_traits<Iterator>::difference_type difference_type; |
| 326 | typedef Iterator pointer; |
| 327 | typedef typename iterator_traits<Iterator>::value_type value_type; |
| 328 | typedef typename iterator_traits<Iterator>::iterator_category iterator_category; |
| 329 | typedef value_type&& reference; |
Louis Dionne | 173f29e | 2019-05-29 16:01:36 +0000 | [diff] [blame] | 330 | |
Marshall Clow | b5f9912 | 2016-11-02 15:30:26 +0000 | [diff] [blame] | 331 | constexpr move_iterator(); // all the constexprs are in C++17 |
| 332 | constexpr explicit move_iterator(Iterator i); |
| 333 | template <class U> |
| 334 | constexpr move_iterator(const move_iterator<U>& u); |
| 335 | template <class U> |
| 336 | constexpr move_iterator& operator=(const move_iterator<U>& u); |
| 337 | constexpr iterator_type base() const; |
| 338 | constexpr reference operator*() const; |
| 339 | constexpr pointer operator->() const; |
| 340 | constexpr move_iterator& operator++(); |
| 341 | constexpr move_iterator operator++(int); |
| 342 | constexpr move_iterator& operator--(); |
| 343 | constexpr move_iterator operator--(int); |
Louis Dionne | 173f29e | 2019-05-29 16:01:36 +0000 | [diff] [blame] | 344 | constexpr move_iterator operator+(difference_type n) const; |
| 345 | constexpr move_iterator& operator+=(difference_type n); |
| 346 | constexpr move_iterator operator-(difference_type n) const; |
| 347 | constexpr move_iterator& operator-=(difference_type n); |
Marshall Clow | b5f9912 | 2016-11-02 15:30:26 +0000 | [diff] [blame] | 348 | constexpr unspecified operator[](difference_type n) const; |
Marshall Clow | f8fec4e | 2016-07-08 16:54:47 +0000 | [diff] [blame] | 349 | private: |
| 350 | Iterator current; // exposition only |
| 351 | }; |
| 352 | |
| 353 | template <class Iterator1, class Iterator2> |
Marshall Clow | b5f9912 | 2016-11-02 15:30:26 +0000 | [diff] [blame] | 354 | constexpr bool // constexpr in C++17 |
Marshall Clow | f8fec4e | 2016-07-08 16:54:47 +0000 | [diff] [blame] | 355 | operator==(const move_iterator<Iterator1>& x, const move_iterator<Iterator2>& y); |
| 356 | |
| 357 | template <class Iterator1, class Iterator2> |
Marshall Clow | b5f9912 | 2016-11-02 15:30:26 +0000 | [diff] [blame] | 358 | constexpr bool // constexpr in C++17 |
Marshall Clow | f8fec4e | 2016-07-08 16:54:47 +0000 | [diff] [blame] | 359 | operator!=(const move_iterator<Iterator1>& x, const move_iterator<Iterator2>& y); |
| 360 | |
| 361 | template <class Iterator1, class Iterator2> |
Marshall Clow | b5f9912 | 2016-11-02 15:30:26 +0000 | [diff] [blame] | 362 | constexpr bool // constexpr in C++17 |
Marshall Clow | f8fec4e | 2016-07-08 16:54:47 +0000 | [diff] [blame] | 363 | operator<(const move_iterator<Iterator1>& x, const move_iterator<Iterator2>& y); |
| 364 | |
| 365 | template <class Iterator1, class Iterator2> |
Marshall Clow | b5f9912 | 2016-11-02 15:30:26 +0000 | [diff] [blame] | 366 | constexpr bool // constexpr in C++17 |
Marshall Clow | f8fec4e | 2016-07-08 16:54:47 +0000 | [diff] [blame] | 367 | operator<=(const move_iterator<Iterator1>& x, const move_iterator<Iterator2>& y); |
| 368 | |
| 369 | template <class Iterator1, class Iterator2> |
Marshall Clow | b5f9912 | 2016-11-02 15:30:26 +0000 | [diff] [blame] | 370 | constexpr bool // constexpr in C++17 |
Marshall Clow | f8fec4e | 2016-07-08 16:54:47 +0000 | [diff] [blame] | 371 | operator>(const move_iterator<Iterator1>& x, const move_iterator<Iterator2>& y); |
| 372 | |
| 373 | template <class Iterator1, class Iterator2> |
Marshall Clow | b5f9912 | 2016-11-02 15:30:26 +0000 | [diff] [blame] | 374 | constexpr bool // constexpr in C++17 |
Marshall Clow | f8fec4e | 2016-07-08 16:54:47 +0000 | [diff] [blame] | 375 | operator>=(const move_iterator<Iterator1>& x, const move_iterator<Iterator2>& y); |
| 376 | |
| 377 | template <class Iterator1, class Iterator2> |
Marshall Clow | b5f9912 | 2016-11-02 15:30:26 +0000 | [diff] [blame] | 378 | constexpr auto // constexpr in C++17 |
Marshall Clow | f8fec4e | 2016-07-08 16:54:47 +0000 | [diff] [blame] | 379 | operator-(const move_iterator<Iterator1>& x, |
| 380 | const move_iterator<Iterator2>& y) -> decltype(x.base() - y.base()); |
| 381 | |
| 382 | template <class Iterator> |
Marshall Clow | b5f9912 | 2016-11-02 15:30:26 +0000 | [diff] [blame] | 383 | constexpr move_iterator<Iterator> operator+( // constexpr in C++17 |
Louis Dionne | 173f29e | 2019-05-29 16:01:36 +0000 | [diff] [blame] | 384 | typename move_iterator<Iterator>::difference_type n, |
Marshall Clow | b5f9912 | 2016-11-02 15:30:26 +0000 | [diff] [blame] | 385 | const move_iterator<Iterator>& x); |
Marshall Clow | f8fec4e | 2016-07-08 16:54:47 +0000 | [diff] [blame] | 386 | |
Marshall Clow | b5f9912 | 2016-11-02 15:30:26 +0000 | [diff] [blame] | 387 | template <class Iterator> // constexpr in C++17 |
| 388 | constexpr move_iterator<Iterator> make_move_iterator(const Iterator& i); |
Marshall Clow | f8fec4e | 2016-07-08 16:54:47 +0000 | [diff] [blame] | 389 | |
zoecarver | 63f1320 | 2021-06-01 12:55:33 -0700 | [diff] [blame] | 390 | // [default.sentinel], default sentinel |
| 391 | struct default_sentinel_t; |
| 392 | inline constexpr default_sentinel_t default_sentinel{}; |
Marshall Clow | f8fec4e | 2016-07-08 16:54:47 +0000 | [diff] [blame] | 393 | |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 394 | template <class T, class charT = char, class traits = char_traits<charT>, class Distance = ptrdiff_t> |
| 395 | class istream_iterator |
Louis Dionne | 8762e2b | 2021-05-25 18:15:58 -0400 | [diff] [blame] | 396 | : public iterator<input_iterator_tag, T, Distance, const T*, const T&> // until C++17 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 397 | { |
| 398 | public: |
Louis Dionne | 3402c3c | 2021-05-27 12:56:12 -0400 | [diff] [blame] | 399 | typedef input_iterator_tag iterator_category; |
| 400 | typedef T value_type; |
| 401 | typedef Distance difference_type; |
| 402 | typedef const T* pointer; |
| 403 | typedef const T& reference; |
| 404 | |
| 405 | typedef charT char_type; |
| 406 | typedef traits traits_type; |
| 407 | typedef basic_istream<charT, traits> istream_type; |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 408 | |
Marshall Clow | 0735e4e | 2015-04-16 21:36:54 +0000 | [diff] [blame] | 409 | constexpr istream_iterator(); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 410 | istream_iterator(istream_type& s); |
| 411 | istream_iterator(const istream_iterator& x); |
| 412 | ~istream_iterator(); |
| 413 | |
| 414 | const T& operator*() const; |
| 415 | const T* operator->() const; |
| 416 | istream_iterator& operator++(); |
| 417 | istream_iterator operator++(int); |
| 418 | }; |
| 419 | |
| 420 | template <class T, class charT, class traits, class Distance> |
| 421 | bool operator==(const istream_iterator<T,charT,traits,Distance>& x, |
| 422 | const istream_iterator<T,charT,traits,Distance>& y); |
| 423 | template <class T, class charT, class traits, class Distance> |
| 424 | bool operator!=(const istream_iterator<T,charT,traits,Distance>& x, |
| 425 | const istream_iterator<T,charT,traits,Distance>& y); |
| 426 | |
| 427 | template <class T, class charT = char, class traits = char_traits<charT> > |
| 428 | class ostream_iterator |
Louis Dionne | 3402c3c | 2021-05-27 12:56:12 -0400 | [diff] [blame] | 429 | : public iterator<output_iterator_tag, void, void, void, void> // until C++17 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 430 | { |
| 431 | public: |
Louis Dionne | 3402c3c | 2021-05-27 12:56:12 -0400 | [diff] [blame] | 432 | typedef output_iterator_tag iterator_category; |
| 433 | typedef void value_type; |
| 434 | typedef void difference_type; // until C++20 |
| 435 | typedef ptrdiff_t difference_type; // since C++20 |
| 436 | typedef void pointer; |
| 437 | typedef void reference; |
| 438 | |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 439 | typedef charT char_type; |
| 440 | typedef traits traits_type; |
| 441 | typedef basic_ostream<charT,traits> ostream_type; |
| 442 | |
| 443 | ostream_iterator(ostream_type& s); |
| 444 | ostream_iterator(ostream_type& s, const charT* delimiter); |
| 445 | ostream_iterator(const ostream_iterator& x); |
| 446 | ~ostream_iterator(); |
| 447 | ostream_iterator& operator=(const T& value); |
| 448 | |
| 449 | ostream_iterator& operator*(); |
| 450 | ostream_iterator& operator++(); |
| 451 | ostream_iterator& operator++(int); |
| 452 | }; |
| 453 | |
| 454 | template<class charT, class traits = char_traits<charT> > |
| 455 | class istreambuf_iterator |
Louis Dionne | 3402c3c | 2021-05-27 12:56:12 -0400 | [diff] [blame] | 456 | : public iterator<input_iterator_tag, charT, traits::off_type, unspecified, charT> // until C++17 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 457 | { |
| 458 | public: |
Louis Dionne | 3402c3c | 2021-05-27 12:56:12 -0400 | [diff] [blame] | 459 | typedef input_iterator_tag iterator_category; |
| 460 | typedef charT value_type; |
| 461 | typedef traits::off_type difference_type; |
| 462 | typedef unspecified pointer; |
| 463 | typedef charT reference; |
| 464 | |
| 465 | typedef charT char_type; |
| 466 | typedef traits traits_type; |
| 467 | typedef traits::int_type int_type; |
| 468 | typedef basic_streambuf<charT, traits> streambuf_type; |
| 469 | typedef basic_istream<charT, traits> istream_type; |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 470 | |
Howard Hinnant | 011138d | 2012-07-20 19:36:34 +0000 | [diff] [blame] | 471 | istreambuf_iterator() noexcept; |
| 472 | istreambuf_iterator(istream_type& s) noexcept; |
| 473 | istreambuf_iterator(streambuf_type* s) noexcept; |
| 474 | istreambuf_iterator(a-private-type) noexcept; |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 475 | |
| 476 | charT operator*() const; |
| 477 | pointer operator->() const; |
| 478 | istreambuf_iterator& operator++(); |
| 479 | a-private-type operator++(int); |
| 480 | |
| 481 | bool equal(const istreambuf_iterator& b) const; |
| 482 | }; |
| 483 | |
| 484 | template <class charT, class traits> |
| 485 | bool operator==(const istreambuf_iterator<charT,traits>& a, |
| 486 | const istreambuf_iterator<charT,traits>& b); |
| 487 | template <class charT, class traits> |
| 488 | bool operator!=(const istreambuf_iterator<charT,traits>& a, |
| 489 | const istreambuf_iterator<charT,traits>& b); |
| 490 | |
| 491 | template <class charT, class traits = char_traits<charT> > |
| 492 | class ostreambuf_iterator |
Louis Dionne | 8762e2b | 2021-05-25 18:15:58 -0400 | [diff] [blame] | 493 | : public iterator<output_iterator_tag, void, void, void, void> // until C++17 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 494 | { |
| 495 | public: |
Louis Dionne | 3402c3c | 2021-05-27 12:56:12 -0400 | [diff] [blame] | 496 | typedef output_iterator_tag iterator_category; |
| 497 | typedef void value_type; |
| 498 | typedef void difference_type; // until C++20 |
| 499 | typedef ptrdiff_t difference_type; // since C++20 |
| 500 | typedef void pointer; |
| 501 | typedef void reference; |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 502 | |
Louis Dionne | 3402c3c | 2021-05-27 12:56:12 -0400 | [diff] [blame] | 503 | typedef charT char_type; |
| 504 | typedef traits traits_type; |
| 505 | typedef basic_streambuf<charT, traits> streambuf_type; |
| 506 | typedef basic_ostream<charT, traits> ostream_type; |
| 507 | |
Howard Hinnant | 011138d | 2012-07-20 19:36:34 +0000 | [diff] [blame] | 508 | ostreambuf_iterator(ostream_type& s) noexcept; |
| 509 | ostreambuf_iterator(streambuf_type* s) noexcept; |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 510 | ostreambuf_iterator& operator=(charT c); |
| 511 | ostreambuf_iterator& operator*(); |
| 512 | ostreambuf_iterator& operator++(); |
| 513 | ostreambuf_iterator& operator++(int); |
Howard Hinnant | 011138d | 2012-07-20 19:36:34 +0000 | [diff] [blame] | 514 | bool failed() const noexcept; |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 515 | }; |
| 516 | |
Marshall Clow | 99ba002 | 2017-01-04 17:58:17 +0000 | [diff] [blame] | 517 | template <class C> constexpr auto begin(C& c) -> decltype(c.begin()); |
| 518 | template <class C> constexpr auto begin(const C& c) -> decltype(c.begin()); |
| 519 | template <class C> constexpr auto end(C& c) -> decltype(c.end()); |
| 520 | template <class C> constexpr auto end(const C& c) -> decltype(c.end()); |
| 521 | template <class T, size_t N> constexpr T* begin(T (&array)[N]); |
| 522 | template <class T, size_t N> constexpr T* end(T (&array)[N]); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 523 | |
Marshall Clow | 99ba002 | 2017-01-04 17:58:17 +0000 | [diff] [blame] | 524 | template <class C> auto constexpr cbegin(const C& c) -> decltype(std::begin(c)); // C++14 |
| 525 | template <class C> auto constexpr cend(const C& c) -> decltype(std::end(c)); // C++14 |
| 526 | template <class C> auto constexpr rbegin(C& c) -> decltype(c.rbegin()); // C++14 |
| 527 | template <class C> auto constexpr rbegin(const C& c) -> decltype(c.rbegin()); // C++14 |
| 528 | template <class C> auto constexpr rend(C& c) -> decltype(c.rend()); // C++14 |
| 529 | template <class C> constexpr auto rend(const C& c) -> decltype(c.rend()); // C++14 |
| 530 | template <class E> reverse_iterator<const E*> constexpr rbegin(initializer_list<E> il); // C++14 |
| 531 | template <class E> reverse_iterator<const E*> constexpr rend(initializer_list<E> il); // C++14 |
| 532 | template <class T, size_t N> reverse_iterator<T*> constexpr rbegin(T (&array)[N]); // C++14 |
| 533 | template <class T, size_t N> reverse_iterator<T*> constexpr rend(T (&array)[N]); // C++14 |
| 534 | template <class C> constexpr auto crbegin(const C& c) -> decltype(std::rbegin(c)); // C++14 |
| 535 | 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] | 536 | |
Marshall Clow | ef35727 | 2014-11-19 19:43:23 +0000 | [diff] [blame] | 537 | // 24.8, container access: |
| 538 | template <class C> constexpr auto size(const C& c) -> decltype(c.size()); // C++17 |
| 539 | template <class T, size_t N> constexpr size_t size(const T (&array)[N]) noexcept; // C++17 |
Marshall Clow | 3c5363e | 2019-02-27 02:58:56 +0000 | [diff] [blame] | 540 | |
| 541 | template <class C> constexpr auto ssize(const C& c) |
Arthur O'Dwyer | 2fc9b5d | 2021-04-17 17:03:20 -0400 | [diff] [blame] | 542 | -> common_type_t<ptrdiff_t, make_signed_t<decltype(c.size())>>; // C++20 |
Marshall Clow | 3c5363e | 2019-02-27 02:58:56 +0000 | [diff] [blame] | 543 | template <class T, ptrdiff_t> constexpr ptrdiff_t ssize(const T (&array)[N]) noexcept; // C++20 |
| 544 | |
Marshall Clow | ef35727 | 2014-11-19 19:43:23 +0000 | [diff] [blame] | 545 | template <class C> constexpr auto empty(const C& c) -> decltype(c.empty()); // C++17 |
| 546 | template <class T, size_t N> constexpr bool empty(const T (&array)[N]) noexcept; // C++17 |
| 547 | template <class E> constexpr bool empty(initializer_list<E> il) noexcept; // C++17 |
| 548 | template <class C> constexpr auto data(C& c) -> decltype(c.data()); // C++17 |
| 549 | template <class C> constexpr auto data(const C& c) -> decltype(c.data()); // C++17 |
| 550 | template <class T, size_t N> constexpr T* data(T (&array)[N]) noexcept; // C++17 |
| 551 | template <class E> constexpr const E* data(initializer_list<E> il) noexcept; // C++17 |
| 552 | |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 553 | } // std |
| 554 | |
| 555 | */ |
| 556 | |
| 557 | #include <__config> |
Arthur O'Dwyer | a2f99ee | 2021-04-29 17:40:17 -0400 | [diff] [blame] | 558 | #include <__debug> |
Marshall Clow | 3dc0550 | 2014-02-27 02:11:50 +0000 | [diff] [blame] | 559 | #include <__functional_base> |
Christopher Di Bella | c6ead65 | 2021-05-05 07:14:08 +0000 | [diff] [blame] | 560 | #include <__iterator/advance.h> |
Louis Dionne | 7724952 | 2021-06-11 09:55:11 -0400 | [diff] [blame] | 561 | #include <__iterator/back_insert_iterator.h> |
Louis Dionne | 463afb8 | 2021-04-22 11:05:30 -0400 | [diff] [blame] | 562 | #include <__iterator/concepts.h> |
zoecarver | 63f1320 | 2021-06-01 12:55:33 -0700 | [diff] [blame] | 563 | #include <__iterator/default_sentinel.h> |
Louis Dionne | 7724952 | 2021-06-11 09:55:11 -0400 | [diff] [blame] | 564 | #include <__iterator/front_insert_iterator.h> |
zoecarver | 61ae1dc | 2021-04-19 14:28:27 -0400 | [diff] [blame] | 565 | #include <__iterator/incrementable_traits.h> |
Louis Dionne | 7724952 | 2021-06-11 09:55:11 -0400 | [diff] [blame] | 566 | #include <__iterator/insert_iterator.h> |
| 567 | #include <__iterator/istream_iterator.h> |
| 568 | #include <__iterator/istreambuf_iterator.h> |
Louis Dionne | ca989a5 | 2021-04-20 14:40:43 -0400 | [diff] [blame] | 569 | #include <__iterator/iter_move.h> |
zoecarver | 31f4f5d | 2021-05-18 16:18:18 -0700 | [diff] [blame] | 570 | #include <__iterator/iter_swap.h> |
zoecarver | 5d41ff5 | 2021-04-19 14:44:42 -0700 | [diff] [blame] | 571 | #include <__iterator/iterator_traits.h> |
Louis Dionne | 7724952 | 2021-06-11 09:55:11 -0400 | [diff] [blame] | 572 | #include <__iterator/iterator.h> |
| 573 | #include <__iterator/move_iterator.h> |
Christopher Di Bella | 9c0adab | 2021-05-08 05:02:43 +0000 | [diff] [blame] | 574 | #include <__iterator/next.h> |
Louis Dionne | 7724952 | 2021-06-11 09:55:11 -0400 | [diff] [blame] | 575 | #include <__iterator/ostream_iterator.h> |
| 576 | #include <__iterator/ostreambuf_iterator.h> |
Christopher Di Bella | b8e2104 | 2021-05-16 01:39:22 +0000 | [diff] [blame] | 577 | #include <__iterator/prev.h> |
Louis Dionne | 170a03c | 2021-04-28 15:02:08 -0400 | [diff] [blame] | 578 | #include <__iterator/projected.h> |
zoecarver | 61ae1dc | 2021-04-19 14:28:27 -0400 | [diff] [blame] | 579 | #include <__iterator/readable_traits.h> |
Louis Dionne | 7724952 | 2021-06-11 09:55:11 -0400 | [diff] [blame] | 580 | #include <__iterator/reverse_iterator.h> |
| 581 | #include <__iterator/wrap_iter.h> |
Louis Dionne | 735bc46 | 2021-04-14 13:59:03 -0400 | [diff] [blame] | 582 | #include <__memory/addressof.h> |
Arthur O'Dwyer | 1ac9f09 | 2021-01-15 12:59:56 -0500 | [diff] [blame] | 583 | #include <__memory/pointer_traits.h> |
Christopher Di Bella | 41f26e8 | 2021-06-05 02:47:47 +0000 | [diff] [blame] | 584 | #include <__utility/forward.h> |
Arthur O'Dwyer | a2f99ee | 2021-04-29 17:40:17 -0400 | [diff] [blame] | 585 | #include <compare> |
| 586 | #include <concepts> // Mandated by the Standard. |
| 587 | #include <cstddef> |
| 588 | #include <initializer_list> |
Arthur O'Dwyer | a2f99ee | 2021-04-29 17:40:17 -0400 | [diff] [blame] | 589 | #include <type_traits> |
Marshall Clow | 0a1e750 | 2018-09-12 19:41:40 +0000 | [diff] [blame] | 590 | #include <version> |
Howard Hinnant | 48fd5d5 | 2012-11-14 21:17:15 +0000 | [diff] [blame] | 591 | |
Howard Hinnant | aaaa52b | 2011-10-17 20:05:10 +0000 | [diff] [blame] | 592 | #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 593 | #pragma GCC system_header |
Howard Hinnant | aaaa52b | 2011-10-17 20:05:10 +0000 | [diff] [blame] | 594 | #endif |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 595 | |
| 596 | _LIBCPP_BEGIN_NAMESPACE_STD |
Christopher Di Bella | 490fe40 | 2021-03-23 03:55:52 +0000 | [diff] [blame] | 597 | |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 598 | template <class _InputIter> |
Marshall Clow | 75468e7 | 2017-05-17 18:51:36 +0000 | [diff] [blame] | 599 | inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 600 | typename iterator_traits<_InputIter>::difference_type |
| 601 | __distance(_InputIter __first, _InputIter __last, input_iterator_tag) |
| 602 | { |
| 603 | typename iterator_traits<_InputIter>::difference_type __r(0); |
| 604 | for (; __first != __last; ++__first) |
| 605 | ++__r; |
| 606 | return __r; |
| 607 | } |
| 608 | |
| 609 | template <class _RandIter> |
Marshall Clow | 75468e7 | 2017-05-17 18:51:36 +0000 | [diff] [blame] | 610 | inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 611 | typename iterator_traits<_RandIter>::difference_type |
| 612 | __distance(_RandIter __first, _RandIter __last, random_access_iterator_tag) |
| 613 | { |
| 614 | return __last - __first; |
| 615 | } |
| 616 | |
| 617 | template <class _InputIter> |
Marshall Clow | 75468e7 | 2017-05-17 18:51:36 +0000 | [diff] [blame] | 618 | inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 619 | typename iterator_traits<_InputIter>::difference_type |
| 620 | distance(_InputIter __first, _InputIter __last) |
| 621 | { |
Arthur O'Dwyer | 6e9069c | 2020-12-07 23:42:47 -0500 | [diff] [blame] | 622 | return _VSTD::__distance(__first, __last, typename iterator_traits<_InputIter>::iterator_category()); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 623 | } |
| 624 | |
Marshall Clow | 8411ebf | 2013-12-02 03:24:33 +0000 | [diff] [blame] | 625 | template <class _Tp, size_t _Np> |
Marshall Clow | 0bd662d | 2019-02-27 03:25:43 +0000 | [diff] [blame] | 626 | _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 |
Marshall Clow | 8411ebf | 2013-12-02 03:24:33 +0000 | [diff] [blame] | 627 | _Tp* |
| 628 | begin(_Tp (&__array)[_Np]) |
| 629 | { |
| 630 | return __array; |
| 631 | } |
| 632 | |
| 633 | template <class _Tp, size_t _Np> |
Marshall Clow | 0bd662d | 2019-02-27 03:25:43 +0000 | [diff] [blame] | 634 | _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 |
Marshall Clow | 8411ebf | 2013-12-02 03:24:33 +0000 | [diff] [blame] | 635 | _Tp* |
| 636 | end(_Tp (&__array)[_Np]) |
| 637 | { |
| 638 | return __array + _Np; |
| 639 | } |
| 640 | |
Eric Fiselier | c6f17cc | 2016-09-25 03:34:28 +0000 | [diff] [blame] | 641 | #if !defined(_LIBCPP_CXX03_LANG) |
Marshall Clow | 037fcb7 | 2013-12-11 19:32:32 +0000 | [diff] [blame] | 642 | |
Howard Hinnant | c834c51 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 643 | template <class _Cp> |
Marshall Clow | 0bd662d | 2019-02-27 03:25:43 +0000 | [diff] [blame] | 644 | _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 645 | auto |
Howard Hinnant | c834c51 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 646 | begin(_Cp& __c) -> decltype(__c.begin()) |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 647 | { |
| 648 | return __c.begin(); |
| 649 | } |
| 650 | |
Howard Hinnant | c834c51 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 651 | template <class _Cp> |
Marshall Clow | 0bd662d | 2019-02-27 03:25:43 +0000 | [diff] [blame] | 652 | _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 653 | auto |
Howard Hinnant | c834c51 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 654 | begin(const _Cp& __c) -> decltype(__c.begin()) |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 655 | { |
| 656 | return __c.begin(); |
| 657 | } |
| 658 | |
Howard Hinnant | c834c51 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 659 | template <class _Cp> |
Marshall Clow | 0bd662d | 2019-02-27 03:25:43 +0000 | [diff] [blame] | 660 | _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 661 | auto |
Howard Hinnant | c834c51 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 662 | end(_Cp& __c) -> decltype(__c.end()) |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 663 | { |
| 664 | return __c.end(); |
| 665 | } |
| 666 | |
Howard Hinnant | c834c51 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 667 | template <class _Cp> |
Marshall Clow | 0bd662d | 2019-02-27 03:25:43 +0000 | [diff] [blame] | 668 | _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 669 | auto |
Howard Hinnant | c834c51 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 670 | end(const _Cp& __c) -> decltype(__c.end()) |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 671 | { |
| 672 | return __c.end(); |
| 673 | } |
| 674 | |
Marshall Clow | b278e9c | 2013-08-30 01:17:07 +0000 | [diff] [blame] | 675 | #if _LIBCPP_STD_VER > 11 |
| 676 | |
Marshall Clow | 8411ebf | 2013-12-02 03:24:33 +0000 | [diff] [blame] | 677 | template <class _Tp, size_t _Np> |
Marshall Clow | 0bd662d | 2019-02-27 03:25:43 +0000 | [diff] [blame] | 678 | _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 |
Marshall Clow | 8411ebf | 2013-12-02 03:24:33 +0000 | [diff] [blame] | 679 | reverse_iterator<_Tp*> rbegin(_Tp (&__array)[_Np]) |
| 680 | { |
| 681 | return reverse_iterator<_Tp*>(__array + _Np); |
| 682 | } |
| 683 | |
| 684 | template <class _Tp, size_t _Np> |
Marshall Clow | 0bd662d | 2019-02-27 03:25:43 +0000 | [diff] [blame] | 685 | _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 |
Marshall Clow | 8411ebf | 2013-12-02 03:24:33 +0000 | [diff] [blame] | 686 | reverse_iterator<_Tp*> rend(_Tp (&__array)[_Np]) |
| 687 | { |
| 688 | return reverse_iterator<_Tp*>(__array); |
| 689 | } |
| 690 | |
| 691 | template <class _Ep> |
Marshall Clow | 0bd662d | 2019-02-27 03:25:43 +0000 | [diff] [blame] | 692 | _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 |
Marshall Clow | 8411ebf | 2013-12-02 03:24:33 +0000 | [diff] [blame] | 693 | reverse_iterator<const _Ep*> rbegin(initializer_list<_Ep> __il) |
| 694 | { |
| 695 | return reverse_iterator<const _Ep*>(__il.end()); |
| 696 | } |
| 697 | |
| 698 | template <class _Ep> |
Marshall Clow | 0bd662d | 2019-02-27 03:25:43 +0000 | [diff] [blame] | 699 | _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 |
Marshall Clow | 8411ebf | 2013-12-02 03:24:33 +0000 | [diff] [blame] | 700 | reverse_iterator<const _Ep*> rend(initializer_list<_Ep> __il) |
| 701 | { |
| 702 | return reverse_iterator<const _Ep*>(__il.begin()); |
| 703 | } |
| 704 | |
Marshall Clow | b278e9c | 2013-08-30 01:17:07 +0000 | [diff] [blame] | 705 | template <class _Cp> |
Marshall Clow | 0bd662d | 2019-02-27 03:25:43 +0000 | [diff] [blame] | 706 | _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 |
Marshall Clow | 3862f53 | 2016-08-10 20:04:46 +0000 | [diff] [blame] | 707 | auto cbegin(const _Cp& __c) -> decltype(_VSTD::begin(__c)) |
Marshall Clow | b278e9c | 2013-08-30 01:17:07 +0000 | [diff] [blame] | 708 | { |
Marshall Clow | 3862f53 | 2016-08-10 20:04:46 +0000 | [diff] [blame] | 709 | return _VSTD::begin(__c); |
Marshall Clow | b278e9c | 2013-08-30 01:17:07 +0000 | [diff] [blame] | 710 | } |
| 711 | |
| 712 | template <class _Cp> |
Marshall Clow | 0bd662d | 2019-02-27 03:25:43 +0000 | [diff] [blame] | 713 | _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 |
Marshall Clow | 3862f53 | 2016-08-10 20:04:46 +0000 | [diff] [blame] | 714 | auto cend(const _Cp& __c) -> decltype(_VSTD::end(__c)) |
Marshall Clow | b278e9c | 2013-08-30 01:17:07 +0000 | [diff] [blame] | 715 | { |
Marshall Clow | 3862f53 | 2016-08-10 20:04:46 +0000 | [diff] [blame] | 716 | return _VSTD::end(__c); |
Marshall Clow | b278e9c | 2013-08-30 01:17:07 +0000 | [diff] [blame] | 717 | } |
| 718 | |
| 719 | template <class _Cp> |
Marshall Clow | 0bd662d | 2019-02-27 03:25:43 +0000 | [diff] [blame] | 720 | _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 |
Marshall Clow | b278e9c | 2013-08-30 01:17:07 +0000 | [diff] [blame] | 721 | auto rbegin(_Cp& __c) -> decltype(__c.rbegin()) |
| 722 | { |
| 723 | return __c.rbegin(); |
| 724 | } |
| 725 | |
| 726 | template <class _Cp> |
Marshall Clow | 0bd662d | 2019-02-27 03:25:43 +0000 | [diff] [blame] | 727 | _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 |
Marshall Clow | b278e9c | 2013-08-30 01:17:07 +0000 | [diff] [blame] | 728 | auto rbegin(const _Cp& __c) -> decltype(__c.rbegin()) |
| 729 | { |
| 730 | return __c.rbegin(); |
| 731 | } |
| 732 | |
| 733 | template <class _Cp> |
Marshall Clow | 0bd662d | 2019-02-27 03:25:43 +0000 | [diff] [blame] | 734 | _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 |
Marshall Clow | b278e9c | 2013-08-30 01:17:07 +0000 | [diff] [blame] | 735 | auto rend(_Cp& __c) -> decltype(__c.rend()) |
| 736 | { |
| 737 | return __c.rend(); |
| 738 | } |
| 739 | |
| 740 | template <class _Cp> |
Marshall Clow | 0bd662d | 2019-02-27 03:25:43 +0000 | [diff] [blame] | 741 | _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 |
Marshall Clow | b278e9c | 2013-08-30 01:17:07 +0000 | [diff] [blame] | 742 | auto rend(const _Cp& __c) -> decltype(__c.rend()) |
| 743 | { |
| 744 | return __c.rend(); |
| 745 | } |
| 746 | |
| 747 | template <class _Cp> |
Marshall Clow | 0bd662d | 2019-02-27 03:25:43 +0000 | [diff] [blame] | 748 | _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 |
Marshall Clow | 3862f53 | 2016-08-10 20:04:46 +0000 | [diff] [blame] | 749 | auto crbegin(const _Cp& __c) -> decltype(_VSTD::rbegin(__c)) |
Marshall Clow | b278e9c | 2013-08-30 01:17:07 +0000 | [diff] [blame] | 750 | { |
Marshall Clow | 3862f53 | 2016-08-10 20:04:46 +0000 | [diff] [blame] | 751 | return _VSTD::rbegin(__c); |
Marshall Clow | b278e9c | 2013-08-30 01:17:07 +0000 | [diff] [blame] | 752 | } |
| 753 | |
| 754 | template <class _Cp> |
Marshall Clow | 0bd662d | 2019-02-27 03:25:43 +0000 | [diff] [blame] | 755 | _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 |
Marshall Clow | 3862f53 | 2016-08-10 20:04:46 +0000 | [diff] [blame] | 756 | auto crend(const _Cp& __c) -> decltype(_VSTD::rend(__c)) |
Marshall Clow | b278e9c | 2013-08-30 01:17:07 +0000 | [diff] [blame] | 757 | { |
Marshall Clow | 3862f53 | 2016-08-10 20:04:46 +0000 | [diff] [blame] | 758 | return _VSTD::rend(__c); |
Marshall Clow | b278e9c | 2013-08-30 01:17:07 +0000 | [diff] [blame] | 759 | } |
| 760 | |
| 761 | #endif |
| 762 | |
| 763 | |
Eric Fiselier | c6f17cc | 2016-09-25 03:34:28 +0000 | [diff] [blame] | 764 | #else // defined(_LIBCPP_CXX03_LANG) |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 765 | |
Howard Hinnant | c834c51 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 766 | template <class _Cp> |
Marshall Clow | 0bd662d | 2019-02-27 03:25:43 +0000 | [diff] [blame] | 767 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | c834c51 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 768 | typename _Cp::iterator |
| 769 | begin(_Cp& __c) |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 770 | { |
| 771 | return __c.begin(); |
| 772 | } |
| 773 | |
Howard Hinnant | c834c51 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 774 | template <class _Cp> |
Marshall Clow | 0bd662d | 2019-02-27 03:25:43 +0000 | [diff] [blame] | 775 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | c834c51 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 776 | typename _Cp::const_iterator |
| 777 | begin(const _Cp& __c) |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 778 | { |
| 779 | return __c.begin(); |
| 780 | } |
| 781 | |
Howard Hinnant | c834c51 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 782 | template <class _Cp> |
Marshall Clow | 0bd662d | 2019-02-27 03:25:43 +0000 | [diff] [blame] | 783 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | c834c51 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 784 | typename _Cp::iterator |
| 785 | end(_Cp& __c) |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 786 | { |
| 787 | return __c.end(); |
| 788 | } |
| 789 | |
Howard Hinnant | c834c51 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 790 | template <class _Cp> |
Marshall Clow | 0bd662d | 2019-02-27 03:25:43 +0000 | [diff] [blame] | 791 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | c834c51 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 792 | typename _Cp::const_iterator |
| 793 | end(const _Cp& __c) |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 794 | { |
| 795 | return __c.end(); |
| 796 | } |
| 797 | |
Louis Dionne | 2b1ceaa | 2021-04-20 12:03:32 -0400 | [diff] [blame] | 798 | #endif // !defined(_LIBCPP_CXX03_LANG) |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 799 | |
Marshall Clow | ef35727 | 2014-11-19 19:43:23 +0000 | [diff] [blame] | 800 | #if _LIBCPP_STD_VER > 14 |
Marshall Clow | 344c41d | 2017-11-16 17:55:41 +0000 | [diff] [blame] | 801 | |
| 802 | // #if _LIBCPP_STD_VER > 11 |
| 803 | // template <> |
| 804 | // struct _LIBCPP_TEMPLATE_VIS plus<void> |
| 805 | // { |
| 806 | // template <class _T1, class _T2> |
| 807 | // _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY |
| 808 | // auto operator()(_T1&& __t, _T2&& __u) const |
| 809 | // _NOEXCEPT_(noexcept(_VSTD::forward<_T1>(__t) + _VSTD::forward<_T2>(__u))) |
| 810 | // -> decltype (_VSTD::forward<_T1>(__t) + _VSTD::forward<_T2>(__u)) |
| 811 | // { return _VSTD::forward<_T1>(__t) + _VSTD::forward<_T2>(__u); } |
| 812 | // typedef void is_transparent; |
| 813 | // }; |
| 814 | // #endif |
| 815 | |
Marshall Clow | c4b4a34 | 2015-02-11 16:14:01 +0000 | [diff] [blame] | 816 | template <class _Cont> |
Marshall Clow | 0bd662d | 2019-02-27 03:25:43 +0000 | [diff] [blame] | 817 | _LIBCPP_INLINE_VISIBILITY |
Marshall Clow | 344c41d | 2017-11-16 17:55:41 +0000 | [diff] [blame] | 818 | constexpr auto size(const _Cont& __c) |
| 819 | _NOEXCEPT_(noexcept(__c.size())) |
| 820 | -> decltype (__c.size()) |
| 821 | { return __c.size(); } |
Marshall Clow | ef35727 | 2014-11-19 19:43:23 +0000 | [diff] [blame] | 822 | |
Marshall Clow | c4b4a34 | 2015-02-11 16:14:01 +0000 | [diff] [blame] | 823 | template <class _Tp, size_t _Sz> |
Marshall Clow | 0bd662d | 2019-02-27 03:25:43 +0000 | [diff] [blame] | 824 | _LIBCPP_INLINE_VISIBILITY |
Eric Fiselier | 6003c77 | 2016-12-23 23:37:52 +0000 | [diff] [blame] | 825 | constexpr size_t size(const _Tp (&)[_Sz]) noexcept { return _Sz; } |
Marshall Clow | ef35727 | 2014-11-19 19:43:23 +0000 | [diff] [blame] | 826 | |
Marshall Clow | 3c5363e | 2019-02-27 02:58:56 +0000 | [diff] [blame] | 827 | #if _LIBCPP_STD_VER > 17 |
| 828 | template <class _Cont> |
Marshall Clow | 0bd662d | 2019-02-27 03:25:43 +0000 | [diff] [blame] | 829 | _LIBCPP_INLINE_VISIBILITY |
Marshall Clow | 3c5363e | 2019-02-27 02:58:56 +0000 | [diff] [blame] | 830 | constexpr auto ssize(const _Cont& __c) |
| 831 | _NOEXCEPT_(noexcept(static_cast<common_type_t<ptrdiff_t, make_signed_t<decltype(__c.size())>>>(__c.size()))) |
| 832 | -> common_type_t<ptrdiff_t, make_signed_t<decltype(__c.size())>> |
| 833 | { return static_cast<common_type_t<ptrdiff_t, make_signed_t<decltype(__c.size())>>>(__c.size()); } |
| 834 | |
| 835 | template <class _Tp, ptrdiff_t _Sz> |
Marshall Clow | 0bd662d | 2019-02-27 03:25:43 +0000 | [diff] [blame] | 836 | _LIBCPP_INLINE_VISIBILITY |
Marshall Clow | 3c5363e | 2019-02-27 02:58:56 +0000 | [diff] [blame] | 837 | constexpr ptrdiff_t ssize(const _Tp (&)[_Sz]) noexcept { return _Sz; } |
| 838 | #endif |
| 839 | |
Marshall Clow | c4b4a34 | 2015-02-11 16:14:01 +0000 | [diff] [blame] | 840 | template <class _Cont> |
Marshall Clow | 0bd662d | 2019-02-27 03:25:43 +0000 | [diff] [blame] | 841 | _LIBCPP_NODISCARD_AFTER_CXX17 _LIBCPP_INLINE_VISIBILITY |
Marshall Clow | 344c41d | 2017-11-16 17:55:41 +0000 | [diff] [blame] | 842 | constexpr auto empty(const _Cont& __c) |
| 843 | _NOEXCEPT_(noexcept(__c.empty())) |
| 844 | -> decltype (__c.empty()) |
| 845 | { return __c.empty(); } |
Marshall Clow | ef35727 | 2014-11-19 19:43:23 +0000 | [diff] [blame] | 846 | |
Marshall Clow | c4b4a34 | 2015-02-11 16:14:01 +0000 | [diff] [blame] | 847 | template <class _Tp, size_t _Sz> |
Marshall Clow | 0bd662d | 2019-02-27 03:25:43 +0000 | [diff] [blame] | 848 | _LIBCPP_NODISCARD_AFTER_CXX17 _LIBCPP_INLINE_VISIBILITY |
Eric Fiselier | 6003c77 | 2016-12-23 23:37:52 +0000 | [diff] [blame] | 849 | constexpr bool empty(const _Tp (&)[_Sz]) noexcept { return false; } |
Marshall Clow | ef35727 | 2014-11-19 19:43:23 +0000 | [diff] [blame] | 850 | |
| 851 | template <class _Ep> |
Marshall Clow | 0bd662d | 2019-02-27 03:25:43 +0000 | [diff] [blame] | 852 | _LIBCPP_NODISCARD_AFTER_CXX17 _LIBCPP_INLINE_VISIBILITY |
Marshall Clow | ef35727 | 2014-11-19 19:43:23 +0000 | [diff] [blame] | 853 | constexpr bool empty(initializer_list<_Ep> __il) noexcept { return __il.size() == 0; } |
| 854 | |
Marshall Clow | c4b4a34 | 2015-02-11 16:14:01 +0000 | [diff] [blame] | 855 | template <class _Cont> constexpr |
Marshall Clow | 0bd662d | 2019-02-27 03:25:43 +0000 | [diff] [blame] | 856 | _LIBCPP_INLINE_VISIBILITY |
Marshall Clow | 344c41d | 2017-11-16 17:55:41 +0000 | [diff] [blame] | 857 | auto data(_Cont& __c) |
| 858 | _NOEXCEPT_(noexcept(__c.data())) |
| 859 | -> decltype (__c.data()) |
| 860 | { return __c.data(); } |
Marshall Clow | ef35727 | 2014-11-19 19:43:23 +0000 | [diff] [blame] | 861 | |
Marshall Clow | c4b4a34 | 2015-02-11 16:14:01 +0000 | [diff] [blame] | 862 | template <class _Cont> constexpr |
Marshall Clow | 0bd662d | 2019-02-27 03:25:43 +0000 | [diff] [blame] | 863 | _LIBCPP_INLINE_VISIBILITY |
Marshall Clow | 344c41d | 2017-11-16 17:55:41 +0000 | [diff] [blame] | 864 | auto data(const _Cont& __c) |
| 865 | _NOEXCEPT_(noexcept(__c.data())) |
Louis Dionne | 173f29e | 2019-05-29 16:01:36 +0000 | [diff] [blame] | 866 | -> decltype (__c.data()) |
Marshall Clow | 344c41d | 2017-11-16 17:55:41 +0000 | [diff] [blame] | 867 | { return __c.data(); } |
Marshall Clow | ef35727 | 2014-11-19 19:43:23 +0000 | [diff] [blame] | 868 | |
Marshall Clow | c4b4a34 | 2015-02-11 16:14:01 +0000 | [diff] [blame] | 869 | template <class _Tp, size_t _Sz> |
Marshall Clow | 0bd662d | 2019-02-27 03:25:43 +0000 | [diff] [blame] | 870 | _LIBCPP_INLINE_VISIBILITY |
Marshall Clow | c4b4a34 | 2015-02-11 16:14:01 +0000 | [diff] [blame] | 871 | constexpr _Tp* data(_Tp (&__array)[_Sz]) noexcept { return __array; } |
Marshall Clow | ef35727 | 2014-11-19 19:43:23 +0000 | [diff] [blame] | 872 | |
| 873 | template <class _Ep> |
Marshall Clow | 0bd662d | 2019-02-27 03:25:43 +0000 | [diff] [blame] | 874 | _LIBCPP_INLINE_VISIBILITY |
Marshall Clow | ef35727 | 2014-11-19 19:43:23 +0000 | [diff] [blame] | 875 | constexpr const _Ep* data(initializer_list<_Ep> __il) noexcept { return __il.begin(); } |
| 876 | #endif |
| 877 | |
Arthur O'Dwyer | b6738bd | 2021-03-21 16:53:09 -0400 | [diff] [blame] | 878 | template <class _Container, class _Predicate> |
| 879 | typename _Container::size_type |
| 880 | __libcpp_erase_if_container(_Container& __c, _Predicate& __pred) { |
| 881 | typename _Container::size_type __old_size = __c.size(); |
| 882 | |
| 883 | const typename _Container::iterator __last = __c.end(); |
| 884 | for (typename _Container::iterator __iter = __c.begin(); __iter != __last;) { |
| 885 | if (__pred(*__iter)) |
| 886 | __iter = __c.erase(__iter); |
| 887 | else |
| 888 | ++__iter; |
| 889 | } |
| 890 | |
| 891 | return __old_size - __c.size(); |
| 892 | } |
Marshall Clow | ef35727 | 2014-11-19 19:43:23 +0000 | [diff] [blame] | 893 | |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 894 | _LIBCPP_END_NAMESPACE_STD |
| 895 | |
Louis Dionne | 2b1ceaa | 2021-04-20 12:03:32 -0400 | [diff] [blame] | 896 | #endif // _LIBCPP_ITERATOR |