- tmp/tmp6nu7pp7u/{from.md → to.md} +1228 -369
tmp/tmp6nu7pp7u/{from.md → to.md}
RENAMED
|
@@ -2,36 +2,35 @@
|
|
| 2 |
|
| 3 |
### Reverse iterators <a id="reverse.iterators">[[reverse.iterators]]</a>
|
| 4 |
|
| 5 |
Class template `reverse_iterator` is an iterator adaptor that iterates
|
| 6 |
from the end of the sequence defined by its underlying iterator to the
|
| 7 |
-
beginning of that sequence.
|
| 8 |
-
iterator and its corresponding iterator `i` is established by the
|
| 9 |
-
identity: `&*(reverse_iterator(i)) == &*(i - 1)`.
|
| 10 |
|
| 11 |
#### Class template `reverse_iterator` <a id="reverse.iterator">[[reverse.iterator]]</a>
|
| 12 |
|
| 13 |
``` cpp
|
| 14 |
namespace std {
|
| 15 |
template<class Iterator>
|
| 16 |
class reverse_iterator {
|
| 17 |
public:
|
| 18 |
using iterator_type = Iterator;
|
| 19 |
-
using
|
| 20 |
-
using
|
| 21 |
-
using
|
|
|
|
| 22 |
using pointer = typename iterator_traits<Iterator>::pointer;
|
| 23 |
-
using reference =
|
| 24 |
|
| 25 |
constexpr reverse_iterator();
|
| 26 |
constexpr explicit reverse_iterator(Iterator x);
|
| 27 |
template<class U> constexpr reverse_iterator(const reverse_iterator<U>& u);
|
| 28 |
template<class U> constexpr reverse_iterator& operator=(const reverse_iterator<U>& u);
|
| 29 |
|
| 30 |
-
constexpr Iterator base() const;
|
| 31 |
constexpr reference operator*() const;
|
| 32 |
-
constexpr pointer operator->() const;
|
| 33 |
|
| 34 |
constexpr reverse_iterator& operator++();
|
| 35 |
constexpr reverse_iterator operator++(int);
|
| 36 |
constexpr reverse_iterator& operator--();
|
| 37 |
constexpr reverse_iterator operator--(int);
|
|
@@ -39,72 +38,60 @@ namespace std {
|
|
| 39 |
constexpr reverse_iterator operator+ (difference_type n) const;
|
| 40 |
constexpr reverse_iterator& operator+=(difference_type n);
|
| 41 |
constexpr reverse_iterator operator- (difference_type n) const;
|
| 42 |
constexpr reverse_iterator& operator-=(difference_type n);
|
| 43 |
constexpr unspecified operator[](difference_type n) const;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 44 |
protected:
|
| 45 |
Iterator current;
|
| 46 |
};
|
| 47 |
-
|
| 48 |
-
template <class Iterator1, class Iterator2>
|
| 49 |
-
constexpr bool operator==(
|
| 50 |
-
const reverse_iterator<Iterator1>& x,
|
| 51 |
-
const reverse_iterator<Iterator2>& y);
|
| 52 |
-
template <class Iterator1, class Iterator2>
|
| 53 |
-
constexpr bool operator<(
|
| 54 |
-
const reverse_iterator<Iterator1>& x,
|
| 55 |
-
const reverse_iterator<Iterator2>& y);
|
| 56 |
-
template <class Iterator1, class Iterator2>
|
| 57 |
-
constexpr bool operator!=(
|
| 58 |
-
const reverse_iterator<Iterator1>& x,
|
| 59 |
-
const reverse_iterator<Iterator2>& y);
|
| 60 |
-
template <class Iterator1, class Iterator2>
|
| 61 |
-
constexpr bool operator>(
|
| 62 |
-
const reverse_iterator<Iterator1>& x,
|
| 63 |
-
const reverse_iterator<Iterator2>& y);
|
| 64 |
-
template <class Iterator1, class Iterator2>
|
| 65 |
-
constexpr bool operator>=(
|
| 66 |
-
const reverse_iterator<Iterator1>& x,
|
| 67 |
-
const reverse_iterator<Iterator2>& y);
|
| 68 |
-
template <class Iterator1, class Iterator2>
|
| 69 |
-
constexpr bool operator<=(
|
| 70 |
-
const reverse_iterator<Iterator1>& x,
|
| 71 |
-
const reverse_iterator<Iterator2>& y);
|
| 72 |
-
template <class Iterator1, class Iterator2>
|
| 73 |
-
constexpr auto operator-(
|
| 74 |
-
const reverse_iterator<Iterator1>& x,
|
| 75 |
-
const reverse_iterator<Iterator2>& y) -> decltype(y.base() - x.base());
|
| 76 |
-
template <class Iterator>
|
| 77 |
-
constexpr reverse_iterator<Iterator> operator+(
|
| 78 |
-
typename reverse_iterator<Iterator>::difference_type n,
|
| 79 |
-
const reverse_iterator<Iterator>& x);
|
| 80 |
-
|
| 81 |
-
template <class Iterator>
|
| 82 |
-
constexpr reverse_iterator<Iterator> make_reverse_iterator(Iterator i);
|
| 83 |
}
|
| 84 |
```
|
| 85 |
|
| 86 |
-
|
| 87 |
-
|
| 88 |
-
|
| 89 |
-
|
| 90 |
-
|
| 91 |
-
|
| 92 |
-
|
| 93 |
-
|
| 94 |
-
|
| 95 |
-
`
|
| 96 |
-
|
| 97 |
-
|
| 98 |
-
|
| 99 |
-
|
| 100 |
-
|
| 101 |
-
|
| 102 |
-
|
| 103 |
-
|
| 104 |
-
|
| 105 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 106 |
|
| 107 |
``` cpp
|
| 108 |
constexpr reverse_iterator();
|
| 109 |
```
|
| 110 |
|
|
@@ -123,31 +110,29 @@ constexpr explicit reverse_iterator(Iterator x);
|
|
| 123 |
template<class U> constexpr reverse_iterator(const reverse_iterator<U>& u);
|
| 124 |
```
|
| 125 |
|
| 126 |
*Effects:* Initializes `current` with `u.current`.
|
| 127 |
|
| 128 |
-
##### `reverse_iterator::operator=` <a id="reverse.iter.op=">[[reverse.iter.op=]]</a>
|
| 129 |
-
|
| 130 |
``` cpp
|
| 131 |
template<class U>
|
| 132 |
constexpr reverse_iterator&
|
| 133 |
operator=(const reverse_iterator<U>& u);
|
| 134 |
```
|
| 135 |
|
| 136 |
-
*Effects:* Assigns `u.base()` to current.
|
| 137 |
|
| 138 |
*Returns:* `*this`.
|
| 139 |
|
| 140 |
-
####
|
| 141 |
|
| 142 |
``` cpp
|
| 143 |
constexpr Iterator base() const; // explicit
|
| 144 |
```
|
| 145 |
|
| 146 |
*Returns:* `current`.
|
| 147 |
|
| 148 |
-
####
|
| 149 |
|
| 150 |
``` cpp
|
| 151 |
constexpr reference operator*() const;
|
| 152 |
```
|
| 153 |
|
|
@@ -156,195 +141,245 @@ constexpr reference operator*() const;
|
|
| 156 |
``` cpp
|
| 157 |
Iterator tmp = current;
|
| 158 |
return *--tmp;
|
| 159 |
```
|
| 160 |
|
| 161 |
-
##### `operator->` <a id="reverse.iter.opref">[[reverse.iter.opref]]</a>
|
| 162 |
-
|
| 163 |
-
``` cpp
|
| 164 |
-
constexpr pointer operator->() const;
|
| 165 |
-
```
|
| 166 |
-
|
| 167 |
-
*Returns:* `addressof(operator*())`.
|
| 168 |
-
|
| 169 |
-
##### `operator++` <a id="reverse.iter.op++">[[reverse.iter.op++]]</a>
|
| 170 |
-
|
| 171 |
-
``` cpp
|
| 172 |
-
constexpr reverse_iterator& operator++();
|
| 173 |
-
```
|
| 174 |
-
|
| 175 |
-
*Effects:* As if by: `current;`
|
| 176 |
-
|
| 177 |
-
*Returns:* `*this`.
|
| 178 |
-
|
| 179 |
``` cpp
|
| 180 |
-
constexpr
|
|
|
|
|
|
|
| 181 |
```
|
| 182 |
|
| 183 |
-
*Effects:*
|
| 184 |
|
| 185 |
-
``
|
| 186 |
-
|
| 187 |
-
-
|
| 188 |
-
return tmp;
|
| 189 |
-
```
|
| 190 |
-
|
| 191 |
-
\[reverse.iter.op\]`operator\dcr`
|
| 192 |
|
| 193 |
``` cpp
|
| 194 |
-
constexpr
|
| 195 |
```
|
| 196 |
|
| 197 |
-
*
|
| 198 |
-
|
| 199 |
-
*Returns:* `*this`.
|
| 200 |
-
|
| 201 |
-
``` cpp
|
| 202 |
-
constexpr reverse_iterator operator--(int);
|
| 203 |
-
```
|
| 204 |
-
|
| 205 |
-
*Effects:* As if by:
|
| 206 |
-
|
| 207 |
-
``` cpp
|
| 208 |
-
reverse_iterator tmp = *this;
|
| 209 |
-
++current;
|
| 210 |
-
return tmp;
|
| 211 |
-
```
|
| 212 |
|
| 213 |
-
####
|
| 214 |
|
| 215 |
``` cpp
|
| 216 |
constexpr reverse_iterator operator+(difference_type n) const;
|
| 217 |
```
|
| 218 |
|
| 219 |
*Returns:* `reverse_iterator(current-n)`.
|
| 220 |
|
| 221 |
-
##### `operator+=` <a id="reverse.iter.op+=">[[reverse.iter.op+=]]</a>
|
| 222 |
-
|
| 223 |
-
``` cpp
|
| 224 |
-
constexpr reverse_iterator& operator+=(difference_type n);
|
| 225 |
-
```
|
| 226 |
-
|
| 227 |
-
*Effects:* As if by: `current -= n;`
|
| 228 |
-
|
| 229 |
-
*Returns:* `*this`.
|
| 230 |
-
|
| 231 |
-
##### `operator-` <a id="reverse.iter.op-">[[reverse.iter.op-]]</a>
|
| 232 |
-
|
| 233 |
``` cpp
|
| 234 |
constexpr reverse_iterator operator-(difference_type n) const;
|
| 235 |
```
|
| 236 |
|
| 237 |
*Returns:* `reverse_iterator(current+n)`.
|
| 238 |
|
| 239 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 240 |
|
| 241 |
``` cpp
|
| 242 |
constexpr reverse_iterator& operator-=(difference_type n);
|
| 243 |
```
|
| 244 |
|
| 245 |
*Effects:* As if by: `current += n;`
|
| 246 |
|
| 247 |
*Returns:* `*this`.
|
| 248 |
|
| 249 |
-
####
|
| 250 |
-
|
| 251 |
-
``` cpp
|
| 252 |
-
constexpr unspecified operator[](difference_type n) const;
|
| 253 |
-
```
|
| 254 |
-
|
| 255 |
-
*Returns:* `current[-n-1]`.
|
| 256 |
-
|
| 257 |
-
##### `operator==` <a id="reverse.iter.op==">[[reverse.iter.op==]]</a>
|
| 258 |
|
| 259 |
``` cpp
|
| 260 |
template<class Iterator1, class Iterator2>
|
| 261 |
constexpr bool operator==(
|
| 262 |
const reverse_iterator<Iterator1>& x,
|
| 263 |
const reverse_iterator<Iterator2>& y);
|
| 264 |
```
|
| 265 |
|
| 266 |
-
*
|
|
|
|
| 267 |
|
| 268 |
-
|
| 269 |
-
|
| 270 |
-
``` cpp
|
| 271 |
-
template <class Iterator1, class Iterator2>
|
| 272 |
-
constexpr bool operator<(
|
| 273 |
-
const reverse_iterator<Iterator1>& x,
|
| 274 |
-
const reverse_iterator<Iterator2>& y);
|
| 275 |
-
```
|
| 276 |
-
|
| 277 |
-
*Returns:* `x.current > y.current`.
|
| 278 |
-
|
| 279 |
-
##### `operator!=` <a id="reverse.iter.op!=">[[reverse.iter.op!=]]</a>
|
| 280 |
|
| 281 |
``` cpp
|
| 282 |
template<class Iterator1, class Iterator2>
|
| 283 |
constexpr bool operator!=(
|
| 284 |
const reverse_iterator<Iterator1>& x,
|
| 285 |
const reverse_iterator<Iterator2>& y);
|
| 286 |
```
|
| 287 |
|
| 288 |
-
*
|
|
|
|
| 289 |
|
| 290 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 291 |
|
| 292 |
``` cpp
|
| 293 |
template<class Iterator1, class Iterator2>
|
| 294 |
constexpr bool operator>(
|
| 295 |
const reverse_iterator<Iterator1>& x,
|
| 296 |
const reverse_iterator<Iterator2>& y);
|
| 297 |
```
|
| 298 |
|
| 299 |
-
*
|
|
|
|
| 300 |
|
| 301 |
-
|
| 302 |
-
|
| 303 |
-
``` cpp
|
| 304 |
-
template <class Iterator1, class Iterator2>
|
| 305 |
-
constexpr bool operator>=(
|
| 306 |
-
const reverse_iterator<Iterator1>& x,
|
| 307 |
-
const reverse_iterator<Iterator2>& y);
|
| 308 |
-
```
|
| 309 |
-
|
| 310 |
-
*Returns:* `x.current <= y.current`.
|
| 311 |
-
|
| 312 |
-
##### `operator<=` <a id="reverse.iter.op<=">[[reverse.iter.op<=]]</a>
|
| 313 |
|
| 314 |
``` cpp
|
| 315 |
template<class Iterator1, class Iterator2>
|
| 316 |
constexpr bool operator<=(
|
| 317 |
const reverse_iterator<Iterator1>& x,
|
| 318 |
const reverse_iterator<Iterator2>& y);
|
| 319 |
```
|
| 320 |
|
| 321 |
-
*
|
|
|
|
| 322 |
|
| 323 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 324 |
|
| 325 |
``` cpp
|
| 326 |
template<class Iterator1, class Iterator2>
|
| 327 |
constexpr auto operator-(
|
| 328 |
const reverse_iterator<Iterator1>& x,
|
| 329 |
const reverse_iterator<Iterator2>& y) -> decltype(y.base() - x.base());
|
| 330 |
```
|
| 331 |
|
| 332 |
-
*Returns:* `y.
|
| 333 |
-
|
| 334 |
-
##### `operator+` <a id="reverse.iter.opsum">[[reverse.iter.opsum]]</a>
|
| 335 |
|
| 336 |
``` cpp
|
| 337 |
template<class Iterator>
|
| 338 |
constexpr reverse_iterator<Iterator> operator+(
|
| 339 |
typename reverse_iterator<Iterator>::difference_type n,
|
| 340 |
const reverse_iterator<Iterator>& x);
|
| 341 |
```
|
| 342 |
|
| 343 |
-
*Returns:* `reverse_iterator<Iterator>
|
| 344 |
|
| 345 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 346 |
|
| 347 |
``` cpp
|
| 348 |
template<class Iterator>
|
| 349 |
constexpr reverse_iterator<Iterator> make_reverse_iterator(Iterator i);
|
| 350 |
```
|
|
@@ -367,16 +402,16 @@ insert corresponding elements into the container. This device allows all
|
|
| 367 |
of the copying algorithms in the library to work in the *insert mode*
|
| 368 |
instead of the *regular overwrite* mode.
|
| 369 |
|
| 370 |
An insert iterator is constructed from a container and possibly one of
|
| 371 |
its iterators pointing to where insertion takes place if it is neither
|
| 372 |
-
at the beginning nor at the end of the container. Insert iterators
|
| 373 |
-
|
| 374 |
-
|
| 375 |
-
|
| 376 |
-
|
| 377 |
-
|
| 378 |
insertion takes place. `back_insert_iterator` inserts elements at the
|
| 379 |
end of a container, `front_insert_iterator` inserts elements at the
|
| 380 |
beginning of a container, and `insert_iterator` inserts elements where
|
| 381 |
the iterator points to in a container. `back_inserter`,
|
| 382 |
`front_inserter`, and `inserter` are three functions making the insert
|
|
@@ -387,84 +422,74 @@ iterators out of a container.
|
|
| 387 |
``` cpp
|
| 388 |
namespace std {
|
| 389 |
template<class Container>
|
| 390 |
class back_insert_iterator {
|
| 391 |
protected:
|
| 392 |
-
Container* container;
|
| 393 |
|
| 394 |
public:
|
| 395 |
using iterator_category = output_iterator_tag;
|
| 396 |
using value_type = void;
|
| 397 |
-
using difference_type =
|
| 398 |
using pointer = void;
|
| 399 |
using reference = void;
|
| 400 |
using container_type = Container;
|
| 401 |
|
| 402 |
-
|
| 403 |
-
|
| 404 |
-
back_insert_iterator& operator=(typename Container::value_type&
|
|
|
|
| 405 |
|
| 406 |
-
back_insert_iterator& operator*();
|
| 407 |
-
back_insert_iterator& operator++();
|
| 408 |
-
back_insert_iterator operator++(int);
|
| 409 |
};
|
| 410 |
-
|
| 411 |
-
template <class Container>
|
| 412 |
-
back_insert_iterator<Container> back_inserter(Container& x);
|
| 413 |
}
|
| 414 |
```
|
| 415 |
|
| 416 |
-
####
|
| 417 |
-
|
| 418 |
-
##### `back_insert_iterator` constructor <a id="back.insert.iter.cons">[[back.insert.iter.cons]]</a>
|
| 419 |
|
| 420 |
``` cpp
|
| 421 |
-
explicit back_insert_iterator(Container& x);
|
| 422 |
```
|
| 423 |
|
| 424 |
*Effects:* Initializes `container` with `addressof(x)`.
|
| 425 |
|
| 426 |
-
##### `back_insert_iterator::operator=` <a id="back.insert.iter.op=">[[back.insert.iter.op=]]</a>
|
| 427 |
-
|
| 428 |
``` cpp
|
| 429 |
-
back_insert_iterator& operator=(const typename Container::value_type& value);
|
| 430 |
```
|
| 431 |
|
| 432 |
*Effects:* As if by: `container->push_back(value);`
|
| 433 |
|
| 434 |
*Returns:* `*this`.
|
| 435 |
|
| 436 |
``` cpp
|
| 437 |
-
back_insert_iterator& operator=(typename Container::value_type&& value);
|
| 438 |
```
|
| 439 |
|
| 440 |
*Effects:* As if by: `container->push_back(std::move(value));`
|
| 441 |
|
| 442 |
*Returns:* `*this`.
|
| 443 |
|
| 444 |
-
##### `back_insert_iterator::operator*` <a id="back.insert.iter.op*">[[back.insert.iter.op*]]</a>
|
| 445 |
-
|
| 446 |
``` cpp
|
| 447 |
-
back_insert_iterator& operator*();
|
| 448 |
```
|
| 449 |
|
| 450 |
*Returns:* `*this`.
|
| 451 |
|
| 452 |
-
##### `back_insert_iterator::operator++` <a id="back.insert.iter.op++">[[back.insert.iter.op++]]</a>
|
| 453 |
-
|
| 454 |
``` cpp
|
| 455 |
-
back_insert_iterator& operator++();
|
| 456 |
-
back_insert_iterator operator++(int);
|
| 457 |
```
|
| 458 |
|
| 459 |
*Returns:* `*this`.
|
| 460 |
|
| 461 |
##### `back_inserter` <a id="back.inserter">[[back.inserter]]</a>
|
| 462 |
|
| 463 |
``` cpp
|
| 464 |
template<class Container>
|
| 465 |
-
back_insert_iterator<Container> back_inserter(Container& x);
|
| 466 |
```
|
| 467 |
|
| 468 |
*Returns:* `back_insert_iterator<Container>(x)`.
|
| 469 |
|
| 470 |
#### Class template `front_insert_iterator` <a id="front.insert.iterator">[[front.insert.iterator]]</a>
|
|
@@ -472,84 +497,74 @@ template <class Container>
|
|
| 472 |
``` cpp
|
| 473 |
namespace std {
|
| 474 |
template<class Container>
|
| 475 |
class front_insert_iterator {
|
| 476 |
protected:
|
| 477 |
-
Container* container;
|
| 478 |
|
| 479 |
public:
|
| 480 |
using iterator_category = output_iterator_tag;
|
| 481 |
using value_type = void;
|
| 482 |
-
using difference_type =
|
| 483 |
using pointer = void;
|
| 484 |
using reference = void;
|
| 485 |
using container_type = Container;
|
| 486 |
|
| 487 |
-
|
| 488 |
-
|
| 489 |
-
front_insert_iterator& operator=(typename Container::value_type&
|
|
|
|
| 490 |
|
| 491 |
-
front_insert_iterator& operator*();
|
| 492 |
-
front_insert_iterator& operator++();
|
| 493 |
-
front_insert_iterator operator++(int);
|
| 494 |
};
|
| 495 |
-
|
| 496 |
-
template <class Container>
|
| 497 |
-
front_insert_iterator<Container> front_inserter(Container& x);
|
| 498 |
}
|
| 499 |
```
|
| 500 |
|
| 501 |
-
####
|
| 502 |
-
|
| 503 |
-
##### `front_insert_iterator` constructor <a id="front.insert.iter.cons">[[front.insert.iter.cons]]</a>
|
| 504 |
|
| 505 |
``` cpp
|
| 506 |
-
explicit front_insert_iterator(Container& x);
|
| 507 |
```
|
| 508 |
|
| 509 |
*Effects:* Initializes `container` with `addressof(x)`.
|
| 510 |
|
| 511 |
-
##### `front_insert_iterator::operator=` <a id="front.insert.iter.op=">[[front.insert.iter.op=]]</a>
|
| 512 |
-
|
| 513 |
``` cpp
|
| 514 |
-
front_insert_iterator& operator=(const typename Container::value_type& value);
|
| 515 |
```
|
| 516 |
|
| 517 |
*Effects:* As if by: `container->push_front(value);`
|
| 518 |
|
| 519 |
*Returns:* `*this`.
|
| 520 |
|
| 521 |
``` cpp
|
| 522 |
-
front_insert_iterator& operator=(typename Container::value_type&& value);
|
| 523 |
```
|
| 524 |
|
| 525 |
*Effects:* As if by: `container->push_front(std::move(value));`
|
| 526 |
|
| 527 |
*Returns:* `*this`.
|
| 528 |
|
| 529 |
-
##### `front_insert_iterator::operator*` <a id="front.insert.iter.op*">[[front.insert.iter.op*]]</a>
|
| 530 |
-
|
| 531 |
``` cpp
|
| 532 |
-
front_insert_iterator& operator*();
|
| 533 |
```
|
| 534 |
|
| 535 |
*Returns:* `*this`.
|
| 536 |
|
| 537 |
-
##### `front_insert_iterator::operator++` <a id="front.insert.iter.op++">[[front.insert.iter.op++]]</a>
|
| 538 |
-
|
| 539 |
``` cpp
|
| 540 |
-
front_insert_iterator& operator++();
|
| 541 |
-
front_insert_iterator operator++(int);
|
| 542 |
```
|
| 543 |
|
| 544 |
*Returns:* `*this`.
|
| 545 |
|
| 546 |
##### `front_inserter` <a id="front.inserter">[[front.inserter]]</a>
|
| 547 |
|
| 548 |
``` cpp
|
| 549 |
template<class Container>
|
| 550 |
-
front_insert_iterator<Container> front_inserter(Container& x);
|
| 551 |
```
|
| 552 |
|
| 553 |
*Returns:* `front_insert_iterator<Container>(x)`.
|
| 554 |
|
| 555 |
#### Class template `insert_iterator` <a id="insert.iterator">[[insert.iterator]]</a>
|
|
@@ -557,50 +572,44 @@ template <class Container>
|
|
| 557 |
``` cpp
|
| 558 |
namespace std {
|
| 559 |
template<class Container>
|
| 560 |
class insert_iterator {
|
| 561 |
protected:
|
| 562 |
-
Container* container;
|
| 563 |
-
|
| 564 |
|
| 565 |
public:
|
| 566 |
using iterator_category = output_iterator_tag;
|
| 567 |
using value_type = void;
|
| 568 |
-
using difference_type =
|
| 569 |
using pointer = void;
|
| 570 |
using reference = void;
|
| 571 |
using container_type = Container;
|
| 572 |
|
| 573 |
-
insert_iterator(
|
| 574 |
-
insert_iterator&
|
| 575 |
-
insert_iterator& operator=(typename Container::value_type&
|
|
|
|
| 576 |
|
| 577 |
-
insert_iterator& operator*();
|
| 578 |
-
insert_iterator& operator++();
|
| 579 |
-
insert_iterator& operator++(int);
|
| 580 |
};
|
| 581 |
-
|
| 582 |
-
template <class Container>
|
| 583 |
-
insert_iterator<Container> inserter(Container& x, typename Container::iterator i);
|
| 584 |
}
|
| 585 |
```
|
| 586 |
|
| 587 |
-
####
|
| 588 |
-
|
| 589 |
-
##### `insert_iterator` constructor <a id="insert.iter.cons">[[insert.iter.cons]]</a>
|
| 590 |
|
| 591 |
``` cpp
|
| 592 |
-
insert_iterator(Container& x,
|
| 593 |
```
|
| 594 |
|
| 595 |
*Effects:* Initializes `container` with `addressof(x)` and `iter` with
|
| 596 |
`i`.
|
| 597 |
|
| 598 |
-
##### `insert_iterator::operator=` <a id="insert.iter.op=">[[insert.iter.op=]]</a>
|
| 599 |
-
|
| 600 |
``` cpp
|
| 601 |
-
insert_iterator& operator=(const typename Container::value_type& value);
|
| 602 |
```
|
| 603 |
|
| 604 |
*Effects:* As if by:
|
| 605 |
|
| 606 |
``` cpp
|
|
@@ -609,11 +618,11 @@ iter = container->insert(iter, value);
|
|
| 609 |
```
|
| 610 |
|
| 611 |
*Returns:* `*this`.
|
| 612 |
|
| 613 |
``` cpp
|
| 614 |
-
insert_iterator& operator=(typename Container::value_type&& value);
|
| 615 |
```
|
| 616 |
|
| 617 |
*Effects:* As if by:
|
| 618 |
|
| 619 |
``` cpp
|
|
@@ -621,37 +630,34 @@ iter = container->insert(iter, std::move(value));
|
|
| 621 |
++iter;
|
| 622 |
```
|
| 623 |
|
| 624 |
*Returns:* `*this`.
|
| 625 |
|
| 626 |
-
##### `insert_iterator::operator*` <a id="insert.iter.op*">[[insert.iter.op*]]</a>
|
| 627 |
-
|
| 628 |
``` cpp
|
| 629 |
-
insert_iterator& operator*();
|
| 630 |
```
|
| 631 |
|
| 632 |
*Returns:* `*this`.
|
| 633 |
|
| 634 |
-
##### `insert_iterator::operator++` <a id="insert.iter.op++">[[insert.iter.op++]]</a>
|
| 635 |
-
|
| 636 |
``` cpp
|
| 637 |
-
insert_iterator& operator++();
|
| 638 |
-
insert_iterator& operator++(int);
|
| 639 |
```
|
| 640 |
|
| 641 |
*Returns:* `*this`.
|
| 642 |
|
| 643 |
##### `inserter` <a id="inserter">[[inserter]]</a>
|
| 644 |
|
| 645 |
``` cpp
|
| 646 |
template<class Container>
|
| 647 |
-
insert_iterator<Container>
|
|
|
|
| 648 |
```
|
| 649 |
|
| 650 |
*Returns:* `insert_iterator<Container>(x, i)`.
|
| 651 |
|
| 652 |
-
### Move iterators <a id="move.iterators">[[move.iterators]]</a>
|
| 653 |
|
| 654 |
Class template `move_iterator` is an iterator adaptor with the same
|
| 655 |
behavior as the underlying iterator except that its indirection operator
|
| 656 |
implicitly converts the value returned by the underlying iterator’s
|
| 657 |
indirection operator to an rvalue. Some generic algorithms can be called
|
|
@@ -675,89 +681,82 @@ vector<string> v2(make_move_iterator(s.begin()),
|
|
| 675 |
namespace std {
|
| 676 |
template<class Iterator>
|
| 677 |
class move_iterator {
|
| 678 |
public:
|
| 679 |
using iterator_type = Iterator;
|
| 680 |
-
using
|
| 681 |
-
using
|
| 682 |
-
using
|
|
|
|
| 683 |
using pointer = Iterator;
|
| 684 |
-
using reference =
|
| 685 |
|
| 686 |
constexpr move_iterator();
|
| 687 |
constexpr explicit move_iterator(Iterator i);
|
| 688 |
template<class U> constexpr move_iterator(const move_iterator<U>& u);
|
| 689 |
template<class U> constexpr move_iterator& operator=(const move_iterator<U>& u);
|
| 690 |
|
| 691 |
-
constexpr iterator_type base() const;
|
|
|
|
| 692 |
constexpr reference operator*() const;
|
| 693 |
-
constexpr pointer operator->() const;
|
| 694 |
|
| 695 |
constexpr move_iterator& operator++();
|
| 696 |
-
constexpr
|
| 697 |
constexpr move_iterator& operator--();
|
| 698 |
constexpr move_iterator operator--(int);
|
| 699 |
|
| 700 |
constexpr move_iterator operator+(difference_type n) const;
|
| 701 |
constexpr move_iterator& operator+=(difference_type n);
|
| 702 |
constexpr move_iterator operator-(difference_type n) const;
|
| 703 |
constexpr move_iterator& operator-=(difference_type n);
|
| 704 |
-
constexpr
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 705 |
|
| 706 |
private:
|
| 707 |
Iterator current; // exposition only
|
| 708 |
};
|
| 709 |
-
|
| 710 |
-
template <class Iterator1, class Iterator2>
|
| 711 |
-
constexpr bool operator==(
|
| 712 |
-
const move_iterator<Iterator1>& x, const move_iterator<Iterator2>& y);
|
| 713 |
-
template <class Iterator1, class Iterator2>
|
| 714 |
-
constexpr bool operator!=(
|
| 715 |
-
const move_iterator<Iterator1>& x, const move_iterator<Iterator2>& y);
|
| 716 |
-
template <class Iterator1, class Iterator2>
|
| 717 |
-
constexpr bool operator<(
|
| 718 |
-
const move_iterator<Iterator1>& x, const move_iterator<Iterator2>& y);
|
| 719 |
-
template <class Iterator1, class Iterator2>
|
| 720 |
-
constexpr bool operator<=(
|
| 721 |
-
const move_iterator<Iterator1>& x, const move_iterator<Iterator2>& y);
|
| 722 |
-
template <class Iterator1, class Iterator2>
|
| 723 |
-
constexpr bool operator>(
|
| 724 |
-
const move_iterator<Iterator1>& x, const move_iterator<Iterator2>& y);
|
| 725 |
-
template <class Iterator1, class Iterator2>
|
| 726 |
-
constexpr bool operator>=(
|
| 727 |
-
const move_iterator<Iterator1>& x, const move_iterator<Iterator2>& y);
|
| 728 |
-
|
| 729 |
-
template <class Iterator1, class Iterator2>
|
| 730 |
-
constexpr auto operator-(
|
| 731 |
-
const move_iterator<Iterator1>& x,
|
| 732 |
-
const move_iterator<Iterator2>& y) -> decltype(x.base() - y.base());
|
| 733 |
-
template <class Iterator>
|
| 734 |
-
constexpr move_iterator<Iterator> operator+(
|
| 735 |
-
typename move_iterator<Iterator>::difference_type n, const move_iterator<Iterator>& x);
|
| 736 |
-
template <class Iterator>
|
| 737 |
-
constexpr move_iterator<Iterator> make_move_iterator(Iterator i);
|
| 738 |
}
|
| 739 |
```
|
| 740 |
|
| 741 |
-
|
| 742 |
-
`is_reference_v<R>` is `true`, the template specialization
|
| 743 |
-
`move_iterator<Iterator>` shall define the nested type named `reference`
|
| 744 |
-
as a synonym for `remove_reference_t<R>&&`, otherwise as a synonym for
|
| 745 |
-
`R`.
|
| 746 |
|
| 747 |
-
|
|
|
|
|
|
|
|
|
|
| 748 |
|
| 749 |
-
|
| 750 |
-
input iterator ([[input.iterators]]). Additionally, if any of the
|
| 751 |
-
bidirectional or random access traversal functions are instantiated, the
|
| 752 |
-
template parameter shall meet the requirements for a Bidirectional
|
| 753 |
-
Iterator ([[bidirectional.iterators]]) or a Random Access Iterator (
|
| 754 |
-
[[random.access.iterators]]), respectively.
|
| 755 |
|
| 756 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 757 |
|
| 758 |
-
####
|
| 759 |
|
| 760 |
``` cpp
|
| 761 |
constexpr move_iterator();
|
| 762 |
```
|
| 763 |
|
|
@@ -769,78 +768,84 @@ value-initialized iterator of type `Iterator`.
|
|
| 769 |
``` cpp
|
| 770 |
constexpr explicit move_iterator(Iterator i);
|
| 771 |
```
|
| 772 |
|
| 773 |
*Effects:* Constructs a `move_iterator`, initializing `current` with
|
| 774 |
-
`i`.
|
| 775 |
|
| 776 |
``` cpp
|
| 777 |
template<class U> constexpr move_iterator(const move_iterator<U>& u);
|
| 778 |
```
|
| 779 |
|
|
|
|
|
|
|
| 780 |
*Effects:* Constructs a `move_iterator`, initializing `current` with
|
| 781 |
`u.base()`.
|
| 782 |
|
| 783 |
-
*Requires:* `U` shall be convertible to `Iterator`.
|
| 784 |
-
|
| 785 |
-
##### `move_iterator::operator=` <a id="move.iter.op=">[[move.iter.op=]]</a>
|
| 786 |
-
|
| 787 |
``` cpp
|
| 788 |
template<class U> constexpr move_iterator& operator=(const move_iterator<U>& u);
|
| 789 |
```
|
| 790 |
|
|
|
|
|
|
|
| 791 |
*Effects:* Assigns `u.base()` to `current`.
|
| 792 |
|
| 793 |
-
|
| 794 |
-
|
| 795 |
-
##### `move_iterator` conversion <a id="move.iter.op.conv">[[move.iter.op.conv]]</a>
|
| 796 |
|
| 797 |
``` cpp
|
| 798 |
-
constexpr Iterator base() const;
|
| 799 |
```
|
| 800 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 801 |
*Returns:* `current`.
|
| 802 |
|
| 803 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 804 |
|
| 805 |
``` cpp
|
| 806 |
constexpr reference operator*() const;
|
| 807 |
```
|
| 808 |
|
| 809 |
-
*
|
| 810 |
-
|
| 811 |
-
##### `move_iterator::operator->` <a id="move.iter.op.ref">[[move.iter.op.ref]]</a>
|
| 812 |
|
| 813 |
``` cpp
|
| 814 |
-
constexpr
|
| 815 |
```
|
| 816 |
|
| 817 |
-
*
|
| 818 |
|
| 819 |
-
####
|
| 820 |
|
| 821 |
``` cpp
|
| 822 |
constexpr move_iterator& operator++();
|
| 823 |
```
|
| 824 |
|
| 825 |
*Effects:* As if by `++current`.
|
| 826 |
|
| 827 |
*Returns:* `*this`.
|
| 828 |
|
| 829 |
``` cpp
|
| 830 |
-
constexpr
|
| 831 |
```
|
| 832 |
|
| 833 |
-
*Effects:*
|
| 834 |
|
| 835 |
``` cpp
|
| 836 |
move_iterator tmp = *this;
|
| 837 |
++current;
|
| 838 |
return tmp;
|
| 839 |
```
|
| 840 |
|
| 841 |
-
|
| 842 |
|
| 843 |
``` cpp
|
| 844 |
constexpr move_iterator& operator--();
|
| 845 |
```
|
| 846 |
|
|
@@ -858,119 +863,973 @@ constexpr move_iterator operator--(int);
|
|
| 858 |
move_iterator tmp = *this;
|
| 859 |
--current;
|
| 860 |
return tmp;
|
| 861 |
```
|
| 862 |
|
| 863 |
-
##### `move_iterator::operator+` <a id="move.iter.op.+">[[move.iter.op.+]]</a>
|
| 864 |
-
|
| 865 |
``` cpp
|
| 866 |
constexpr move_iterator operator+(difference_type n) const;
|
| 867 |
```
|
| 868 |
|
| 869 |
*Returns:* `move_iterator(current + n)`.
|
| 870 |
|
| 871 |
-
##### `move_iterator::operator+=` <a id="move.iter.op.+=">[[move.iter.op.+=]]</a>
|
| 872 |
-
|
| 873 |
``` cpp
|
| 874 |
constexpr move_iterator& operator+=(difference_type n);
|
| 875 |
```
|
| 876 |
|
| 877 |
*Effects:* As if by: `current += n;`
|
| 878 |
|
| 879 |
*Returns:* `*this`.
|
| 880 |
|
| 881 |
-
##### `move_iterator::operator-` <a id="move.iter.op.-">[[move.iter.op.-]]</a>
|
| 882 |
-
|
| 883 |
``` cpp
|
| 884 |
constexpr move_iterator operator-(difference_type n) const;
|
| 885 |
```
|
| 886 |
|
| 887 |
*Returns:* `move_iterator(current - n)`.
|
| 888 |
|
| 889 |
-
##### `move_iterator::operator-=` <a id="move.iter.op.-=">[[move.iter.op.-=]]</a>
|
| 890 |
-
|
| 891 |
``` cpp
|
| 892 |
constexpr move_iterator& operator-=(difference_type n);
|
| 893 |
```
|
| 894 |
|
| 895 |
*Effects:* As if by: `current -= n;`
|
| 896 |
|
| 897 |
*Returns:* `*this`.
|
| 898 |
|
| 899 |
-
####
|
| 900 |
-
|
| 901 |
-
``` cpp
|
| 902 |
-
constexpr unspecified operator[](difference_type n) const;
|
| 903 |
-
```
|
| 904 |
-
|
| 905 |
-
*Returns:* `std::move(current[n])`.
|
| 906 |
-
|
| 907 |
-
##### `move_iterator` comparisons <a id="move.iter.op.comp">[[move.iter.op.comp]]</a>
|
| 908 |
|
| 909 |
``` cpp
|
| 910 |
template<class Iterator1, class Iterator2>
|
| 911 |
-
constexpr bool operator==(const move_iterator<Iterator1>& x,
|
|
|
|
|
|
|
|
|
|
|
|
|
| 912 |
```
|
| 913 |
|
|
|
|
|
|
|
|
|
|
| 914 |
*Returns:* `x.base() == y.base()`.
|
| 915 |
|
| 916 |
-
``` cpp
|
| 917 |
-
template <class Iterator1, class Iterator2>
|
| 918 |
-
constexpr bool operator!=(const move_iterator<Iterator1>& x, const move_iterator<Iterator2>& y);
|
| 919 |
-
```
|
| 920 |
-
|
| 921 |
-
*Returns:* `!(x == y)`.
|
| 922 |
-
|
| 923 |
``` cpp
|
| 924 |
template<class Iterator1, class Iterator2>
|
| 925 |
constexpr bool operator<(const move_iterator<Iterator1>& x, const move_iterator<Iterator2>& y);
|
| 926 |
```
|
| 927 |
|
|
|
|
|
|
|
|
|
|
| 928 |
*Returns:* `x.base() < y.base()`.
|
| 929 |
|
| 930 |
-
``` cpp
|
| 931 |
-
template <class Iterator1, class Iterator2>
|
| 932 |
-
constexpr bool operator<=(const move_iterator<Iterator1>& x, const move_iterator<Iterator2>& y);
|
| 933 |
-
```
|
| 934 |
-
|
| 935 |
-
*Returns:* `!(y < x)`.
|
| 936 |
-
|
| 937 |
``` cpp
|
| 938 |
template<class Iterator1, class Iterator2>
|
| 939 |
constexpr bool operator>(const move_iterator<Iterator1>& x, const move_iterator<Iterator2>& y);
|
| 940 |
```
|
| 941 |
|
|
|
|
|
|
|
|
|
|
| 942 |
*Returns:* `y < x`.
|
| 943 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 944 |
``` cpp
|
| 945 |
template<class Iterator1, class Iterator2>
|
| 946 |
constexpr bool operator>=(const move_iterator<Iterator1>& x, const move_iterator<Iterator2>& y);
|
| 947 |
```
|
| 948 |
|
|
|
|
|
|
|
|
|
|
| 949 |
*Returns:* `!(x < y)`.
|
| 950 |
|
| 951 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 952 |
|
| 953 |
``` cpp
|
| 954 |
template<class Iterator1, class Iterator2>
|
| 955 |
-
|
| 956 |
-
|
| 957 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 958 |
```
|
| 959 |
|
| 960 |
*Returns:* `x.base() - y.base()`.
|
| 961 |
|
| 962 |
``` cpp
|
| 963 |
template<class Iterator>
|
| 964 |
-
constexpr move_iterator<Iterator>
|
| 965 |
-
|
| 966 |
```
|
| 967 |
|
|
|
|
|
|
|
| 968 |
*Returns:* `x + n`.
|
| 969 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 970 |
``` cpp
|
| 971 |
template<class Iterator>
|
| 972 |
constexpr move_iterator<Iterator> make_move_iterator(Iterator i);
|
| 973 |
```
|
| 974 |
|
| 975 |
-
*Returns:* `move_iterator<Iterator>(i)`.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 976 |
|
|
|
|
| 2 |
|
| 3 |
### Reverse iterators <a id="reverse.iterators">[[reverse.iterators]]</a>
|
| 4 |
|
| 5 |
Class template `reverse_iterator` is an iterator adaptor that iterates
|
| 6 |
from the end of the sequence defined by its underlying iterator to the
|
| 7 |
+
beginning of that sequence.
|
|
|
|
|
|
|
| 8 |
|
| 9 |
#### Class template `reverse_iterator` <a id="reverse.iterator">[[reverse.iterator]]</a>
|
| 10 |
|
| 11 |
``` cpp
|
| 12 |
namespace std {
|
| 13 |
template<class Iterator>
|
| 14 |
class reverse_iterator {
|
| 15 |
public:
|
| 16 |
using iterator_type = Iterator;
|
| 17 |
+
using iterator_concept = see below;
|
| 18 |
+
using iterator_category = see below;
|
| 19 |
+
using value_type = iter_value_t<Iterator>;
|
| 20 |
+
using difference_type = iter_difference_t<Iterator>;
|
| 21 |
using pointer = typename iterator_traits<Iterator>::pointer;
|
| 22 |
+
using reference = iter_reference_t<Iterator>;
|
| 23 |
|
| 24 |
constexpr reverse_iterator();
|
| 25 |
constexpr explicit reverse_iterator(Iterator x);
|
| 26 |
template<class U> constexpr reverse_iterator(const reverse_iterator<U>& u);
|
| 27 |
template<class U> constexpr reverse_iterator& operator=(const reverse_iterator<U>& u);
|
| 28 |
|
| 29 |
+
constexpr Iterator base() const;
|
| 30 |
constexpr reference operator*() const;
|
| 31 |
+
constexpr pointer operator->() const requires see below;
|
| 32 |
|
| 33 |
constexpr reverse_iterator& operator++();
|
| 34 |
constexpr reverse_iterator operator++(int);
|
| 35 |
constexpr reverse_iterator& operator--();
|
| 36 |
constexpr reverse_iterator operator--(int);
|
|
|
|
| 38 |
constexpr reverse_iterator operator+ (difference_type n) const;
|
| 39 |
constexpr reverse_iterator& operator+=(difference_type n);
|
| 40 |
constexpr reverse_iterator operator- (difference_type n) const;
|
| 41 |
constexpr reverse_iterator& operator-=(difference_type n);
|
| 42 |
constexpr unspecified operator[](difference_type n) const;
|
| 43 |
+
|
| 44 |
+
friend constexpr iter_rvalue_reference_t<Iterator>
|
| 45 |
+
iter_move(const reverse_iterator& i) noexcept(see below);
|
| 46 |
+
template<indirectly_swappable<Iterator> Iterator2>
|
| 47 |
+
friend constexpr void
|
| 48 |
+
iter_swap(const reverse_iterator& x,
|
| 49 |
+
const reverse_iterator<Iterator2>& y) noexcept(see below);
|
| 50 |
+
|
| 51 |
protected:
|
| 52 |
Iterator current;
|
| 53 |
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 54 |
}
|
| 55 |
```
|
| 56 |
|
| 57 |
+
The member *typedef-name* `iterator_concept` denotes
|
| 58 |
+
|
| 59 |
+
- `random_access_iterator_tag` if `Iterator` models
|
| 60 |
+
`random_access_iterator`, and
|
| 61 |
+
- `bidirectional_iterator_tag` otherwise.
|
| 62 |
+
|
| 63 |
+
The member *typedef-name* `iterator_category` denotes
|
| 64 |
+
|
| 65 |
+
- `random_access_iterator_tag` if the type
|
| 66 |
+
`iterator_traits<{}Iterator>::iterator_category` models
|
| 67 |
+
`derived_from<random_access_iterator_tag>`, and
|
| 68 |
+
- `iterator_traits<{}Iterator>::iterator_category` otherwise.
|
| 69 |
+
|
| 70 |
+
#### Requirements <a id="reverse.iter.requirements">[[reverse.iter.requirements]]</a>
|
| 71 |
+
|
| 72 |
+
The template parameter `Iterator` shall either meet the requirements of
|
| 73 |
+
a *Cpp17BidirectionalIterator* [[bidirectional.iterators]] or model
|
| 74 |
+
`bidirectional_iterator` [[iterator.concept.bidir]].
|
| 75 |
+
|
| 76 |
+
Additionally, `Iterator` shall either meet the requirements of a
|
| 77 |
+
*Cpp17RandomAccessIterator* [[random.access.iterators]] or model
|
| 78 |
+
`random_access_iterator` [[iterator.concept.random.access]] if the
|
| 79 |
+
definitions of any of the members
|
| 80 |
+
|
| 81 |
+
- `operator+`, `operator-`, `operator+=`, `operator-=`
|
| 82 |
+
[[reverse.iter.nav]], or
|
| 83 |
+
- `operator[]` [[reverse.iter.elem]],
|
| 84 |
+
|
| 85 |
+
or the non-member operators [[reverse.iter.cmp]]
|
| 86 |
+
|
| 87 |
+
- `operator<`, `operator>`, `operator<=`, `operator>=`, `operator-`, or
|
| 88 |
+
`operator+` [[reverse.iter.nonmember]]
|
| 89 |
+
|
| 90 |
+
are instantiated [[temp.inst]].
|
| 91 |
+
|
| 92 |
+
#### Construction and assignment <a id="reverse.iter.cons">[[reverse.iter.cons]]</a>
|
| 93 |
|
| 94 |
``` cpp
|
| 95 |
constexpr reverse_iterator();
|
| 96 |
```
|
| 97 |
|
|
|
|
| 110 |
template<class U> constexpr reverse_iterator(const reverse_iterator<U>& u);
|
| 111 |
```
|
| 112 |
|
| 113 |
*Effects:* Initializes `current` with `u.current`.
|
| 114 |
|
|
|
|
|
|
|
| 115 |
``` cpp
|
| 116 |
template<class U>
|
| 117 |
constexpr reverse_iterator&
|
| 118 |
operator=(const reverse_iterator<U>& u);
|
| 119 |
```
|
| 120 |
|
| 121 |
+
*Effects:* Assigns `u.base()` to `current`.
|
| 122 |
|
| 123 |
*Returns:* `*this`.
|
| 124 |
|
| 125 |
+
#### Conversion <a id="reverse.iter.conv">[[reverse.iter.conv]]</a>
|
| 126 |
|
| 127 |
``` cpp
|
| 128 |
constexpr Iterator base() const; // explicit
|
| 129 |
```
|
| 130 |
|
| 131 |
*Returns:* `current`.
|
| 132 |
|
| 133 |
+
#### Element access <a id="reverse.iter.elem">[[reverse.iter.elem]]</a>
|
| 134 |
|
| 135 |
``` cpp
|
| 136 |
constexpr reference operator*() const;
|
| 137 |
```
|
| 138 |
|
|
|
|
| 141 |
``` cpp
|
| 142 |
Iterator tmp = current;
|
| 143 |
return *--tmp;
|
| 144 |
```
|
| 145 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 146 |
``` cpp
|
| 147 |
+
constexpr pointer operator->() const
|
| 148 |
+
requires (is_pointer_v<Iterator> ||
|
| 149 |
+
requires (const Iterator i) { i.operator->(); });
|
| 150 |
```
|
| 151 |
|
| 152 |
+
*Effects:*
|
| 153 |
|
| 154 |
+
- If `Iterator` is a pointer type, equivalent to:
|
| 155 |
+
`return prev(current);`
|
| 156 |
+
- Otherwise, equivalent to: `return prev(current).operator->();`
|
|
|
|
|
|
|
|
|
|
|
|
|
| 157 |
|
| 158 |
``` cpp
|
| 159 |
+
constexpr unspecified operator[](difference_type n) const;
|
| 160 |
```
|
| 161 |
|
| 162 |
+
*Returns:* `current[-n-1]`.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 163 |
|
| 164 |
+
#### Navigation <a id="reverse.iter.nav">[[reverse.iter.nav]]</a>
|
| 165 |
|
| 166 |
``` cpp
|
| 167 |
constexpr reverse_iterator operator+(difference_type n) const;
|
| 168 |
```
|
| 169 |
|
| 170 |
*Returns:* `reverse_iterator(current-n)`.
|
| 171 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 172 |
``` cpp
|
| 173 |
constexpr reverse_iterator operator-(difference_type n) const;
|
| 174 |
```
|
| 175 |
|
| 176 |
*Returns:* `reverse_iterator(current+n)`.
|
| 177 |
|
| 178 |
+
``` cpp
|
| 179 |
+
constexpr reverse_iterator& operator++();
|
| 180 |
+
```
|
| 181 |
+
|
| 182 |
+
*Effects:* As if by: `current;`
|
| 183 |
+
|
| 184 |
+
*Returns:* `*this`.
|
| 185 |
+
|
| 186 |
+
``` cpp
|
| 187 |
+
constexpr reverse_iterator operator++(int);
|
| 188 |
+
```
|
| 189 |
+
|
| 190 |
+
*Effects:* As if by:
|
| 191 |
+
|
| 192 |
+
``` cpp
|
| 193 |
+
reverse_iterator tmp = *this;
|
| 194 |
+
--current;
|
| 195 |
+
return tmp;
|
| 196 |
+
```
|
| 197 |
+
|
| 198 |
+
``` cpp
|
| 199 |
+
constexpr reverse_iterator& operator--();
|
| 200 |
+
```
|
| 201 |
+
|
| 202 |
+
*Effects:* As if by `++current`.
|
| 203 |
+
|
| 204 |
+
*Returns:* `*this`.
|
| 205 |
+
|
| 206 |
+
``` cpp
|
| 207 |
+
constexpr reverse_iterator operator--(int);
|
| 208 |
+
```
|
| 209 |
+
|
| 210 |
+
*Effects:* As if by:
|
| 211 |
+
|
| 212 |
+
``` cpp
|
| 213 |
+
reverse_iterator tmp = *this;
|
| 214 |
+
++current;
|
| 215 |
+
return tmp;
|
| 216 |
+
```
|
| 217 |
+
|
| 218 |
+
``` cpp
|
| 219 |
+
constexpr reverse_iterator& operator+=(difference_type n);
|
| 220 |
+
```
|
| 221 |
+
|
| 222 |
+
*Effects:* As if by: `current -= n;`
|
| 223 |
+
|
| 224 |
+
*Returns:* `*this`.
|
| 225 |
|
| 226 |
``` cpp
|
| 227 |
constexpr reverse_iterator& operator-=(difference_type n);
|
| 228 |
```
|
| 229 |
|
| 230 |
*Effects:* As if by: `current += n;`
|
| 231 |
|
| 232 |
*Returns:* `*this`.
|
| 233 |
|
| 234 |
+
#### Comparisons <a id="reverse.iter.cmp">[[reverse.iter.cmp]]</a>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 235 |
|
| 236 |
``` cpp
|
| 237 |
template<class Iterator1, class Iterator2>
|
| 238 |
constexpr bool operator==(
|
| 239 |
const reverse_iterator<Iterator1>& x,
|
| 240 |
const reverse_iterator<Iterator2>& y);
|
| 241 |
```
|
| 242 |
|
| 243 |
+
*Constraints:* `x.base() == y.base()` is well-formed and convertible to
|
| 244 |
+
`bool`.
|
| 245 |
|
| 246 |
+
*Returns:* `x.base() == y.base()`.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 247 |
|
| 248 |
``` cpp
|
| 249 |
template<class Iterator1, class Iterator2>
|
| 250 |
constexpr bool operator!=(
|
| 251 |
const reverse_iterator<Iterator1>& x,
|
| 252 |
const reverse_iterator<Iterator2>& y);
|
| 253 |
```
|
| 254 |
|
| 255 |
+
*Constraints:* `x.base() != y.base()` is well-formed and convertible to
|
| 256 |
+
`bool`.
|
| 257 |
|
| 258 |
+
*Returns:* `x.base() != y.base()`.
|
| 259 |
+
|
| 260 |
+
``` cpp
|
| 261 |
+
template<class Iterator1, class Iterator2>
|
| 262 |
+
constexpr bool operator<(
|
| 263 |
+
const reverse_iterator<Iterator1>& x,
|
| 264 |
+
const reverse_iterator<Iterator2>& y);
|
| 265 |
+
```
|
| 266 |
+
|
| 267 |
+
*Constraints:* `x.base() > y.base()` is well-formed and convertible to
|
| 268 |
+
`bool`.
|
| 269 |
+
|
| 270 |
+
*Returns:* `x.base() > y.base()`.
|
| 271 |
|
| 272 |
``` cpp
|
| 273 |
template<class Iterator1, class Iterator2>
|
| 274 |
constexpr bool operator>(
|
| 275 |
const reverse_iterator<Iterator1>& x,
|
| 276 |
const reverse_iterator<Iterator2>& y);
|
| 277 |
```
|
| 278 |
|
| 279 |
+
*Constraints:* `x.base() < y.base()` is well-formed and convertible to
|
| 280 |
+
`bool`.
|
| 281 |
|
| 282 |
+
*Returns:* `x.base() < y.base()`.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 283 |
|
| 284 |
``` cpp
|
| 285 |
template<class Iterator1, class Iterator2>
|
| 286 |
constexpr bool operator<=(
|
| 287 |
const reverse_iterator<Iterator1>& x,
|
| 288 |
const reverse_iterator<Iterator2>& y);
|
| 289 |
```
|
| 290 |
|
| 291 |
+
*Constraints:* `x.base() >= y.base()` is well-formed and convertible to
|
| 292 |
+
`bool`.
|
| 293 |
|
| 294 |
+
*Returns:* `x.base() >= y.base()`.
|
| 295 |
+
|
| 296 |
+
``` cpp
|
| 297 |
+
template<class Iterator1, class Iterator2>
|
| 298 |
+
constexpr bool operator>=(
|
| 299 |
+
const reverse_iterator<Iterator1>& x,
|
| 300 |
+
const reverse_iterator<Iterator2>& y);
|
| 301 |
+
```
|
| 302 |
+
|
| 303 |
+
*Constraints:* `x.base() <= y.base()` is well-formed and convertible to
|
| 304 |
+
`bool`.
|
| 305 |
+
|
| 306 |
+
*Returns:* `x.base() <= y.base()`.
|
| 307 |
+
|
| 308 |
+
``` cpp
|
| 309 |
+
template<class Iterator1, three_way_comparable_with<Iterator1> Iterator2>
|
| 310 |
+
constexpr compare_three_way_result_t<Iterator1, Iterator2>
|
| 311 |
+
operator<=>(const reverse_iterator<Iterator1>& x,
|
| 312 |
+
const reverse_iterator<Iterator2>& y);
|
| 313 |
+
```
|
| 314 |
+
|
| 315 |
+
*Returns:* `y.base() <=> x.base()`.
|
| 316 |
+
|
| 317 |
+
[*Note 1*: The argument order in the *Returns:* element is reversed
|
| 318 |
+
because this is a reverse iterator. — *end note*]
|
| 319 |
+
|
| 320 |
+
#### Non-member functions <a id="reverse.iter.nonmember">[[reverse.iter.nonmember]]</a>
|
| 321 |
|
| 322 |
``` cpp
|
| 323 |
template<class Iterator1, class Iterator2>
|
| 324 |
constexpr auto operator-(
|
| 325 |
const reverse_iterator<Iterator1>& x,
|
| 326 |
const reverse_iterator<Iterator2>& y) -> decltype(y.base() - x.base());
|
| 327 |
```
|
| 328 |
|
| 329 |
+
*Returns:* `y.base() - x.base()`.
|
|
|
|
|
|
|
| 330 |
|
| 331 |
``` cpp
|
| 332 |
template<class Iterator>
|
| 333 |
constexpr reverse_iterator<Iterator> operator+(
|
| 334 |
typename reverse_iterator<Iterator>::difference_type n,
|
| 335 |
const reverse_iterator<Iterator>& x);
|
| 336 |
```
|
| 337 |
|
| 338 |
+
*Returns:* `reverse_iterator<Iterator>(x.base() - n)`.
|
| 339 |
|
| 340 |
+
``` cpp
|
| 341 |
+
friend constexpr iter_rvalue_reference_t<Iterator>
|
| 342 |
+
iter_move(const reverse_iterator& i) noexcept(see below);
|
| 343 |
+
```
|
| 344 |
+
|
| 345 |
+
*Effects:* Equivalent to:
|
| 346 |
+
|
| 347 |
+
``` cpp
|
| 348 |
+
auto tmp = i.base();
|
| 349 |
+
return ranges::iter_move(--tmp);
|
| 350 |
+
```
|
| 351 |
+
|
| 352 |
+
*Remarks:* The expression in `noexcept` is equivalent to:
|
| 353 |
+
|
| 354 |
+
``` cpp
|
| 355 |
+
is_nothrow_copy_constructible_v<Iterator> &&
|
| 356 |
+
noexcept(ranges::iter_move(--declval<Iterator&>()))
|
| 357 |
+
```
|
| 358 |
+
|
| 359 |
+
``` cpp
|
| 360 |
+
template<indirectly_swappable<Iterator> Iterator2>
|
| 361 |
+
friend constexpr void
|
| 362 |
+
iter_swap(const reverse_iterator& x,
|
| 363 |
+
const reverse_iterator<Iterator2>& y) noexcept(see below);
|
| 364 |
+
```
|
| 365 |
+
|
| 366 |
+
*Effects:* Equivalent to:
|
| 367 |
+
|
| 368 |
+
``` cpp
|
| 369 |
+
auto xtmp = x.base();
|
| 370 |
+
auto ytmp = y.base();
|
| 371 |
+
ranges::iter_swap(--xtmp, --ytmp);
|
| 372 |
+
```
|
| 373 |
+
|
| 374 |
+
*Remarks:* The expression in `noexcept` is equivalent to:
|
| 375 |
+
|
| 376 |
+
``` cpp
|
| 377 |
+
is_nothrow_copy_constructible_v<Iterator> &&
|
| 378 |
+
is_nothrow_copy_constructible_v<Iterator2> &&
|
| 379 |
+
noexcept(ranges::iter_swap(--declval<Iterator&>(), --declval<Iterator2&>()))
|
| 380 |
+
```
|
| 381 |
|
| 382 |
``` cpp
|
| 383 |
template<class Iterator>
|
| 384 |
constexpr reverse_iterator<Iterator> make_reverse_iterator(Iterator i);
|
| 385 |
```
|
|
|
|
| 402 |
of the copying algorithms in the library to work in the *insert mode*
|
| 403 |
instead of the *regular overwrite* mode.
|
| 404 |
|
| 405 |
An insert iterator is constructed from a container and possibly one of
|
| 406 |
its iterators pointing to where insertion takes place if it is neither
|
| 407 |
+
at the beginning nor at the end of the container. Insert iterators meet
|
| 408 |
+
the requirements of output iterators. `operator*` returns the insert
|
| 409 |
+
iterator itself. The assignment `operator=(const T& x)` is defined on
|
| 410 |
+
insert iterators to allow writing into them, it inserts `x` right before
|
| 411 |
+
where the insert iterator is pointing. In other words, an insert
|
| 412 |
+
iterator is like a cursor pointing into the container where the
|
| 413 |
insertion takes place. `back_insert_iterator` inserts elements at the
|
| 414 |
end of a container, `front_insert_iterator` inserts elements at the
|
| 415 |
beginning of a container, and `insert_iterator` inserts elements where
|
| 416 |
the iterator points to in a container. `back_inserter`,
|
| 417 |
`front_inserter`, and `inserter` are three functions making the insert
|
|
|
|
| 422 |
``` cpp
|
| 423 |
namespace std {
|
| 424 |
template<class Container>
|
| 425 |
class back_insert_iterator {
|
| 426 |
protected:
|
| 427 |
+
Container* container = nullptr;
|
| 428 |
|
| 429 |
public:
|
| 430 |
using iterator_category = output_iterator_tag;
|
| 431 |
using value_type = void;
|
| 432 |
+
using difference_type = ptrdiff_t;
|
| 433 |
using pointer = void;
|
| 434 |
using reference = void;
|
| 435 |
using container_type = Container;
|
| 436 |
|
| 437 |
+
constexpr back_insert_iterator() noexcept = default;
|
| 438 |
+
constexpr explicit back_insert_iterator(Container& x);
|
| 439 |
+
constexpr back_insert_iterator& operator=(const typename Container::value_type& value);
|
| 440 |
+
constexpr back_insert_iterator& operator=(typename Container::value_type&& value);
|
| 441 |
|
| 442 |
+
constexpr back_insert_iterator& operator*();
|
| 443 |
+
constexpr back_insert_iterator& operator++();
|
| 444 |
+
constexpr back_insert_iterator operator++(int);
|
| 445 |
};
|
|
|
|
|
|
|
|
|
|
| 446 |
}
|
| 447 |
```
|
| 448 |
|
| 449 |
+
##### Operations <a id="back.insert.iter.ops">[[back.insert.iter.ops]]</a>
|
|
|
|
|
|
|
| 450 |
|
| 451 |
``` cpp
|
| 452 |
+
constexpr explicit back_insert_iterator(Container& x);
|
| 453 |
```
|
| 454 |
|
| 455 |
*Effects:* Initializes `container` with `addressof(x)`.
|
| 456 |
|
|
|
|
|
|
|
| 457 |
``` cpp
|
| 458 |
+
constexpr back_insert_iterator& operator=(const typename Container::value_type& value);
|
| 459 |
```
|
| 460 |
|
| 461 |
*Effects:* As if by: `container->push_back(value);`
|
| 462 |
|
| 463 |
*Returns:* `*this`.
|
| 464 |
|
| 465 |
``` cpp
|
| 466 |
+
constexpr back_insert_iterator& operator=(typename Container::value_type&& value);
|
| 467 |
```
|
| 468 |
|
| 469 |
*Effects:* As if by: `container->push_back(std::move(value));`
|
| 470 |
|
| 471 |
*Returns:* `*this`.
|
| 472 |
|
|
|
|
|
|
|
| 473 |
``` cpp
|
| 474 |
+
constexpr back_insert_iterator& operator*();
|
| 475 |
```
|
| 476 |
|
| 477 |
*Returns:* `*this`.
|
| 478 |
|
|
|
|
|
|
|
| 479 |
``` cpp
|
| 480 |
+
constexpr back_insert_iterator& operator++();
|
| 481 |
+
constexpr back_insert_iterator operator++(int);
|
| 482 |
```
|
| 483 |
|
| 484 |
*Returns:* `*this`.
|
| 485 |
|
| 486 |
##### `back_inserter` <a id="back.inserter">[[back.inserter]]</a>
|
| 487 |
|
| 488 |
``` cpp
|
| 489 |
template<class Container>
|
| 490 |
+
constexpr back_insert_iterator<Container> back_inserter(Container& x);
|
| 491 |
```
|
| 492 |
|
| 493 |
*Returns:* `back_insert_iterator<Container>(x)`.
|
| 494 |
|
| 495 |
#### Class template `front_insert_iterator` <a id="front.insert.iterator">[[front.insert.iterator]]</a>
|
|
|
|
| 497 |
``` cpp
|
| 498 |
namespace std {
|
| 499 |
template<class Container>
|
| 500 |
class front_insert_iterator {
|
| 501 |
protected:
|
| 502 |
+
Container* container = nullptr;
|
| 503 |
|
| 504 |
public:
|
| 505 |
using iterator_category = output_iterator_tag;
|
| 506 |
using value_type = void;
|
| 507 |
+
using difference_type = ptrdiff_t;
|
| 508 |
using pointer = void;
|
| 509 |
using reference = void;
|
| 510 |
using container_type = Container;
|
| 511 |
|
| 512 |
+
constexpr front_insert_iterator() noexcept = default;
|
| 513 |
+
constexpr explicit front_insert_iterator(Container& x);
|
| 514 |
+
constexpr front_insert_iterator& operator=(const typename Container::value_type& value);
|
| 515 |
+
constexpr front_insert_iterator& operator=(typename Container::value_type&& value);
|
| 516 |
|
| 517 |
+
constexpr front_insert_iterator& operator*();
|
| 518 |
+
constexpr front_insert_iterator& operator++();
|
| 519 |
+
constexpr front_insert_iterator operator++(int);
|
| 520 |
};
|
|
|
|
|
|
|
|
|
|
| 521 |
}
|
| 522 |
```
|
| 523 |
|
| 524 |
+
##### Operations <a id="front.insert.iter.ops">[[front.insert.iter.ops]]</a>
|
|
|
|
|
|
|
| 525 |
|
| 526 |
``` cpp
|
| 527 |
+
constexpr explicit front_insert_iterator(Container& x);
|
| 528 |
```
|
| 529 |
|
| 530 |
*Effects:* Initializes `container` with `addressof(x)`.
|
| 531 |
|
|
|
|
|
|
|
| 532 |
``` cpp
|
| 533 |
+
constexpr front_insert_iterator& operator=(const typename Container::value_type& value);
|
| 534 |
```
|
| 535 |
|
| 536 |
*Effects:* As if by: `container->push_front(value);`
|
| 537 |
|
| 538 |
*Returns:* `*this`.
|
| 539 |
|
| 540 |
``` cpp
|
| 541 |
+
constexpr front_insert_iterator& operator=(typename Container::value_type&& value);
|
| 542 |
```
|
| 543 |
|
| 544 |
*Effects:* As if by: `container->push_front(std::move(value));`
|
| 545 |
|
| 546 |
*Returns:* `*this`.
|
| 547 |
|
|
|
|
|
|
|
| 548 |
``` cpp
|
| 549 |
+
constexpr front_insert_iterator& operator*();
|
| 550 |
```
|
| 551 |
|
| 552 |
*Returns:* `*this`.
|
| 553 |
|
|
|
|
|
|
|
| 554 |
``` cpp
|
| 555 |
+
constexpr front_insert_iterator& operator++();
|
| 556 |
+
constexpr front_insert_iterator operator++(int);
|
| 557 |
```
|
| 558 |
|
| 559 |
*Returns:* `*this`.
|
| 560 |
|
| 561 |
##### `front_inserter` <a id="front.inserter">[[front.inserter]]</a>
|
| 562 |
|
| 563 |
``` cpp
|
| 564 |
template<class Container>
|
| 565 |
+
constexpr front_insert_iterator<Container> front_inserter(Container& x);
|
| 566 |
```
|
| 567 |
|
| 568 |
*Returns:* `front_insert_iterator<Container>(x)`.
|
| 569 |
|
| 570 |
#### Class template `insert_iterator` <a id="insert.iterator">[[insert.iterator]]</a>
|
|
|
|
| 572 |
``` cpp
|
| 573 |
namespace std {
|
| 574 |
template<class Container>
|
| 575 |
class insert_iterator {
|
| 576 |
protected:
|
| 577 |
+
Container* container = nullptr;
|
| 578 |
+
ranges::iterator_t<Container> iter = ranges::iterator_t<Container>();
|
| 579 |
|
| 580 |
public:
|
| 581 |
using iterator_category = output_iterator_tag;
|
| 582 |
using value_type = void;
|
| 583 |
+
using difference_type = ptrdiff_t;
|
| 584 |
using pointer = void;
|
| 585 |
using reference = void;
|
| 586 |
using container_type = Container;
|
| 587 |
|
| 588 |
+
insert_iterator() = default;
|
| 589 |
+
constexpr insert_iterator(Container& x, ranges::iterator_t<Container> i);
|
| 590 |
+
constexpr insert_iterator& operator=(const typename Container::value_type& value);
|
| 591 |
+
constexpr insert_iterator& operator=(typename Container::value_type&& value);
|
| 592 |
|
| 593 |
+
constexpr insert_iterator& operator*();
|
| 594 |
+
constexpr insert_iterator& operator++();
|
| 595 |
+
constexpr insert_iterator& operator++(int);
|
| 596 |
};
|
|
|
|
|
|
|
|
|
|
| 597 |
}
|
| 598 |
```
|
| 599 |
|
| 600 |
+
##### Operations <a id="insert.iter.ops">[[insert.iter.ops]]</a>
|
|
|
|
|
|
|
| 601 |
|
| 602 |
``` cpp
|
| 603 |
+
constexpr insert_iterator(Container& x, ranges::iterator_t<Container> i);
|
| 604 |
```
|
| 605 |
|
| 606 |
*Effects:* Initializes `container` with `addressof(x)` and `iter` with
|
| 607 |
`i`.
|
| 608 |
|
|
|
|
|
|
|
| 609 |
``` cpp
|
| 610 |
+
constexpr insert_iterator& operator=(const typename Container::value_type& value);
|
| 611 |
```
|
| 612 |
|
| 613 |
*Effects:* As if by:
|
| 614 |
|
| 615 |
``` cpp
|
|
|
|
| 618 |
```
|
| 619 |
|
| 620 |
*Returns:* `*this`.
|
| 621 |
|
| 622 |
``` cpp
|
| 623 |
+
constexpr insert_iterator& operator=(typename Container::value_type&& value);
|
| 624 |
```
|
| 625 |
|
| 626 |
*Effects:* As if by:
|
| 627 |
|
| 628 |
``` cpp
|
|
|
|
| 630 |
++iter;
|
| 631 |
```
|
| 632 |
|
| 633 |
*Returns:* `*this`.
|
| 634 |
|
|
|
|
|
|
|
| 635 |
``` cpp
|
| 636 |
+
constexpr insert_iterator& operator*();
|
| 637 |
```
|
| 638 |
|
| 639 |
*Returns:* `*this`.
|
| 640 |
|
|
|
|
|
|
|
| 641 |
``` cpp
|
| 642 |
+
constexpr insert_iterator& operator++();
|
| 643 |
+
constexpr insert_iterator& operator++(int);
|
| 644 |
```
|
| 645 |
|
| 646 |
*Returns:* `*this`.
|
| 647 |
|
| 648 |
##### `inserter` <a id="inserter">[[inserter]]</a>
|
| 649 |
|
| 650 |
``` cpp
|
| 651 |
template<class Container>
|
| 652 |
+
constexpr insert_iterator<Container>
|
| 653 |
+
inserter(Container& x, ranges::iterator_t<Container> i);
|
| 654 |
```
|
| 655 |
|
| 656 |
*Returns:* `insert_iterator<Container>(x, i)`.
|
| 657 |
|
| 658 |
+
### Move iterators and sentinels <a id="move.iterators">[[move.iterators]]</a>
|
| 659 |
|
| 660 |
Class template `move_iterator` is an iterator adaptor with the same
|
| 661 |
behavior as the underlying iterator except that its indirection operator
|
| 662 |
implicitly converts the value returned by the underlying iterator’s
|
| 663 |
indirection operator to an rvalue. Some generic algorithms can be called
|
|
|
|
| 681 |
namespace std {
|
| 682 |
template<class Iterator>
|
| 683 |
class move_iterator {
|
| 684 |
public:
|
| 685 |
using iterator_type = Iterator;
|
| 686 |
+
using iterator_concept = input_iterator_tag;
|
| 687 |
+
using iterator_category = see below;
|
| 688 |
+
using value_type = iter_value_t<Iterator>;
|
| 689 |
+
using difference_type = iter_difference_t<Iterator>;
|
| 690 |
using pointer = Iterator;
|
| 691 |
+
using reference = iter_rvalue_reference_t<Iterator>;
|
| 692 |
|
| 693 |
constexpr move_iterator();
|
| 694 |
constexpr explicit move_iterator(Iterator i);
|
| 695 |
template<class U> constexpr move_iterator(const move_iterator<U>& u);
|
| 696 |
template<class U> constexpr move_iterator& operator=(const move_iterator<U>& u);
|
| 697 |
|
| 698 |
+
constexpr iterator_type base() const &;
|
| 699 |
+
constexpr iterator_type base() &&;
|
| 700 |
constexpr reference operator*() const;
|
|
|
|
| 701 |
|
| 702 |
constexpr move_iterator& operator++();
|
| 703 |
+
constexpr auto operator++(int);
|
| 704 |
constexpr move_iterator& operator--();
|
| 705 |
constexpr move_iterator operator--(int);
|
| 706 |
|
| 707 |
constexpr move_iterator operator+(difference_type n) const;
|
| 708 |
constexpr move_iterator& operator+=(difference_type n);
|
| 709 |
constexpr move_iterator operator-(difference_type n) const;
|
| 710 |
constexpr move_iterator& operator-=(difference_type n);
|
| 711 |
+
constexpr reference operator[](difference_type n) const;
|
| 712 |
+
|
| 713 |
+
template<sentinel_for<Iterator> S>
|
| 714 |
+
friend constexpr bool
|
| 715 |
+
operator==(const move_iterator& x, const move_sentinel<S>& y);
|
| 716 |
+
template<sized_sentinel_for<Iterator> S>
|
| 717 |
+
friend constexpr iter_difference_t<Iterator>
|
| 718 |
+
operator-(const move_sentinel<S>& x, const move_iterator& y);
|
| 719 |
+
template<sized_sentinel_for<Iterator> S>
|
| 720 |
+
friend constexpr iter_difference_t<Iterator>
|
| 721 |
+
operator-(const move_iterator& x, const move_sentinel<S>& y);
|
| 722 |
+
friend constexpr iter_rvalue_reference_t<Iterator>
|
| 723 |
+
iter_move(const move_iterator& i)
|
| 724 |
+
noexcept(noexcept(ranges::iter_move(i.current)));
|
| 725 |
+
template<indirectly_swappable<Iterator> Iterator2>
|
| 726 |
+
friend constexpr void
|
| 727 |
+
iter_swap(const move_iterator& x, const move_iterator<Iterator2>& y)
|
| 728 |
+
noexcept(noexcept(ranges::iter_swap(x.current, y.current)));
|
| 729 |
|
| 730 |
private:
|
| 731 |
Iterator current; // exposition only
|
| 732 |
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 733 |
}
|
| 734 |
```
|
| 735 |
|
| 736 |
+
The member *typedef-name* `iterator_category` denotes
|
|
|
|
|
|
|
|
|
|
|
|
|
| 737 |
|
| 738 |
+
- `random_access_iterator_tag` if the type
|
| 739 |
+
`iterator_traits<{}Iterator>::iterator_category` models
|
| 740 |
+
`derived_from<random_access_iterator_tag>`, and
|
| 741 |
+
- `iterator_traits<{}Iterator>::iterator_category` otherwise.
|
| 742 |
|
| 743 |
+
#### Requirements <a id="move.iter.requirements">[[move.iter.requirements]]</a>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 744 |
|
| 745 |
+
The template parameter `Iterator` shall either meet the
|
| 746 |
+
*Cpp17InputIterator* requirements [[input.iterators]] or model
|
| 747 |
+
`input_iterator` [[iterator.concept.input]]. Additionally, if any of the
|
| 748 |
+
bidirectional traversal functions are instantiated, the template
|
| 749 |
+
parameter shall either meet the *Cpp17BidirectionalIterator*
|
| 750 |
+
requirements [[bidirectional.iterators]] or model
|
| 751 |
+
`bidirectional_iterator` [[iterator.concept.bidir]]. If any of the
|
| 752 |
+
random access traversal functions are instantiated, the template
|
| 753 |
+
parameter shall either meet the *Cpp17RandomAccessIterator* requirements
|
| 754 |
+
[[random.access.iterators]] or model `random_access_iterator`
|
| 755 |
+
[[iterator.concept.random.access]].
|
| 756 |
|
| 757 |
+
#### Construction and assignment <a id="move.iter.cons">[[move.iter.cons]]</a>
|
| 758 |
|
| 759 |
``` cpp
|
| 760 |
constexpr move_iterator();
|
| 761 |
```
|
| 762 |
|
|
|
|
| 768 |
``` cpp
|
| 769 |
constexpr explicit move_iterator(Iterator i);
|
| 770 |
```
|
| 771 |
|
| 772 |
*Effects:* Constructs a `move_iterator`, initializing `current` with
|
| 773 |
+
`std::move(i)`.
|
| 774 |
|
| 775 |
``` cpp
|
| 776 |
template<class U> constexpr move_iterator(const move_iterator<U>& u);
|
| 777 |
```
|
| 778 |
|
| 779 |
+
*Mandates:* `U` is convertible to `Iterator`.
|
| 780 |
+
|
| 781 |
*Effects:* Constructs a `move_iterator`, initializing `current` with
|
| 782 |
`u.base()`.
|
| 783 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 784 |
``` cpp
|
| 785 |
template<class U> constexpr move_iterator& operator=(const move_iterator<U>& u);
|
| 786 |
```
|
| 787 |
|
| 788 |
+
*Mandates:* `U` is convertible to `Iterator`.
|
| 789 |
+
|
| 790 |
*Effects:* Assigns `u.base()` to `current`.
|
| 791 |
|
| 792 |
+
#### Conversion <a id="move.iter.op.conv">[[move.iter.op.conv]]</a>
|
|
|
|
|
|
|
| 793 |
|
| 794 |
``` cpp
|
| 795 |
+
constexpr Iterator base() const &;
|
| 796 |
```
|
| 797 |
|
| 798 |
+
*Constraints:* `Iterator` satisfies `copy_constructible`.
|
| 799 |
+
|
| 800 |
+
*Preconditions:* `Iterator` models `copy_constructible`.
|
| 801 |
+
|
| 802 |
*Returns:* `current`.
|
| 803 |
|
| 804 |
+
``` cpp
|
| 805 |
+
constexpr Iterator base() &&;
|
| 806 |
+
```
|
| 807 |
+
|
| 808 |
+
*Returns:* `std::move(current)`.
|
| 809 |
+
|
| 810 |
+
#### Element access <a id="move.iter.elem">[[move.iter.elem]]</a>
|
| 811 |
|
| 812 |
``` cpp
|
| 813 |
constexpr reference operator*() const;
|
| 814 |
```
|
| 815 |
|
| 816 |
+
*Effects:* Equivalent to: `return ranges::iter_move(current);`
|
|
|
|
|
|
|
| 817 |
|
| 818 |
``` cpp
|
| 819 |
+
constexpr reference operator[](difference_type n) const;
|
| 820 |
```
|
| 821 |
|
| 822 |
+
*Effects:* Equivalent to: `ranges::iter_move(current + n);`
|
| 823 |
|
| 824 |
+
#### Navigation <a id="move.iter.nav">[[move.iter.nav]]</a>
|
| 825 |
|
| 826 |
``` cpp
|
| 827 |
constexpr move_iterator& operator++();
|
| 828 |
```
|
| 829 |
|
| 830 |
*Effects:* As if by `++current`.
|
| 831 |
|
| 832 |
*Returns:* `*this`.
|
| 833 |
|
| 834 |
``` cpp
|
| 835 |
+
constexpr auto operator++(int);
|
| 836 |
```
|
| 837 |
|
| 838 |
+
*Effects:* If `Iterator` models `forward_iterator`, equivalent to:
|
| 839 |
|
| 840 |
``` cpp
|
| 841 |
move_iterator tmp = *this;
|
| 842 |
++current;
|
| 843 |
return tmp;
|
| 844 |
```
|
| 845 |
|
| 846 |
+
Otherwise, equivalent to `++current`.
|
| 847 |
|
| 848 |
``` cpp
|
| 849 |
constexpr move_iterator& operator--();
|
| 850 |
```
|
| 851 |
|
|
|
|
| 863 |
move_iterator tmp = *this;
|
| 864 |
--current;
|
| 865 |
return tmp;
|
| 866 |
```
|
| 867 |
|
|
|
|
|
|
|
| 868 |
``` cpp
|
| 869 |
constexpr move_iterator operator+(difference_type n) const;
|
| 870 |
```
|
| 871 |
|
| 872 |
*Returns:* `move_iterator(current + n)`.
|
| 873 |
|
|
|
|
|
|
|
| 874 |
``` cpp
|
| 875 |
constexpr move_iterator& operator+=(difference_type n);
|
| 876 |
```
|
| 877 |
|
| 878 |
*Effects:* As if by: `current += n;`
|
| 879 |
|
| 880 |
*Returns:* `*this`.
|
| 881 |
|
|
|
|
|
|
|
| 882 |
``` cpp
|
| 883 |
constexpr move_iterator operator-(difference_type n) const;
|
| 884 |
```
|
| 885 |
|
| 886 |
*Returns:* `move_iterator(current - n)`.
|
| 887 |
|
|
|
|
|
|
|
| 888 |
``` cpp
|
| 889 |
constexpr move_iterator& operator-=(difference_type n);
|
| 890 |
```
|
| 891 |
|
| 892 |
*Effects:* As if by: `current -= n;`
|
| 893 |
|
| 894 |
*Returns:* `*this`.
|
| 895 |
|
| 896 |
+
#### Comparisons <a id="move.iter.op.comp">[[move.iter.op.comp]]</a>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 897 |
|
| 898 |
``` cpp
|
| 899 |
template<class Iterator1, class Iterator2>
|
| 900 |
+
constexpr bool operator==(const move_iterator<Iterator1>& x,
|
| 901 |
+
const move_iterator<Iterator2>& y);
|
| 902 |
+
template<sentinel_for<Iterator> S>
|
| 903 |
+
friend constexpr bool operator==(const move_iterator& x,
|
| 904 |
+
const move_sentinel<S>& y);
|
| 905 |
```
|
| 906 |
|
| 907 |
+
*Constraints:* `x.base() == y.base()` is well-formed and convertible to
|
| 908 |
+
`bool`.
|
| 909 |
+
|
| 910 |
*Returns:* `x.base() == y.base()`.
|
| 911 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 912 |
``` cpp
|
| 913 |
template<class Iterator1, class Iterator2>
|
| 914 |
constexpr bool operator<(const move_iterator<Iterator1>& x, const move_iterator<Iterator2>& y);
|
| 915 |
```
|
| 916 |
|
| 917 |
+
*Constraints:* `x.base() < y.base()` is well-formed and convertible to
|
| 918 |
+
`bool`.
|
| 919 |
+
|
| 920 |
*Returns:* `x.base() < y.base()`.
|
| 921 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 922 |
``` cpp
|
| 923 |
template<class Iterator1, class Iterator2>
|
| 924 |
constexpr bool operator>(const move_iterator<Iterator1>& x, const move_iterator<Iterator2>& y);
|
| 925 |
```
|
| 926 |
|
| 927 |
+
*Constraints:* `y.base() < x.base()` is well-formed and convertible to
|
| 928 |
+
`bool`.
|
| 929 |
+
|
| 930 |
*Returns:* `y < x`.
|
| 931 |
|
| 932 |
+
``` cpp
|
| 933 |
+
template<class Iterator1, class Iterator2>
|
| 934 |
+
constexpr bool operator<=(const move_iterator<Iterator1>& x, const move_iterator<Iterator2>& y);
|
| 935 |
+
```
|
| 936 |
+
|
| 937 |
+
*Constraints:* `y.base() < x.base()` is well-formed and convertible to
|
| 938 |
+
`bool`.
|
| 939 |
+
|
| 940 |
+
*Returns:* `!(y < x)`.
|
| 941 |
+
|
| 942 |
``` cpp
|
| 943 |
template<class Iterator1, class Iterator2>
|
| 944 |
constexpr bool operator>=(const move_iterator<Iterator1>& x, const move_iterator<Iterator2>& y);
|
| 945 |
```
|
| 946 |
|
| 947 |
+
*Constraints:* `x.base() < y.base()` is well-formed and convertible to
|
| 948 |
+
`bool`.
|
| 949 |
+
|
| 950 |
*Returns:* `!(x < y)`.
|
| 951 |
|
| 952 |
+
``` cpp
|
| 953 |
+
template<class Iterator1, three_way_comparable_with<Iterator1> Iterator2>
|
| 954 |
+
constexpr compare_three_way_result_t<Iterator1, Iterator2>
|
| 955 |
+
operator<=>(const move_iterator<Iterator1>& x,
|
| 956 |
+
const move_iterator<Iterator2>& y);
|
| 957 |
+
```
|
| 958 |
+
|
| 959 |
+
*Returns:* `x.base() <=> y.base()`.
|
| 960 |
+
|
| 961 |
+
#### Non-member functions <a id="move.iter.nonmember">[[move.iter.nonmember]]</a>
|
| 962 |
|
| 963 |
``` cpp
|
| 964 |
template<class Iterator1, class Iterator2>
|
| 965 |
+
constexpr auto operator-(const move_iterator<Iterator1>& x,
|
| 966 |
+
const move_iterator<Iterator2>& y)
|
| 967 |
+
-> decltype(x.base() - y.base());
|
| 968 |
+
template<sized_sentinel_for<Iterator> S>
|
| 969 |
+
friend constexpr iter_difference_t<Iterator>
|
| 970 |
+
operator-(const move_sentinel<S>& x, const move_iterator& y);
|
| 971 |
+
template<sized_sentinel_for<Iterator> S>
|
| 972 |
+
friend constexpr iter_difference_t<Iterator>
|
| 973 |
+
operator-(const move_iterator& x, const move_sentinel<S>& y);
|
| 974 |
```
|
| 975 |
|
| 976 |
*Returns:* `x.base() - y.base()`.
|
| 977 |
|
| 978 |
``` cpp
|
| 979 |
template<class Iterator>
|
| 980 |
+
constexpr move_iterator<Iterator>
|
| 981 |
+
operator+(iter_difference_t<Iterator> n, const move_iterator<Iterator>& x);
|
| 982 |
```
|
| 983 |
|
| 984 |
+
*Constraints:* `x + n` is well-formed and has type `Iterator`.
|
| 985 |
+
|
| 986 |
*Returns:* `x + n`.
|
| 987 |
|
| 988 |
+
``` cpp
|
| 989 |
+
friend constexpr iter_rvalue_reference_t<Iterator>
|
| 990 |
+
iter_move(const move_iterator& i)
|
| 991 |
+
noexcept(noexcept(ranges::iter_move(i.current)));
|
| 992 |
+
```
|
| 993 |
+
|
| 994 |
+
*Effects:* Equivalent to: `return ranges::iter_move(i.current);`
|
| 995 |
+
|
| 996 |
+
``` cpp
|
| 997 |
+
template<indirectly_swappable<Iterator> Iterator2>
|
| 998 |
+
friend constexpr void
|
| 999 |
+
iter_swap(const move_iterator& x, const move_iterator<Iterator2>& y)
|
| 1000 |
+
noexcept(noexcept(ranges::iter_swap(x.current, y.current)));
|
| 1001 |
+
```
|
| 1002 |
+
|
| 1003 |
+
*Effects:* Equivalent to: `ranges::iter_swap(x.current, y.current)`.
|
| 1004 |
+
|
| 1005 |
``` cpp
|
| 1006 |
template<class Iterator>
|
| 1007 |
constexpr move_iterator<Iterator> make_move_iterator(Iterator i);
|
| 1008 |
```
|
| 1009 |
|
| 1010 |
+
*Returns:* `move_iterator<Iterator>(std::move(i))`.
|
| 1011 |
+
|
| 1012 |
+
#### Class template `move_sentinel` <a id="move.sentinel">[[move.sentinel]]</a>
|
| 1013 |
+
|
| 1014 |
+
Class template `move_sentinel` is a sentinel adaptor useful for denoting
|
| 1015 |
+
ranges together with `move_iterator`. When an input iterator type `I`
|
| 1016 |
+
and sentinel type `S` model `sentinel_for<S, I>`, `move_sentinel<S>` and
|
| 1017 |
+
`move_iterator<I>` model
|
| 1018 |
+
`sentinel_for<move_sentinel<S>, move_iterator<I>{>}` as well.
|
| 1019 |
+
|
| 1020 |
+
[*Example 1*:
|
| 1021 |
+
|
| 1022 |
+
A `move_if` algorithm is easily implemented with `copy_if` using
|
| 1023 |
+
`move_iterator` and `move_sentinel`:
|
| 1024 |
+
|
| 1025 |
+
``` cpp
|
| 1026 |
+
template<input_iterator I, sentinel_for<I> S, weakly_incrementable O,
|
| 1027 |
+
indirect_unary_predicate<I> Pred>
|
| 1028 |
+
requires indirectly_movable<I, O>
|
| 1029 |
+
void move_if(I first, S last, O out, Pred pred) {
|
| 1030 |
+
std::ranges::copy_if(move_iterator<I>{first}, move_sentinel<S>{last}, out, pred);
|
| 1031 |
+
}
|
| 1032 |
+
```
|
| 1033 |
+
|
| 1034 |
+
— *end example*]
|
| 1035 |
+
|
| 1036 |
+
``` cpp
|
| 1037 |
+
namespace std {
|
| 1038 |
+
template<semiregular S>
|
| 1039 |
+
class move_sentinel {
|
| 1040 |
+
public:
|
| 1041 |
+
constexpr move_sentinel();
|
| 1042 |
+
constexpr explicit move_sentinel(S s);
|
| 1043 |
+
template<class S2>
|
| 1044 |
+
requires convertible_to<const S2&, S>
|
| 1045 |
+
constexpr move_sentinel(const move_sentinel<S2>& s);
|
| 1046 |
+
template<class S2>
|
| 1047 |
+
requires assignable_from<S&, const S2&>
|
| 1048 |
+
constexpr move_sentinel& operator=(const move_sentinel<S2>& s);
|
| 1049 |
+
|
| 1050 |
+
constexpr S base() const;
|
| 1051 |
+
private:
|
| 1052 |
+
S last; // exposition only
|
| 1053 |
+
};
|
| 1054 |
+
}
|
| 1055 |
+
```
|
| 1056 |
+
|
| 1057 |
+
#### Operations <a id="move.sent.ops">[[move.sent.ops]]</a>
|
| 1058 |
+
|
| 1059 |
+
``` cpp
|
| 1060 |
+
constexpr move_sentinel();
|
| 1061 |
+
```
|
| 1062 |
+
|
| 1063 |
+
*Effects:* Value-initializes `last`. If
|
| 1064 |
+
`is_trivially_default_constructible_v<S>` is `true`, then this
|
| 1065 |
+
constructor is a `constexpr` constructor.
|
| 1066 |
+
|
| 1067 |
+
``` cpp
|
| 1068 |
+
constexpr explicit move_sentinel(S s);
|
| 1069 |
+
```
|
| 1070 |
+
|
| 1071 |
+
*Effects:* Initializes `last` with `std::move(s)`.
|
| 1072 |
+
|
| 1073 |
+
``` cpp
|
| 1074 |
+
template<class S2>
|
| 1075 |
+
requires convertible_to<const S2&, S>
|
| 1076 |
+
constexpr move_sentinel(const move_sentinel<S2>& s);
|
| 1077 |
+
```
|
| 1078 |
+
|
| 1079 |
+
*Effects:* Initializes `last` with `s.last`.
|
| 1080 |
+
|
| 1081 |
+
``` cpp
|
| 1082 |
+
template<class S2>
|
| 1083 |
+
requires assignable_from<S&, const S2&>
|
| 1084 |
+
constexpr move_sentinel& operator=(const move_sentinel<S2>& s);
|
| 1085 |
+
```
|
| 1086 |
+
|
| 1087 |
+
*Effects:* Equivalent to: `last = s.last; return *this;`
|
| 1088 |
+
|
| 1089 |
+
``` cpp
|
| 1090 |
+
constexpr S base() const;
|
| 1091 |
+
```
|
| 1092 |
+
|
| 1093 |
+
*Returns:* `last`.
|
| 1094 |
+
|
| 1095 |
+
### Common iterators <a id="iterators.common">[[iterators.common]]</a>
|
| 1096 |
+
|
| 1097 |
+
#### Class template `common_iterator` <a id="common.iterator">[[common.iterator]]</a>
|
| 1098 |
+
|
| 1099 |
+
Class template `common_iterator` is an iterator/sentinel adaptor that is
|
| 1100 |
+
capable of representing a non-common range of elements (where the types
|
| 1101 |
+
of the iterator and sentinel differ) as a common range (where they are
|
| 1102 |
+
the same). It does this by holding either an iterator or a sentinel, and
|
| 1103 |
+
implementing the equality comparison operators appropriately.
|
| 1104 |
+
|
| 1105 |
+
[*Note 1*: The `common_iterator` type is useful for interfacing with
|
| 1106 |
+
legacy code that expects the begin and end of a range to have the same
|
| 1107 |
+
type. — *end note*]
|
| 1108 |
+
|
| 1109 |
+
[*Example 1*:
|
| 1110 |
+
|
| 1111 |
+
``` cpp
|
| 1112 |
+
template<class ForwardIterator>
|
| 1113 |
+
void fun(ForwardIterator begin, ForwardIterator end);
|
| 1114 |
+
|
| 1115 |
+
list<int> s;
|
| 1116 |
+
// populate the list s
|
| 1117 |
+
using CI = common_iterator<counted_iterator<list<int>::iterator>, default_sentinel_t>;
|
| 1118 |
+
// call fun on a range of 10 ints
|
| 1119 |
+
fun(CI(counted_iterator(s.begin(), 10)), CI(default_sentinel));
|
| 1120 |
+
```
|
| 1121 |
+
|
| 1122 |
+
— *end example*]
|
| 1123 |
+
|
| 1124 |
+
``` cpp
|
| 1125 |
+
namespace std {
|
| 1126 |
+
template<input_or_output_iterator I, sentinel_for<I> S>
|
| 1127 |
+
requires (!same_as<I, S> && copyable<I>)
|
| 1128 |
+
class common_iterator {
|
| 1129 |
+
public:
|
| 1130 |
+
constexpr common_iterator() = default;
|
| 1131 |
+
constexpr common_iterator(I i);
|
| 1132 |
+
constexpr common_iterator(S s);
|
| 1133 |
+
template<class I2, class S2>
|
| 1134 |
+
requires convertible_to<const I2&, I> && convertible_to<const S2&, S>
|
| 1135 |
+
constexpr common_iterator(const common_iterator<I2, S2>& x);
|
| 1136 |
+
|
| 1137 |
+
template<class I2, class S2>
|
| 1138 |
+
requires convertible_to<const I2&, I> && convertible_to<const S2&, S> &&
|
| 1139 |
+
assignable_from<I&, const I2&> && assignable_from<S&, const S2&>
|
| 1140 |
+
common_iterator& operator=(const common_iterator<I2, S2>& x);
|
| 1141 |
+
|
| 1142 |
+
decltype(auto) operator*();
|
| 1143 |
+
decltype(auto) operator*() const
|
| 1144 |
+
requires dereferenceable<const I>;
|
| 1145 |
+
decltype(auto) operator->() const
|
| 1146 |
+
requires see below;
|
| 1147 |
+
|
| 1148 |
+
common_iterator& operator++();
|
| 1149 |
+
decltype(auto) operator++(int);
|
| 1150 |
+
|
| 1151 |
+
template<class I2, sentinel_for<I> S2>
|
| 1152 |
+
requires sentinel_for<S, I2>
|
| 1153 |
+
friend bool operator==(
|
| 1154 |
+
const common_iterator& x, const common_iterator<I2, S2>& y);
|
| 1155 |
+
template<class I2, sentinel_for<I> S2>
|
| 1156 |
+
requires sentinel_for<S, I2> && equality_comparable_with<I, I2>
|
| 1157 |
+
friend bool operator==(
|
| 1158 |
+
const common_iterator& x, const common_iterator<I2, S2>& y);
|
| 1159 |
+
|
| 1160 |
+
template<sized_sentinel_for<I> I2, sized_sentinel_for<I> S2>
|
| 1161 |
+
requires sized_sentinel_for<S, I2>
|
| 1162 |
+
friend iter_difference_t<I2> operator-(
|
| 1163 |
+
const common_iterator& x, const common_iterator<I2, S2>& y);
|
| 1164 |
+
|
| 1165 |
+
friend iter_rvalue_reference_t<I> iter_move(const common_iterator& i)
|
| 1166 |
+
noexcept(noexcept(ranges::iter_move(declval<const I&>())))
|
| 1167 |
+
requires input_iterator<I>;
|
| 1168 |
+
template<indirectly_swappable<I> I2, class S2>
|
| 1169 |
+
friend void iter_swap(const common_iterator& x, const common_iterator<I2, S2>& y)
|
| 1170 |
+
noexcept(noexcept(ranges::iter_swap(declval<const I&>(), declval<const I2&>())));
|
| 1171 |
+
|
| 1172 |
+
private:
|
| 1173 |
+
variant<I, S> v_; // exposition only
|
| 1174 |
+
};
|
| 1175 |
+
|
| 1176 |
+
template<class I, class S>
|
| 1177 |
+
struct incrementable_traits<common_iterator<I, S>> {
|
| 1178 |
+
using difference_type = iter_difference_t<I>;
|
| 1179 |
+
};
|
| 1180 |
+
|
| 1181 |
+
template<input_iterator I, class S>
|
| 1182 |
+
struct iterator_traits<common_iterator<I, S>> {
|
| 1183 |
+
using iterator_concept = see below;
|
| 1184 |
+
using iterator_category = see below;
|
| 1185 |
+
using value_type = iter_value_t<I>;
|
| 1186 |
+
using difference_type = iter_difference_t<I>;
|
| 1187 |
+
using pointer = see below;
|
| 1188 |
+
using reference = iter_reference_t<I>;
|
| 1189 |
+
};
|
| 1190 |
+
}
|
| 1191 |
+
```
|
| 1192 |
+
|
| 1193 |
+
#### Associated types <a id="common.iter.types">[[common.iter.types]]</a>
|
| 1194 |
+
|
| 1195 |
+
The nested *typedef-name*s of the specialization of `iterator_traits`
|
| 1196 |
+
for `common_iterator<I, S>` are defined as follows.
|
| 1197 |
+
|
| 1198 |
+
- `iterator_concept` denotes `forward_iterator_tag` if `I` models
|
| 1199 |
+
`forward_iterator`; otherwise it denotes `input_iterator_tag`.
|
| 1200 |
+
- `iterator_category` denotes `forward_iterator_tag` if
|
| 1201 |
+
`iterator_traits<I>::iterator_category` models
|
| 1202 |
+
`derived_from<forward_iterator_tag>`; otherwise it denotes
|
| 1203 |
+
`input_iterator_tag`.
|
| 1204 |
+
- If the expression `a.operator->()` is well-formed, where `a` is an
|
| 1205 |
+
lvalue of type `const common_iterator<I, S>`, then `pointer` denotes
|
| 1206 |
+
the type of that expression. Otherwise, `pointer` denotes `void`.
|
| 1207 |
+
|
| 1208 |
+
#### Constructors and conversions <a id="common.iter.const">[[common.iter.const]]</a>
|
| 1209 |
+
|
| 1210 |
+
``` cpp
|
| 1211 |
+
constexpr common_iterator(I i);
|
| 1212 |
+
```
|
| 1213 |
+
|
| 1214 |
+
*Effects:* Initializes `v_` as if by
|
| 1215 |
+
`v_{in_place_type<I>, std::move(i)}`.
|
| 1216 |
+
|
| 1217 |
+
``` cpp
|
| 1218 |
+
constexpr common_iterator(S s);
|
| 1219 |
+
```
|
| 1220 |
+
|
| 1221 |
+
*Effects:* Initializes `v_` as if by
|
| 1222 |
+
`v_{in_place_type<S>, std::move(s)}`.
|
| 1223 |
+
|
| 1224 |
+
``` cpp
|
| 1225 |
+
template<class I2, class S2>
|
| 1226 |
+
requires convertible_to<const I2&, I> && convertible_to<const S2&, S>
|
| 1227 |
+
constexpr common_iterator(const common_iterator<I2, S2>& x);
|
| 1228 |
+
```
|
| 1229 |
+
|
| 1230 |
+
*Preconditions:* `x.v_.valueless_by_exception()` is `false`.
|
| 1231 |
+
|
| 1232 |
+
*Effects:* Initializes `v_` as if by
|
| 1233 |
+
`v_{in_place_index<`i`>, get<`i`>(x.v_)}`, where i is `x.v_.index()`.
|
| 1234 |
+
|
| 1235 |
+
``` cpp
|
| 1236 |
+
template<class I2, class S2>
|
| 1237 |
+
requires convertible_to<const I2&, I> && convertible_to<const S2&, S> &&
|
| 1238 |
+
assignable_from<I&, const I2&> && assignable_from<S&, const S2&>
|
| 1239 |
+
common_iterator& operator=(const common_iterator<I2, S2>& x);
|
| 1240 |
+
```
|
| 1241 |
+
|
| 1242 |
+
*Preconditions:* `x.v_.valueless_by_exception()` is `false`.
|
| 1243 |
+
|
| 1244 |
+
*Effects:* Equivalent to:
|
| 1245 |
+
|
| 1246 |
+
- If `v_.index() == x.v_.index()`, then `get<`i`>(v_) = get<`i`>(x.v_)`.
|
| 1247 |
+
- Otherwise, `v_.emplace<`i`>(get<`i`>(x.v_))`.
|
| 1248 |
+
|
| 1249 |
+
where i is `x.v_.index()`.
|
| 1250 |
+
|
| 1251 |
+
*Returns:* `*this`
|
| 1252 |
+
|
| 1253 |
+
#### Accessors <a id="common.iter.access">[[common.iter.access]]</a>
|
| 1254 |
+
|
| 1255 |
+
``` cpp
|
| 1256 |
+
decltype(auto) operator*();
|
| 1257 |
+
decltype(auto) operator*() const
|
| 1258 |
+
requires dereferenceable<const I>;
|
| 1259 |
+
```
|
| 1260 |
+
|
| 1261 |
+
*Preconditions:* `holds_alternative<I>(v_)`.
|
| 1262 |
+
|
| 1263 |
+
*Effects:* Equivalent to: `return *get<I>(v_);`
|
| 1264 |
+
|
| 1265 |
+
``` cpp
|
| 1266 |
+
decltype(auto) operator->() const
|
| 1267 |
+
requires see below;
|
| 1268 |
+
```
|
| 1269 |
+
|
| 1270 |
+
The expression in the requires clause is equivalent to:
|
| 1271 |
+
|
| 1272 |
+
``` cpp
|
| 1273 |
+
indirectly_readable<const I> &&
|
| 1274 |
+
(requires(const I& i) { i.operator->(); } ||
|
| 1275 |
+
is_reference_v<iter_reference_t<I>> ||
|
| 1276 |
+
constructible_from<iter_value_t<I>, iter_reference_t<I>>)
|
| 1277 |
+
```
|
| 1278 |
+
|
| 1279 |
+
*Preconditions:* `holds_alternative<I>(v_)`.
|
| 1280 |
+
|
| 1281 |
+
*Effects:*
|
| 1282 |
+
|
| 1283 |
+
- If `I` is a pointer type or if the expression
|
| 1284 |
+
`get<I>(v_).operator->()` is well-formed, equivalent to:
|
| 1285 |
+
`return get<I>(v_);`
|
| 1286 |
+
- Otherwise, if `iter_reference_t<I>` is a reference type, equivalent
|
| 1287 |
+
to:
|
| 1288 |
+
``` cpp
|
| 1289 |
+
auto&& tmp = *get<I>(v_);
|
| 1290 |
+
return addressof(tmp);
|
| 1291 |
+
```
|
| 1292 |
+
- Otherwise, equivalent to: `return `*`proxy`*`(*get<I>(v_));` where
|
| 1293 |
+
*proxy* is the exposition-only class:
|
| 1294 |
+
``` cpp
|
| 1295 |
+
class proxy {
|
| 1296 |
+
iter_value_t<I> keep_;
|
| 1297 |
+
proxy(iter_reference_t<I>&& x)
|
| 1298 |
+
: keep_(std::move(x)) {}
|
| 1299 |
+
public:
|
| 1300 |
+
const iter_value_t<I>* operator->() const {
|
| 1301 |
+
return addressof(keep_);
|
| 1302 |
+
}
|
| 1303 |
+
};
|
| 1304 |
+
```
|
| 1305 |
+
|
| 1306 |
+
#### Navigation <a id="common.iter.nav">[[common.iter.nav]]</a>
|
| 1307 |
+
|
| 1308 |
+
``` cpp
|
| 1309 |
+
common_iterator& operator++();
|
| 1310 |
+
```
|
| 1311 |
+
|
| 1312 |
+
*Preconditions:* `holds_alternative<I>(v_)`.
|
| 1313 |
+
|
| 1314 |
+
*Effects:* Equivalent to `++get<I>(v_)`.
|
| 1315 |
+
|
| 1316 |
+
*Returns:* `*this`.
|
| 1317 |
+
|
| 1318 |
+
``` cpp
|
| 1319 |
+
decltype(auto) operator++(int);
|
| 1320 |
+
```
|
| 1321 |
+
|
| 1322 |
+
*Preconditions:* `holds_alternative<I>(v_)`.
|
| 1323 |
+
|
| 1324 |
+
*Effects:* If `I` models `forward_iterator`, equivalent to:
|
| 1325 |
+
|
| 1326 |
+
``` cpp
|
| 1327 |
+
common_iterator tmp = *this;
|
| 1328 |
+
++*this;
|
| 1329 |
+
return tmp;
|
| 1330 |
+
```
|
| 1331 |
+
|
| 1332 |
+
Otherwise, equivalent to: `return get<I>(v_)++;`
|
| 1333 |
+
|
| 1334 |
+
#### Comparisons <a id="common.iter.cmp">[[common.iter.cmp]]</a>
|
| 1335 |
+
|
| 1336 |
+
``` cpp
|
| 1337 |
+
template<class I2, sentinel_for<I> S2>
|
| 1338 |
+
requires sentinel_for<S, I2>
|
| 1339 |
+
friend bool operator==(
|
| 1340 |
+
const common_iterator& x, const common_iterator<I2, S2>& y);
|
| 1341 |
+
```
|
| 1342 |
+
|
| 1343 |
+
*Preconditions:* `x.v_.valueless_by_exception()` and
|
| 1344 |
+
`y.v_.valueless_by_exception()` are each `false`.
|
| 1345 |
+
|
| 1346 |
+
*Returns:* `true` if i` == `j, and otherwise
|
| 1347 |
+
`get<`i`>(x.v_) == get<`j`>(y.v_)`, where i is `x.v_.index()` and j is
|
| 1348 |
+
`y.v_.index()`.
|
| 1349 |
+
|
| 1350 |
+
``` cpp
|
| 1351 |
+
template<class I2, sentinel_for<I> S2>
|
| 1352 |
+
requires sentinel_for<S, I2> && equality_comparable_with<I, I2>
|
| 1353 |
+
friend bool operator==(
|
| 1354 |
+
const common_iterator& x, const common_iterator<I2, S2>& y);
|
| 1355 |
+
```
|
| 1356 |
+
|
| 1357 |
+
*Preconditions:* `x.v_.valueless_by_exception()` and
|
| 1358 |
+
`y.v_.valueless_by_exception()` are each `false`.
|
| 1359 |
+
|
| 1360 |
+
*Returns:* `true` if i and j are each `1`, and otherwise
|
| 1361 |
+
`get<`i`>(x.v_) == get<`j`>(y.v_)`, where i is `x.v_.index()` and j is
|
| 1362 |
+
`y.v_.index()`.
|
| 1363 |
+
|
| 1364 |
+
``` cpp
|
| 1365 |
+
template<sized_sentinel_for<I> I2, sized_sentinel_for<I> S2>
|
| 1366 |
+
requires sized_sentinel_for<S, I2>
|
| 1367 |
+
friend iter_difference_t<I2> operator-(
|
| 1368 |
+
const common_iterator& x, const common_iterator<I2, S2>& y);
|
| 1369 |
+
```
|
| 1370 |
+
|
| 1371 |
+
*Preconditions:* `x.v_.valueless_by_exception()` and
|
| 1372 |
+
`y.v_.valueless_by_exception()` are each `false`.
|
| 1373 |
+
|
| 1374 |
+
*Returns:* `0` if i and j are each `1`, and otherwise
|
| 1375 |
+
`get<`i`>(x.v_) - get<`j`>(y.v_)`, where i is `x.v_.index()` and j is
|
| 1376 |
+
`y.v_.index()`.
|
| 1377 |
+
|
| 1378 |
+
#### Customization <a id="common.iter.cust">[[common.iter.cust]]</a>
|
| 1379 |
+
|
| 1380 |
+
``` cpp
|
| 1381 |
+
friend iter_rvalue_reference_t<I> iter_move(const common_iterator& i)
|
| 1382 |
+
noexcept(noexcept(ranges::iter_move(declval<const I&>())))
|
| 1383 |
+
requires input_iterator<I>;
|
| 1384 |
+
```
|
| 1385 |
+
|
| 1386 |
+
*Preconditions:* `holds_alternative<I>(v_)`.
|
| 1387 |
+
|
| 1388 |
+
*Effects:* Equivalent to: `return ranges::iter_move(get<I>(i.v_));`
|
| 1389 |
+
|
| 1390 |
+
``` cpp
|
| 1391 |
+
template<indirectly_swappable<I> I2, class S2>
|
| 1392 |
+
friend void iter_swap(const common_iterator& x, const common_iterator<I2, S2>& y)
|
| 1393 |
+
noexcept(noexcept(ranges::iter_swap(declval<const I&>(), declval<const I2&>())));
|
| 1394 |
+
```
|
| 1395 |
+
|
| 1396 |
+
*Preconditions:* `holds_alternative<I>(x.v_)` and
|
| 1397 |
+
`holds_alternative<I2>(y.v_)` are each `true`.
|
| 1398 |
+
|
| 1399 |
+
*Effects:* Equivalent to
|
| 1400 |
+
`ranges::iter_swap(get<I>(x.v_), get<I2>(y.v_))`.
|
| 1401 |
+
|
| 1402 |
+
### Default sentinels <a id="default.sentinels">[[default.sentinels]]</a>
|
| 1403 |
+
|
| 1404 |
+
``` cpp
|
| 1405 |
+
namespace std {
|
| 1406 |
+
struct default_sentinel_t { };
|
| 1407 |
+
}
|
| 1408 |
+
```
|
| 1409 |
+
|
| 1410 |
+
Class `default_sentinel_t` is an empty type used to denote the end of a
|
| 1411 |
+
range. It can be used together with iterator types that know the bound
|
| 1412 |
+
of their range (e.g., `counted_iterator` [[counted.iterator]]).
|
| 1413 |
+
|
| 1414 |
+
### Counted iterators <a id="iterators.counted">[[iterators.counted]]</a>
|
| 1415 |
+
|
| 1416 |
+
#### Class template `counted_iterator` <a id="counted.iterator">[[counted.iterator]]</a>
|
| 1417 |
+
|
| 1418 |
+
Class template `counted_iterator` is an iterator adaptor with the same
|
| 1419 |
+
behavior as the underlying iterator except that it keeps track of the
|
| 1420 |
+
distance to the end of its range. It can be used together with
|
| 1421 |
+
`default_sentinel` in calls to generic algorithms to operate on a range
|
| 1422 |
+
of N elements starting at a given position without needing to know the
|
| 1423 |
+
end position a priori.
|
| 1424 |
+
|
| 1425 |
+
[*Example 1*:
|
| 1426 |
+
|
| 1427 |
+
``` cpp
|
| 1428 |
+
list<string> s;
|
| 1429 |
+
// populate the list s with at least 10 strings
|
| 1430 |
+
vector<string> v;
|
| 1431 |
+
// copies 10 strings into v:
|
| 1432 |
+
ranges::copy(counted_iterator(s.begin(), 10), default_sentinel, back_inserter(v));
|
| 1433 |
+
```
|
| 1434 |
+
|
| 1435 |
+
— *end example*]
|
| 1436 |
+
|
| 1437 |
+
Two values `i1` and `i2` of types `counted_iterator<I1>` and
|
| 1438 |
+
`counted_iterator<I2>` refer to elements of the same sequence if and
|
| 1439 |
+
only if `next(i1.base(), i1.count())` and `next(i2.base(), i2.count())`
|
| 1440 |
+
refer to the same (possibly past-the-end) element.
|
| 1441 |
+
|
| 1442 |
+
``` cpp
|
| 1443 |
+
namespace std {
|
| 1444 |
+
template<input_or_output_iterator I>
|
| 1445 |
+
class counted_iterator {
|
| 1446 |
+
public:
|
| 1447 |
+
using iterator_type = I;
|
| 1448 |
+
|
| 1449 |
+
constexpr counted_iterator() = default;
|
| 1450 |
+
constexpr counted_iterator(I x, iter_difference_t<I> n);
|
| 1451 |
+
template<class I2>
|
| 1452 |
+
requires convertible_to<const I2&, I>
|
| 1453 |
+
constexpr counted_iterator(const counted_iterator<I2>& x);
|
| 1454 |
+
|
| 1455 |
+
template<class I2>
|
| 1456 |
+
requires assignable_from<I&, const I2&>
|
| 1457 |
+
constexpr counted_iterator& operator=(const counted_iterator<I2>& x);
|
| 1458 |
+
|
| 1459 |
+
constexpr I base() const & requires copy_constructible<I>;
|
| 1460 |
+
constexpr I base() &&;
|
| 1461 |
+
constexpr iter_difference_t<I> count() const noexcept;
|
| 1462 |
+
constexpr decltype(auto) operator*();
|
| 1463 |
+
constexpr decltype(auto) operator*() const
|
| 1464 |
+
requires dereferenceable<const I>;
|
| 1465 |
+
|
| 1466 |
+
constexpr counted_iterator& operator++();
|
| 1467 |
+
decltype(auto) operator++(int);
|
| 1468 |
+
constexpr counted_iterator operator++(int)
|
| 1469 |
+
requires forward_iterator<I>;
|
| 1470 |
+
constexpr counted_iterator& operator--()
|
| 1471 |
+
requires bidirectional_iterator<I>;
|
| 1472 |
+
constexpr counted_iterator operator--(int)
|
| 1473 |
+
requires bidirectional_iterator<I>;
|
| 1474 |
+
|
| 1475 |
+
constexpr counted_iterator operator+(iter_difference_t<I> n) const
|
| 1476 |
+
requires random_access_iterator<I>;
|
| 1477 |
+
friend constexpr counted_iterator operator+(
|
| 1478 |
+
iter_difference_t<I> n, const counted_iterator& x)
|
| 1479 |
+
requires random_access_iterator<I>;
|
| 1480 |
+
constexpr counted_iterator& operator+=(iter_difference_t<I> n)
|
| 1481 |
+
requires random_access_iterator<I>;
|
| 1482 |
+
|
| 1483 |
+
constexpr counted_iterator operator-(iter_difference_t<I> n) const
|
| 1484 |
+
requires random_access_iterator<I>;
|
| 1485 |
+
template<common_with<I> I2>
|
| 1486 |
+
friend constexpr iter_difference_t<I2> operator-(
|
| 1487 |
+
const counted_iterator& x, const counted_iterator<I2>& y);
|
| 1488 |
+
friend constexpr iter_difference_t<I> operator-(
|
| 1489 |
+
const counted_iterator& x, default_sentinel_t);
|
| 1490 |
+
friend constexpr iter_difference_t<I> operator-(
|
| 1491 |
+
default_sentinel_t, const counted_iterator& y);
|
| 1492 |
+
constexpr counted_iterator& operator-=(iter_difference_t<I> n)
|
| 1493 |
+
requires random_access_iterator<I>;
|
| 1494 |
+
|
| 1495 |
+
constexpr decltype(auto) operator[](iter_difference_t<I> n) const
|
| 1496 |
+
requires random_access_iterator<I>;
|
| 1497 |
+
|
| 1498 |
+
template<common_with<I> I2>
|
| 1499 |
+
friend constexpr bool operator==(
|
| 1500 |
+
const counted_iterator& x, const counted_iterator<I2>& y);
|
| 1501 |
+
friend constexpr bool operator==(
|
| 1502 |
+
const counted_iterator& x, default_sentinel_t);
|
| 1503 |
+
|
| 1504 |
+
template<common_with<I> I2>
|
| 1505 |
+
friend constexpr strong_ordering operator<=>(
|
| 1506 |
+
const counted_iterator& x, const counted_iterator<I2>& y);
|
| 1507 |
+
|
| 1508 |
+
friend constexpr iter_rvalue_reference_t<I> iter_move(const counted_iterator& i)
|
| 1509 |
+
noexcept(noexcept(ranges::iter_move(i.current)))
|
| 1510 |
+
requires input_iterator<I>;
|
| 1511 |
+
template<indirectly_swappable<I> I2>
|
| 1512 |
+
friend constexpr void iter_swap(const counted_iterator& x, const counted_iterator<I2>& y)
|
| 1513 |
+
noexcept(noexcept(ranges::iter_swap(x.current, y.current)));
|
| 1514 |
+
|
| 1515 |
+
private:
|
| 1516 |
+
I current = I(); // exposition only
|
| 1517 |
+
iter_difference_t<I> length = 0; // exposition only
|
| 1518 |
+
};
|
| 1519 |
+
|
| 1520 |
+
template<class I>
|
| 1521 |
+
struct incrementable_traits<counted_iterator<I>> {
|
| 1522 |
+
using difference_type = iter_difference_t<I>;
|
| 1523 |
+
};
|
| 1524 |
+
|
| 1525 |
+
template<input_iterator I>
|
| 1526 |
+
struct iterator_traits<counted_iterator<I>> : iterator_traits<I> {
|
| 1527 |
+
using pointer = void;
|
| 1528 |
+
};
|
| 1529 |
+
}
|
| 1530 |
+
```
|
| 1531 |
+
|
| 1532 |
+
#### Constructors and conversions <a id="counted.iter.const">[[counted.iter.const]]</a>
|
| 1533 |
+
|
| 1534 |
+
``` cpp
|
| 1535 |
+
constexpr counted_iterator(I i, iter_difference_t<I> n);
|
| 1536 |
+
```
|
| 1537 |
+
|
| 1538 |
+
*Preconditions:* `n >= 0`.
|
| 1539 |
+
|
| 1540 |
+
*Effects:* Initializes `current` with `std::move(i)` and `length` with
|
| 1541 |
+
`n`.
|
| 1542 |
+
|
| 1543 |
+
``` cpp
|
| 1544 |
+
template<class I2>
|
| 1545 |
+
requires convertible_to<const I2&, I>
|
| 1546 |
+
constexpr counted_iterator(const counted_iterator<I2>& x);
|
| 1547 |
+
```
|
| 1548 |
+
|
| 1549 |
+
*Effects:* Initializes `current` with `x.current` and `length` with
|
| 1550 |
+
`x.length`.
|
| 1551 |
+
|
| 1552 |
+
``` cpp
|
| 1553 |
+
template<class I2>
|
| 1554 |
+
requires assignable_from<I&, const I2&>
|
| 1555 |
+
constexpr counted_iterator& operator=(const counted_iterator<I2>& x);
|
| 1556 |
+
```
|
| 1557 |
+
|
| 1558 |
+
*Effects:* Assigns `x.current` to `current` and `x.length` to `length`.
|
| 1559 |
+
|
| 1560 |
+
*Returns:* `*this`.
|
| 1561 |
+
|
| 1562 |
+
#### Accessors <a id="counted.iter.access">[[counted.iter.access]]</a>
|
| 1563 |
+
|
| 1564 |
+
``` cpp
|
| 1565 |
+
constexpr I base() const & requires copy_constructible<I>;
|
| 1566 |
+
```
|
| 1567 |
+
|
| 1568 |
+
*Effects:* Equivalent to: `return current;`
|
| 1569 |
+
|
| 1570 |
+
``` cpp
|
| 1571 |
+
constexpr I base() &&;
|
| 1572 |
+
```
|
| 1573 |
+
|
| 1574 |
+
*Returns:* `std::move(current)`.
|
| 1575 |
+
|
| 1576 |
+
``` cpp
|
| 1577 |
+
constexpr iter_difference_t<I> count() const noexcept;
|
| 1578 |
+
```
|
| 1579 |
+
|
| 1580 |
+
*Effects:* Equivalent to: `return length;`
|
| 1581 |
+
|
| 1582 |
+
#### Element access <a id="counted.iter.elem">[[counted.iter.elem]]</a>
|
| 1583 |
+
|
| 1584 |
+
``` cpp
|
| 1585 |
+
constexpr decltype(auto) operator*();
|
| 1586 |
+
constexpr decltype(auto) operator*() const
|
| 1587 |
+
requires dereferenceable<const I>;
|
| 1588 |
+
```
|
| 1589 |
+
|
| 1590 |
+
*Effects:* Equivalent to: `return *current;`
|
| 1591 |
+
|
| 1592 |
+
``` cpp
|
| 1593 |
+
constexpr decltype(auto) operator[](iter_difference_t<I> n) const
|
| 1594 |
+
requires random_access_iterator<I>;
|
| 1595 |
+
```
|
| 1596 |
+
|
| 1597 |
+
*Preconditions:* `n < length`.
|
| 1598 |
+
|
| 1599 |
+
*Effects:* Equivalent to: `return current[n];`
|
| 1600 |
+
|
| 1601 |
+
#### Navigation <a id="counted.iter.nav">[[counted.iter.nav]]</a>
|
| 1602 |
+
|
| 1603 |
+
``` cpp
|
| 1604 |
+
constexpr counted_iterator& operator++();
|
| 1605 |
+
```
|
| 1606 |
+
|
| 1607 |
+
*Preconditions:* `length > 0`.
|
| 1608 |
+
|
| 1609 |
+
*Effects:* Equivalent to:
|
| 1610 |
+
|
| 1611 |
+
``` cpp
|
| 1612 |
+
++current;
|
| 1613 |
+
--length;
|
| 1614 |
+
return *this;
|
| 1615 |
+
```
|
| 1616 |
+
|
| 1617 |
+
``` cpp
|
| 1618 |
+
decltype(auto) operator++(int);
|
| 1619 |
+
```
|
| 1620 |
+
|
| 1621 |
+
*Preconditions:* `length > 0`.
|
| 1622 |
+
|
| 1623 |
+
*Effects:* Equivalent to:
|
| 1624 |
+
|
| 1625 |
+
``` cpp
|
| 1626 |
+
--length;
|
| 1627 |
+
try { return current++; }
|
| 1628 |
+
catch(...) { ++length; throw; }
|
| 1629 |
+
```
|
| 1630 |
+
|
| 1631 |
+
``` cpp
|
| 1632 |
+
constexpr counted_iterator operator++(int)
|
| 1633 |
+
requires forward_iterator<I>;
|
| 1634 |
+
```
|
| 1635 |
+
|
| 1636 |
+
*Effects:* Equivalent to:
|
| 1637 |
+
|
| 1638 |
+
``` cpp
|
| 1639 |
+
counted_iterator tmp = *this;
|
| 1640 |
+
++*this;
|
| 1641 |
+
return tmp;
|
| 1642 |
+
```
|
| 1643 |
+
|
| 1644 |
+
``` cpp
|
| 1645 |
+
constexpr counted_iterator& operator--()
|
| 1646 |
+
requires bidirectional_iterator<I>;
|
| 1647 |
+
```
|
| 1648 |
+
|
| 1649 |
+
*Effects:* Equivalent to:
|
| 1650 |
+
|
| 1651 |
+
``` cpp
|
| 1652 |
+
--current;
|
| 1653 |
+
++length;
|
| 1654 |
+
return *this;
|
| 1655 |
+
```
|
| 1656 |
+
|
| 1657 |
+
``` cpp
|
| 1658 |
+
constexpr counted_iterator operator--(int)
|
| 1659 |
+
requires bidirectional_iterator<I>;
|
| 1660 |
+
```
|
| 1661 |
+
|
| 1662 |
+
*Effects:* Equivalent to:
|
| 1663 |
+
|
| 1664 |
+
``` cpp
|
| 1665 |
+
counted_iterator tmp = *this;
|
| 1666 |
+
--*this;
|
| 1667 |
+
return tmp;
|
| 1668 |
+
```
|
| 1669 |
+
|
| 1670 |
+
``` cpp
|
| 1671 |
+
constexpr counted_iterator operator+(iter_difference_t<I> n) const
|
| 1672 |
+
requires random_access_iterator<I>;
|
| 1673 |
+
```
|
| 1674 |
+
|
| 1675 |
+
*Effects:* Equivalent to:
|
| 1676 |
+
`return counted_iterator(current + n, length - n);`
|
| 1677 |
+
|
| 1678 |
+
``` cpp
|
| 1679 |
+
friend constexpr counted_iterator operator+(
|
| 1680 |
+
iter_difference_t<I> n, const counted_iterator& x)
|
| 1681 |
+
requires random_access_iterator<I>;
|
| 1682 |
+
```
|
| 1683 |
+
|
| 1684 |
+
*Effects:* Equivalent to: `return x + n;`
|
| 1685 |
+
|
| 1686 |
+
``` cpp
|
| 1687 |
+
constexpr counted_iterator& operator+=(iter_difference_t<I> n)
|
| 1688 |
+
requires random_access_iterator<I>;
|
| 1689 |
+
```
|
| 1690 |
+
|
| 1691 |
+
*Preconditions:* `n <= length`.
|
| 1692 |
+
|
| 1693 |
+
*Effects:* Equivalent to:
|
| 1694 |
+
|
| 1695 |
+
``` cpp
|
| 1696 |
+
current += n;
|
| 1697 |
+
length -= n;
|
| 1698 |
+
return *this;
|
| 1699 |
+
```
|
| 1700 |
+
|
| 1701 |
+
``` cpp
|
| 1702 |
+
constexpr counted_iterator operator-(iter_difference_t<I> n) const
|
| 1703 |
+
requires random_access_iterator<I>;
|
| 1704 |
+
```
|
| 1705 |
+
|
| 1706 |
+
*Effects:* Equivalent to:
|
| 1707 |
+
`return counted_iterator(current - n, length + n);`
|
| 1708 |
+
|
| 1709 |
+
``` cpp
|
| 1710 |
+
template<common_with<I> I2>
|
| 1711 |
+
friend constexpr iter_difference_t<I2> operator-(
|
| 1712 |
+
const counted_iterator& x, const counted_iterator<I2>& y);
|
| 1713 |
+
```
|
| 1714 |
+
|
| 1715 |
+
*Preconditions:* `x` and `y` refer to elements of the same
|
| 1716 |
+
sequence [[counted.iterator]].
|
| 1717 |
+
|
| 1718 |
+
*Effects:* Equivalent to: `return y.length - x.length;`
|
| 1719 |
+
|
| 1720 |
+
``` cpp
|
| 1721 |
+
friend constexpr iter_difference_t<I> operator-(
|
| 1722 |
+
const counted_iterator& x, default_sentinel_t);
|
| 1723 |
+
```
|
| 1724 |
+
|
| 1725 |
+
*Effects:* Equivalent to: `return -x.length;`
|
| 1726 |
+
|
| 1727 |
+
``` cpp
|
| 1728 |
+
friend constexpr iter_difference_t<I> operator-(
|
| 1729 |
+
default_sentinel_t, const counted_iterator& y);
|
| 1730 |
+
```
|
| 1731 |
+
|
| 1732 |
+
*Effects:* Equivalent to: `return y.length;`
|
| 1733 |
+
|
| 1734 |
+
``` cpp
|
| 1735 |
+
constexpr counted_iterator& operator-=(iter_difference_t<I> n)
|
| 1736 |
+
requires random_access_iterator<I>;
|
| 1737 |
+
```
|
| 1738 |
+
|
| 1739 |
+
*Preconditions:* `-n <= length`.
|
| 1740 |
+
|
| 1741 |
+
*Effects:* Equivalent to:
|
| 1742 |
+
|
| 1743 |
+
``` cpp
|
| 1744 |
+
current -= n;
|
| 1745 |
+
length += n;
|
| 1746 |
+
return *this;
|
| 1747 |
+
```
|
| 1748 |
+
|
| 1749 |
+
#### Comparisons <a id="counted.iter.cmp">[[counted.iter.cmp]]</a>
|
| 1750 |
+
|
| 1751 |
+
``` cpp
|
| 1752 |
+
template<common_with<I> I2>
|
| 1753 |
+
friend constexpr bool operator==(
|
| 1754 |
+
const counted_iterator& x, const counted_iterator<I2>& y);
|
| 1755 |
+
```
|
| 1756 |
+
|
| 1757 |
+
*Preconditions:* `x` and `y` refer to elements of the same
|
| 1758 |
+
sequence [[counted.iterator]].
|
| 1759 |
+
|
| 1760 |
+
*Effects:* Equivalent to: `return x.length == y.length;`
|
| 1761 |
+
|
| 1762 |
+
``` cpp
|
| 1763 |
+
friend constexpr bool operator==(
|
| 1764 |
+
const counted_iterator& x, default_sentinel_t);
|
| 1765 |
+
```
|
| 1766 |
+
|
| 1767 |
+
*Effects:* Equivalent to: `return x.length == 0;`
|
| 1768 |
+
|
| 1769 |
+
``` cpp
|
| 1770 |
+
template<common_with<I> I2>
|
| 1771 |
+
friend constexpr strong_ordering operator<=>(
|
| 1772 |
+
const counted_iterator& x, const counted_iterator<I2>& y);
|
| 1773 |
+
```
|
| 1774 |
+
|
| 1775 |
+
*Preconditions:* `x` and `y` refer to elements of the same
|
| 1776 |
+
sequence [[counted.iterator]].
|
| 1777 |
+
|
| 1778 |
+
*Effects:* Equivalent to: `return y.length <=> x.length;`
|
| 1779 |
+
|
| 1780 |
+
[*Note 1*: The argument order in the *Effects:* element is reversed
|
| 1781 |
+
because `length` counts down, not up. — *end note*]
|
| 1782 |
+
|
| 1783 |
+
#### Customizations <a id="counted.iter.cust">[[counted.iter.cust]]</a>
|
| 1784 |
+
|
| 1785 |
+
``` cpp
|
| 1786 |
+
friend constexpr iter_rvalue_reference_t<I>
|
| 1787 |
+
iter_move(const counted_iterator& i)
|
| 1788 |
+
noexcept(noexcept(ranges::iter_move(i.current)))
|
| 1789 |
+
requires input_iterator<I>;
|
| 1790 |
+
```
|
| 1791 |
+
|
| 1792 |
+
*Effects:* Equivalent to: `return ranges::iter_move(i.current);`
|
| 1793 |
+
|
| 1794 |
+
``` cpp
|
| 1795 |
+
template<indirectly_swappable<I> I2>
|
| 1796 |
+
friend constexpr void
|
| 1797 |
+
iter_swap(const counted_iterator& x, const counted_iterator<I2>& y)
|
| 1798 |
+
noexcept(noexcept(ranges::iter_swap(x.current, y.current)));
|
| 1799 |
+
```
|
| 1800 |
+
|
| 1801 |
+
*Effects:* Equivalent to `ranges::iter_swap(x.current, y.current)`.
|
| 1802 |
+
|
| 1803 |
+
### Unreachable sentinel <a id="unreachable.sentinels">[[unreachable.sentinels]]</a>
|
| 1804 |
+
|
| 1805 |
+
#### Class `unreachable_sentinel_t` <a id="unreachable.sentinel">[[unreachable.sentinel]]</a>
|
| 1806 |
+
|
| 1807 |
+
Class `unreachable_sentinel_t` can be used with any
|
| 1808 |
+
`weakly_incrementable` type to denote the “upper bound” of an unbounded
|
| 1809 |
+
interval.
|
| 1810 |
+
|
| 1811 |
+
[*Example 1*:
|
| 1812 |
+
|
| 1813 |
+
``` cpp
|
| 1814 |
+
char* p;
|
| 1815 |
+
// set p to point to a character buffer containing newlines
|
| 1816 |
+
char* nl = find(p, unreachable_sentinel, '\n');
|
| 1817 |
+
```
|
| 1818 |
+
|
| 1819 |
+
Provided a newline character really exists in the buffer, the use of
|
| 1820 |
+
`unreachable_sentinel` above potentially makes the call to `find` more
|
| 1821 |
+
efficient since the loop test against the sentinel does not require a
|
| 1822 |
+
conditional branch.
|
| 1823 |
+
|
| 1824 |
+
— *end example*]
|
| 1825 |
+
|
| 1826 |
+
``` cpp
|
| 1827 |
+
namespace std {
|
| 1828 |
+
struct unreachable_sentinel_t {
|
| 1829 |
+
template<weakly_incrementable I>
|
| 1830 |
+
friend constexpr bool operator==(unreachable_sentinel_t, const I&) noexcept
|
| 1831 |
+
{ return false; }
|
| 1832 |
+
};
|
| 1833 |
+
}
|
| 1834 |
+
```
|
| 1835 |
|