- tmp/tmp0osa8now/{from.md → to.md} +2227 -1093
tmp/tmp0osa8now/{from.md → to.md}
RENAMED
|
@@ -34,46 +34,53 @@ Table [[tab:containers.lib.summary]].
|
|
| 34 |
Containers are objects that store other objects. They control allocation
|
| 35 |
and deallocation of these objects through constructors, destructors,
|
| 36 |
insert and erase operations.
|
| 37 |
|
| 38 |
All of the complexity requirements in this Clause are stated solely in
|
| 39 |
-
terms of the number of operations on the contained objects.
|
| 40 |
-
|
| 41 |
-
|
| 42 |
-
linear
|
|
|
|
| 43 |
|
| 44 |
For the components affected by this subclause that declare an
|
| 45 |
`allocator_type`, objects stored in these components shall be
|
| 46 |
-
constructed using the
|
| 47 |
-
|
| 48 |
-
|
| 49 |
-
|
| 50 |
-
|
| 51 |
-
|
| 52 |
-
|
| 53 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 54 |
|
| 55 |
In Tables [[tab:containers.container.requirements]],
|
| 56 |
[[tab:containers.reversible.requirements]], and
|
| 57 |
[[tab:containers.optional.operations]] `X` denotes a container class
|
| 58 |
containing objects of type `T`, `a` and `b` denote values of type `X`,
|
| 59 |
`u` denotes an identifier, `r` denotes a non-const value of type `X`,
|
| 60 |
and `rv` denotes a non-const rvalue of type `X`.
|
| 61 |
|
| 62 |
-
Notes: the algorithm `equal()` is defined in Clause [[algorithms]].
|
| 63 |
Those entries marked “(Note A)” or “(Note B)” have linear complexity for
|
| 64 |
`array` and have constant complexity for all other standard containers.
|
| 65 |
|
|
|
|
|
|
|
|
|
|
| 66 |
The member function `size()` returns the number of elements in the
|
| 67 |
container. The number of elements is defined by the rules of
|
| 68 |
constructors, inserts, and erases.
|
| 69 |
|
| 70 |
`begin()`
|
| 71 |
|
| 72 |
returns an iterator referring to the first element in the container.
|
| 73 |
`end()` returns an iterator which is the past-the-end value for the
|
| 74 |
-
container. If the container is empty, then `begin() == end()`
|
| 75 |
|
| 76 |
In the expressions
|
| 77 |
|
| 78 |
``` cpp
|
| 79 |
i == j
|
|
@@ -89,50 +96,59 @@ where `i` and `j` denote objects of a container’s `iterator` type,
|
|
| 89 |
either or both may be replaced by an object of the container’s
|
| 90 |
`const_iterator` type referring to the same element with no change in
|
| 91 |
semantics.
|
| 92 |
|
| 93 |
Unless otherwise specified, all containers defined in this clause obtain
|
| 94 |
-
memory using an allocator (see [[allocator.requirements]]).
|
| 95 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 96 |
`allocator_traits<allocator_type>::select_on_container_copy_construction`
|
| 97 |
on the allocator belonging to the container being copied. Move
|
| 98 |
constructors obtain an allocator by move construction from the allocator
|
| 99 |
belonging to the container being moved. Such move construction of the
|
| 100 |
allocator shall not exit via an exception. All other constructors for
|
| 101 |
-
these container types take a `const allocator_type&` argument.
|
| 102 |
-
|
| 103 |
-
|
| 104 |
-
|
| 105 |
-
|
| 106 |
-
|
| 107 |
-
|
| 108 |
-
|
| 109 |
-
|
|
|
|
|
|
|
|
|
|
| 110 |
`allocator_traits<allocator_type>::propagate_on_container_copy_assignment::value`,
|
| 111 |
`allocator_traits<allocator_type>::propagate_on_container_move_assignment::value`,
|
| 112 |
or
|
| 113 |
`allocator_traits<allocator_type>::propagate_on_container_swap::value`
|
| 114 |
-
is true within the implementation of the corresponding container
|
| 115 |
-
operation.
|
| 116 |
-
undefined unless the objects being swapped have allocators that compare
|
| 117 |
-
equal or
|
| 118 |
-
`allocator_traits<allocator_type>::propagate_on_container_swap::value`
|
| 119 |
-
is true. In all container types defined in this Clause, the member
|
| 120 |
`get_allocator()` returns a copy of the allocator used to construct the
|
| 121 |
container or, if that allocator has been replaced, a copy of the most
|
| 122 |
recent replacement.
|
| 123 |
|
| 124 |
The expression `a.swap(b)`, for containers `a` and `b` of a standard
|
| 125 |
container type other than `array`, shall exchange the values of `a` and
|
| 126 |
`b` without invoking any move, copy, or swap operations on the
|
| 127 |
-
individual container elements.
|
| 128 |
-
belonging to `a` and `b` shall be swappable and shall be
|
| 129 |
-
|
|
|
|
| 130 |
`allocator_traits<allocator_type>::propagate_on_container_swap::value`
|
| 131 |
-
is `true`, then
|
| 132 |
-
|
| 133 |
-
|
|
|
|
| 134 |
`a.get_allocator() == b.get_allocator()`. Every iterator referring to an
|
| 135 |
element in one container before the swap shall refer to the same element
|
| 136 |
in the other container after the swap. It is unspecified whether an
|
| 137 |
iterator with value `a.end()` before the swap will have value `b.end()`
|
| 138 |
after the swap.
|
|
@@ -157,39 +173,45 @@ requirements:
|
|
| 157 |
- no copy constructor or assignment operator of a returned iterator
|
| 158 |
throws an exception.
|
| 159 |
- no `swap()` function throws an exception.
|
| 160 |
- no `swap()` function invalidates any references, pointers, or
|
| 161 |
iterators referring to the elements of the containers being swapped.
|
| 162 |
-
The `end()` iterator does not refer to any element, so it
|
| 163 |
-
invalidated.
|
| 164 |
|
| 165 |
Unless otherwise specified (either explicitly or by defining a function
|
| 166 |
in terms of other functions), invoking a container member function or
|
| 167 |
passing a container as an argument to a library function shall not
|
| 168 |
invalidate iterators to, or change the values of, objects within that
|
| 169 |
container.
|
| 170 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 171 |
Table [[tab:containers.optional.operations]] lists operations that are
|
| 172 |
provided for some types of containers but not others. Those containers
|
| 173 |
for which the listed operations are provided shall implement the
|
| 174 |
semantics described in Table [[tab:containers.optional.operations]]
|
| 175 |
unless otherwise stated.
|
| 176 |
|
| 177 |
-
Note:
|
| 178 |
-
[[algorithms]].
|
| 179 |
|
| 180 |
-
All of the containers defined in this Clause and in
|
| 181 |
except `array` meet the additional requirements of an allocator-aware
|
| 182 |
container, as described in Table [[tab:containers.allocatoraware]].
|
| 183 |
|
| 184 |
-
Given
|
| 185 |
-
|
| 186 |
-
|
| 187 |
-
`
|
| 188 |
-
`
|
| 189 |
-
`
|
| 190 |
-
|
|
|
|
| 191 |
|
| 192 |
- `T` is *`DefaultInsertable` into `X`* means that the following
|
| 193 |
expression is well-formed:
|
| 194 |
``` cpp
|
| 195 |
allocator_traits<A>::construct(m, p)
|
|
@@ -208,11 +230,13 @@ specializations of `std::allocator<T>` are not instantiated:
|
|
| 208 |
allocator_traits<A>::construct(m, p, rv)
|
| 209 |
```
|
| 210 |
|
| 211 |
and its evaluation causes the following postcondition to hold: The
|
| 212 |
value of `*p` is equivalent to the value of `rv` before the
|
| 213 |
-
evaluation.
|
|
|
|
|
|
|
| 214 |
- `T` is *`CopyInsertable` into `X`* means that, in addition to `T`
|
| 215 |
being `MoveInsertable` into `X`, the following expression is
|
| 216 |
well-formed:
|
| 217 |
``` cpp
|
| 218 |
allocator_traits<A>::construct(m, p, v)
|
|
@@ -229,40 +253,56 @@ specializations of `std::allocator<T>` are not instantiated:
|
|
| 229 |
well-formed:
|
| 230 |
``` cpp
|
| 231 |
allocator_traits<A>::destroy(m, p)
|
| 232 |
```
|
| 233 |
|
| 234 |
-
|
| 235 |
-
construct
|
| 236 |
-
`
|
| 237 |
-
|
|
|
|
| 238 |
|
| 239 |
In Table [[tab:containers.allocatoraware]], `X` denotes an
|
| 240 |
allocator-aware container class with a `value_type` of `T` using
|
| 241 |
allocator of type `A`, `u` denotes a variable, `a` and `b` denote
|
| 242 |
non-const lvalues of type `X`, `t` denotes an lvalue or a const rvalue
|
| 243 |
of type `X`, `rv` denotes a non-const rvalue of type `X`, and `m` is a
|
| 244 |
value of type `A`.
|
| 245 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 246 |
### Container data races <a id="container.requirements.dataraces">[[container.requirements.dataraces]]</a>
|
| 247 |
|
| 248 |
For purposes of avoiding data races ([[res.on.data.races]]),
|
| 249 |
implementations shall consider the following functions to be `const`:
|
| 250 |
`begin`, `end`, `rbegin`, `rend`, `front`, `back`, `data`, `find`,
|
| 251 |
`lower_bound`, `upper_bound`, `equal_range`, `at` and, except in
|
| 252 |
associative or unordered associative containers, `operator[]`.
|
| 253 |
|
| 254 |
-
Notwithstanding
|
| 255 |
-
|
| 256 |
-
|
| 257 |
-
|
| 258 |
|
| 259 |
-
For a `vector<int> x` with a size greater than one,
|
| 260 |
-
`*x.begin() = 10` can be executed concurrently without a
|
| 261 |
-
`x[0] = 5` and `*x.begin() = 10` executed concurrently
|
| 262 |
-
data race. As an exception to the general rule, for a
|
| 263 |
-
`y[0] = true` may race with
|
|
|
|
| 264 |
|
| 265 |
### Sequence containers <a id="sequence.reqmts">[[sequence.reqmts]]</a>
|
| 266 |
|
| 267 |
A sequence container organizes a finite set of objects, all of the same
|
| 268 |
type, into a strictly linear arrangement. The library provides four
|
|
@@ -282,30 +322,28 @@ deletions from the middle of the sequence. `deque` is the data structure
|
|
| 282 |
of choice when most insertions and deletions take place at the beginning
|
| 283 |
or at the end of the sequence.
|
| 284 |
|
| 285 |
In Tables [[tab:containers.sequence.requirements]] and
|
| 286 |
[[tab:containers.sequence.optional]], `X` denotes a sequence container
|
| 287 |
-
class, `a` denotes a value of `X` containing elements of type `T`,
|
| 288 |
-
|
| 289 |
-
|
| 290 |
-
|
| 291 |
-
`
|
| 292 |
-
|
| 293 |
-
|
| 294 |
-
|
| 295 |
-
|
| 296 |
-
|
| 297 |
-
|
| 298 |
-
|
|
|
|
|
|
|
|
|
|
| 299 |
|
| 300 |
The complexities of the expressions are sequence dependent.
|
| 301 |
|
| 302 |
-
`iterator`
|
| 303 |
-
|
| 304 |
-
and `const_iterator` types for sequence containers shall be at least of
|
| 305 |
-
the forward iterator category.
|
| 306 |
-
|
| 307 |
The iterator returned from `a.insert(p, t)` points to the copy of `t`
|
| 308 |
inserted into `a`.
|
| 309 |
|
| 310 |
The iterator returned from `a.insert(p, rv)` points to the copy of `rv`
|
| 311 |
inserted into `a`.
|
|
@@ -335,45 +373,271 @@ For every sequence container defined in this Clause and in Clause
|
|
| 335 |
|
| 336 |
- If the constructor
|
| 337 |
``` cpp
|
| 338 |
template <class InputIterator>
|
| 339 |
X(InputIterator first, InputIterator last,
|
| 340 |
-
|
| 341 |
```
|
| 342 |
|
| 343 |
is called with a type `InputIterator` that does not qualify as an
|
| 344 |
input iterator, then the constructor shall not participate in overload
|
| 345 |
resolution.
|
| 346 |
- If the member functions of the forms:
|
| 347 |
``` cpp
|
| 348 |
-
template <class InputIterator>
|
| 349 |
-
|
|
|
|
| 350 |
|
| 351 |
-
template <class InputIterator>
|
| 352 |
-
|
| 353 |
|
| 354 |
-
template <class InputIterator>
|
| 355 |
-
|
|
|
|
| 356 |
```
|
| 357 |
|
| 358 |
are called with a type `InputIterator` that does not qualify as an
|
| 359 |
input iterator, then these functions shall not participate in overload
|
| 360 |
resolution.
|
| 361 |
-
|
| 362 |
-
|
| 363 |
-
|
| 364 |
-
|
|
|
|
|
|
|
| 365 |
|
| 366 |
Table [[tab:containers.sequence.optional]] lists operations that are
|
| 367 |
provided for some types of sequence containers but not others. An
|
| 368 |
implementation shall provide these operations for all container types
|
| 369 |
shown in the “container” column, and shall implement them so as to take
|
| 370 |
amortized constant time.
|
| 371 |
|
| 372 |
The member function `at()` provides bounds-checked access to container
|
| 373 |
elements. `at()` throws `out_of_range` if `n >= a.size()`.
|
| 374 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 375 |
### Associative containers <a id="associative.reqmts">[[associative.reqmts]]</a>
|
| 376 |
|
| 377 |
Associative containers provide fast retrieval of data based on keys. The
|
| 378 |
library provides four basic kinds of associative containers: `set`,
|
| 379 |
`multiset`, `map` and `multimap`.
|
|
@@ -405,65 +669,82 @@ For `set` and `multiset` the value type is the same as the key type. For
|
|
| 405 |
|
| 406 |
of an associative container is of the bidirectional iterator category.
|
| 407 |
For associative containers where the value type is the same as the key
|
| 408 |
type, both `iterator` and `const_iterator` are constant iterators. It is
|
| 409 |
unspecified whether or not `iterator` and `const_iterator` are the same
|
| 410 |
-
type.
|
| 411 |
-
|
| 412 |
-
|
| 413 |
-
|
|
|
|
|
|
|
| 414 |
|
| 415 |
The associative containers meet all the requirements of Allocator-aware
|
| 416 |
containers ([[container.requirements.general]]), except that for `map`
|
| 417 |
and `multimap`, the requirements placed on `value_type` in Table
|
| 418 |
[[tab:containers.container.requirements]] apply instead to `key_type`
|
| 419 |
-
and `mapped_type`.
|
| 420 |
-
|
| 421 |
-
|
| 422 |
-
`CopyAssignable`
|
|
|
|
|
|
|
| 423 |
|
| 424 |
In Table [[tab:containers.associative.requirements]], `X` denotes an
|
| 425 |
-
associative container class, `a` denotes a value of `X`, `
|
| 426 |
-
denotes a value of
|
| 427 |
-
|
| 428 |
-
|
| 429 |
-
|
| 430 |
-
|
| 431 |
-
|
| 432 |
-
|
| 433 |
-
|
| 434 |
-
|
| 435 |
-
|
| 436 |
-
|
| 437 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 438 |
`c(r, kl)`, with `r` the key value of `e` and `e` in `a`; `ku` is a
|
| 439 |
value such that `a` is partitioned with respect to `!c(ku, r)`; `ke` is
|
| 440 |
a value such that `a` is partitioned with respect to `c(r, ke)` and
|
| 441 |
`!c(ke, r)`, with `c(r, ke)` implying `!c(ke, r)`. `A` denotes the
|
| 442 |
-
storage allocator used by `X`, if any, or
|
| 443 |
-
|
| 444 |
-
|
| 445 |
|
| 446 |
The `insert` and `emplace` members shall not affect the validity of
|
| 447 |
iterators and references to the container, and the `erase` members shall
|
| 448 |
invalidate only iterators and references to the erased elements.
|
| 449 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 450 |
The fundamental property of iterators of associative containers is that
|
| 451 |
they iterate through the containers in the non-descending order of keys
|
| 452 |
where non-descending is defined by the comparison that was used to
|
| 453 |
construct them. For any two dereferenceable iterators `i` and `j` such
|
| 454 |
-
that distance from `i` to `j` is positive,
|
|
|
|
| 455 |
|
| 456 |
``` cpp
|
| 457 |
value_comp(*j, *i) == false
|
| 458 |
```
|
| 459 |
|
| 460 |
For associative containers with unique keys the stronger condition
|
| 461 |
-
holds
|
| 462 |
|
| 463 |
``` cpp
|
| 464 |
-
value_comp(*i, *j) != false
|
| 465 |
```
|
| 466 |
|
| 467 |
When an associative container is constructed by passing a comparison
|
| 468 |
object the container shall not store a pointer or reference to the
|
| 469 |
passed object, even if that object is passed by reference. When an
|
|
@@ -472,13 +753,23 @@ assignment operator, the target container shall then use the comparison
|
|
| 472 |
object from the container being copied, as if that comparison object had
|
| 473 |
been passed to the target container in its constructor.
|
| 474 |
|
| 475 |
The member function templates `find`, `count`, `lower_bound`,
|
| 476 |
`upper_bound`, and `equal_range` shall not participate in overload
|
| 477 |
-
resolution unless the qualified-id `Compare::is_transparent` is valid
|
| 478 |
and denotes a type ([[temp.deduct]]).
|
| 479 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 480 |
#### Exception safety guarantees <a id="associative.reqmts.except">[[associative.reqmts.except]]</a>
|
| 481 |
|
| 482 |
For associative containers, no `clear()` function throws an exception.
|
| 483 |
`erase(k)` does not throw an exception unless that exception is thrown
|
| 484 |
by the container’s `Compare` object (if any).
|
|
@@ -518,42 +809,47 @@ the *hash function* of the container. The container’s object of type
|
|
| 518 |
the container.
|
| 519 |
|
| 520 |
Two values `k1` and `k2` of type `Key` are considered equivalent if the
|
| 521 |
container’s key equality predicate returns `true` when passed those
|
| 522 |
values. If `k1` and `k2` are equivalent, the container’s hash function
|
| 523 |
-
shall return the same value for both.
|
| 524 |
-
|
| 525 |
-
|
| 526 |
-
|
| 527 |
-
|
| 528 |
-
|
|
|
|
|
|
|
|
|
|
| 529 |
|
| 530 |
An unordered associative container supports *unique keys* if it may
|
| 531 |
contain at most one element for each key. Otherwise, it supports
|
| 532 |
*equivalent keys*. `unordered_set` and `unordered_map` support unique
|
| 533 |
keys. `unordered_multiset` and `unordered_multimap` support equivalent
|
| 534 |
keys. In containers that support equivalent keys, elements with
|
| 535 |
equivalent keys are adjacent to each other in the iteration order of the
|
| 536 |
container. Thus, although the absolute order of elements in an unordered
|
| 537 |
container is not specified, its elements are grouped into
|
| 538 |
-
*equivalent-key
|
| 539 |
equivalent keys. Mutating operations on unordered containers shall
|
| 540 |
preserve the relative order of elements within each equivalent-key group
|
| 541 |
unless otherwise specified.
|
| 542 |
|
| 543 |
For `unordered_set` and `unordered_multiset` the value type is the same
|
| 544 |
as the key type. For `unordered_map` and `unordered_multimap` it is
|
| 545 |
-
`
|
| 546 |
T>`.
|
| 547 |
|
| 548 |
For unordered containers where the value type is the same as the key
|
| 549 |
type, both `iterator` and `const_iterator` are constant iterators. It is
|
| 550 |
unspecified whether or not `iterator` and `const_iterator` are the same
|
| 551 |
-
type.
|
| 552 |
-
|
| 553 |
-
|
| 554 |
-
|
|
|
|
|
|
|
| 555 |
|
| 556 |
The elements of an unordered associative container are organized into
|
| 557 |
*buckets*. Keys with the same hash code appear in the same bucket. The
|
| 558 |
number of buckets is automatically increased as elements are added to an
|
| 559 |
unordered associative container, so that the average number of elements
|
|
@@ -566,37 +862,43 @@ the relative ordering of equivalent elements.
|
|
| 566 |
The unordered associative containers meet all the requirements of
|
| 567 |
Allocator-aware containers ([[container.requirements.general]]), except
|
| 568 |
that for `unordered_map` and `unordered_multimap`, the requirements
|
| 569 |
placed on `value_type` in Table
|
| 570 |
[[tab:containers.container.requirements]] apply instead to `key_type`
|
| 571 |
-
and `mapped_type`.
|
| 572 |
-
sometimes required to be `CopyAssignable` even though the associated
|
| 573 |
-
`value_type`, `pair<const key_type, mapped_type>`, is not
|
| 574 |
-
`CopyAssignable`.
|
| 575 |
|
| 576 |
-
|
| 577 |
-
|
| 578 |
-
|
| 579 |
-
|
| 580 |
-
|
| 581 |
-
|
| 582 |
-
|
| 583 |
-
|
| 584 |
-
|
| 585 |
-
`X
|
| 586 |
-
|
| 587 |
-
|
| 588 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 589 |
|
| 590 |
Two unordered containers `a` and `b` compare equal if
|
| 591 |
`a.size() == b.size()` and, for every equivalent-key group \[`Ea1`,
|
| 592 |
`Ea2`) obtained from `a.equal_range(Ea1)`, there exists an
|
| 593 |
equivalent-key group \[`Eb1`, `Eb2`) obtained from `b.equal_range(Ea1)`,
|
| 594 |
such that `is_permutation(Ea1, Ea2, Eb1, Eb2)` returns `true`. For
|
| 595 |
`unordered_set` and `unordered_map`, the complexity of `operator==`
|
| 596 |
(i.e., the number of calls to the `==` operator of the `value_type`, to
|
| 597 |
-
the predicate returned by `
|
| 598 |
`hash_function()`) is proportional to N in the average case and to N² in
|
| 599 |
the worst case, where N is a.size(). For `unordered_multiset` and
|
| 600 |
`unordered_multimap`, the complexity of `operator==` is proportional to
|
| 601 |
$\sum E_i^2$ in the average case and to N² in the worst case, where N is
|
| 602 |
`a.size()`, and Eᵢ is the size of the iᵗʰ equivalent-key group in `a`.
|
|
@@ -607,31 +909,51 @@ same container), then the average-case complexity for
|
|
| 607 |
`unordered_multiset` and `unordered_multimap` becomes proportional to N
|
| 608 |
(but worst-case complexity remains 𝑂(N^2), e.g., for a pathologically
|
| 609 |
bad hash function). The behavior of a program that uses `operator==` or
|
| 610 |
`operator!=` on unordered containers is undefined unless the `Hash` and
|
| 611 |
`Pred` function objects respectively have the same behavior for both
|
| 612 |
-
containers and the equality comparison
|
| 613 |
refinement[^1] of the partition into equivalent-key groups produced by
|
| 614 |
`Pred`.
|
| 615 |
|
| 616 |
The iterator types `iterator` and `const_iterator` of an unordered
|
| 617 |
associative container are of at least the forward iterator category. For
|
| 618 |
unordered associative containers where the key type and value type are
|
| 619 |
-
the same, both `iterator` and `const_iterator` are
|
| 620 |
|
| 621 |
The `insert` and `emplace` members shall not affect the validity of
|
| 622 |
references to container elements, but may invalidate all iterators to
|
| 623 |
the container. The `erase` members shall invalidate only iterators and
|
| 624 |
references to the erased elements, and preserve the relative order of
|
| 625 |
the elements that are not erased.
|
| 626 |
|
| 627 |
The `insert` and `emplace` members shall not affect the validity of
|
| 628 |
-
iterators if `(N+n) < z * B`, where `N` is the number of elements in
|
| 629 |
-
container prior to the insert operation, `n` is the number of
|
| 630 |
-
inserted, `B` is the container’s bucket count, and `z` is the
|
| 631 |
container’s maximum load factor.
|
| 632 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 633 |
#### Exception safety guarantees <a id="unord.req.except">[[unord.req.except]]</a>
|
| 634 |
|
| 635 |
For unordered associative containers, no `clear()` function throws an
|
| 636 |
exception. `erase(k)` does not throw an exception unless that exception
|
| 637 |
is thrown by the container’s `Hash` or `Pred` object (if any).
|
|
@@ -641,34 +963,31 @@ operation other than the container’s hash function from within an
|
|
| 641 |
`insert` or `emplace` function inserting a single element, the insertion
|
| 642 |
has no effect.
|
| 643 |
|
| 644 |
For unordered associative containers, no `swap` function throws an
|
| 645 |
exception unless that exception is thrown by the swap of the container’s
|
| 646 |
-
Hash or Pred object (if any).
|
| 647 |
|
| 648 |
For unordered associative containers, if an exception is thrown from
|
| 649 |
within a `rehash()` function other than by the container’s hash function
|
| 650 |
or comparison function, the `rehash()` function has no effect.
|
| 651 |
|
| 652 |
## Sequence containers <a id="sequences">[[sequences]]</a>
|
| 653 |
|
| 654 |
### In general <a id="sequences.general">[[sequences.general]]</a>
|
| 655 |
|
| 656 |
The headers `<array>`, `<deque>`, `<forward_list>`, `<list>`, and
|
| 657 |
-
`<vector>` define
|
| 658 |
sequence containers.
|
| 659 |
|
| 660 |
-
|
| 661 |
-
[[container.adaptors]]) that also meet the requirements for sequence
|
| 662 |
-
containers.
|
| 663 |
-
|
| 664 |
-
\synopsis{Header \texttt{\<array\>} synopsis}
|
| 665 |
|
| 666 |
``` cpp
|
| 667 |
#include <initializer_list>
|
| 668 |
|
| 669 |
namespace std {
|
|
|
|
| 670 |
template <class T, size_t N> struct array;
|
| 671 |
template <class T, size_t N>
|
| 672 |
bool operator==(const array<T, N>& x, const array<T, N>& y);
|
| 673 |
template <class T, size_t N>
|
| 674 |
bool operator!=(const array<T, N>& x, const array<T, N>& y);
|
|
@@ -693,19 +1012,22 @@ namespace std {
|
|
| 693 |
constexpr T& get(array<T, N>&) noexcept;
|
| 694 |
template <size_t I, class T, size_t N>
|
| 695 |
constexpr T&& get(array<T, N>&&) noexcept;
|
| 696 |
template <size_t I, class T, size_t N>
|
| 697 |
constexpr const T& get(const array<T, N>&) noexcept;
|
|
|
|
|
|
|
| 698 |
}
|
| 699 |
```
|
| 700 |
|
| 701 |
-
|
| 702 |
|
| 703 |
``` cpp
|
| 704 |
#include <initializer_list>
|
| 705 |
|
| 706 |
namespace std {
|
|
|
|
| 707 |
template <class T, class Allocator = allocator<T>> class deque;
|
| 708 |
template <class T, class Allocator>
|
| 709 |
bool operator==(const deque<T, Allocator>& x, const deque<T, Allocator>& y);
|
| 710 |
template <class T, class Allocator>
|
| 711 |
bool operator< (const deque<T, Allocator>& x, const deque<T, Allocator>& y);
|
|
@@ -716,20 +1038,27 @@ namespace std {
|
|
| 716 |
template <class T, class Allocator>
|
| 717 |
bool operator>=(const deque<T, Allocator>& x, const deque<T, Allocator>& y);
|
| 718 |
template <class T, class Allocator>
|
| 719 |
bool operator<=(const deque<T, Allocator>& x, const deque<T, Allocator>& y);
|
| 720 |
template <class T, class Allocator>
|
| 721 |
-
void swap(deque<T,Allocator>& x, deque<T,Allocator>& y)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 722 |
}
|
| 723 |
```
|
| 724 |
|
| 725 |
-
|
| 726 |
|
| 727 |
``` cpp
|
| 728 |
#include <initializer_list>
|
| 729 |
|
| 730 |
namespace std {
|
|
|
|
| 731 |
template <class T, class Allocator = allocator<T>> class forward_list;
|
| 732 |
template <class T, class Allocator>
|
| 733 |
bool operator==(const forward_list<T, Allocator>& x, const forward_list<T, Allocator>& y);
|
| 734 |
template <class T, class Allocator>
|
| 735 |
bool operator< (const forward_list<T, Allocator>& x, const forward_list<T, Allocator>& y);
|
|
@@ -740,20 +1069,27 @@ namespace std {
|
|
| 740 |
template <class T, class Allocator>
|
| 741 |
bool operator>=(const forward_list<T, Allocator>& x, const forward_list<T, Allocator>& y);
|
| 742 |
template <class T, class Allocator>
|
| 743 |
bool operator<=(const forward_list<T, Allocator>& x, const forward_list<T, Allocator>& y);
|
| 744 |
template <class T, class Allocator>
|
| 745 |
-
void swap(forward_list<T,Allocator>& x, forward_list<T,Allocator>& y)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 746 |
}
|
| 747 |
```
|
| 748 |
|
| 749 |
-
|
| 750 |
|
| 751 |
``` cpp
|
| 752 |
#include <initializer_list>
|
| 753 |
|
| 754 |
namespace std {
|
|
|
|
| 755 |
template <class T, class Allocator = allocator<T>> class list;
|
| 756 |
template <class T, class Allocator>
|
| 757 |
bool operator==(const list<T, Allocator>& x, const list<T, Allocator>& y);
|
| 758 |
template <class T, class Allocator>
|
| 759 |
bool operator< (const list<T, Allocator>& x, const list<T, Allocator>& y);
|
|
@@ -764,20 +1100,27 @@ namespace std {
|
|
| 764 |
template <class T, class Allocator>
|
| 765 |
bool operator>=(const list<T, Allocator>& x, const list<T, Allocator>& y);
|
| 766 |
template <class T, class Allocator>
|
| 767 |
bool operator<=(const list<T, Allocator>& x, const list<T, Allocator>& y);
|
| 768 |
template <class T, class Allocator>
|
| 769 |
-
void swap(list<T,Allocator>& x, list<T,Allocator>& y)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 770 |
}
|
| 771 |
```
|
| 772 |
|
| 773 |
-
|
| 774 |
|
| 775 |
``` cpp
|
| 776 |
#include <initializer_list>
|
| 777 |
|
| 778 |
namespace std {
|
|
|
|
| 779 |
template <class T, class Allocator = allocator<T>> class vector;
|
| 780 |
template <class T, class Allocator>
|
| 781 |
bool operator==(const vector<T, Allocator>& x, const vector<T, Allocator>& y);
|
| 782 |
template <class T, class Allocator>
|
| 783 |
bool operator< (const vector<T, Allocator>& x, const vector<T, Allocator>& y);
|
|
@@ -788,40 +1131,39 @@ namespace std {
|
|
| 788 |
template <class T, class Allocator>
|
| 789 |
bool operator>=(const vector<T, Allocator>& x, const vector<T, Allocator>& y);
|
| 790 |
template <class T, class Allocator>
|
| 791 |
bool operator<=(const vector<T, Allocator>& x, const vector<T, Allocator>& y);
|
| 792 |
template <class T, class Allocator>
|
| 793 |
-
void swap(vector<T,Allocator>& x, vector<T,Allocator>& y)
|
|
|
|
| 794 |
|
|
|
|
| 795 |
template <class Allocator> class vector<bool, Allocator>;
|
| 796 |
|
| 797 |
// hash support
|
| 798 |
template <class T> struct hash;
|
| 799 |
template <class Allocator> struct hash<vector<bool, Allocator>>;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 800 |
}
|
| 801 |
```
|
| 802 |
|
| 803 |
### Class template `array` <a id="array">[[array]]</a>
|
| 804 |
|
| 805 |
#### Class template `array` overview <a id="array.overview">[[array.overview]]</a>
|
| 806 |
|
| 807 |
The header `<array>` defines a class template for storing fixed-size
|
| 808 |
-
sequences of objects. An `array`
|
| 809 |
-
instance of `array<T, N>` stores
|
| 810 |
-
`size() == N` is an invariant.
|
| 811 |
-
contiguously, meaning that if `a` is an `array<T, N>` then it obeys the
|
| 812 |
-
identity `&a[n] == &a[0] + n` for all `0 <= n < N`.
|
| 813 |
|
| 814 |
-
An `array` is an aggregate ([[dcl.init.aggr]]) that can be
|
| 815 |
-
with
|
| 816 |
-
|
| 817 |
-
``` cpp
|
| 818 |
-
array<T, N> a = { initializer-list };
|
| 819 |
-
```
|
| 820 |
-
|
| 821 |
-
where *initializer-list* is a comma-separated list of up to `N` elements
|
| 822 |
-
whose types are convertible to `T`.
|
| 823 |
|
| 824 |
An `array` satisfies all of the requirements of a container and of a
|
| 825 |
reversible container ([[container.requirements]]), except that a
|
| 826 |
default constructed `array` object is not empty and that `swap` does not
|
| 827 |
have constant complexity. An `array` satisfies some of the requirements
|
|
@@ -833,70 +1175,67 @@ semantic information.
|
|
| 833 |
``` cpp
|
| 834 |
namespace std {
|
| 835 |
template <class T, size_t N>
|
| 836 |
struct array {
|
| 837 |
// types:
|
| 838 |
-
|
| 839 |
-
|
| 840 |
-
|
| 841 |
-
|
| 842 |
-
|
| 843 |
-
|
| 844 |
-
|
| 845 |
-
|
| 846 |
-
|
| 847 |
-
|
| 848 |
-
|
| 849 |
-
|
| 850 |
-
T elems[N]; // exposition only
|
| 851 |
|
| 852 |
// no explicit construct/copy/destroy for aggregate type
|
| 853 |
|
| 854 |
void fill(const T& u);
|
| 855 |
-
void swap(array&) noexcept(
|
| 856 |
|
| 857 |
// iterators:
|
| 858 |
-
iterator begin() noexcept;
|
| 859 |
-
const_iterator begin() const noexcept;
|
| 860 |
-
iterator end() noexcept;
|
| 861 |
-
const_iterator end() const noexcept;
|
| 862 |
|
| 863 |
-
reverse_iterator rbegin() noexcept;
|
| 864 |
-
const_reverse_iterator rbegin() const noexcept;
|
| 865 |
-
reverse_iterator rend() noexcept;
|
| 866 |
-
const_reverse_iterator rend() const noexcept;
|
| 867 |
|
| 868 |
-
const_iterator cbegin() const noexcept;
|
| 869 |
-
const_iterator cend() const noexcept;
|
| 870 |
-
const_reverse_iterator crbegin() const noexcept;
|
| 871 |
-
const_reverse_iterator crend() const noexcept;
|
| 872 |
|
| 873 |
// capacity:
|
|
|
|
| 874 |
constexpr size_type size() const noexcept;
|
| 875 |
constexpr size_type max_size() const noexcept;
|
| 876 |
-
constexpr bool empty() const noexcept;
|
| 877 |
|
| 878 |
// element access:
|
| 879 |
-
reference
|
| 880 |
constexpr const_reference operator[](size_type n) const;
|
| 881 |
-
reference
|
| 882 |
constexpr const_reference at(size_type n) const;
|
| 883 |
-
reference
|
| 884 |
constexpr const_reference front() const;
|
| 885 |
-
reference
|
| 886 |
constexpr const_reference back() const;
|
| 887 |
|
| 888 |
-
T * data() noexcept;
|
| 889 |
-
const T * data() const noexcept;
|
| 890 |
};
|
|
|
|
|
|
|
|
|
|
| 891 |
}
|
| 892 |
```
|
| 893 |
|
| 894 |
-
The member variable `elems` is shown for exposition only, to emphasize
|
| 895 |
-
that `array` is a class aggregate. The name `elems` is not part of
|
| 896 |
-
`array`’s interface.
|
| 897 |
-
|
| 898 |
#### `array` constructors, copy, and assignment <a id="array.cons">[[array.cons]]</a>
|
| 899 |
|
| 900 |
The conditions for an aggregate ([[dcl.init.aggr]]) shall be met. Class
|
| 901 |
`array` relies on the implicitly-declared special member functions (
|
| 902 |
[[class.ctor]], [[class.dtor]], and [[class.copy]]) to conform to the
|
|
@@ -904,63 +1243,70 @@ container requirements table in [[container.requirements]]. In addition
|
|
| 904 |
to the requirements specified in the container requirements table, the
|
| 905 |
implicit move constructor and move assignment operator for `array`
|
| 906 |
require that `T` be `MoveConstructible` or `MoveAssignable`,
|
| 907 |
respectively.
|
| 908 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 909 |
#### `array` specialized algorithms <a id="array.special">[[array.special]]</a>
|
| 910 |
|
| 911 |
``` cpp
|
| 912 |
-
template <class T, size_t N>
|
|
|
|
| 913 |
```
|
| 914 |
|
| 915 |
-
*
|
|
|
|
| 916 |
|
| 917 |
-
``
|
| 918 |
-
x.swap(y);
|
| 919 |
-
```
|
| 920 |
|
| 921 |
*Complexity:* Linear in `N`.
|
| 922 |
|
| 923 |
#### `array::size` <a id="array.size">[[array.size]]</a>
|
| 924 |
|
| 925 |
``` cpp
|
| 926 |
template <class T, size_t N> constexpr size_type array<T, N>::size() const noexcept;
|
| 927 |
```
|
| 928 |
|
| 929 |
-
*Returns:* `N`
|
| 930 |
|
| 931 |
#### `array::data` <a id="array.data">[[array.data]]</a>
|
| 932 |
|
| 933 |
``` cpp
|
| 934 |
-
T* data() noexcept;
|
| 935 |
-
const T* data() const noexcept;
|
| 936 |
```
|
| 937 |
|
| 938 |
-
*Returns:* `
|
|
|
|
| 939 |
|
| 940 |
#### `array::fill` <a id="array.fill">[[array.fill]]</a>
|
| 941 |
|
| 942 |
``` cpp
|
| 943 |
void fill(const T& u);
|
| 944 |
```
|
| 945 |
|
| 946 |
-
*Effects:* `fill_n(begin(), N, u)`
|
| 947 |
|
| 948 |
#### `array::swap` <a id="array.swap">[[array.swap]]</a>
|
| 949 |
|
| 950 |
``` cpp
|
| 951 |
-
void swap(array& y) noexcept(
|
| 952 |
```
|
| 953 |
|
| 954 |
-
*Effects:* `swap_ranges(begin(), end(), y.begin())`
|
| 955 |
|
| 956 |
-
*
|
| 957 |
-
exception
|
| 958 |
-
|
| 959 |
-
|
| 960 |
-
takes linear time, may exit via an exception, and does not cause
|
| 961 |
-
iterators to become associated with the other container.
|
| 962 |
|
| 963 |
#### Zero sized arrays <a id="array.zero">[[array.zero]]</a>
|
| 964 |
|
| 965 |
`array` shall provide support for the special case `N == 0`.
|
| 966 |
|
|
@@ -968,19 +1314,18 @@ In the case that `N == 0`, `begin() == end() ==` unique value. The
|
|
| 968 |
return value of `data()` is unspecified.
|
| 969 |
|
| 970 |
The effect of calling `front()` or `back()` for a zero-sized array is
|
| 971 |
undefined.
|
| 972 |
|
| 973 |
-
Member function `swap()` shall have a
|
| 974 |
-
|
| 975 |
|
| 976 |
#### Tuple interface to class template `array` <a id="array.tuple">[[array.tuple]]</a>
|
| 977 |
|
| 978 |
``` cpp
|
| 979 |
template <class T, size_t N>
|
| 980 |
-
struct tuple_size<array<T, N>>
|
| 981 |
-
: integral_constant<size_t, N> { };
|
| 982 |
```
|
| 983 |
|
| 984 |
``` cpp
|
| 985 |
tuple_element<I, array<T, N>>::type
|
| 986 |
```
|
|
@@ -990,44 +1335,33 @@ tuple_element<I, array<T, N> >::type
|
|
| 990 |
*Value:* The type T.
|
| 991 |
|
| 992 |
``` cpp
|
| 993 |
template <size_t I, class T, size_t N>
|
| 994 |
constexpr T& get(array<T, N>& a) noexcept;
|
| 995 |
-
```
|
| 996 |
-
|
| 997 |
-
*Requires:* `I < N`. The program is ill-formed if `I` is out of bounds.
|
| 998 |
-
|
| 999 |
-
*Returns:* A reference to the `I`th element of `a`, where indexing is
|
| 1000 |
-
zero-based.
|
| 1001 |
-
|
| 1002 |
-
``` cpp
|
| 1003 |
template <size_t I, class T, size_t N>
|
| 1004 |
constexpr T&& get(array<T, N>&& a) noexcept;
|
| 1005 |
-
```
|
| 1006 |
-
|
| 1007 |
-
*Effects:* Equivalent to `return std::move(get<I>(a));`
|
| 1008 |
-
|
| 1009 |
-
``` cpp
|
| 1010 |
template <size_t I, class T, size_t N>
|
| 1011 |
constexpr const T& get(const array<T, N>& a) noexcept;
|
|
|
|
|
|
|
| 1012 |
```
|
| 1013 |
|
| 1014 |
*Requires:* `I < N`. The program is ill-formed if `I` is out of bounds.
|
| 1015 |
|
| 1016 |
-
*Returns:* A
|
| 1017 |
-
|
| 1018 |
|
| 1019 |
### Class template `deque` <a id="deque">[[deque]]</a>
|
| 1020 |
|
| 1021 |
#### Class template `deque` overview <a id="deque.overview">[[deque.overview]]</a>
|
| 1022 |
|
| 1023 |
-
A `deque` is a sequence container that
|
| 1024 |
-
|
| 1025 |
insert and erase operations at the beginning or the end; insert and
|
| 1026 |
erase in the middle take linear time. That is, a deque is especially
|
| 1027 |
-
optimized for pushing and popping elements at the beginning and end.
|
| 1028 |
-
|
| 1029 |
|
| 1030 |
A `deque` satisfies all of the requirements of a container, of a
|
| 1031 |
reversible container (given in tables in [[container.requirements]]),
|
| 1032 |
of a sequence container, including the optional sequence container
|
| 1033 |
requirements ([[sequence.reqmts]]), and of an allocator-aware container
|
|
@@ -1040,24 +1374,24 @@ information.
|
|
| 1040 |
namespace std {
|
| 1041 |
template <class T, class Allocator = allocator<T>>
|
| 1042 |
class deque {
|
| 1043 |
public:
|
| 1044 |
// types:
|
| 1045 |
-
|
| 1046 |
-
|
| 1047 |
-
|
| 1048 |
-
|
| 1049 |
-
|
| 1050 |
-
|
| 1051 |
-
|
| 1052 |
-
|
| 1053 |
-
|
| 1054 |
-
|
| 1055 |
-
|
| 1056 |
-
|
| 1057 |
|
| 1058 |
-
// [deque.cons], construct/copy/destroy
|
| 1059 |
deque() : deque(Allocator()) { }
|
| 1060 |
explicit deque(const Allocator&);
|
| 1061 |
explicit deque(size_type n, const Allocator& = Allocator());
|
| 1062 |
deque(size_type n, const T& value, const Allocator& = Allocator());
|
| 1063 |
template <class InputIterator>
|
|
@@ -1068,11 +1402,12 @@ namespace std {
|
|
| 1068 |
deque(deque&&, const Allocator&);
|
| 1069 |
deque(initializer_list<T>, const Allocator& = Allocator());
|
| 1070 |
|
| 1071 |
~deque();
|
| 1072 |
deque& operator=(const deque& x);
|
| 1073 |
-
deque& operator=(deque&& x)
|
|
|
|
| 1074 |
deque& operator=(initializer_list<T>);
|
| 1075 |
template <class InputIterator>
|
| 1076 |
void assign(InputIterator first, InputIterator last);
|
| 1077 |
void assign(size_type n, const T& t);
|
| 1078 |
void assign(initializer_list<T>);
|
|
@@ -1091,17 +1426,17 @@ namespace std {
|
|
| 1091 |
const_iterator cbegin() const noexcept;
|
| 1092 |
const_iterator cend() const noexcept;
|
| 1093 |
const_reverse_iterator crbegin() const noexcept;
|
| 1094 |
const_reverse_iterator crend() const noexcept;
|
| 1095 |
|
| 1096 |
-
// [deque.capacity], capacity
|
|
|
|
| 1097 |
size_type size() const noexcept;
|
| 1098 |
size_type max_size() const noexcept;
|
| 1099 |
void resize(size_type sz);
|
| 1100 |
void resize(size_type sz, const T& c);
|
| 1101 |
void shrink_to_fit();
|
| 1102 |
-
bool empty() const noexcept;
|
| 1103 |
|
| 1104 |
// element access:
|
| 1105 |
reference operator[](size_type n);
|
| 1106 |
const_reference operator[](size_type n) const;
|
| 1107 |
reference at(size_type n);
|
|
@@ -1109,13 +1444,13 @@ namespace std {
|
|
| 1109 |
reference front();
|
| 1110 |
const_reference front() const;
|
| 1111 |
reference back();
|
| 1112 |
const_reference back() const;
|
| 1113 |
|
| 1114 |
-
// [deque.modifiers], modifiers
|
| 1115 |
-
template <class... Args>
|
| 1116 |
-
template <class... Args>
|
| 1117 |
template <class... Args> iterator emplace(const_iterator position, Args&&... args);
|
| 1118 |
|
| 1119 |
void push_front(const T& x);
|
| 1120 |
void push_front(T&& x);
|
| 1121 |
void push_back(const T& x);
|
|
@@ -1131,14 +1466,20 @@ namespace std {
|
|
| 1131 |
void pop_front();
|
| 1132 |
void pop_back();
|
| 1133 |
|
| 1134 |
iterator erase(const_iterator position);
|
| 1135 |
iterator erase(const_iterator first, const_iterator last);
|
| 1136 |
-
void swap(deque&)
|
|
|
|
| 1137 |
void clear() noexcept;
|
| 1138 |
};
|
| 1139 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1140 |
template <class T, class Allocator>
|
| 1141 |
bool operator==(const deque<T, Allocator>& x, const deque<T, Allocator>& y);
|
| 1142 |
template <class T, class Allocator>
|
| 1143 |
bool operator< (const deque<T, Allocator>& x, const deque<T, Allocator>& y);
|
| 1144 |
template <class T, class Allocator>
|
|
@@ -1148,13 +1489,14 @@ namespace std {
|
|
| 1148 |
template <class T, class Allocator>
|
| 1149 |
bool operator>=(const deque<T, Allocator>& x, const deque<T, Allocator>& y);
|
| 1150 |
template <class T, class Allocator>
|
| 1151 |
bool operator<=(const deque<T, Allocator>& x, const deque<T, Allocator>& y);
|
| 1152 |
|
| 1153 |
-
// specialized algorithms
|
| 1154 |
template <class T, class Allocator>
|
| 1155 |
-
void swap(deque<T,Allocator>& x, deque<T,Allocator>& y)
|
|
|
|
| 1156 |
}
|
| 1157 |
```
|
| 1158 |
|
| 1159 |
#### `deque` constructors, copy, and assignment <a id="deque.cons">[[deque.cons]]</a>
|
| 1160 |
|
|
@@ -1176,12 +1518,11 @@ the specified allocator.
|
|
| 1176 |
*Requires:* `T` shall be `DefaultInsertable` into `*this`.
|
| 1177 |
|
| 1178 |
*Complexity:* Linear in `n`.
|
| 1179 |
|
| 1180 |
``` cpp
|
| 1181 |
-
deque(size_type n, const T& value,
|
| 1182 |
-
const Allocator& = Allocator());
|
| 1183 |
```
|
| 1184 |
|
| 1185 |
*Effects:* Constructs a `deque` with `n` copies of `value`, using the
|
| 1186 |
specified allocator.
|
| 1187 |
|
|
@@ -1189,12 +1530,11 @@ specified allocator.
|
|
| 1189 |
|
| 1190 |
*Complexity:* Linear in `n`.
|
| 1191 |
|
| 1192 |
``` cpp
|
| 1193 |
template <class InputIterator>
|
| 1194 |
-
deque(InputIterator first, InputIterator last,
|
| 1195 |
-
const Allocator& = Allocator());
|
| 1196 |
```
|
| 1197 |
|
| 1198 |
*Effects:* Constructs a `deque` equal to the range \[`first`, `last`),
|
| 1199 |
using the specified allocator.
|
| 1200 |
|
|
@@ -1204,38 +1544,47 @@ using the specified allocator.
|
|
| 1204 |
|
| 1205 |
``` cpp
|
| 1206 |
void resize(size_type sz);
|
| 1207 |
```
|
| 1208 |
|
| 1209 |
-
*Effects:* If `sz <
|
| 1210 |
-
|
| 1211 |
-
|
| 1212 |
|
| 1213 |
*Requires:* `T` shall be `MoveInsertable` and `DefaultInsertable` into
|
| 1214 |
`*this`.
|
| 1215 |
|
| 1216 |
``` cpp
|
| 1217 |
void resize(size_type sz, const T& c);
|
| 1218 |
```
|
| 1219 |
|
| 1220 |
-
*Effects:* If `sz <
|
| 1221 |
-
|
| 1222 |
-
|
| 1223 |
|
| 1224 |
*Requires:* `T` shall be `CopyInsertable` into `*this`.
|
| 1225 |
|
| 1226 |
``` cpp
|
| 1227 |
void shrink_to_fit();
|
| 1228 |
```
|
| 1229 |
|
| 1230 |
*Requires:* `T` shall be `MoveInsertable` into `*this`.
|
| 1231 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1232 |
*Complexity:* Linear in the size of the sequence.
|
| 1233 |
|
| 1234 |
-
*Remarks:* `shrink_to_fit`
|
| 1235 |
-
|
| 1236 |
-
|
| 1237 |
|
| 1238 |
#### `deque` modifiers <a id="deque.modifiers">[[deque.modifiers]]</a>
|
| 1239 |
|
| 1240 |
``` cpp
|
| 1241 |
iterator insert(const_iterator position, const T& x);
|
|
@@ -1244,12 +1593,12 @@ iterator insert(const_iterator position, size_type n, const T& x);
|
|
| 1244 |
template <class InputIterator>
|
| 1245 |
iterator insert(const_iterator position,
|
| 1246 |
InputIterator first, InputIterator last);
|
| 1247 |
iterator insert(const_iterator position, initializer_list<T>);
|
| 1248 |
|
| 1249 |
-
template <class... Args>
|
| 1250 |
-
template <class... Args>
|
| 1251 |
template <class... Args> iterator emplace(const_iterator position, Args&&... args);
|
| 1252 |
void push_front(const T& x);
|
| 1253 |
void push_front(T&& x);
|
| 1254 |
void push_back(const T& x);
|
| 1255 |
void push_back(T&& x);
|
|
@@ -1274,54 +1623,58 @@ a deque always takes constant time and causes a single call to a
|
|
| 1274 |
constructor of `T`.
|
| 1275 |
|
| 1276 |
``` cpp
|
| 1277 |
iterator erase(const_iterator position);
|
| 1278 |
iterator erase(const_iterator first, const_iterator last);
|
|
|
|
|
|
|
| 1279 |
```
|
| 1280 |
|
| 1281 |
*Effects:* An erase operation that erases the last element of a deque
|
| 1282 |
invalidates only the past-the-end iterator and all iterators and
|
| 1283 |
references to the erased elements. An erase operation that erases the
|
| 1284 |
-
first element of a deque but not the last element invalidates only
|
| 1285 |
-
erased elements. An erase operation that
|
| 1286 |
-
element nor the last element of a deque
|
| 1287 |
-
iterator and all iterators and references
|
| 1288 |
-
deque.
|
| 1289 |
|
| 1290 |
-
*
|
| 1291 |
-
|
| 1292 |
-
|
| 1293 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1294 |
|
| 1295 |
*Throws:* Nothing unless an exception is thrown by the copy constructor,
|
| 1296 |
move constructor, assignment operator, or move assignment operator of
|
| 1297 |
`T`.
|
| 1298 |
|
| 1299 |
#### `deque` specialized algorithms <a id="deque.special">[[deque.special]]</a>
|
| 1300 |
|
| 1301 |
``` cpp
|
| 1302 |
template <class T, class Allocator>
|
| 1303 |
-
void swap(deque<T,Allocator>& x, deque<T,Allocator>& y)
|
|
|
|
| 1304 |
```
|
| 1305 |
|
| 1306 |
-
*Effects:*
|
| 1307 |
-
|
| 1308 |
-
``` cpp
|
| 1309 |
-
x.swap(y);
|
| 1310 |
-
```
|
| 1311 |
|
| 1312 |
### Class template `forward_list` <a id="forwardlist">[[forwardlist]]</a>
|
| 1313 |
|
| 1314 |
#### Class template `forward_list` overview <a id="forwardlist.overview">[[forwardlist.overview]]</a>
|
| 1315 |
|
| 1316 |
A `forward_list` is a container that supports forward iterators and
|
| 1317 |
allows constant time insert and erase operations anywhere within the
|
| 1318 |
sequence, with storage management handled automatically. Fast random
|
| 1319 |
-
access to list elements is not supported.
|
| 1320 |
-
|
| 1321 |
-
|
| 1322 |
-
|
|
|
|
| 1323 |
|
| 1324 |
A `forward_list` satisfies all of the requirements of a container
|
| 1325 |
(Table [[tab:containers.container.requirements]]), except that the
|
| 1326 |
`size()` member function is not provided and `operator==` has linear
|
| 1327 |
complexity. A `forward_list` also satisfies all of the requirements for
|
|
@@ -1331,34 +1684,34 @@ In addition, a `forward_list` provides the `assign` member functions
|
|
| 1331 |
optional container requirements (Table
|
| 1332 |
[[tab:containers.sequence.optional]]). Descriptions are provided here
|
| 1333 |
only for operations on `forward_list` that are not described in that
|
| 1334 |
table or for operations where there is additional semantic information.
|
| 1335 |
|
| 1336 |
-
Modifying any list requires access to the element preceding
|
| 1337 |
-
element of interest, but in a `forward_list` there is no
|
| 1338 |
-
way to access a preceding element. For this reason, ranges
|
| 1339 |
-
modified, such as those supplied to `erase` and `splice`, must
|
| 1340 |
-
at the beginning.
|
| 1341 |
|
| 1342 |
``` cpp
|
| 1343 |
namespace std {
|
| 1344 |
template <class T, class Allocator = allocator<T>>
|
| 1345 |
class forward_list {
|
| 1346 |
public:
|
| 1347 |
// types:
|
| 1348 |
-
|
| 1349 |
-
|
| 1350 |
-
|
| 1351 |
-
|
| 1352 |
-
|
| 1353 |
-
|
| 1354 |
-
|
| 1355 |
-
|
| 1356 |
-
|
| 1357 |
-
|
| 1358 |
|
| 1359 |
-
// [forwardlist.cons], construct/copy/destroy
|
| 1360 |
forward_list() : forward_list(Allocator()) { }
|
| 1361 |
explicit forward_list(const Allocator&);
|
| 1362 |
explicit forward_list(size_type n, const Allocator& = Allocator());
|
| 1363 |
forward_list(size_type n, const T& value,
|
| 1364 |
const Allocator& = Allocator());
|
|
@@ -1370,19 +1723,20 @@ namespace std {
|
|
| 1370 |
forward_list(const forward_list& x, const Allocator&);
|
| 1371 |
forward_list(forward_list&& x, const Allocator&);
|
| 1372 |
forward_list(initializer_list<T>, const Allocator& = Allocator());
|
| 1373 |
~forward_list();
|
| 1374 |
forward_list& operator=(const forward_list& x);
|
| 1375 |
-
forward_list& operator=(forward_list&& x)
|
|
|
|
| 1376 |
forward_list& operator=(initializer_list<T>);
|
| 1377 |
template <class InputIterator>
|
| 1378 |
void assign(InputIterator first, InputIterator last);
|
| 1379 |
void assign(size_type n, const T& t);
|
| 1380 |
void assign(initializer_list<T>);
|
| 1381 |
allocator_type get_allocator() const noexcept;
|
| 1382 |
|
| 1383 |
-
// [forwardlist.iter], iterators
|
| 1384 |
iterator before_begin() noexcept;
|
| 1385 |
const_iterator before_begin() const noexcept;
|
| 1386 |
iterator begin() noexcept;
|
| 1387 |
const_iterator begin() const noexcept;
|
| 1388 |
iterator end() noexcept;
|
|
@@ -1394,16 +1748,16 @@ namespace std {
|
|
| 1394 |
|
| 1395 |
// capacity:
|
| 1396 |
bool empty() const noexcept;
|
| 1397 |
size_type max_size() const noexcept;
|
| 1398 |
|
| 1399 |
-
// [forwardlist.access], element access
|
| 1400 |
reference front();
|
| 1401 |
const_reference front() const;
|
| 1402 |
|
| 1403 |
-
// [forwardlist.modifiers], modifiers
|
| 1404 |
-
template <class... Args>
|
| 1405 |
void push_front(const T& x);
|
| 1406 |
void push_front(T&& x);
|
| 1407 |
void pop_front();
|
| 1408 |
|
| 1409 |
template <class... Args> iterator emplace_after(const_iterator position, Args&&... args);
|
|
@@ -1415,17 +1769,18 @@ namespace std {
|
|
| 1415 |
iterator insert_after(const_iterator position, InputIterator first, InputIterator last);
|
| 1416 |
iterator insert_after(const_iterator position, initializer_list<T> il);
|
| 1417 |
|
| 1418 |
iterator erase_after(const_iterator position);
|
| 1419 |
iterator erase_after(const_iterator position, const_iterator last);
|
| 1420 |
-
void swap(forward_list&)
|
|
|
|
| 1421 |
|
| 1422 |
void resize(size_type sz);
|
| 1423 |
void resize(size_type sz, const value_type& c);
|
| 1424 |
void clear() noexcept;
|
| 1425 |
|
| 1426 |
-
// [forwardlist.ops], forward_list operations
|
| 1427 |
void splice_after(const_iterator position, forward_list& x);
|
| 1428 |
void splice_after(const_iterator position, forward_list&& x);
|
| 1429 |
void splice_after(const_iterator position, forward_list& x,
|
| 1430 |
const_iterator i);
|
| 1431 |
void splice_after(const_iterator position, forward_list&& x,
|
|
@@ -1450,11 +1805,15 @@ namespace std {
|
|
| 1450 |
template <class Compare> void sort(Compare comp);
|
| 1451 |
|
| 1452 |
void reverse() noexcept;
|
| 1453 |
};
|
| 1454 |
|
| 1455 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1456 |
template <class T, class Allocator>
|
| 1457 |
bool operator==(const forward_list<T, Allocator>& x, const forward_list<T, Allocator>& y);
|
| 1458 |
template <class T, class Allocator>
|
| 1459 |
bool operator< (const forward_list<T, Allocator>& x, const forward_list<T, Allocator>& y);
|
| 1460 |
template <class T, class Allocator>
|
|
@@ -1464,16 +1823,23 @@ namespace std {
|
|
| 1464 |
template <class T, class Allocator>
|
| 1465 |
bool operator>=(const forward_list<T, Allocator>& x, const forward_list<T, Allocator>& y);
|
| 1466 |
template <class T, class Allocator>
|
| 1467 |
bool operator<=(const forward_list<T, Allocator>& x, const forward_list<T, Allocator>& y);
|
| 1468 |
|
| 1469 |
-
// [forwardlist.spec], specialized algorithms
|
| 1470 |
template <class T, class Allocator>
|
| 1471 |
-
void swap(forward_list<T,Allocator>& x, forward_list<T,Allocator>& y)
|
|
|
|
| 1472 |
}
|
| 1473 |
```
|
| 1474 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1475 |
#### `forward_list` constructors, copy, assignment <a id="forwardlist.cons">[[forwardlist.cons]]</a>
|
| 1476 |
|
| 1477 |
``` cpp
|
| 1478 |
explicit forward_list(const Allocator&);
|
| 1479 |
```
|
|
@@ -1550,11 +1916,11 @@ elements into a `forward_list` is linear in `n`, and the number of calls
|
|
| 1550 |
to the copy or move constructor of `T` is exactly equal to `n`. Erasing
|
| 1551 |
`n` elements from a `forward_list` is linear in `n` and the number of
|
| 1552 |
calls to the destructor of type `T` is exactly equal to `n`.
|
| 1553 |
|
| 1554 |
``` cpp
|
| 1555 |
-
template <class... Args>
|
| 1556 |
```
|
| 1557 |
|
| 1558 |
*Effects:* Inserts an object of type `value_type` constructed with
|
| 1559 |
`value_type(std::forward<Args>(args)...)` at the beginning of the list.
|
| 1560 |
|
|
@@ -1567,11 +1933,11 @@ void push_front(T&& x);
|
|
| 1567 |
|
| 1568 |
``` cpp
|
| 1569 |
void pop_front();
|
| 1570 |
```
|
| 1571 |
|
| 1572 |
-
*Effects:* `erase_after(before_begin())`
|
| 1573 |
|
| 1574 |
``` cpp
|
| 1575 |
iterator insert_after(const_iterator position, const T& x);
|
| 1576 |
iterator insert_after(const_iterator position, T&& x);
|
| 1577 |
```
|
|
@@ -1674,14 +2040,12 @@ end of the list.
|
|
| 1674 |
void resize(size_type sz, const value_type& c);
|
| 1675 |
```
|
| 1676 |
|
| 1677 |
*Effects:* If `sz < distance(begin(), end())`, erases the last
|
| 1678 |
`distance(begin(), end()) - sz` elements from the list. Otherwise,
|
| 1679 |
-
inserts `sz - distance(begin(), end())`
|
| 1680 |
-
|
| 1681 |
-
to calling
|
| 1682 |
-
`allocator_traits<allocator_type>::construct(get_allocator(), std::addressof(e), c)`.
|
| 1683 |
|
| 1684 |
*Requires:* `T` shall be `CopyInsertable` into `*this`.
|
| 1685 |
|
| 1686 |
``` cpp
|
| 1687 |
void clear() noexcept;
|
|
@@ -1708,11 +2072,11 @@ those same elements but as members of `*this`. Iterators referring to
|
|
| 1708 |
the moved elements will continue to refer to their elements, but they
|
| 1709 |
now behave as iterators into `*this`, not into `x`.
|
| 1710 |
|
| 1711 |
*Throws:* Nothing.
|
| 1712 |
|
| 1713 |
-
*Complexity:* 𝑂(distance(x.begin(), x.end()))
|
| 1714 |
|
| 1715 |
``` cpp
|
| 1716 |
void splice_after(const_iterator position, forward_list& x, const_iterator i);
|
| 1717 |
void splice_after(const_iterator position, forward_list&& x, const_iterator i);
|
| 1718 |
```
|
|
@@ -1751,20 +2115,20 @@ dereferenceable. `position` is not an iterator in the range (`first`,
|
|
| 1751 |
the moved elements of `x` now refer to those same elements but as
|
| 1752 |
members of `*this`. Iterators referring to the moved elements will
|
| 1753 |
continue to refer to their elements, but they now behave as iterators
|
| 1754 |
into `*this`, not into `x`.
|
| 1755 |
|
| 1756 |
-
*Complexity:* 𝑂(distance(first, last))
|
| 1757 |
|
| 1758 |
``` cpp
|
| 1759 |
void remove(const T& value);
|
| 1760 |
template <class Predicate> void remove_if(Predicate pred);
|
| 1761 |
```
|
| 1762 |
|
| 1763 |
*Effects:* Erases all the elements in the list referred by a list
|
| 1764 |
iterator `i` for which the following conditions hold: `*i == value` (for
|
| 1765 |
-
`remove()`), `pred(*i)` is true (for `remove_if()`). Invalidates only
|
| 1766 |
the iterators and references to the erased elements.
|
| 1767 |
|
| 1768 |
*Throws:* Nothing unless an exception is thrown by the equality
|
| 1769 |
comparison or the predicate.
|
| 1770 |
|
|
@@ -1810,11 +2174,11 @@ references to the moved elements of `x` now refer to those same elements
|
|
| 1810 |
but as members of `*this`. Iterators referring to the moved elements
|
| 1811 |
will continue to refer to their elements, but they now behave as
|
| 1812 |
iterators into `*this`, not into `x`.
|
| 1813 |
|
| 1814 |
*Remarks:* Stable ([[algorithm.stable]]). The behavior is undefined if
|
| 1815 |
-
`
|
| 1816 |
|
| 1817 |
*Complexity:* At most
|
| 1818 |
`distance(begin(), end()) + distance(x.begin(), x.end()) - 1`
|
| 1819 |
comparisons.
|
| 1820 |
|
|
@@ -1826,11 +2190,11 @@ template <class Compare> void sort(Compare comp);
|
|
| 1826 |
*Requires:* `operator<` (for the version with no arguments) or `comp`
|
| 1827 |
(for the version with a comparison argument) defines a strict weak
|
| 1828 |
ordering ([[alg.sorting]]).
|
| 1829 |
|
| 1830 |
*Effects:* Sorts the list according to the `operator<` or the `comp`
|
| 1831 |
-
function object. If an exception is thrown the order of the elements in
|
| 1832 |
`*this` is unspecified. Does not affect the validity of iterators and
|
| 1833 |
references.
|
| 1834 |
|
| 1835 |
*Remarks:* Stable ([[algorithm.stable]]).
|
| 1836 |
|
|
@@ -1848,14 +2212,15 @@ affect the validity of iterators and references.
|
|
| 1848 |
|
| 1849 |
#### `forward_list` specialized algorithms <a id="forwardlist.spec">[[forwardlist.spec]]</a>
|
| 1850 |
|
| 1851 |
``` cpp
|
| 1852 |
template <class T, class Allocator>
|
| 1853 |
-
void swap(forward_list<T,Allocator>& x, forward_list<T,Allocator>& y)
|
|
|
|
| 1854 |
```
|
| 1855 |
|
| 1856 |
-
*Effects:* `x.swap(y)`
|
| 1857 |
|
| 1858 |
### Class template `list` <a id="list">[[list]]</a>
|
| 1859 |
|
| 1860 |
#### Class template `list` overview <a id="list.overview">[[list.overview]]</a>
|
| 1861 |
|
|
@@ -1881,24 +2246,24 @@ information.
|
|
| 1881 |
namespace std {
|
| 1882 |
template <class T, class Allocator = allocator<T>>
|
| 1883 |
class list {
|
| 1884 |
public:
|
| 1885 |
// types:
|
| 1886 |
-
|
| 1887 |
-
|
| 1888 |
-
|
| 1889 |
-
|
| 1890 |
-
|
| 1891 |
-
|
| 1892 |
-
|
| 1893 |
-
|
| 1894 |
-
|
| 1895 |
-
|
| 1896 |
-
|
| 1897 |
-
|
| 1898 |
|
| 1899 |
-
// [list.cons], construct/copy/destroy
|
| 1900 |
list() : list(Allocator()) { }
|
| 1901 |
explicit list(const Allocator&);
|
| 1902 |
explicit list(size_type n, const Allocator& = Allocator());
|
| 1903 |
list(size_type n, const T& value, const Allocator& = Allocator());
|
| 1904 |
template <class InputIterator>
|
|
@@ -1908,11 +2273,12 @@ namespace std {
|
|
| 1908 |
list(const list&, const Allocator&);
|
| 1909 |
list(list&&, const Allocator&);
|
| 1910 |
list(initializer_list<T>, const Allocator& = Allocator());
|
| 1911 |
~list();
|
| 1912 |
list& operator=(const list& x);
|
| 1913 |
-
list& operator=(list&& x)
|
|
|
|
| 1914 |
list& operator=(initializer_list<T>);
|
| 1915 |
template <class InputIterator>
|
| 1916 |
void assign(InputIterator first, InputIterator last);
|
| 1917 |
void assign(size_type n, const T& t);
|
| 1918 |
void assign(initializer_list<T>);
|
|
@@ -1931,11 +2297,11 @@ namespace std {
|
|
| 1931 |
const_iterator cbegin() const noexcept;
|
| 1932 |
const_iterator cend() const noexcept;
|
| 1933 |
const_reverse_iterator crbegin() const noexcept;
|
| 1934 |
const_reverse_iterator crend() const noexcept;
|
| 1935 |
|
| 1936 |
-
// [list.capacity], capacity
|
| 1937 |
bool empty() const noexcept;
|
| 1938 |
size_type size() const noexcept;
|
| 1939 |
size_type max_size() const noexcept;
|
| 1940 |
void resize(size_type sz);
|
| 1941 |
void resize(size_type sz, const T& c);
|
|
@@ -1944,16 +2310,16 @@ namespace std {
|
|
| 1944 |
reference front();
|
| 1945 |
const_reference front() const;
|
| 1946 |
reference back();
|
| 1947 |
const_reference back() const;
|
| 1948 |
|
| 1949 |
-
// [list.modifiers], modifiers
|
| 1950 |
-
template <class... Args>
|
| 1951 |
-
|
| 1952 |
-
template <class... Args> void emplace_back(Args&&... args);
|
| 1953 |
void push_front(const T& x);
|
| 1954 |
void push_front(T&& x);
|
|
|
|
| 1955 |
void push_back(const T& x);
|
| 1956 |
void push_back(T&& x);
|
| 1957 |
void pop_back();
|
| 1958 |
|
| 1959 |
template <class... Args> iterator emplace(const_iterator position, Args&&... args);
|
|
@@ -1965,14 +2331,15 @@ namespace std {
|
|
| 1965 |
InputIterator last);
|
| 1966 |
iterator insert(const_iterator position, initializer_list<T> il);
|
| 1967 |
|
| 1968 |
iterator erase(const_iterator position);
|
| 1969 |
iterator erase(const_iterator position, const_iterator last);
|
| 1970 |
-
void swap(list&)
|
|
|
|
| 1971 |
void clear() noexcept;
|
| 1972 |
|
| 1973 |
-
// [list.ops], list operations
|
| 1974 |
void splice(const_iterator position, list& x);
|
| 1975 |
void splice(const_iterator position, list&& x);
|
| 1976 |
void splice(const_iterator position, list& x, const_iterator i);
|
| 1977 |
void splice(const_iterator position, list&& x, const_iterator i);
|
| 1978 |
void splice(const_iterator position, list& x,
|
|
@@ -1996,10 +2363,15 @@ namespace std {
|
|
| 1996 |
template <class Compare> void sort(Compare comp);
|
| 1997 |
|
| 1998 |
void reverse() noexcept;
|
| 1999 |
};
|
| 2000 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 2001 |
template <class T, class Allocator>
|
| 2002 |
bool operator==(const list<T, Allocator>& x, const list<T, Allocator>& y);
|
| 2003 |
template <class T, class Allocator>
|
| 2004 |
bool operator< (const list<T, Allocator>& x, const list<T, Allocator>& y);
|
| 2005 |
template <class T, class Allocator>
|
|
@@ -2009,16 +2381,22 @@ namespace std {
|
|
| 2009 |
template <class T, class Allocator>
|
| 2010 |
bool operator>=(const list<T, Allocator>& x, const list<T, Allocator>& y);
|
| 2011 |
template <class T, class Allocator>
|
| 2012 |
bool operator<=(const list<T, Allocator>& x, const list<T, Allocator>& y);
|
| 2013 |
|
| 2014 |
-
// specialized algorithms
|
| 2015 |
template <class T, class Allocator>
|
| 2016 |
-
void swap(list<T,Allocator>& x, list<T,Allocator>& y)
|
|
|
|
| 2017 |
}
|
| 2018 |
```
|
| 2019 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 2020 |
#### `list` constructors, copy, and assignment <a id="list.cons">[[list.cons]]</a>
|
| 2021 |
|
| 2022 |
``` cpp
|
| 2023 |
explicit list(const Allocator&);
|
| 2024 |
```
|
|
@@ -2037,12 +2415,11 @@ the specified allocator.
|
|
| 2037 |
*Requires:* `T` shall be `DefaultInsertable` into `*this`.
|
| 2038 |
|
| 2039 |
*Complexity:* Linear in `n`.
|
| 2040 |
|
| 2041 |
``` cpp
|
| 2042 |
-
list(size_type n, const T& value,
|
| 2043 |
-
const Allocator& = Allocator());
|
| 2044 |
```
|
| 2045 |
|
| 2046 |
*Effects:* Constructs a `list` with `n` copies of `value`, using the
|
| 2047 |
specified allocator.
|
| 2048 |
|
|
@@ -2050,12 +2427,11 @@ specified allocator.
|
|
| 2050 |
|
| 2051 |
*Complexity:* Linear in `n`.
|
| 2052 |
|
| 2053 |
``` cpp
|
| 2054 |
template <class InputIterator>
|
| 2055 |
-
list(InputIterator first, InputIterator last,
|
| 2056 |
-
const Allocator& = Allocator());
|
| 2057 |
```
|
| 2058 |
|
| 2059 |
*Effects:* Constructs a `list` equal to the range \[`first`, `last`).
|
| 2060 |
|
| 2061 |
*Complexity:* Linear in `distance(first, last)`.
|
|
@@ -2065,11 +2441,11 @@ list(InputIterator first, InputIterator last,
|
|
| 2065 |
``` cpp
|
| 2066 |
void resize(size_type sz);
|
| 2067 |
```
|
| 2068 |
|
| 2069 |
*Effects:* If `size() < sz`, appends `sz - size()` default-inserted
|
| 2070 |
-
elements to the sequence. If `sz <= size()`, equivalent to
|
| 2071 |
|
| 2072 |
``` cpp
|
| 2073 |
list<T>::iterator it = begin();
|
| 2074 |
advance(it, sz);
|
| 2075 |
erase(it, end());
|
|
@@ -2079,11 +2455,11 @@ erase(it, end());
|
|
| 2079 |
|
| 2080 |
``` cpp
|
| 2081 |
void resize(size_type sz, const T& c);
|
| 2082 |
```
|
| 2083 |
|
| 2084 |
-
*Effects:*
|
| 2085 |
|
| 2086 |
``` cpp
|
| 2087 |
if (sz > size())
|
| 2088 |
insert(end(), sz-size(), c);
|
| 2089 |
else if (sz < size()) {
|
|
@@ -2106,12 +2482,12 @@ iterator insert(const_iterator position, size_type n, const T& x);
|
|
| 2106 |
template <class InputIterator>
|
| 2107 |
iterator insert(const_iterator position, InputIterator first,
|
| 2108 |
InputIterator last);
|
| 2109 |
iterator insert(const_iterator position, initializer_list<T>);
|
| 2110 |
|
| 2111 |
-
template <class... Args>
|
| 2112 |
-
template <class... Args>
|
| 2113 |
template <class... Args> iterator emplace(const_iterator position, Args&&... args);
|
| 2114 |
void push_front(const T& x);
|
| 2115 |
void push_front(T&& x);
|
| 2116 |
void push_back(const T& x);
|
| 2117 |
void push_back(T&& x);
|
|
@@ -2175,19 +2551,19 @@ now behave as iterators into `*this`, not into `x`.
|
|
| 2175 |
``` cpp
|
| 2176 |
void splice(const_iterator position, list& x, const_iterator i);
|
| 2177 |
void splice(const_iterator position, list&& x, const_iterator i);
|
| 2178 |
```
|
| 2179 |
|
|
|
|
|
|
|
| 2180 |
*Effects:* Inserts an element pointed to by `i` from list `x` before
|
| 2181 |
`position` and removes the element from `x`. The result is unchanged if
|
| 2182 |
`position == i` or `position == ++i`. Pointers and references to `*i`
|
| 2183 |
continue to refer to this same element but as a member of `*this`.
|
| 2184 |
Iterators to `*i` (including `i` itself) continue to refer to the same
|
| 2185 |
element, but now behave as iterators into `*this`, not into `x`.
|
| 2186 |
|
| 2187 |
-
*Requires:* `i` is a valid dereferenceable iterator of `x`.
|
| 2188 |
-
|
| 2189 |
*Throws:* Nothing.
|
| 2190 |
|
| 2191 |
*Complexity:* Constant time.
|
| 2192 |
|
| 2193 |
``` cpp
|
|
@@ -2195,19 +2571,20 @@ void splice(const_iterator position, list& x, const_iterator first,
|
|
| 2195 |
const_iterator last);
|
| 2196 |
void splice(const_iterator position, list&& x, const_iterator first,
|
| 2197 |
const_iterator last);
|
| 2198 |
```
|
| 2199 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 2200 |
*Effects:* Inserts elements in the range \[`first`, `last`) before
|
| 2201 |
-
`position` and removes the elements from `x`.
|
| 2202 |
-
|
| 2203 |
-
|
| 2204 |
-
|
| 2205 |
-
|
| 2206 |
-
same elements but as members of `*this`. Iterators referring to the
|
| 2207 |
-
moved elements will continue to refer to their elements, but they now
|
| 2208 |
-
behave as iterators into `*this`, not into `x`.
|
| 2209 |
|
| 2210 |
*Throws:* Nothing.
|
| 2211 |
|
| 2212 |
*Complexity:* Constant time if `&x == this`; otherwise, linear time.
|
| 2213 |
|
|
@@ -2262,20 +2639,20 @@ shall be sorted according to this ordering.
|
|
| 2262 |
*Effects:* If `(&x == this)` does nothing; otherwise, merges the two
|
| 2263 |
sorted ranges `[begin(), end())` and `[x.begin(), x.end())`. The result
|
| 2264 |
is a range in which the elements will be sorted in non-decreasing order
|
| 2265 |
according to the ordering defined by `comp`; that is, for every iterator
|
| 2266 |
`i`, in the range other than the first, the condition
|
| 2267 |
-
`comp(*i, *(i - 1))` will be false. Pointers and references to the
|
| 2268 |
-
elements of `x` now refer to those same elements but as members of
|
| 2269 |
`*this`. Iterators referring to the moved elements will continue to
|
| 2270 |
refer to their elements, but they now behave as iterators into `*this`,
|
| 2271 |
not into `x`.
|
| 2272 |
|
| 2273 |
*Remarks:* Stable ([[algorithm.stable]]). If `(&x != this)` the range
|
| 2274 |
`[x.begin(), x.end())` is empty after the merge. No elements are copied
|
| 2275 |
by this operation. The behavior is undefined if
|
| 2276 |
-
`
|
| 2277 |
|
| 2278 |
*Complexity:* At most `size() + x.size() - 1` applications of `comp` if
|
| 2279 |
`(&x != this)`; otherwise, no applications of `comp` are performed. If
|
| 2280 |
an exception is thrown other than by a comparison there are no effects.
|
| 2281 |
|
|
@@ -2295,89 +2672,85 @@ template <class Compare> void sort(Compare comp);
|
|
| 2295 |
|
| 2296 |
*Requires:* `operator<` (for the first version) or `comp` (for the
|
| 2297 |
second version) shall define a strict weak ordering ([[alg.sorting]]).
|
| 2298 |
|
| 2299 |
*Effects:* Sorts the list according to the `operator<` or a `Compare`
|
| 2300 |
-
function object.
|
|
|
|
| 2301 |
references.
|
| 2302 |
|
| 2303 |
*Remarks:* Stable ([[algorithm.stable]]).
|
| 2304 |
|
| 2305 |
-
*Complexity:* Approximately N log
|
| 2306 |
|
| 2307 |
#### `list` specialized algorithms <a id="list.special">[[list.special]]</a>
|
| 2308 |
|
| 2309 |
``` cpp
|
| 2310 |
template <class T, class Allocator>
|
| 2311 |
-
void swap(list<T,Allocator>& x, list<T,Allocator>& y)
|
|
|
|
| 2312 |
```
|
| 2313 |
|
| 2314 |
-
*Effects:*
|
| 2315 |
-
|
| 2316 |
-
``` cpp
|
| 2317 |
-
x.swap(y);
|
| 2318 |
-
```
|
| 2319 |
|
| 2320 |
### Class template `vector` <a id="vector">[[vector]]</a>
|
| 2321 |
|
| 2322 |
#### Class template `vector` overview <a id="vector.overview">[[vector.overview]]</a>
|
| 2323 |
|
| 2324 |
-
A `vector` is a sequence container that supports
|
| 2325 |
-
|
| 2326 |
-
|
| 2327 |
-
|
| 2328 |
-
given to improve efficiency. The elements of a vector are stored
|
| 2329 |
-
contiguously, meaning that if `v` is a `vector<T, Allocator>` where `T`
|
| 2330 |
-
is some type other than `bool`, then it obeys the identity
|
| 2331 |
-
`&v[n] == &v[0] + n` for all `0 <= n < v.size()`.
|
| 2332 |
|
| 2333 |
A `vector` satisfies all of the requirements of a container and of a
|
| 2334 |
reversible container (given in two tables in
|
| 2335 |
[[container.requirements]]), of a sequence container, including most of
|
| 2336 |
-
the optional sequence container requirements ([[sequence.reqmts]]),
|
| 2337 |
-
|
| 2338 |
-
|
| 2339 |
-
|
| 2340 |
-
|
| 2341 |
-
|
| 2342 |
-
|
|
|
|
| 2343 |
|
| 2344 |
``` cpp
|
| 2345 |
namespace std {
|
| 2346 |
template <class T, class Allocator = allocator<T>>
|
| 2347 |
class vector {
|
| 2348 |
public:
|
| 2349 |
// types:
|
| 2350 |
-
|
| 2351 |
-
|
| 2352 |
-
|
| 2353 |
-
|
| 2354 |
-
|
| 2355 |
-
|
| 2356 |
-
|
| 2357 |
-
|
| 2358 |
-
|
| 2359 |
-
|
| 2360 |
-
|
| 2361 |
-
|
| 2362 |
|
| 2363 |
-
// [vector.cons], construct/copy/destroy
|
| 2364 |
-
vector() : vector(Allocator()) { }
|
| 2365 |
-
explicit vector(const Allocator&);
|
| 2366 |
explicit vector(size_type n, const Allocator& = Allocator());
|
| 2367 |
vector(size_type n, const T& value, const Allocator& = Allocator());
|
| 2368 |
template <class InputIterator>
|
| 2369 |
-
vector(InputIterator first, InputIterator last,
|
| 2370 |
-
const Allocator& = Allocator());
|
| 2371 |
vector(const vector& x);
|
| 2372 |
-
vector(vector&&);
|
| 2373 |
vector(const vector&, const Allocator&);
|
| 2374 |
vector(vector&&, const Allocator&);
|
| 2375 |
vector(initializer_list<T>, const Allocator& = Allocator());
|
| 2376 |
~vector();
|
| 2377 |
vector& operator=(const vector& x);
|
| 2378 |
-
vector& operator=(vector&& x)
|
|
|
|
|
|
|
| 2379 |
vector& operator=(initializer_list<T>);
|
| 2380 |
template <class InputIterator>
|
| 2381 |
void assign(InputIterator first, InputIterator last);
|
| 2382 |
void assign(size_type n, const T& u);
|
| 2383 |
void assign(initializer_list<T>);
|
|
@@ -2396,17 +2769,17 @@ namespace std {
|
|
| 2396 |
const_iterator cbegin() const noexcept;
|
| 2397 |
const_iterator cend() const noexcept;
|
| 2398 |
const_reverse_iterator crbegin() const noexcept;
|
| 2399 |
const_reverse_iterator crend() const noexcept;
|
| 2400 |
|
| 2401 |
-
// [vector.capacity], capacity
|
|
|
|
| 2402 |
size_type size() const noexcept;
|
| 2403 |
size_type max_size() const noexcept;
|
|
|
|
| 2404 |
void resize(size_type sz);
|
| 2405 |
void resize(size_type sz, const T& c);
|
| 2406 |
-
size_type capacity() const noexcept;
|
| 2407 |
-
bool empty() const noexcept;
|
| 2408 |
void reserve(size_type n);
|
| 2409 |
void shrink_to_fit();
|
| 2410 |
|
| 2411 |
// element access:
|
| 2412 |
reference operator[](size_type n);
|
|
@@ -2420,30 +2793,36 @@ namespace std {
|
|
| 2420 |
|
| 2421 |
// [vector.data], data access
|
| 2422 |
T* data() noexcept;
|
| 2423 |
const T* data() const noexcept;
|
| 2424 |
|
| 2425 |
-
// [vector.modifiers], modifiers
|
| 2426 |
-
template <class... Args>
|
| 2427 |
void push_back(const T& x);
|
| 2428 |
void push_back(T&& x);
|
| 2429 |
void pop_back();
|
| 2430 |
|
| 2431 |
template <class... Args> iterator emplace(const_iterator position, Args&&... args);
|
| 2432 |
iterator insert(const_iterator position, const T& x);
|
| 2433 |
iterator insert(const_iterator position, T&& x);
|
| 2434 |
iterator insert(const_iterator position, size_type n, const T& x);
|
| 2435 |
template <class InputIterator>
|
| 2436 |
-
|
| 2437 |
-
InputIterator first, InputIterator last);
|
| 2438 |
iterator insert(const_iterator position, initializer_list<T> il);
|
| 2439 |
iterator erase(const_iterator position);
|
| 2440 |
iterator erase(const_iterator first, const_iterator last);
|
| 2441 |
-
void swap(vector&)
|
|
|
|
|
|
|
| 2442 |
void clear() noexcept;
|
| 2443 |
};
|
| 2444 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 2445 |
template <class T, class Allocator>
|
| 2446 |
bool operator==(const vector<T, Allocator>& x, const vector<T, Allocator>& y);
|
| 2447 |
template <class T, class Allocator>
|
| 2448 |
bool operator< (const vector<T, Allocator>& x, const vector<T, Allocator>& y);
|
| 2449 |
template <class T, class Allocator>
|
|
@@ -2453,16 +2832,22 @@ namespace std {
|
|
| 2453 |
template <class T, class Allocator>
|
| 2454 |
bool operator>=(const vector<T, Allocator>& x, const vector<T, Allocator>& y);
|
| 2455 |
template <class T, class Allocator>
|
| 2456 |
bool operator<=(const vector<T, Allocator>& x, const vector<T, Allocator>& y);
|
| 2457 |
|
| 2458 |
-
// [vector.special], specialized algorithms
|
| 2459 |
template <class T, class Allocator>
|
| 2460 |
-
void swap(vector<T,Allocator>& x, vector<T,Allocator>& y)
|
|
|
|
| 2461 |
}
|
| 2462 |
```
|
| 2463 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 2464 |
#### `vector` constructors, copy, and assignment <a id="vector.cons">[[vector.cons]]</a>
|
| 2465 |
|
| 2466 |
``` cpp
|
| 2467 |
explicit vector(const Allocator&);
|
| 2468 |
```
|
|
@@ -2503,13 +2888,13 @@ template <class InputIterator>
|
|
| 2503 |
*Effects:* Constructs a `vector` equal to the range \[`first`, `last`),
|
| 2504 |
using the specified allocator.
|
| 2505 |
|
| 2506 |
*Complexity:* Makes only N calls to the copy constructor of `T` (where N
|
| 2507 |
is the distance between `first` and `last`) and no reallocations if
|
| 2508 |
-
iterators first and last are of forward, bidirectional, or random
|
| 2509 |
-
categories. It makes order `N` calls to the copy constructor of
|
| 2510 |
-
order log
|
| 2511 |
|
| 2512 |
#### `vector` capacity <a id="vector.capacity">[[vector.capacity]]</a>
|
| 2513 |
|
| 2514 |
``` cpp
|
| 2515 |
size_type capacity() const noexcept;
|
|
@@ -2548,20 +2933,30 @@ vector greater than the value of `capacity()`.
|
|
| 2548 |
void shrink_to_fit();
|
| 2549 |
```
|
| 2550 |
|
| 2551 |
*Requires:* `T` shall be `MoveInsertable` into `*this`.
|
| 2552 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 2553 |
*Complexity:* Linear in the size of the sequence.
|
| 2554 |
|
| 2555 |
-
*Remarks:*
|
| 2556 |
-
|
| 2557 |
-
|
| 2558 |
-
other than by the move constructor of a non-`CopyInsertable` `T` there
|
| 2559 |
-
are no effects.
|
| 2560 |
|
| 2561 |
``` cpp
|
| 2562 |
-
void swap(vector& x)
|
|
|
|
|
|
|
| 2563 |
```
|
| 2564 |
|
| 2565 |
*Effects:* Exchanges the contents and `capacity()` of `*this` with that
|
| 2566 |
of `x`.
|
| 2567 |
|
|
@@ -2569,13 +2964,13 @@ of `x`.
|
|
| 2569 |
|
| 2570 |
``` cpp
|
| 2571 |
void resize(size_type sz);
|
| 2572 |
```
|
| 2573 |
|
| 2574 |
-
*Effects:* If `sz <
|
| 2575 |
-
|
| 2576 |
-
|
| 2577 |
|
| 2578 |
*Requires:* `T` shall be `MoveInsertable` and `DefaultInsertable` into
|
| 2579 |
`*this`.
|
| 2580 |
|
| 2581 |
*Remarks:* If an exception is thrown other than by the move constructor
|
|
@@ -2583,13 +2978,13 @@ of a non-`CopyInsertable` `T` there are no effects.
|
|
| 2583 |
|
| 2584 |
``` cpp
|
| 2585 |
void resize(size_type sz, const T& c);
|
| 2586 |
```
|
| 2587 |
|
| 2588 |
-
*Effects:* If `sz <
|
| 2589 |
-
|
| 2590 |
-
|
| 2591 |
|
| 2592 |
*Requires:* `T` shall be `CopyInsertable` into `*this`.
|
| 2593 |
|
| 2594 |
*Remarks:* If an exception is thrown there are no effects.
|
| 2595 |
|
|
@@ -2599,11 +2994,11 @@ void resize(size_type sz, const T& c);
|
|
| 2599 |
T* data() noexcept;
|
| 2600 |
const T* data() const noexcept;
|
| 2601 |
```
|
| 2602 |
|
| 2603 |
*Returns:* A pointer such that \[`data()`, `data() + size()`) is a valid
|
| 2604 |
-
range. For a non-empty vector, `data()` `==` `
|
| 2605 |
|
| 2606 |
*Complexity:* Constant time.
|
| 2607 |
|
| 2608 |
#### `vector` modifiers <a id="vector.modifiers">[[vector.modifiers]]</a>
|
| 2609 |
|
|
@@ -2613,81 +3008,81 @@ iterator insert(const_iterator position, T&& x);
|
|
| 2613 |
iterator insert(const_iterator position, size_type n, const T& x);
|
| 2614 |
template <class InputIterator>
|
| 2615 |
iterator insert(const_iterator position, InputIterator first, InputIterator last);
|
| 2616 |
iterator insert(const_iterator position, initializer_list<T>);
|
| 2617 |
|
| 2618 |
-
template <class... Args>
|
| 2619 |
template <class... Args> iterator emplace(const_iterator position, Args&&... args);
|
| 2620 |
void push_back(const T& x);
|
| 2621 |
void push_back(T&& x);
|
| 2622 |
```
|
| 2623 |
|
| 2624 |
*Remarks:* Causes reallocation if the new size is greater than the old
|
| 2625 |
-
capacity.
|
| 2626 |
-
|
| 2627 |
-
|
| 2628 |
-
|
| 2629 |
-
|
| 2630 |
-
|
| 2631 |
-
|
| 2632 |
-
|
| 2633 |
-
|
|
|
|
|
|
|
| 2634 |
|
| 2635 |
*Complexity:* The complexity is linear in the number of elements
|
| 2636 |
inserted plus the distance to the end of the vector.
|
| 2637 |
|
| 2638 |
``` cpp
|
| 2639 |
iterator erase(const_iterator position);
|
| 2640 |
iterator erase(const_iterator first, const_iterator last);
|
|
|
|
| 2641 |
```
|
| 2642 |
|
| 2643 |
*Effects:* Invalidates iterators and references at or after the point of
|
| 2644 |
the erase.
|
| 2645 |
|
| 2646 |
*Complexity:* The destructor of `T` is called the number of times equal
|
| 2647 |
-
to the number of the elements erased, but the
|
| 2648 |
-
|
| 2649 |
-
|
| 2650 |
|
| 2651 |
-
*Throws:* Nothing unless an exception is thrown by the
|
| 2652 |
-
|
| 2653 |
-
`T`.
|
| 2654 |
|
| 2655 |
#### `vector` specialized algorithms <a id="vector.special">[[vector.special]]</a>
|
| 2656 |
|
| 2657 |
``` cpp
|
| 2658 |
template <class T, class Allocator>
|
| 2659 |
-
void swap(vector<T,Allocator>& x, vector<T,Allocator>& y)
|
|
|
|
| 2660 |
```
|
| 2661 |
|
| 2662 |
-
*Effects:*
|
| 2663 |
-
|
| 2664 |
-
``` cpp
|
| 2665 |
-
x.swap(y);
|
| 2666 |
-
```
|
| 2667 |
|
| 2668 |
### Class `vector<bool>` <a id="vector.bool">[[vector.bool]]</a>
|
| 2669 |
|
| 2670 |
To optimize space allocation, a specialization of vector for `bool`
|
| 2671 |
elements is provided:
|
| 2672 |
|
| 2673 |
``` cpp
|
| 2674 |
namespace std {
|
| 2675 |
-
template <class Allocator>
|
|
|
|
| 2676 |
public:
|
| 2677 |
// types:
|
| 2678 |
-
|
| 2679 |
-
|
| 2680 |
-
|
| 2681 |
-
|
| 2682 |
-
|
| 2683 |
-
|
| 2684 |
-
|
| 2685 |
-
|
| 2686 |
-
|
| 2687 |
-
|
| 2688 |
-
|
| 2689 |
|
| 2690 |
// bit reference:
|
| 2691 |
class reference {
|
| 2692 |
friend class vector;
|
| 2693 |
reference() noexcept;
|
|
@@ -2737,15 +3132,15 @@ namespace std {
|
|
| 2737 |
const_iterator cend() const noexcept;
|
| 2738 |
const_reverse_iterator crbegin() const noexcept;
|
| 2739 |
const_reverse_iterator crend() const noexcept;
|
| 2740 |
|
| 2741 |
// capacity:
|
|
|
|
| 2742 |
size_type size() const noexcept;
|
| 2743 |
size_type max_size() const noexcept;
|
|
|
|
| 2744 |
void resize(size_type sz, bool c = false);
|
| 2745 |
-
size_type capacity() const noexcept;
|
| 2746 |
-
bool empty() const noexcept;
|
| 2747 |
void reserve(size_type n);
|
| 2748 |
void shrink_to_fit();
|
| 2749 |
|
| 2750 |
// element access:
|
| 2751 |
reference operator[](size_type n);
|
|
@@ -2756,11 +3151,11 @@ namespace std {
|
|
| 2756 |
const_reference front() const;
|
| 2757 |
reference back();
|
| 2758 |
const_reference back() const;
|
| 2759 |
|
| 2760 |
// modifiers:
|
| 2761 |
-
template <class... Args>
|
| 2762 |
void push_back(const bool& x);
|
| 2763 |
void pop_back();
|
| 2764 |
template <class... Args> iterator emplace(const_iterator position, Args&&... args);
|
| 2765 |
iterator insert(const_iterator position, const bool& x);
|
| 2766 |
iterator insert(const_iterator position, size_type n, const bool& x);
|
|
@@ -2780,21 +3175,21 @@ namespace std {
|
|
| 2780 |
```
|
| 2781 |
|
| 2782 |
Unless described below, all operations have the same requirements and
|
| 2783 |
semantics as the primary `vector` template, except that operations
|
| 2784 |
dealing with the `bool` value type map to bit values in the container
|
| 2785 |
-
storage and allocator_traits::construct (
|
| 2786 |
-
is not used to construct these values.
|
| 2787 |
|
| 2788 |
There is no requirement that the data be stored as a contiguous
|
| 2789 |
allocation of `bool` values. A space-optimized representation of bits is
|
| 2790 |
recommended instead.
|
| 2791 |
|
| 2792 |
`reference`
|
| 2793 |
|
| 2794 |
is a class that simulates the behavior of references of a single bit in
|
| 2795 |
-
`vector<bool>`. The conversion
|
| 2796 |
set, and `false` otherwise. The assignment operator sets the bit when
|
| 2797 |
the argument is (convertible to) `true` and clears it otherwise. `flip`
|
| 2798 |
reverses the state of the bit.
|
| 2799 |
|
| 2800 |
``` cpp
|
|
@@ -2805,11 +3200,11 @@ void flip() noexcept;
|
|
| 2805 |
|
| 2806 |
``` cpp
|
| 2807 |
static void swap(reference x, reference y) noexcept;
|
| 2808 |
```
|
| 2809 |
|
| 2810 |
-
*Effects:*
|
| 2811 |
|
| 2812 |
``` cpp
|
| 2813 |
bool b = x;
|
| 2814 |
x = y;
|
| 2815 |
y = b;
|
|
@@ -2817,27 +3212,42 @@ y = b;
|
|
| 2817 |
|
| 2818 |
``` cpp
|
| 2819 |
template <class Allocator> struct hash<vector<bool, Allocator>>;
|
| 2820 |
```
|
| 2821 |
|
| 2822 |
-
The
|
| 2823 |
-
template `hash` ([[unord.hash]]).
|
| 2824 |
|
| 2825 |
## Associative containers <a id="associative">[[associative]]</a>
|
| 2826 |
|
| 2827 |
### In general <a id="associative.general">[[associative.general]]</a>
|
| 2828 |
|
| 2829 |
The header `<map>` defines the class templates `map` and `multimap`; the
|
| 2830 |
header `<set>` defines the class templates `set` and `multiset`.
|
| 2831 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 2832 |
### Header `<map>` synopsis <a id="associative.map.syn">[[associative.map.syn]]</a>
|
| 2833 |
|
| 2834 |
``` cpp
|
| 2835 |
#include <initializer_list>
|
| 2836 |
|
| 2837 |
namespace std {
|
| 2838 |
-
|
| 2839 |
template <class Key, class T, class Compare = less<Key>,
|
| 2840 |
class Allocator = allocator<pair<const Key, T>>>
|
| 2841 |
class map;
|
| 2842 |
template <class Key, class T, class Compare, class Allocator>
|
| 2843 |
bool operator==(const map<Key, T, Compare, Allocator>& x,
|
|
@@ -2857,12 +3267,14 @@ namespace std {
|
|
| 2857 |
template <class Key, class T, class Compare, class Allocator>
|
| 2858 |
bool operator<=(const map<Key, T, Compare, Allocator>& x,
|
| 2859 |
const map<Key, T, Compare, Allocator>& y);
|
| 2860 |
template <class Key, class T, class Compare, class Allocator>
|
| 2861 |
void swap(map<Key, T, Compare, Allocator>& x,
|
| 2862 |
-
map<Key,T,Compare,Allocator>& y)
|
|
|
|
| 2863 |
|
|
|
|
| 2864 |
template <class Key, class T, class Compare = less<Key>,
|
| 2865 |
class Allocator = allocator<pair<const Key, T>>>
|
| 2866 |
class multimap;
|
| 2867 |
template <class Key, class T, class Compare, class Allocator>
|
| 2868 |
bool operator==(const multimap<Key, T, Compare, Allocator>& x,
|
|
@@ -2882,21 +3294,32 @@ namespace std {
|
|
| 2882 |
template <class Key, class T, class Compare, class Allocator>
|
| 2883 |
bool operator<=(const multimap<Key, T, Compare, Allocator>& x,
|
| 2884 |
const multimap<Key, T, Compare, Allocator>& y);
|
| 2885 |
template <class Key, class T, class Compare, class Allocator>
|
| 2886 |
void swap(multimap<Key, T, Compare, Allocator>& x,
|
| 2887 |
-
multimap<Key,T,Compare,Allocator>& y)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 2888 |
}
|
| 2889 |
```
|
| 2890 |
|
| 2891 |
### Header `<set>` synopsis <a id="associative.set.syn">[[associative.set.syn]]</a>
|
| 2892 |
|
| 2893 |
``` cpp
|
| 2894 |
#include <initializer_list>
|
| 2895 |
|
| 2896 |
namespace std {
|
| 2897 |
-
|
| 2898 |
template <class Key, class Compare = less<Key>,
|
| 2899 |
class Allocator = allocator<Key>>
|
| 2900 |
class set;
|
| 2901 |
template <class Key, class Compare, class Allocator>
|
| 2902 |
bool operator==(const set<Key, Compare, Allocator>& x,
|
|
@@ -2916,12 +3339,14 @@ namespace std {
|
|
| 2916 |
template <class Key, class Compare, class Allocator>
|
| 2917 |
bool operator<=(const set<Key, Compare, Allocator>& x,
|
| 2918 |
const set<Key, Compare, Allocator>& y);
|
| 2919 |
template <class Key, class Compare, class Allocator>
|
| 2920 |
void swap(set<Key, Compare, Allocator>& x,
|
| 2921 |
-
set<Key,Compare,Allocator>& y)
|
|
|
|
| 2922 |
|
|
|
|
| 2923 |
template <class Key, class Compare = less<Key>,
|
| 2924 |
class Allocator = allocator<Key>>
|
| 2925 |
class multiset;
|
| 2926 |
template <class Key, class Compare, class Allocator>
|
| 2927 |
bool operator==(const multiset<Key, Compare, Allocator>& x,
|
|
@@ -2941,11 +3366,22 @@ namespace std {
|
|
| 2941 |
template <class Key, class Compare, class Allocator>
|
| 2942 |
bool operator<=(const multiset<Key, Compare, Allocator>& x,
|
| 2943 |
const multiset<Key, Compare, Allocator>& y);
|
| 2944 |
template <class Key, class Compare, class Allocator>
|
| 2945 |
void swap(multiset<Key, Compare, Allocator>& x,
|
| 2946 |
-
multiset<Key,Compare,Allocator>& y)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 2947 |
}
|
| 2948 |
```
|
| 2949 |
|
| 2950 |
### Class template `map` <a id="map">[[map]]</a>
|
| 2951 |
|
|
@@ -2958,59 +3394,57 @@ bidirectional iterators.
|
|
| 2958 |
|
| 2959 |
A `map` satisfies all of the requirements of a container, of a
|
| 2960 |
reversible container ([[container.requirements]]), of an associative
|
| 2961 |
container ([[associative.reqmts]]), and of an allocator-aware container
|
| 2962 |
(Table [[tab:containers.allocatoraware]]). A `map` also provides most
|
| 2963 |
-
operations described in
|
| 2964 |
-
means that a `map` supports the `a_uniq` operations in
|
| 2965 |
-
[[associative.reqmts]]
|
| 2966 |
-
|
| 2967 |
-
|
| 2968 |
-
|
| 2969 |
-
|
| 2970 |
|
| 2971 |
``` cpp
|
| 2972 |
namespace std {
|
| 2973 |
template <class Key, class T, class Compare = less<Key>,
|
| 2974 |
class Allocator = allocator<pair<const Key, T>>>
|
| 2975 |
class map {
|
| 2976 |
public:
|
| 2977 |
// types:
|
| 2978 |
-
|
| 2979 |
-
|
| 2980 |
-
|
| 2981 |
-
|
| 2982 |
-
|
| 2983 |
-
|
| 2984 |
-
|
| 2985 |
-
|
| 2986 |
-
|
| 2987 |
-
|
| 2988 |
-
|
| 2989 |
-
|
| 2990 |
-
|
| 2991 |
-
|
| 2992 |
-
|
|
|
|
|
|
|
| 2993 |
|
| 2994 |
class value_compare {
|
| 2995 |
friend class map;
|
| 2996 |
protected:
|
| 2997 |
Compare comp;
|
| 2998 |
value_compare(Compare c) : comp(c) {}
|
| 2999 |
public:
|
| 3000 |
-
typedef bool result_type;
|
| 3001 |
-
typedef value_type first_argument_type;
|
| 3002 |
-
typedef value_type second_argument_type;
|
| 3003 |
bool operator()(const value_type& x, const value_type& y) const {
|
| 3004 |
return comp(x.first, y.first);
|
| 3005 |
}
|
| 3006 |
};
|
| 3007 |
|
| 3008 |
-
// [map.cons], construct/copy/destroy
|
| 3009 |
map() : map(Compare()) { }
|
| 3010 |
-
explicit map(const Compare& comp,
|
| 3011 |
-
const Allocator& = Allocator());
|
| 3012 |
template <class InputIterator>
|
| 3013 |
map(InputIterator first, InputIterator last,
|
| 3014 |
const Compare& comp = Compare(), const Allocator& = Allocator());
|
| 3015 |
map(const map& x);
|
| 3016 |
map(map&& x);
|
|
@@ -3025,11 +3459,13 @@ namespace std {
|
|
| 3025 |
: map(first, last, Compare(), a) { }
|
| 3026 |
map(initializer_list<value_type> il, const Allocator& a)
|
| 3027 |
: map(il, Compare(), a) { }
|
| 3028 |
~map();
|
| 3029 |
map& operator=(const map& x);
|
| 3030 |
-
map& operator=(map&& x)
|
|
|
|
|
|
|
| 3031 |
map& operator=(initializer_list<value_type>);
|
| 3032 |
allocator_type get_allocator() const noexcept;
|
| 3033 |
|
| 3034 |
// iterators:
|
| 3035 |
iterator begin() noexcept;
|
|
@@ -3050,34 +3486,70 @@ namespace std {
|
|
| 3050 |
// capacity:
|
| 3051 |
bool empty() const noexcept;
|
| 3052 |
size_type size() const noexcept;
|
| 3053 |
size_type max_size() const noexcept;
|
| 3054 |
|
| 3055 |
-
// [map.access], element access
|
| 3056 |
T& operator[](const key_type& x);
|
| 3057 |
T& operator[](key_type&& x);
|
| 3058 |
T& at(const key_type& x);
|
| 3059 |
const T& at(const key_type& x) const;
|
| 3060 |
|
| 3061 |
-
// [map.modifiers], modifiers
|
| 3062 |
template <class... Args> pair<iterator, bool> emplace(Args&&... args);
|
| 3063 |
template <class... Args> iterator emplace_hint(const_iterator position, Args&&... args);
|
| 3064 |
pair<iterator, bool> insert(const value_type& x);
|
|
|
|
| 3065 |
template <class P> pair<iterator, bool> insert(P&& x);
|
| 3066 |
iterator insert(const_iterator position, const value_type& x);
|
|
|
|
| 3067 |
template <class P>
|
| 3068 |
iterator insert(const_iterator position, P&&);
|
| 3069 |
template <class InputIterator>
|
| 3070 |
void insert(InputIterator first, InputIterator last);
|
| 3071 |
void insert(initializer_list<value_type>);
|
| 3072 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 3073 |
iterator erase(const_iterator position);
|
| 3074 |
size_type erase(const key_type& x);
|
| 3075 |
iterator erase(const_iterator first, const_iterator last);
|
| 3076 |
-
void
|
|
|
|
|
|
|
| 3077 |
void clear() noexcept;
|
| 3078 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 3079 |
// observers:
|
| 3080 |
key_compare key_comp() const;
|
| 3081 |
value_compare value_comp() const;
|
| 3082 |
|
| 3083 |
// map operations:
|
|
@@ -3097,20 +3569,36 @@ namespace std {
|
|
| 3097 |
iterator upper_bound(const key_type& x);
|
| 3098 |
const_iterator upper_bound(const key_type& x) const;
|
| 3099 |
template <class K> iterator upper_bound(const K& x);
|
| 3100 |
template <class K> const_iterator upper_bound(const K& x) const;
|
| 3101 |
|
| 3102 |
-
pair<iterator,iterator>
|
| 3103 |
-
|
| 3104 |
-
pair<const_iterator,const_iterator>
|
| 3105 |
-
equal_range(const key_type& x) const;
|
| 3106 |
template <class K>
|
| 3107 |
pair<iterator, iterator> equal_range(const K& x);
|
| 3108 |
template <class K>
|
| 3109 |
pair<const_iterator, const_iterator> equal_range(const K& x) const;
|
| 3110 |
};
|
| 3111 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 3112 |
template <class Key, class T, class Compare, class Allocator>
|
| 3113 |
bool operator==(const map<Key, T, Compare, Allocator>& x,
|
| 3114 |
const map<Key, T, Compare, Allocator>& y);
|
| 3115 |
template <class Key, class T, class Compare, class Allocator>
|
| 3116 |
bool operator< (const map<Key, T, Compare, Allocator>& x,
|
|
@@ -3126,22 +3614,22 @@ namespace std {
|
|
| 3126 |
const map<Key, T, Compare, Allocator>& y);
|
| 3127 |
template <class Key, class T, class Compare, class Allocator>
|
| 3128 |
bool operator<=(const map<Key, T, Compare, Allocator>& x,
|
| 3129 |
const map<Key, T, Compare, Allocator>& y);
|
| 3130 |
|
| 3131 |
-
// specialized algorithms
|
| 3132 |
template <class Key, class T, class Compare, class Allocator>
|
| 3133 |
void swap(map<Key, T, Compare, Allocator>& x,
|
| 3134 |
-
map<Key,T,Compare,Allocator>& y)
|
|
|
|
| 3135 |
}
|
| 3136 |
```
|
| 3137 |
|
| 3138 |
#### `map` constructors, copy, and assignment <a id="map.cons">[[map.cons]]</a>
|
| 3139 |
|
| 3140 |
``` cpp
|
| 3141 |
-
explicit map(const Compare& comp,
|
| 3142 |
-
const Allocator& = Allocator());
|
| 3143 |
```
|
| 3144 |
|
| 3145 |
*Effects:* Constructs an empty `map` using the specified comparison
|
| 3146 |
object and allocator.
|
| 3147 |
|
|
@@ -3151,51 +3639,30 @@ object and allocator.
|
|
| 3151 |
template <class InputIterator>
|
| 3152 |
map(InputIterator first, InputIterator last,
|
| 3153 |
const Compare& comp = Compare(), const Allocator& = Allocator());
|
| 3154 |
```
|
| 3155 |
|
| 3156 |
-
*Requires:* If the iterator’s indirection operator returns an lvalue or
|
| 3157 |
-
a const rvalue `pair<key_type, mapped_type>`, then both `key_type` and
|
| 3158 |
-
`mapped_type` shall be `CopyInsertable` into `*this`.
|
| 3159 |
-
|
| 3160 |
*Effects:* Constructs an empty `map` using the specified comparison
|
| 3161 |
object and allocator, and inserts elements from the range \[`first`,
|
| 3162 |
`last`).
|
| 3163 |
|
| 3164 |
*Complexity:* Linear in N if the range \[`first`, `last`) is already
|
| 3165 |
-
sorted using `comp` and otherwise N log N, where N is `last
|
| 3166 |
|
| 3167 |
#### `map` element access <a id="map.access">[[map.access]]</a>
|
| 3168 |
|
| 3169 |
``` cpp
|
| 3170 |
T& operator[](const key_type& x);
|
| 3171 |
```
|
| 3172 |
|
| 3173 |
-
*Effects:*
|
| 3174 |
-
`value_type(x, T())` into the map.
|
| 3175 |
-
|
| 3176 |
-
*Requires:* `key_type` shall be `CopyInsertable` and `mapped_type` shall
|
| 3177 |
-
be `DefaultInsertable` into `*this`.
|
| 3178 |
-
|
| 3179 |
-
*Returns:* A reference to the `mapped_type` corresponding to `x` in
|
| 3180 |
-
`*this`.
|
| 3181 |
-
|
| 3182 |
-
*Complexity:* Logarithmic.
|
| 3183 |
|
| 3184 |
``` cpp
|
| 3185 |
T& operator[](key_type&& x);
|
| 3186 |
```
|
| 3187 |
|
| 3188 |
-
*Effects:*
|
| 3189 |
-
`value_type(std::move(x), T())` into the map.
|
| 3190 |
-
|
| 3191 |
-
*Requires:* `mapped_type` shall be `DefaultInsertable` into `*this`.
|
| 3192 |
-
|
| 3193 |
-
*Returns:* A reference to the `mapped_type` corresponding to `x` in
|
| 3194 |
-
`*this`.
|
| 3195 |
-
|
| 3196 |
-
*Complexity:* Logarithmic.
|
| 3197 |
|
| 3198 |
``` cpp
|
| 3199 |
T& at(const key_type& x);
|
| 3200 |
const T& at(const key_type& x) const;
|
| 3201 |
```
|
|
@@ -3209,36 +3676,122 @@ is present.
|
|
| 3209 |
*Complexity:* Logarithmic.
|
| 3210 |
|
| 3211 |
#### `map` modifiers <a id="map.modifiers">[[map.modifiers]]</a>
|
| 3212 |
|
| 3213 |
``` cpp
|
| 3214 |
-
template <class P>
|
| 3215 |
-
|
| 3216 |
-
template <class
|
| 3217 |
-
|
| 3218 |
```
|
| 3219 |
|
| 3220 |
*Effects:* The first form is equivalent to
|
| 3221 |
`return emplace(std::forward<P>(x))`. The second form is equivalent to
|
| 3222 |
`return emplace_hint(position, std::forward<P>(x))`.
|
| 3223 |
|
| 3224 |
*Remarks:* These signatures shall not participate in overload resolution
|
| 3225 |
-
unless `
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 3226 |
|
| 3227 |
#### `map` specialized algorithms <a id="map.special">[[map.special]]</a>
|
| 3228 |
|
| 3229 |
``` cpp
|
| 3230 |
template <class Key, class T, class Compare, class Allocator>
|
| 3231 |
void swap(map<Key, T, Compare, Allocator>& x,
|
| 3232 |
-
map<Key,T,Compare,Allocator>& y)
|
|
|
|
| 3233 |
```
|
| 3234 |
|
| 3235 |
-
*Effects:*
|
| 3236 |
-
|
| 3237 |
-
``` cpp
|
| 3238 |
-
x.swap(y);
|
| 3239 |
-
```
|
| 3240 |
|
| 3241 |
### Class template `multimap` <a id="multimap">[[multimap]]</a>
|
| 3242 |
|
| 3243 |
#### Class template `multimap` overview <a id="multimap.overview">[[multimap.overview]]</a>
|
| 3244 |
|
|
@@ -3249,13 +3802,13 @@ for fast retrieval of values of another type `T` based on the keys. The
|
|
| 3249 |
|
| 3250 |
A `multimap` satisfies all of the requirements of a container and of a
|
| 3251 |
reversible container ([[container.requirements]]), of an associative
|
| 3252 |
container ([[associative.reqmts]]), and of an allocator-aware container
|
| 3253 |
(Table [[tab:containers.allocatoraware]]). A `multimap` also provides
|
| 3254 |
-
most operations described in
|
| 3255 |
-
This means that a `multimap` supports the `a_eq` operations in
|
| 3256 |
-
[[associative.reqmts]]
|
| 3257 |
`multimap<Key,T>` the `key_type` is `Key` and the `value_type` is
|
| 3258 |
`pair<const Key,T>`. Descriptions are provided here only for operations
|
| 3259 |
on `multimap` that are not described in one of those tables or for
|
| 3260 |
operations where there is additional semantic information.
|
| 3261 |
|
|
@@ -3264,44 +3817,41 @@ namespace std {
|
|
| 3264 |
template <class Key, class T, class Compare = less<Key>,
|
| 3265 |
class Allocator = allocator<pair<const Key, T>>>
|
| 3266 |
class multimap {
|
| 3267 |
public:
|
| 3268 |
// types:
|
| 3269 |
-
|
| 3270 |
-
|
| 3271 |
-
|
| 3272 |
-
|
| 3273 |
-
|
| 3274 |
-
|
| 3275 |
-
|
| 3276 |
-
|
| 3277 |
-
|
| 3278 |
-
|
| 3279 |
-
|
| 3280 |
-
|
| 3281 |
-
|
| 3282 |
-
|
| 3283 |
-
|
|
|
|
| 3284 |
|
| 3285 |
class value_compare {
|
| 3286 |
friend class multimap;
|
| 3287 |
protected:
|
| 3288 |
Compare comp;
|
| 3289 |
value_compare(Compare c) : comp(c) { }
|
| 3290 |
public:
|
| 3291 |
-
typedef bool result_type;
|
| 3292 |
-
typedef value_type first_argument_type;
|
| 3293 |
-
typedef value_type second_argument_type;
|
| 3294 |
bool operator()(const value_type& x, const value_type& y) const {
|
| 3295 |
return comp(x.first, y.first);
|
| 3296 |
}
|
| 3297 |
};
|
| 3298 |
|
| 3299 |
-
// construct/copy/destroy
|
| 3300 |
multimap() : multimap(Compare()) { }
|
| 3301 |
-
explicit multimap(const Compare& comp,
|
| 3302 |
-
const Allocator& = Allocator());
|
| 3303 |
template <class InputIterator>
|
| 3304 |
multimap(InputIterator first, InputIterator last,
|
| 3305 |
const Compare& comp = Compare(),
|
| 3306 |
const Allocator& = Allocator());
|
| 3307 |
multimap(const multimap& x);
|
|
@@ -3317,11 +3867,13 @@ namespace std {
|
|
| 3317 |
: multimap(first, last, Compare(), a) { }
|
| 3318 |
multimap(initializer_list<value_type> il, const Allocator& a)
|
| 3319 |
: multimap(il, Compare(), a) { }
|
| 3320 |
~multimap();
|
| 3321 |
multimap& operator=(const multimap& x);
|
| 3322 |
-
multimap& operator=(multimap&& x)
|
|
|
|
|
|
|
| 3323 |
multimap& operator=(initializer_list<value_type>);
|
| 3324 |
allocator_type get_allocator() const noexcept;
|
| 3325 |
|
| 3326 |
// iterators:
|
| 3327 |
iterator begin() noexcept;
|
|
@@ -3342,27 +3894,46 @@ namespace std {
|
|
| 3342 |
// capacity:
|
| 3343 |
bool empty() const noexcept;
|
| 3344 |
size_type size() const noexcept;
|
| 3345 |
size_type max_size() const noexcept;
|
| 3346 |
|
| 3347 |
-
// modifiers
|
| 3348 |
template <class... Args> iterator emplace(Args&&... args);
|
| 3349 |
template <class... Args> iterator emplace_hint(const_iterator position, Args&&... args);
|
| 3350 |
iterator insert(const value_type& x);
|
|
|
|
| 3351 |
template <class P> iterator insert(P&& x);
|
| 3352 |
iterator insert(const_iterator position, const value_type& x);
|
|
|
|
| 3353 |
template <class P> iterator insert(const_iterator position, P&& x);
|
| 3354 |
template <class InputIterator>
|
| 3355 |
void insert(InputIterator first, InputIterator last);
|
| 3356 |
void insert(initializer_list<value_type>);
|
| 3357 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 3358 |
iterator erase(const_iterator position);
|
| 3359 |
size_type erase(const key_type& x);
|
| 3360 |
iterator erase(const_iterator first, const_iterator last);
|
| 3361 |
-
void
|
|
|
|
|
|
|
| 3362 |
void clear() noexcept;
|
| 3363 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 3364 |
// observers:
|
| 3365 |
key_compare key_comp() const;
|
| 3366 |
value_compare value_comp() const;
|
| 3367 |
|
| 3368 |
// map operations:
|
|
@@ -3382,20 +3953,37 @@ namespace std {
|
|
| 3382 |
iterator upper_bound(const key_type& x);
|
| 3383 |
const_iterator upper_bound(const key_type& x) const;
|
| 3384 |
template <class K> iterator upper_bound(const K& x);
|
| 3385 |
template <class K> const_iterator upper_bound(const K& x) const;
|
| 3386 |
|
| 3387 |
-
pair<iterator,iterator>
|
| 3388 |
-
|
| 3389 |
-
pair<const_iterator,const_iterator>
|
| 3390 |
-
equal_range(const key_type& x) const;
|
| 3391 |
template <class K>
|
| 3392 |
pair<iterator, iterator> equal_range(const K& x);
|
| 3393 |
template <class K>
|
| 3394 |
pair<const_iterator, const_iterator> equal_range(const K& x) const;
|
| 3395 |
};
|
| 3396 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 3397 |
template <class Key, class T, class Compare, class Allocator>
|
| 3398 |
bool operator==(const multimap<Key, T, Compare, Allocator>& x,
|
| 3399 |
const multimap<Key, T, Compare, Allocator>& y);
|
| 3400 |
template <class Key, class T, class Compare, class Allocator>
|
| 3401 |
bool operator< (const multimap<Key, T, Compare, Allocator>& x,
|
|
@@ -3411,22 +3999,22 @@ namespace std {
|
|
| 3411 |
const multimap<Key, T, Compare, Allocator>& y);
|
| 3412 |
template <class Key, class T, class Compare, class Allocator>
|
| 3413 |
bool operator<=(const multimap<Key, T, Compare, Allocator>& x,
|
| 3414 |
const multimap<Key, T, Compare, Allocator>& y);
|
| 3415 |
|
| 3416 |
-
// specialized algorithms
|
| 3417 |
template <class Key, class T, class Compare, class Allocator>
|
| 3418 |
void swap(multimap<Key, T, Compare, Allocator>& x,
|
| 3419 |
-
multimap<Key,T,Compare,Allocator>& y)
|
|
|
|
| 3420 |
}
|
| 3421 |
```
|
| 3422 |
|
| 3423 |
#### `multimap` constructors <a id="multimap.cons">[[multimap.cons]]</a>
|
| 3424 |
|
| 3425 |
``` cpp
|
| 3426 |
-
explicit multimap(const Compare& comp,
|
| 3427 |
-
const Allocator& = Allocator());
|
| 3428 |
```
|
| 3429 |
|
| 3430 |
*Effects:* Constructs an empty `multimap` using the specified comparison
|
| 3431 |
object and allocator.
|
| 3432 |
|
|
@@ -3437,14 +4025,10 @@ template <class InputIterator>
|
|
| 3437 |
multimap(InputIterator first, InputIterator last,
|
| 3438 |
const Compare& comp = Compare(),
|
| 3439 |
const Allocator& = Allocator());
|
| 3440 |
```
|
| 3441 |
|
| 3442 |
-
*Requires:* If the iterator’s indirection operator returns an lvalue or
|
| 3443 |
-
a const rvalue `pair<key_type, mapped_type>`, then both `key_type` and
|
| 3444 |
-
`mapped_type` shall be `CopyInsertable` into `*this`.
|
| 3445 |
-
|
| 3446 |
*Effects:* Constructs an empty `multimap` using the specified comparison
|
| 3447 |
object and allocator, and inserts elements from the range \[`first`,
|
| 3448 |
`last`).
|
| 3449 |
|
| 3450 |
*Complexity:* Linear in N if the range \[`first`, `last`) is already
|
|
@@ -3460,25 +4044,22 @@ template <class P> iterator insert(const_iterator position, P&& x);
|
|
| 3460 |
*Effects:* The first form is equivalent to
|
| 3461 |
`return emplace(std::forward<P>(x))`. The second form is equivalent to
|
| 3462 |
`return emplace_hint(position, std::forward<P>(x))`.
|
| 3463 |
|
| 3464 |
*Remarks:* These signatures shall not participate in overload resolution
|
| 3465 |
-
unless `
|
| 3466 |
|
| 3467 |
#### `multimap` specialized algorithms <a id="multimap.special">[[multimap.special]]</a>
|
| 3468 |
|
| 3469 |
``` cpp
|
| 3470 |
template <class Key, class T, class Compare, class Allocator>
|
| 3471 |
void swap(multimap<Key, T, Compare, Allocator>& x,
|
| 3472 |
-
multimap<Key,T,Compare,Allocator>& y)
|
|
|
|
| 3473 |
```
|
| 3474 |
|
| 3475 |
-
*Effects:*
|
| 3476 |
-
|
| 3477 |
-
``` cpp
|
| 3478 |
-
x.swap(y);
|
| 3479 |
-
```
|
| 3480 |
|
| 3481 |
### Class template `set` <a id="set">[[set]]</a>
|
| 3482 |
|
| 3483 |
#### Class template `set` overview <a id="set.overview">[[set.overview]]</a>
|
| 3484 |
|
|
@@ -3488,13 +4069,13 @@ keys themselves. The `set` class supports bidirectional iterators.
|
|
| 3488 |
|
| 3489 |
A `set` satisfies all of the requirements of a container, of a
|
| 3490 |
reversible container ([[container.requirements]]), of an associative
|
| 3491 |
container ([[associative.reqmts]]), and of an allocator-aware container
|
| 3492 |
(Table [[tab:containers.allocatoraware]]). A `set` also provides most
|
| 3493 |
-
operations described in
|
| 3494 |
-
means that a `set` supports the `a_uniq` operations in
|
| 3495 |
-
[[associative.reqmts]]
|
| 3496 |
both the `key_type` and `value_type` are `Key`. Descriptions are
|
| 3497 |
provided here only for operations on `set` that are not described in one
|
| 3498 |
of these tables and for operations where there is additional semantic
|
| 3499 |
information.
|
| 3500 |
|
|
@@ -3503,49 +4084,51 @@ namespace std {
|
|
| 3503 |
template <class Key, class Compare = less<Key>,
|
| 3504 |
class Allocator = allocator<Key>>
|
| 3505 |
class set {
|
| 3506 |
public:
|
| 3507 |
// types:
|
| 3508 |
-
|
| 3509 |
-
|
| 3510 |
-
|
| 3511 |
-
|
| 3512 |
-
|
| 3513 |
-
|
| 3514 |
-
|
| 3515 |
-
|
| 3516 |
-
|
| 3517 |
-
|
| 3518 |
-
|
| 3519 |
-
|
| 3520 |
-
|
| 3521 |
-
|
| 3522 |
-
|
|
|
|
|
|
|
| 3523 |
|
| 3524 |
-
// [set.cons], construct/copy/destroy
|
| 3525 |
set() : set(Compare()) { }
|
| 3526 |
-
explicit set(const Compare& comp,
|
| 3527 |
-
const Allocator& = Allocator());
|
| 3528 |
template <class InputIterator>
|
| 3529 |
set(InputIterator first, InputIterator last,
|
| 3530 |
const Compare& comp = Compare(), const Allocator& = Allocator());
|
| 3531 |
set(const set& x);
|
| 3532 |
set(set&& x);
|
| 3533 |
explicit set(const Allocator&);
|
| 3534 |
set(const set&, const Allocator&);
|
| 3535 |
set(set&&, const Allocator&);
|
| 3536 |
-
set(initializer_list<value_type>,
|
| 3537 |
-
const Compare& = Compare(),
|
| 3538 |
const Allocator& = Allocator());
|
| 3539 |
template <class InputIterator>
|
| 3540 |
set(InputIterator first, InputIterator last, const Allocator& a)
|
| 3541 |
: set(first, last, Compare(), a) { }
|
| 3542 |
set(initializer_list<value_type> il, const Allocator& a)
|
| 3543 |
: set(il, Compare(), a) { }
|
| 3544 |
~set();
|
| 3545 |
set& operator=(const set& x);
|
| 3546 |
-
set& operator=(set&& x)
|
|
|
|
|
|
|
| 3547 |
set& operator=(initializer_list<value_type>);
|
| 3548 |
allocator_type get_allocator() const noexcept;
|
| 3549 |
|
| 3550 |
// iterators:
|
| 3551 |
iterator begin() noexcept;
|
|
@@ -3577,16 +4160,33 @@ namespace std {
|
|
| 3577 |
iterator insert(const_iterator position, value_type&& x);
|
| 3578 |
template <class InputIterator>
|
| 3579 |
void insert(InputIterator first, InputIterator last);
|
| 3580 |
void insert(initializer_list<value_type>);
|
| 3581 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 3582 |
iterator erase(const_iterator position);
|
| 3583 |
size_type erase(const key_type& x);
|
| 3584 |
iterator erase(const_iterator first, const_iterator last);
|
| 3585 |
-
void
|
|
|
|
|
|
|
| 3586 |
void clear() noexcept;
|
| 3587 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 3588 |
// observers:
|
| 3589 |
key_compare key_comp() const;
|
| 3590 |
value_compare value_comp() const;
|
| 3591 |
|
| 3592 |
// set operations:
|
|
@@ -3614,10 +4214,29 @@ namespace std {
|
|
| 3614 |
pair<iterator, iterator> equal_range(const K& x);
|
| 3615 |
template <class K>
|
| 3616 |
pair<const_iterator, const_iterator> equal_range(const K& x) const;
|
| 3617 |
};
|
| 3618 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 3619 |
template <class Key, class Compare, class Allocator>
|
| 3620 |
bool operator==(const set<Key, Compare, Allocator>& x,
|
| 3621 |
const set<Key, Compare, Allocator>& y);
|
| 3622 |
template <class Key, class Compare, class Allocator>
|
| 3623 |
bool operator< (const set<Key, Compare, Allocator>& x,
|
|
@@ -3633,25 +4252,25 @@ namespace std {
|
|
| 3633 |
const set<Key, Compare, Allocator>& y);
|
| 3634 |
template <class Key, class Compare, class Allocator>
|
| 3635 |
bool operator<=(const set<Key, Compare, Allocator>& x,
|
| 3636 |
const set<Key, Compare, Allocator>& y);
|
| 3637 |
|
| 3638 |
-
// specialized algorithms
|
| 3639 |
template <class Key, class Compare, class Allocator>
|
| 3640 |
void swap(set<Key, Compare, Allocator>& x,
|
| 3641 |
-
set<Key,Compare,Allocator>& y)
|
|
|
|
| 3642 |
}
|
| 3643 |
```
|
| 3644 |
|
| 3645 |
#### `set` constructors, copy, and assignment <a id="set.cons">[[set.cons]]</a>
|
| 3646 |
|
| 3647 |
``` cpp
|
| 3648 |
-
explicit set(const Compare& comp,
|
| 3649 |
-
const Allocator& = Allocator());
|
| 3650 |
```
|
| 3651 |
|
| 3652 |
-
*Effects:* Constructs an empty set using the specified comparison
|
| 3653 |
objects and allocator.
|
| 3654 |
|
| 3655 |
*Complexity:* Constant.
|
| 3656 |
|
| 3657 |
``` cpp
|
|
@@ -3662,29 +4281,23 @@ template <class InputIterator>
|
|
| 3662 |
|
| 3663 |
*Effects:* Constructs an empty `set` using the specified comparison
|
| 3664 |
object and allocator, and inserts elements from the range \[`first`,
|
| 3665 |
`last`).
|
| 3666 |
|
| 3667 |
-
*Requires:* If the iterator’s indirection operator returns an lvalue or
|
| 3668 |
-
a non-const rvalue, then `Key` shall be `CopyInsertable` into `*this`.
|
| 3669 |
-
|
| 3670 |
*Complexity:* Linear in N if the range \[`first`, `last`) is already
|
| 3671 |
sorted using `comp` and otherwise N log N, where N is `last - first`.
|
| 3672 |
|
| 3673 |
#### `set` specialized algorithms <a id="set.special">[[set.special]]</a>
|
| 3674 |
|
| 3675 |
``` cpp
|
| 3676 |
template <class Key, class Compare, class Allocator>
|
| 3677 |
void swap(set<Key, Compare, Allocator>& x,
|
| 3678 |
-
set<Key,Compare,Allocator>& y)
|
|
|
|
| 3679 |
```
|
| 3680 |
|
| 3681 |
-
*Effects:*
|
| 3682 |
-
|
| 3683 |
-
``` cpp
|
| 3684 |
-
x.swap(y);
|
| 3685 |
-
```
|
| 3686 |
|
| 3687 |
### Class template `multiset` <a id="multiset">[[multiset]]</a>
|
| 3688 |
|
| 3689 |
#### Class template `multiset` overview <a id="multiset.overview">[[multiset.overview]]</a>
|
| 3690 |
|
|
@@ -3695,13 +4308,13 @@ bidirectional iterators.
|
|
| 3695 |
|
| 3696 |
A `multiset` satisfies all of the requirements of a container, of a
|
| 3697 |
reversible container ([[container.requirements]]), of an associative
|
| 3698 |
container ([[associative.reqmts]]), and of an allocator-aware container
|
| 3699 |
(Table [[tab:containers.allocatoraware]]). `multiset` also provides
|
| 3700 |
-
most operations described in
|
| 3701 |
-
|
| 3702 |
-
[[associative.reqmts]]
|
| 3703 |
`multiset<Key>` both the `key_type` and `value_type` are `Key`.
|
| 3704 |
Descriptions are provided here only for operations on `multiset` that
|
| 3705 |
are not described in one of these tables and for operations where there
|
| 3706 |
is additional semantic information.
|
| 3707 |
|
|
@@ -3710,50 +4323,50 @@ namespace std {
|
|
| 3710 |
template <class Key, class Compare = less<Key>,
|
| 3711 |
class Allocator = allocator<Key>>
|
| 3712 |
class multiset {
|
| 3713 |
public:
|
| 3714 |
// types:
|
| 3715 |
-
|
| 3716 |
-
|
| 3717 |
-
|
| 3718 |
-
|
| 3719 |
-
|
| 3720 |
-
|
| 3721 |
-
|
| 3722 |
-
|
| 3723 |
-
|
| 3724 |
-
|
| 3725 |
-
|
| 3726 |
-
|
| 3727 |
-
|
| 3728 |
-
|
| 3729 |
-
|
|
|
|
| 3730 |
|
| 3731 |
-
// construct/copy/destroy
|
| 3732 |
multiset() : multiset(Compare()) { }
|
| 3733 |
-
explicit multiset(const Compare& comp,
|
| 3734 |
-
const Allocator& = Allocator());
|
| 3735 |
template <class InputIterator>
|
| 3736 |
multiset(InputIterator first, InputIterator last,
|
| 3737 |
-
const Compare& comp = Compare(),
|
| 3738 |
-
const Allocator& = Allocator());
|
| 3739 |
multiset(const multiset& x);
|
| 3740 |
multiset(multiset&& x);
|
| 3741 |
explicit multiset(const Allocator&);
|
| 3742 |
multiset(const multiset&, const Allocator&);
|
| 3743 |
multiset(multiset&&, const Allocator&);
|
| 3744 |
-
multiset(initializer_list<value_type>,
|
| 3745 |
-
const Compare& = Compare(),
|
| 3746 |
const Allocator& = Allocator());
|
| 3747 |
template <class InputIterator>
|
| 3748 |
multiset(InputIterator first, InputIterator last, const Allocator& a)
|
| 3749 |
: multiset(first, last, Compare(), a) { }
|
| 3750 |
multiset(initializer_list<value_type> il, const Allocator& a)
|
| 3751 |
: multiset(il, Compare(), a) { }
|
| 3752 |
~multiset();
|
| 3753 |
multiset& operator=(const multiset& x);
|
| 3754 |
-
multiset& operator=(multiset&& x)
|
|
|
|
|
|
|
| 3755 |
multiset& operator=(initializer_list<value_type>);
|
| 3756 |
allocator_type get_allocator() const noexcept;
|
| 3757 |
|
| 3758 |
// iterators:
|
| 3759 |
iterator begin() noexcept;
|
|
@@ -3785,16 +4398,33 @@ namespace std {
|
|
| 3785 |
iterator insert(const_iterator position, value_type&& x);
|
| 3786 |
template <class InputIterator>
|
| 3787 |
void insert(InputIterator first, InputIterator last);
|
| 3788 |
void insert(initializer_list<value_type>);
|
| 3789 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 3790 |
iterator erase(const_iterator position);
|
| 3791 |
size_type erase(const key_type& x);
|
| 3792 |
iterator erase(const_iterator first, const_iterator last);
|
| 3793 |
-
void
|
|
|
|
|
|
|
| 3794 |
void clear() noexcept;
|
| 3795 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 3796 |
// observers:
|
| 3797 |
key_compare key_comp() const;
|
| 3798 |
value_compare value_comp() const;
|
| 3799 |
|
| 3800 |
// set operations:
|
|
@@ -3822,10 +4452,29 @@ namespace std {
|
|
| 3822 |
pair<iterator, iterator> equal_range(const K& x);
|
| 3823 |
template <class K>
|
| 3824 |
pair<const_iterator, const_iterator> equal_range(const K& x) const;
|
| 3825 |
};
|
| 3826 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 3827 |
template <class Key, class Compare, class Allocator>
|
| 3828 |
bool operator==(const multiset<Key, Compare, Allocator>& x,
|
| 3829 |
const multiset<Key, Compare, Allocator>& y);
|
| 3830 |
template <class Key, class Compare, class Allocator>
|
| 3831 |
bool operator< (const multiset<Key, Compare, Allocator>& x,
|
|
@@ -3841,38 +4490,35 @@ namespace std {
|
|
| 3841 |
const multiset<Key, Compare, Allocator>& y);
|
| 3842 |
template <class Key, class Compare, class Allocator>
|
| 3843 |
bool operator<=(const multiset<Key, Compare, Allocator>& x,
|
| 3844 |
const multiset<Key, Compare, Allocator>& y);
|
| 3845 |
|
| 3846 |
-
// specialized algorithms
|
| 3847 |
template <class Key, class Compare, class Allocator>
|
| 3848 |
void swap(multiset<Key, Compare, Allocator>& x,
|
| 3849 |
-
multiset<Key,Compare,Allocator>& y)
|
|
|
|
| 3850 |
}
|
| 3851 |
```
|
| 3852 |
|
| 3853 |
#### `multiset` constructors <a id="multiset.cons">[[multiset.cons]]</a>
|
| 3854 |
|
| 3855 |
``` cpp
|
| 3856 |
-
explicit multiset(const Compare& comp,
|
| 3857 |
-
const Allocator& = Allocator());
|
| 3858 |
```
|
| 3859 |
|
| 3860 |
-
*Effects:* Constructs an empty
|
| 3861 |
-
and allocator.
|
| 3862 |
|
| 3863 |
*Complexity:* Constant.
|
| 3864 |
|
| 3865 |
``` cpp
|
| 3866 |
template <class InputIterator>
|
| 3867 |
multiset(InputIterator first, InputIterator last,
|
| 3868 |
const Compare& comp = Compare(), const Allocator& = Allocator());
|
| 3869 |
```
|
| 3870 |
|
| 3871 |
-
*Requires:* If the iterator’s indirection operator returns an lvalue or
|
| 3872 |
-
a const rvalue, then `Key` shall be `CopyInsertable` into `*this`.
|
| 3873 |
-
|
| 3874 |
*Effects:* Constructs an empty `multiset` using the specified comparison
|
| 3875 |
object and allocator, and inserts elements from the range \[`first`,
|
| 3876 |
`last`).
|
| 3877 |
|
| 3878 |
*Complexity:* Linear in N if the range \[`first`, `last`) is already
|
|
@@ -3881,57 +4527,59 @@ sorted using `comp` and otherwise N log N, where N is `last - first`.
|
|
| 3881 |
#### `multiset` specialized algorithms <a id="multiset.special">[[multiset.special]]</a>
|
| 3882 |
|
| 3883 |
``` cpp
|
| 3884 |
template <class Key, class Compare, class Allocator>
|
| 3885 |
void swap(multiset<Key, Compare, Allocator>& x,
|
| 3886 |
-
multiset<Key,Compare,Allocator>& y)
|
|
|
|
| 3887 |
```
|
| 3888 |
|
| 3889 |
-
*Effects:*
|
| 3890 |
-
|
| 3891 |
-
``` cpp
|
| 3892 |
-
x.swap(y);
|
| 3893 |
-
```
|
| 3894 |
|
| 3895 |
## Unordered associative containers <a id="unord">[[unord]]</a>
|
| 3896 |
|
| 3897 |
### In general <a id="unord.general">[[unord.general]]</a>
|
| 3898 |
|
| 3899 |
The header `<unordered_map>` defines the class templates `unordered_map`
|
| 3900 |
and `unordered_multimap`; the header `<unordered_set>` defines the class
|
| 3901 |
templates `unordered_set` and `unordered_multiset`.
|
| 3902 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 3903 |
### Header `<unordered_map>` synopsis <a id="unord.map.syn">[[unord.map.syn]]</a>
|
| 3904 |
|
| 3905 |
``` cpp
|
| 3906 |
#include <initializer_list>
|
| 3907 |
|
| 3908 |
namespace std {
|
| 3909 |
-
|
| 3910 |
-
// [unord.map], class template unordered_map:
|
| 3911 |
template <class Key,
|
| 3912 |
class T,
|
| 3913 |
class Hash = hash<Key>,
|
| 3914 |
-
class Pred =
|
| 3915 |
-
class Alloc =
|
| 3916 |
class unordered_map;
|
| 3917 |
|
| 3918 |
-
// [unord.multimap], class template unordered_multimap
|
| 3919 |
template <class Key,
|
| 3920 |
class T,
|
| 3921 |
class Hash = hash<Key>,
|
| 3922 |
-
class Pred =
|
| 3923 |
-
class Alloc =
|
| 3924 |
class unordered_multimap;
|
| 3925 |
|
| 3926 |
template <class Key, class T, class Hash, class Pred, class Alloc>
|
| 3927 |
void swap(unordered_map<Key, T, Hash, Pred, Alloc>& x,
|
| 3928 |
-
unordered_map<Key, T, Hash, Pred, Alloc>& y)
|
|
|
|
| 3929 |
|
| 3930 |
template <class Key, class T, class Hash, class Pred, class Alloc>
|
| 3931 |
void swap(unordered_multimap<Key, T, Hash, Pred, Alloc>& x,
|
| 3932 |
-
unordered_multimap<Key, T, Hash, Pred, Alloc>& y)
|
|
|
|
| 3933 |
|
| 3934 |
template <class Key, class T, class Hash, class Pred, class Alloc>
|
| 3935 |
bool operator==(const unordered_map<Key, T, Hash, Pred, Alloc>& a,
|
| 3936 |
const unordered_map<Key, T, Hash, Pred, Alloc>& b);
|
| 3937 |
template <class Key, class T, class Hash, class Pred, class Alloc>
|
|
@@ -3941,41 +4589,60 @@ namespace std {
|
|
| 3941 |
bool operator==(const unordered_multimap<Key, T, Hash, Pred, Alloc>& a,
|
| 3942 |
const unordered_multimap<Key, T, Hash, Pred, Alloc>& b);
|
| 3943 |
template <class Key, class T, class Hash, class Pred, class Alloc>
|
| 3944 |
bool operator!=(const unordered_multimap<Key, T, Hash, Pred, Alloc>& a,
|
| 3945 |
const unordered_multimap<Key, T, Hash, Pred, Alloc>& b);
|
| 3946 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 3947 |
```
|
| 3948 |
|
| 3949 |
### Header `<unordered_set>` synopsis <a id="unord.set.syn">[[unord.set.syn]]</a>
|
| 3950 |
|
| 3951 |
``` cpp
|
| 3952 |
#include <initializer_list>
|
| 3953 |
|
| 3954 |
namespace std {
|
| 3955 |
-
|
| 3956 |
-
// [unord.set], class template unordered_set:
|
| 3957 |
template <class Key,
|
| 3958 |
class Hash = hash<Key>,
|
| 3959 |
-
class Pred =
|
| 3960 |
-
class Alloc =
|
| 3961 |
class unordered_set;
|
| 3962 |
|
| 3963 |
-
// [unord.multiset], class template unordered_multiset
|
| 3964 |
template <class Key,
|
| 3965 |
class Hash = hash<Key>,
|
| 3966 |
-
class Pred =
|
| 3967 |
-
class Alloc =
|
| 3968 |
class unordered_multiset;
|
| 3969 |
|
| 3970 |
template <class Key, class Hash, class Pred, class Alloc>
|
| 3971 |
void swap(unordered_set<Key, Hash, Pred, Alloc>& x,
|
| 3972 |
-
unordered_set<Key, Hash, Pred, Alloc>& y)
|
|
|
|
| 3973 |
|
| 3974 |
template <class Key, class Hash, class Pred, class Alloc>
|
| 3975 |
void swap(unordered_multiset<Key, Hash, Pred, Alloc>& x,
|
| 3976 |
-
unordered_multiset<Key, Hash, Pred, Alloc>& y)
|
|
|
|
| 3977 |
|
| 3978 |
template <class Key, class Hash, class Pred, class Alloc>
|
| 3979 |
bool operator==(const unordered_set<Key, Hash, Pred, Alloc>& a,
|
| 3980 |
const unordered_set<Key, Hash, Pred, Alloc>& b);
|
| 3981 |
template <class Key, class Hash, class Pred, class Alloc>
|
|
@@ -3985,11 +4652,25 @@ namespace std {
|
|
| 3985 |
bool operator==(const unordered_multiset<Key, Hash, Pred, Alloc>& a,
|
| 3986 |
const unordered_multiset<Key, Hash, Pred, Alloc>& b);
|
| 3987 |
template <class Key, class Hash, class Pred, class Alloc>
|
| 3988 |
bool operator!=(const unordered_multiset<Key, Hash, Pred, Alloc>& a,
|
| 3989 |
const unordered_multiset<Key, Hash, Pred, Alloc>& b);
|
| 3990 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 3991 |
```
|
| 3992 |
|
| 3993 |
### Class template `unordered_map` <a id="unord.map">[[unord.map]]</a>
|
| 3994 |
|
| 3995 |
#### Class template `unordered_map` overview <a id="unord.map.overview">[[unord.map.overview]]</a>
|
|
@@ -4004,46 +4685,47 @@ an unordered associative container, and of an allocator-aware container
|
|
| 4004 |
(Table [[tab:containers.allocatoraware]]). It provides the operations
|
| 4005 |
described in the preceding requirements table for unique keys; that is,
|
| 4006 |
an `unordered_map` supports the `a_uniq` operations in that table, not
|
| 4007 |
the `a_eq` operations. For an `unordered_map<Key, T>` the `key type` is
|
| 4008 |
`Key`, the mapped type is `T`, and the value type is
|
| 4009 |
-
`
|
| 4010 |
|
| 4011 |
This section only describes operations on `unordered_map` that are not
|
| 4012 |
described in one of the requirement tables, or for which there is
|
| 4013 |
additional semantic information.
|
| 4014 |
|
| 4015 |
``` cpp
|
| 4016 |
namespace std {
|
| 4017 |
template <class Key,
|
| 4018 |
class T,
|
| 4019 |
class Hash = hash<Key>,
|
| 4020 |
-
class Pred
|
| 4021 |
-
class Allocator =
|
| 4022 |
-
class unordered_map
|
| 4023 |
-
{
|
| 4024 |
public:
|
| 4025 |
-
// types
|
| 4026 |
-
|
| 4027 |
-
|
| 4028 |
-
|
| 4029 |
-
|
| 4030 |
-
|
| 4031 |
-
|
| 4032 |
-
|
| 4033 |
-
|
| 4034 |
-
|
| 4035 |
-
|
| 4036 |
-
|
| 4037 |
-
|
| 4038 |
|
| 4039 |
-
|
| 4040 |
-
|
| 4041 |
-
|
| 4042 |
-
|
|
|
|
|
|
|
| 4043 |
|
| 4044 |
-
// construct/
|
| 4045 |
unordered_map();
|
| 4046 |
explicit unordered_map(size_type n,
|
| 4047 |
const hasher& hf = hasher(),
|
| 4048 |
const key_equal& eql = key_equal(),
|
| 4049 |
const allocator_type& a = allocator_type());
|
|
@@ -4056,12 +4738,12 @@ namespace std {
|
|
| 4056 |
unordered_map(const unordered_map&);
|
| 4057 |
unordered_map(unordered_map&&);
|
| 4058 |
explicit unordered_map(const Allocator&);
|
| 4059 |
unordered_map(const unordered_map&, const Allocator&);
|
| 4060 |
unordered_map(unordered_map&&, const Allocator&);
|
| 4061 |
-
unordered_map(initializer_list<value_type>,
|
| 4062 |
-
|
| 4063 |
const hasher& hf = hasher(),
|
| 4064 |
const key_equal& eql = key_equal(),
|
| 4065 |
const allocator_type& a = allocator_type());
|
| 4066 |
unordered_map(size_type n, const allocator_type& a)
|
| 4067 |
: unordered_map(n, hasher(), key_equal(), a) { }
|
|
@@ -4079,61 +4761,101 @@ namespace std {
|
|
| 4079 |
unordered_map(initializer_list<value_type> il, size_type n, const hasher& hf,
|
| 4080 |
const allocator_type& a)
|
| 4081 |
: unordered_map(il, n, hf, key_equal(), a) { }
|
| 4082 |
~unordered_map();
|
| 4083 |
unordered_map& operator=(const unordered_map&);
|
| 4084 |
-
unordered_map& operator=(unordered_map&&)
|
|
|
|
|
|
|
|
|
|
| 4085 |
unordered_map& operator=(initializer_list<value_type>);
|
| 4086 |
allocator_type get_allocator() const noexcept;
|
| 4087 |
|
| 4088 |
-
//
|
| 4089 |
-
bool empty() const noexcept;
|
| 4090 |
-
size_type size() const noexcept;
|
| 4091 |
-
size_type max_size() const noexcept;
|
| 4092 |
-
|
| 4093 |
-
// iterators
|
| 4094 |
iterator begin() noexcept;
|
| 4095 |
const_iterator begin() const noexcept;
|
| 4096 |
iterator end() noexcept;
|
| 4097 |
const_iterator end() const noexcept;
|
| 4098 |
const_iterator cbegin() const noexcept;
|
| 4099 |
const_iterator cend() const noexcept;
|
| 4100 |
|
| 4101 |
-
//
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 4102 |
template <class... Args> pair<iterator, bool> emplace(Args&&... args);
|
| 4103 |
template <class... Args> iterator emplace_hint(const_iterator position, Args&&... args);
|
| 4104 |
pair<iterator, bool> insert(const value_type& obj);
|
|
|
|
| 4105 |
template <class P> pair<iterator, bool> insert(P&& obj);
|
| 4106 |
iterator insert(const_iterator hint, const value_type& obj);
|
|
|
|
| 4107 |
template <class P> iterator insert(const_iterator hint, P&& obj);
|
| 4108 |
template <class InputIterator> void insert(InputIterator first, InputIterator last);
|
| 4109 |
void insert(initializer_list<value_type>);
|
| 4110 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 4111 |
iterator erase(const_iterator position);
|
| 4112 |
size_type erase(const key_type& k);
|
| 4113 |
iterator erase(const_iterator first, const_iterator last);
|
|
|
|
|
|
|
|
|
|
|
|
|
| 4114 |
void clear() noexcept;
|
| 4115 |
|
| 4116 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 4117 |
|
| 4118 |
-
// observers
|
| 4119 |
hasher hash_function() const;
|
| 4120 |
key_equal key_eq() const;
|
| 4121 |
|
| 4122 |
-
//
|
| 4123 |
iterator find(const key_type& k);
|
| 4124 |
const_iterator find(const key_type& k) const;
|
| 4125 |
size_type count(const key_type& k) const;
|
| 4126 |
-
|
| 4127 |
-
|
| 4128 |
|
|
|
|
| 4129 |
mapped_type& operator[](const key_type& k);
|
| 4130 |
mapped_type& operator[](key_type&& k);
|
| 4131 |
mapped_type& at(const key_type& k);
|
| 4132 |
const mapped_type& at(const key_type& k) const;
|
| 4133 |
|
| 4134 |
-
// bucket interface
|
| 4135 |
size_type bucket_count() const noexcept;
|
| 4136 |
size_type max_bucket_count() const noexcept;
|
| 4137 |
size_type bucket_size(size_type n) const;
|
| 4138 |
size_type bucket(const key_type& k) const;
|
| 4139 |
local_iterator begin(size_type n);
|
|
@@ -4141,31 +4863,84 @@ namespace std {
|
|
| 4141 |
local_iterator end(size_type n);
|
| 4142 |
const_local_iterator end(size_type n) const;
|
| 4143 |
const_local_iterator cbegin(size_type n) const;
|
| 4144 |
const_local_iterator cend(size_type n) const;
|
| 4145 |
|
| 4146 |
-
// hash policy
|
| 4147 |
float load_factor() const noexcept;
|
| 4148 |
float max_load_factor() const noexcept;
|
| 4149 |
void max_load_factor(float z);
|
| 4150 |
void rehash(size_type n);
|
| 4151 |
void reserve(size_type n);
|
| 4152 |
};
|
| 4153 |
|
| 4154 |
-
template
|
| 4155 |
-
|
| 4156 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 4157 |
|
| 4158 |
template <class Key, class T, class Hash, class Pred, class Alloc>
|
| 4159 |
bool operator==(const unordered_map<Key, T, Hash, Pred, Alloc>& a,
|
| 4160 |
const unordered_map<Key, T, Hash, Pred, Alloc>& b);
|
| 4161 |
template <class Key, class T, class Hash, class Pred, class Alloc>
|
| 4162 |
bool operator!=(const unordered_map<Key, T, Hash, Pred, Alloc>& a,
|
| 4163 |
const unordered_map<Key, T, Hash, Pred, Alloc>& b);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 4164 |
}
|
| 4165 |
```
|
| 4166 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 4167 |
#### `unordered_map` constructors <a id="unord.map.cnstr">[[unord.map.cnstr]]</a>
|
| 4168 |
|
| 4169 |
``` cpp
|
| 4170 |
unordered_map() : unordered_map(size_type(see below)) { }
|
| 4171 |
explicit unordered_map(size_type n,
|
|
@@ -4173,53 +4948,52 @@ explicit unordered_map(size_type n,
|
|
| 4173 |
const key_equal& eql = key_equal(),
|
| 4174 |
const allocator_type& a = allocator_type());
|
| 4175 |
```
|
| 4176 |
|
| 4177 |
*Effects:* Constructs an empty `unordered_map` using the specified hash
|
| 4178 |
-
function, key equality
|
| 4179 |
buckets. For the default constructor, the number of buckets is
|
| 4180 |
-
*implementation-defined*. `max_load_factor()` returns 1.0.
|
| 4181 |
|
| 4182 |
*Complexity:* Constant.
|
| 4183 |
|
| 4184 |
``` cpp
|
| 4185 |
template <class InputIterator>
|
| 4186 |
unordered_map(InputIterator f, InputIterator l,
|
| 4187 |
size_type n = see below,
|
| 4188 |
const hasher& hf = hasher(),
|
| 4189 |
const key_equal& eql = key_equal(),
|
| 4190 |
const allocator_type& a = allocator_type());
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 4191 |
```
|
| 4192 |
|
| 4193 |
*Effects:* Constructs an empty `unordered_map` using the specified hash
|
| 4194 |
-
function, key equality
|
| 4195 |
-
buckets. If
|
| 4196 |
-
*implementation-defined*. Then inserts elements from the range
|
| 4197 |
-
`
|
|
|
|
| 4198 |
|
| 4199 |
*Complexity:* Average case linear, worst case quadratic.
|
| 4200 |
|
| 4201 |
#### `unordered_map` element access <a id="unord.map.elem">[[unord.map.elem]]</a>
|
| 4202 |
|
| 4203 |
``` cpp
|
| 4204 |
mapped_type& operator[](const key_type& k);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 4205 |
mapped_type& operator[](key_type&& k);
|
| 4206 |
```
|
| 4207 |
|
| 4208 |
-
*
|
| 4209 |
-
the first operator, `key_type` shall be `CopyInsertable` into `*this`.
|
| 4210 |
-
For the second operator, `key_type` shall be `MoveConstructible`.
|
| 4211 |
-
|
| 4212 |
-
*Effects:* If the `unordered_map` does not already contain an element
|
| 4213 |
-
whose key is equivalent to *`k`*, the first operator inserts the value
|
| 4214 |
-
`value_type(k, mapped_type())` and the second operator inserts the value
|
| 4215 |
-
`value_type(std::move(k), mapped_type())`.
|
| 4216 |
-
|
| 4217 |
-
*Returns:* A reference to `x.second`, where `x` is the (unique) element
|
| 4218 |
-
whose key is equivalent to *`k`*.
|
| 4219 |
-
|
| 4220 |
-
*Complexity:* Average case 𝑂(1), worst case 𝑂(`size()`).
|
| 4221 |
|
| 4222 |
``` cpp
|
| 4223 |
mapped_type& at(const key_type& k);
|
| 4224 |
const mapped_type& at(const key_type& k) const;
|
| 4225 |
```
|
|
@@ -4235,35 +5009,126 @@ is present.
|
|
| 4235 |
``` cpp
|
| 4236 |
template <class P>
|
| 4237 |
pair<iterator, bool> insert(P&& obj);
|
| 4238 |
```
|
| 4239 |
|
| 4240 |
-
*Effects:* Equivalent to `return emplace(std::forward<P>(obj))`
|
| 4241 |
|
| 4242 |
*Remarks:* This signature shall not participate in overload resolution
|
| 4243 |
-
unless `
|
| 4244 |
|
| 4245 |
``` cpp
|
| 4246 |
template <class P>
|
| 4247 |
iterator insert(const_iterator hint, P&& obj);
|
| 4248 |
```
|
| 4249 |
|
| 4250 |
-
*Effects:* Equivalent to
|
| 4251 |
-
`return emplace_hint(hint, std::forward<P>(obj))`
|
| 4252 |
|
| 4253 |
*Remarks:* This signature shall not participate in overload resolution
|
| 4254 |
-
unless `
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 4255 |
|
| 4256 |
#### `unordered_map` swap <a id="unord.map.swap">[[unord.map.swap]]</a>
|
| 4257 |
|
| 4258 |
``` cpp
|
| 4259 |
template <class Key, class T, class Hash, class Pred, class Alloc>
|
| 4260 |
void swap(unordered_map<Key, T, Hash, Pred, Alloc>& x,
|
| 4261 |
-
unordered_map<Key, T, Hash, Pred, Alloc>& y)
|
|
|
|
| 4262 |
```
|
| 4263 |
|
| 4264 |
-
*Effects:* `x.swap(y)`.
|
| 4265 |
|
| 4266 |
### Class template `unordered_multimap` <a id="unord.multimap">[[unord.multimap]]</a>
|
| 4267 |
|
| 4268 |
#### Class template `unordered_multimap` overview <a id="unord.multimap.overview">[[unord.multimap.overview]]</a>
|
| 4269 |
|
|
@@ -4278,46 +5143,46 @@ container, of an unordered associative container, and of an
|
|
| 4278 |
allocator-aware container (Table [[tab:containers.allocatoraware]]). It
|
| 4279 |
provides the operations described in the preceding requirements table
|
| 4280 |
for equivalent keys; that is, an `unordered_multimap` supports the
|
| 4281 |
`a_eq` operations in that table, not the `a_uniq` operations. For an
|
| 4282 |
`unordered_multimap<Key, T>` the `key type` is `Key`, the mapped type is
|
| 4283 |
-
`T`, and the value type is `
|
| 4284 |
|
| 4285 |
This section only describes operations on `unordered_multimap` that are
|
| 4286 |
not described in one of the requirement tables, or for which there is
|
| 4287 |
additional semantic information.
|
| 4288 |
|
| 4289 |
``` cpp
|
| 4290 |
namespace std {
|
| 4291 |
template <class Key,
|
| 4292 |
class T,
|
| 4293 |
class Hash = hash<Key>,
|
| 4294 |
-
class Pred
|
| 4295 |
-
class Allocator =
|
| 4296 |
-
class unordered_multimap
|
| 4297 |
-
{
|
| 4298 |
public:
|
| 4299 |
-
// types
|
| 4300 |
-
|
| 4301 |
-
|
| 4302 |
-
|
| 4303 |
-
|
| 4304 |
-
|
| 4305 |
-
|
| 4306 |
-
|
| 4307 |
-
|
| 4308 |
-
|
| 4309 |
-
|
| 4310 |
-
|
| 4311 |
-
|
| 4312 |
|
| 4313 |
-
|
| 4314 |
-
|
| 4315 |
-
|
| 4316 |
-
|
|
|
|
| 4317 |
|
| 4318 |
-
// construct/
|
| 4319 |
unordered_multimap();
|
| 4320 |
explicit unordered_multimap(size_type n,
|
| 4321 |
const hasher& hf = hasher(),
|
| 4322 |
const key_equal& eql = key_equal(),
|
| 4323 |
const allocator_type& a = allocator_type());
|
|
@@ -4330,12 +5195,12 @@ namespace std {
|
|
| 4330 |
unordered_multimap(const unordered_multimap&);
|
| 4331 |
unordered_multimap(unordered_multimap&&);
|
| 4332 |
explicit unordered_multimap(const Allocator&);
|
| 4333 |
unordered_multimap(const unordered_multimap&, const Allocator&);
|
| 4334 |
unordered_multimap(unordered_multimap&&, const Allocator&);
|
| 4335 |
-
unordered_multimap(initializer_list<value_type>,
|
| 4336 |
-
|
| 4337 |
const hasher& hf = hasher(),
|
| 4338 |
const key_equal& eql = key_equal(),
|
| 4339 |
const allocator_type& a = allocator_type());
|
| 4340 |
unordered_multimap(size_type n, const allocator_type& a)
|
| 4341 |
: unordered_multimap(n, hasher(), key_equal(), a) { }
|
|
@@ -4353,56 +5218,78 @@ namespace std {
|
|
| 4353 |
unordered_multimap(initializer_list<value_type> il, size_type n, const hasher& hf,
|
| 4354 |
const allocator_type& a)
|
| 4355 |
: unordered_multimap(il, n, hf, key_equal(), a) { }
|
| 4356 |
~unordered_multimap();
|
| 4357 |
unordered_multimap& operator=(const unordered_multimap&);
|
| 4358 |
-
unordered_multimap& operator=(unordered_multimap&&)
|
|
|
|
|
|
|
|
|
|
| 4359 |
unordered_multimap& operator=(initializer_list<value_type>);
|
| 4360 |
allocator_type get_allocator() const noexcept;
|
| 4361 |
|
| 4362 |
-
//
|
| 4363 |
-
bool empty() const noexcept;
|
| 4364 |
-
size_type size() const noexcept;
|
| 4365 |
-
size_type max_size() const noexcept;
|
| 4366 |
-
|
| 4367 |
-
// iterators
|
| 4368 |
iterator begin() noexcept;
|
| 4369 |
const_iterator begin() const noexcept;
|
| 4370 |
iterator end() noexcept;
|
| 4371 |
const_iterator end() const noexcept;
|
| 4372 |
const_iterator cbegin() const noexcept;
|
| 4373 |
const_iterator cend() const noexcept;
|
| 4374 |
|
| 4375 |
-
//
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 4376 |
template <class... Args> iterator emplace(Args&&... args);
|
| 4377 |
template <class... Args> iterator emplace_hint(const_iterator position, Args&&... args);
|
| 4378 |
iterator insert(const value_type& obj);
|
|
|
|
| 4379 |
template <class P> iterator insert(P&& obj);
|
| 4380 |
iterator insert(const_iterator hint, const value_type& obj);
|
|
|
|
| 4381 |
template <class P> iterator insert(const_iterator hint, P&& obj);
|
| 4382 |
template <class InputIterator> void insert(InputIterator first, InputIterator last);
|
| 4383 |
void insert(initializer_list<value_type>);
|
| 4384 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 4385 |
iterator erase(const_iterator position);
|
| 4386 |
size_type erase(const key_type& k);
|
| 4387 |
iterator erase(const_iterator first, const_iterator last);
|
|
|
|
|
|
|
|
|
|
|
|
|
| 4388 |
void clear() noexcept;
|
| 4389 |
|
| 4390 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 4391 |
|
| 4392 |
-
// observers
|
| 4393 |
hasher hash_function() const;
|
| 4394 |
key_equal key_eq() const;
|
| 4395 |
|
| 4396 |
-
//
|
| 4397 |
iterator find(const key_type& k);
|
| 4398 |
const_iterator find(const key_type& k) const;
|
| 4399 |
size_type count(const key_type& k) const;
|
| 4400 |
-
|
| 4401 |
-
|
| 4402 |
|
| 4403 |
-
// bucket interface
|
| 4404 |
size_type bucket_count() const noexcept;
|
| 4405 |
size_type max_bucket_count() const noexcept;
|
| 4406 |
size_type bucket_size(size_type n) const;
|
| 4407 |
size_type bucket(const key_type& k) const;
|
| 4408 |
local_iterator begin(size_type n);
|
|
@@ -4418,23 +5305,78 @@ namespace std {
|
|
| 4418 |
void max_load_factor(float z);
|
| 4419 |
void rehash(size_type n);
|
| 4420 |
void reserve(size_type n);
|
| 4421 |
};
|
| 4422 |
|
| 4423 |
-
template
|
| 4424 |
-
|
| 4425 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 4426 |
|
| 4427 |
template <class Key, class T, class Hash, class Pred, class Alloc>
|
| 4428 |
bool operator==(const unordered_multimap<Key, T, Hash, Pred, Alloc>& a,
|
| 4429 |
const unordered_multimap<Key, T, Hash, Pred, Alloc>& b);
|
| 4430 |
template <class Key, class T, class Hash, class Pred, class Alloc>
|
| 4431 |
bool operator!=(const unordered_multimap<Key, T, Hash, Pred, Alloc>& a,
|
| 4432 |
const unordered_multimap<Key, T, Hash, Pred, Alloc>& b);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 4433 |
}
|
| 4434 |
```
|
| 4435 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 4436 |
#### `unordered_multimap` constructors <a id="unord.multimap.cnstr">[[unord.multimap.cnstr]]</a>
|
| 4437 |
|
| 4438 |
``` cpp
|
| 4439 |
unordered_multimap() : unordered_multimap(size_type(see below)) { }
|
| 4440 |
explicit unordered_multimap(size_type n,
|
|
@@ -4442,65 +5384,72 @@ explicit unordered_multimap(size_type n,
|
|
| 4442 |
const key_equal& eql = key_equal(),
|
| 4443 |
const allocator_type& a = allocator_type());
|
| 4444 |
```
|
| 4445 |
|
| 4446 |
*Effects:* Constructs an empty `unordered_multimap` using the specified
|
| 4447 |
-
hash function, key equality
|
| 4448 |
-
|
| 4449 |
-
*implementation-defined*. `max_load_factor()` returns 1.0.
|
| 4450 |
|
| 4451 |
*Complexity:* Constant.
|
| 4452 |
|
| 4453 |
``` cpp
|
| 4454 |
template <class InputIterator>
|
| 4455 |
unordered_multimap(InputIterator f, InputIterator l,
|
| 4456 |
size_type n = see below,
|
| 4457 |
const hasher& hf = hasher(),
|
| 4458 |
const key_equal& eql = key_equal(),
|
| 4459 |
const allocator_type& a = allocator_type());
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 4460 |
```
|
| 4461 |
|
| 4462 |
*Effects:* Constructs an empty `unordered_multimap` using the specified
|
| 4463 |
-
hash function, key equality
|
| 4464 |
-
|
| 4465 |
-
*implementation-defined*. Then inserts elements from the range
|
| 4466 |
-
`
|
|
|
|
| 4467 |
|
| 4468 |
*Complexity:* Average case linear, worst case quadratic.
|
| 4469 |
|
| 4470 |
#### `unordered_multimap` modifiers <a id="unord.multimap.modifiers">[[unord.multimap.modifiers]]</a>
|
| 4471 |
|
| 4472 |
``` cpp
|
| 4473 |
template <class P>
|
| 4474 |
iterator insert(P&& obj);
|
| 4475 |
```
|
| 4476 |
|
| 4477 |
-
*Effects:* Equivalent to `return emplace(std::forward<P>(obj))`
|
| 4478 |
|
| 4479 |
*Remarks:* This signature shall not participate in overload resolution
|
| 4480 |
-
unless `
|
| 4481 |
|
| 4482 |
``` cpp
|
| 4483 |
template <class P>
|
| 4484 |
iterator insert(const_iterator hint, P&& obj);
|
| 4485 |
```
|
| 4486 |
|
| 4487 |
-
*Effects:* Equivalent to
|
| 4488 |
-
`return emplace_hint(hint, std::forward<P>(obj))`
|
| 4489 |
|
| 4490 |
*Remarks:* This signature shall not participate in overload resolution
|
| 4491 |
-
unless `
|
| 4492 |
|
| 4493 |
#### `unordered_multimap` swap <a id="unord.multimap.swap">[[unord.multimap.swap]]</a>
|
| 4494 |
|
| 4495 |
``` cpp
|
| 4496 |
template <class Key, class T, class Hash, class Pred, class Alloc>
|
| 4497 |
void swap(unordered_multimap<Key, T, Hash, Pred, Alloc>& x,
|
| 4498 |
-
unordered_multimap<Key, T, Hash, Pred, Alloc>& y)
|
|
|
|
| 4499 |
```
|
| 4500 |
|
| 4501 |
-
*Effects:* `x.swap(y)`.
|
| 4502 |
|
| 4503 |
### Class template `unordered_set` <a id="unord.set">[[unord.set]]</a>
|
| 4504 |
|
| 4505 |
#### Class template `unordered_set` overview <a id="unord.set.overview">[[unord.set.overview]]</a>
|
| 4506 |
|
|
@@ -4514,45 +5463,46 @@ an unordered associative container, and of an allocator-aware container
|
|
| 4514 |
(Table [[tab:containers.allocatoraware]]). It provides the operations
|
| 4515 |
described in the preceding requirements table for unique keys; that is,
|
| 4516 |
an `unordered_set` supports the `a_uniq` operations in that table, not
|
| 4517 |
the `a_eq` operations. For an `unordered_set<Key>` the `key type` and
|
| 4518 |
the value type are both `Key`. The `iterator` and `const_iterator` types
|
| 4519 |
-
are both
|
| 4520 |
same type.
|
| 4521 |
|
| 4522 |
This section only describes operations on `unordered_set` that are not
|
| 4523 |
described in one of the requirement tables, or for which there is
|
| 4524 |
additional semantic information.
|
| 4525 |
|
| 4526 |
``` cpp
|
| 4527 |
namespace std {
|
| 4528 |
template <class Key,
|
| 4529 |
class Hash = hash<Key>,
|
| 4530 |
-
class Pred
|
| 4531 |
-
class Allocator =
|
| 4532 |
-
class unordered_set
|
| 4533 |
-
{
|
| 4534 |
public:
|
| 4535 |
-
// types
|
| 4536 |
-
|
| 4537 |
-
|
| 4538 |
-
|
| 4539 |
-
|
| 4540 |
-
|
| 4541 |
-
|
| 4542 |
-
|
| 4543 |
-
|
| 4544 |
-
|
| 4545 |
-
|
| 4546 |
-
|
| 4547 |
|
| 4548 |
-
|
| 4549 |
-
|
| 4550 |
-
|
| 4551 |
-
|
|
|
|
|
|
|
| 4552 |
|
| 4553 |
-
// construct/
|
| 4554 |
unordered_set();
|
| 4555 |
explicit unordered_set(size_type n,
|
| 4556 |
const hasher& hf = hasher(),
|
| 4557 |
const key_equal& eql = key_equal(),
|
| 4558 |
const allocator_type& a = allocator_type());
|
|
@@ -4565,12 +5515,12 @@ namespace std {
|
|
| 4565 |
unordered_set(const unordered_set&);
|
| 4566 |
unordered_set(unordered_set&&);
|
| 4567 |
explicit unordered_set(const Allocator&);
|
| 4568 |
unordered_set(const unordered_set&, const Allocator&);
|
| 4569 |
unordered_set(unordered_set&&, const Allocator&);
|
| 4570 |
-
unordered_set(initializer_list<value_type>,
|
| 4571 |
-
|
| 4572 |
const hasher& hf = hasher(),
|
| 4573 |
const key_equal& eql = key_equal(),
|
| 4574 |
const allocator_type& a = allocator_type());
|
| 4575 |
unordered_set(size_type n, const allocator_type& a)
|
| 4576 |
: unordered_set(n, hasher(), key_equal(), a) { }
|
|
@@ -4588,56 +5538,76 @@ namespace std {
|
|
| 4588 |
unordered_set(initializer_list<value_type> il, size_type n, const hasher& hf,
|
| 4589 |
const allocator_type& a)
|
| 4590 |
: unordered_set(il, n, hf, key_equal(), a) { }
|
| 4591 |
~unordered_set();
|
| 4592 |
unordered_set& operator=(const unordered_set&);
|
| 4593 |
-
unordered_set& operator=(unordered_set&&)
|
|
|
|
|
|
|
|
|
|
| 4594 |
unordered_set& operator=(initializer_list<value_type>);
|
| 4595 |
allocator_type get_allocator() const noexcept;
|
| 4596 |
|
| 4597 |
-
//
|
| 4598 |
-
bool empty() const noexcept;
|
| 4599 |
-
size_type size() const noexcept;
|
| 4600 |
-
size_type max_size() const noexcept;
|
| 4601 |
-
|
| 4602 |
-
// iterators
|
| 4603 |
iterator begin() noexcept;
|
| 4604 |
const_iterator begin() const noexcept;
|
| 4605 |
iterator end() noexcept;
|
| 4606 |
const_iterator end() const noexcept;
|
| 4607 |
const_iterator cbegin() const noexcept;
|
| 4608 |
const_iterator cend() const noexcept;
|
| 4609 |
|
| 4610 |
-
//
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 4611 |
template <class... Args> pair<iterator, bool> emplace(Args&&... args);
|
| 4612 |
template <class... Args> iterator emplace_hint(const_iterator position, Args&&... args);
|
| 4613 |
pair<iterator, bool> insert(const value_type& obj);
|
| 4614 |
pair<iterator, bool> insert(value_type&& obj);
|
| 4615 |
iterator insert(const_iterator hint, const value_type& obj);
|
| 4616 |
iterator insert(const_iterator hint, value_type&& obj);
|
| 4617 |
template <class InputIterator> void insert(InputIterator first, InputIterator last);
|
| 4618 |
void insert(initializer_list<value_type>);
|
| 4619 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 4620 |
iterator erase(const_iterator position);
|
| 4621 |
size_type erase(const key_type& k);
|
| 4622 |
iterator erase(const_iterator first, const_iterator last);
|
|
|
|
|
|
|
|
|
|
|
|
|
| 4623 |
void clear() noexcept;
|
| 4624 |
|
| 4625 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 4626 |
|
| 4627 |
-
// observers
|
| 4628 |
hasher hash_function() const;
|
| 4629 |
key_equal key_eq() const;
|
| 4630 |
|
| 4631 |
-
//
|
| 4632 |
iterator find(const key_type& k);
|
| 4633 |
const_iterator find(const key_type& k) const;
|
| 4634 |
size_type count(const key_type& k) const;
|
| 4635 |
-
|
| 4636 |
-
|
| 4637 |
|
| 4638 |
-
// bucket interface
|
| 4639 |
size_type bucket_count() const noexcept;
|
| 4640 |
size_type max_bucket_count() const noexcept;
|
| 4641 |
size_type bucket_size(size_type n) const;
|
| 4642 |
size_type bucket(const key_type& k) const;
|
| 4643 |
local_iterator begin(size_type n);
|
|
@@ -4645,31 +5615,74 @@ namespace std {
|
|
| 4645 |
local_iterator end(size_type n);
|
| 4646 |
const_local_iterator end(size_type n) const;
|
| 4647 |
const_local_iterator cbegin(size_type n) const;
|
| 4648 |
const_local_iterator cend(size_type n) const;
|
| 4649 |
|
| 4650 |
-
// hash policy
|
| 4651 |
float load_factor() const noexcept;
|
| 4652 |
float max_load_factor() const noexcept;
|
| 4653 |
void max_load_factor(float z);
|
| 4654 |
void rehash(size_type n);
|
| 4655 |
void reserve(size_type n);
|
| 4656 |
};
|
| 4657 |
|
| 4658 |
-
template
|
| 4659 |
-
|
| 4660 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 4661 |
|
| 4662 |
template <class Key, class Hash, class Pred, class Alloc>
|
| 4663 |
bool operator==(const unordered_set<Key, Hash, Pred, Alloc>& a,
|
| 4664 |
const unordered_set<Key, Hash, Pred, Alloc>& b);
|
| 4665 |
template <class Key, class Hash, class Pred, class Alloc>
|
| 4666 |
bool operator!=(const unordered_set<Key, Hash, Pred, Alloc>& a,
|
| 4667 |
const unordered_set<Key, Hash, Pred, Alloc>& b);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 4668 |
}
|
| 4669 |
```
|
| 4670 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 4671 |
#### `unordered_set` constructors <a id="unord.set.cnstr">[[unord.set.cnstr]]</a>
|
| 4672 |
|
| 4673 |
``` cpp
|
| 4674 |
unordered_set() : unordered_set(size_type(see below)) { }
|
| 4675 |
explicit unordered_set(size_type n,
|
|
@@ -4677,42 +5690,49 @@ explicit unordered_set(size_type n,
|
|
| 4677 |
const key_equal& eql = key_equal(),
|
| 4678 |
const allocator_type& a = allocator_type());
|
| 4679 |
```
|
| 4680 |
|
| 4681 |
*Effects:* Constructs an empty `unordered_set` using the specified hash
|
| 4682 |
-
function, key equality
|
| 4683 |
buckets. For the default constructor, the number of buckets is
|
| 4684 |
-
*implementation-defined*. `max_load_factor()` returns 1.0.
|
| 4685 |
|
| 4686 |
*Complexity:* Constant.
|
| 4687 |
|
| 4688 |
``` cpp
|
| 4689 |
template <class InputIterator>
|
| 4690 |
unordered_set(InputIterator f, InputIterator l,
|
| 4691 |
size_type n = see below,
|
| 4692 |
const hasher& hf = hasher(),
|
| 4693 |
const key_equal& eql = key_equal(),
|
| 4694 |
const allocator_type& a = allocator_type());
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 4695 |
```
|
| 4696 |
|
| 4697 |
*Effects:* Constructs an empty `unordered_set` using the specified hash
|
| 4698 |
-
function, key equality
|
| 4699 |
-
buckets. If
|
| 4700 |
-
*implementation-defined*. Then inserts elements from the range
|
| 4701 |
-
`
|
|
|
|
| 4702 |
|
| 4703 |
*Complexity:* Average case linear, worst case quadratic.
|
| 4704 |
|
| 4705 |
#### `unordered_set` swap <a id="unord.set.swap">[[unord.set.swap]]</a>
|
| 4706 |
|
| 4707 |
``` cpp
|
| 4708 |
template <class Key, class Hash, class Pred, class Alloc>
|
| 4709 |
void swap(unordered_set<Key, Hash, Pred, Alloc>& x,
|
| 4710 |
-
unordered_set<Key, Hash, Pred, Alloc>& y)
|
|
|
|
| 4711 |
```
|
| 4712 |
|
| 4713 |
-
*Effects:* `x.swap(y)`.
|
| 4714 |
|
| 4715 |
### Class template `unordered_multiset` <a id="unord.multiset">[[unord.multiset]]</a>
|
| 4716 |
|
| 4717 |
#### Class template `unordered_multiset` overview <a id="unord.multiset.overview">[[unord.multiset.overview]]</a>
|
| 4718 |
|
|
@@ -4727,45 +5747,45 @@ container, of an unordered associative container, and of an
|
|
| 4727 |
allocator-aware container (Table [[tab:containers.allocatoraware]]). It
|
| 4728 |
provides the operations described in the preceding requirements table
|
| 4729 |
for equivalent keys; that is, an `unordered_multiset` supports the
|
| 4730 |
`a_eq` operations in that table, not the `a_uniq` operations. For an
|
| 4731 |
`unordered_multiset<Key>` the `key type` and the value type are both
|
| 4732 |
-
`Key`. The `iterator` and `const_iterator` types are both
|
| 4733 |
-
types. It is unspecified whether they are the same type.
|
| 4734 |
|
| 4735 |
This section only describes operations on `unordered_multiset` that are
|
| 4736 |
not described in one of the requirement tables, or for which there is
|
| 4737 |
additional semantic information.
|
| 4738 |
|
| 4739 |
``` cpp
|
| 4740 |
namespace std {
|
| 4741 |
template <class Key,
|
| 4742 |
class Hash = hash<Key>,
|
| 4743 |
-
class Pred
|
| 4744 |
-
class Allocator =
|
| 4745 |
-
class unordered_multiset
|
| 4746 |
-
{
|
| 4747 |
public:
|
| 4748 |
-
// types
|
| 4749 |
-
|
| 4750 |
-
|
| 4751 |
-
|
| 4752 |
-
|
| 4753 |
-
|
| 4754 |
-
|
| 4755 |
-
|
| 4756 |
-
|
| 4757 |
-
|
| 4758 |
-
|
| 4759 |
-
|
| 4760 |
|
| 4761 |
-
|
| 4762 |
-
|
| 4763 |
-
|
| 4764 |
-
|
|
|
|
| 4765 |
|
| 4766 |
-
// construct/
|
| 4767 |
unordered_multiset();
|
| 4768 |
explicit unordered_multiset(size_type n,
|
| 4769 |
const hasher& hf = hasher(),
|
| 4770 |
const key_equal& eql = key_equal(),
|
| 4771 |
const allocator_type& a = allocator_type());
|
|
@@ -4778,12 +5798,12 @@ namespace std {
|
|
| 4778 |
unordered_multiset(const unordered_multiset&);
|
| 4779 |
unordered_multiset(unordered_multiset&&);
|
| 4780 |
explicit unordered_multiset(const Allocator&);
|
| 4781 |
unordered_multiset(const unordered_multiset&, const Allocator&);
|
| 4782 |
unordered_multiset(unordered_multiset&&, const Allocator&);
|
| 4783 |
-
unordered_multiset(initializer_list<value_type>,
|
| 4784 |
-
|
| 4785 |
const hasher& hf = hasher(),
|
| 4786 |
const key_equal& eql = key_equal(),
|
| 4787 |
const allocator_type& a = allocator_type());
|
| 4788 |
unordered_multiset(size_type n, const allocator_type& a)
|
| 4789 |
: unordered_multiset(n, hasher(), key_equal(), a) { }
|
|
@@ -4801,56 +5821,76 @@ namespace std {
|
|
| 4801 |
unordered_multiset(initializer_list<value_type> il, size_type n, const hasher& hf,
|
| 4802 |
const allocator_type& a)
|
| 4803 |
: unordered_multiset(il, n, hf, key_equal(), a) { }
|
| 4804 |
~unordered_multiset();
|
| 4805 |
unordered_multiset& operator=(const unordered_multiset&);
|
| 4806 |
-
unordered_multiset& operator=(unordered_multiset&&)
|
|
|
|
|
|
|
|
|
|
| 4807 |
unordered_multiset& operator=(initializer_list<value_type>);
|
| 4808 |
allocator_type get_allocator() const noexcept;
|
| 4809 |
|
| 4810 |
-
//
|
| 4811 |
-
bool empty() const noexcept;
|
| 4812 |
-
size_type size() const noexcept;
|
| 4813 |
-
size_type max_size() const noexcept;
|
| 4814 |
-
|
| 4815 |
-
// iterators
|
| 4816 |
iterator begin() noexcept;
|
| 4817 |
const_iterator begin() const noexcept;
|
| 4818 |
iterator end() noexcept;
|
| 4819 |
const_iterator end() const noexcept;
|
| 4820 |
const_iterator cbegin() const noexcept;
|
| 4821 |
const_iterator cend() const noexcept;
|
| 4822 |
|
| 4823 |
-
//
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 4824 |
template <class... Args> iterator emplace(Args&&... args);
|
| 4825 |
template <class... Args> iterator emplace_hint(const_iterator position, Args&&... args);
|
| 4826 |
iterator insert(const value_type& obj);
|
| 4827 |
iterator insert(value_type&& obj);
|
| 4828 |
iterator insert(const_iterator hint, const value_type& obj);
|
| 4829 |
iterator insert(const_iterator hint, value_type&& obj);
|
| 4830 |
template <class InputIterator> void insert(InputIterator first, InputIterator last);
|
| 4831 |
void insert(initializer_list<value_type>);
|
| 4832 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 4833 |
iterator erase(const_iterator position);
|
| 4834 |
size_type erase(const key_type& k);
|
| 4835 |
iterator erase(const_iterator first, const_iterator last);
|
|
|
|
|
|
|
|
|
|
|
|
|
| 4836 |
void clear() noexcept;
|
| 4837 |
|
| 4838 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 4839 |
|
| 4840 |
-
// observers
|
| 4841 |
hasher hash_function() const;
|
| 4842 |
key_equal key_eq() const;
|
| 4843 |
|
| 4844 |
-
//
|
| 4845 |
iterator find(const key_type& k);
|
| 4846 |
const_iterator find(const key_type& k) const;
|
| 4847 |
size_type count(const key_type& k) const;
|
| 4848 |
-
|
| 4849 |
-
|
| 4850 |
|
| 4851 |
-
// bucket interface
|
| 4852 |
size_type bucket_count() const noexcept;
|
| 4853 |
size_type max_bucket_count() const noexcept;
|
| 4854 |
size_type bucket_size(size_type n) const;
|
| 4855 |
size_type bucket(const key_type& k) const;
|
| 4856 |
local_iterator begin(size_type n);
|
|
@@ -4858,30 +5898,74 @@ namespace std {
|
|
| 4858 |
local_iterator end(size_type n);
|
| 4859 |
const_local_iterator end(size_type n) const;
|
| 4860 |
const_local_iterator cbegin(size_type n) const;
|
| 4861 |
const_local_iterator cend(size_type n) const;
|
| 4862 |
|
| 4863 |
-
// hash policy
|
| 4864 |
float load_factor() const noexcept;
|
| 4865 |
float max_load_factor() const noexcept;
|
| 4866 |
void max_load_factor(float z);
|
| 4867 |
void rehash(size_type n);
|
| 4868 |
void reserve(size_type n);
|
| 4869 |
};
|
| 4870 |
|
| 4871 |
-
template
|
| 4872 |
-
|
| 4873 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 4874 |
template <class Key, class Hash, class Pred, class Alloc>
|
| 4875 |
bool operator==(const unordered_multiset<Key, Hash, Pred, Alloc>& a,
|
| 4876 |
const unordered_multiset<Key, Hash, Pred, Alloc>& b);
|
| 4877 |
template <class Key, class Hash, class Pred, class Alloc>
|
| 4878 |
bool operator!=(const unordered_multiset<Key, Hash, Pred, Alloc>& a,
|
| 4879 |
const unordered_multiset<Key, Hash, Pred, Alloc>& b);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 4880 |
}
|
| 4881 |
```
|
| 4882 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 4883 |
#### `unordered_multiset` constructors <a id="unord.multiset.cnstr">[[unord.multiset.cnstr]]</a>
|
| 4884 |
|
| 4885 |
``` cpp
|
| 4886 |
unordered_multiset() : unordered_multiset(size_type(see below)) { }
|
| 4887 |
explicit unordered_multiset(size_type n,
|
|
@@ -4889,42 +5973,49 @@ explicit unordered_multiset(size_type n,
|
|
| 4889 |
const key_equal& eql = key_equal(),
|
| 4890 |
const allocator_type& a = allocator_type());
|
| 4891 |
```
|
| 4892 |
|
| 4893 |
*Effects:* Constructs an empty `unordered_multiset` using the specified
|
| 4894 |
-
hash function, key equality
|
| 4895 |
-
|
| 4896 |
-
*implementation-defined*. `max_load_factor()` returns 1.0.
|
| 4897 |
|
| 4898 |
*Complexity:* Constant.
|
| 4899 |
|
| 4900 |
``` cpp
|
| 4901 |
template <class InputIterator>
|
| 4902 |
unordered_multiset(InputIterator f, InputIterator l,
|
| 4903 |
size_type n = see below,
|
| 4904 |
const hasher& hf = hasher(),
|
| 4905 |
const key_equal& eql = key_equal(),
|
| 4906 |
const allocator_type& a = allocator_type());
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 4907 |
```
|
| 4908 |
|
| 4909 |
*Effects:* Constructs an empty `unordered_multiset` using the specified
|
| 4910 |
-
hash function, key equality
|
| 4911 |
-
|
| 4912 |
-
*implementation-defined*. Then inserts elements from the range
|
| 4913 |
-
`
|
|
|
|
| 4914 |
|
| 4915 |
*Complexity:* Average case linear, worst case quadratic.
|
| 4916 |
|
| 4917 |
#### `unordered_multiset` swap <a id="unord.multiset.swap">[[unord.multiset.swap]]</a>
|
| 4918 |
|
| 4919 |
``` cpp
|
| 4920 |
template <class Key, class Hash, class Pred, class Alloc>
|
| 4921 |
void swap(unordered_multiset<Key, Hash, Pred, Alloc>& x,
|
| 4922 |
-
unordered_multiset<Key, Hash, Pred, Alloc>& y)
|
|
|
|
| 4923 |
```
|
| 4924 |
|
| 4925 |
-
*Effects:* `x.swap(y)
|
| 4926 |
|
| 4927 |
## Container adaptors <a id="container.adaptors">[[container.adaptors]]</a>
|
| 4928 |
|
| 4929 |
### In general <a id="container.adaptors.general">[[container.adaptors.general]]</a>
|
| 4930 |
|
|
@@ -4934,23 +6025,38 @@ The headers `<queue>` and `<stack>` define the container adaptors
|
|
| 4934 |
The container adaptors each take a `Container` template parameter, and
|
| 4935 |
each constructor takes a `Container` reference argument. This container
|
| 4936 |
is copied into the `Container` member of each adaptor. If the container
|
| 4937 |
takes an allocator, then a compatible allocator may be passed in to the
|
| 4938 |
adaptor’s constructor. Otherwise, normal copy or move construction is
|
| 4939 |
-
used for the container argument.
|
|
|
|
|
|
|
| 4940 |
|
| 4941 |
For container adaptors, no `swap` function throws an exception unless
|
| 4942 |
that exception is thrown by the swap of the adaptor’s `Container` or
|
| 4943 |
`Compare` object (if any).
|
| 4944 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 4945 |
### Header `<queue>` synopsis <a id="queue.syn">[[queue.syn]]</a>
|
| 4946 |
|
| 4947 |
``` cpp
|
| 4948 |
#include <initializer_list>
|
| 4949 |
|
| 4950 |
namespace std {
|
| 4951 |
-
|
| 4952 |
template <class T, class Container = deque<T>> class queue;
|
| 4953 |
template <class T, class Container = vector<T>,
|
| 4954 |
class Compare = less<typename Container::value_type>>
|
| 4955 |
class priority_queue;
|
| 4956 |
|
|
@@ -4973,10 +6079,34 @@ namespace std {
|
|
| 4973 |
void swap(priority_queue<T, Container, Compare>& x,
|
| 4974 |
priority_queue<T, Container, Compare>& y) noexcept(noexcept(x.swap(y)));
|
| 4975 |
}
|
| 4976 |
```
|
| 4977 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 4978 |
### Class template `queue` <a id="queue">[[queue]]</a>
|
| 4979 |
|
| 4980 |
#### `queue` definition <a id="queue.defn">[[queue.defn]]</a>
|
| 4981 |
|
| 4982 |
Any sequence container supporting operations `front()`, `back()`,
|
|
@@ -4986,15 +6116,16 @@ particular, `list` ([[list]]) and `deque` ([[deque]]) can be used.
|
|
| 4986 |
``` cpp
|
| 4987 |
namespace std {
|
| 4988 |
template <class T, class Container = deque<T>>
|
| 4989 |
class queue {
|
| 4990 |
public:
|
| 4991 |
-
|
| 4992 |
-
|
| 4993 |
-
|
| 4994 |
-
|
| 4995 |
-
|
|
|
|
| 4996 |
protected:
|
| 4997 |
Container c;
|
| 4998 |
|
| 4999 |
public:
|
| 5000 |
explicit queue(const Container&);
|
|
@@ -5011,17 +6142,23 @@ namespace std {
|
|
| 5011 |
const_reference front() const { return c.front(); }
|
| 5012 |
reference back() { return c.back(); }
|
| 5013 |
const_reference back() const { return c.back(); }
|
| 5014 |
void push(const value_type& x) { c.push_back(x); }
|
| 5015 |
void push(value_type&& x) { c.push_back(std::move(x)); }
|
| 5016 |
-
template <class... Args>
|
| 5017 |
-
{ c.emplace_back(std::forward<Args>(args)...); }
|
| 5018 |
void pop() { c.pop_front(); }
|
| 5019 |
-
void swap(queue& q) noexcept(
|
| 5020 |
{ using std::swap; swap(c, q.c); }
|
| 5021 |
};
|
| 5022 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 5023 |
template <class T, class Container>
|
| 5024 |
bool operator==(const queue<T, Container>& x, const queue<T, Container>& y);
|
| 5025 |
template <class T, class Container>
|
| 5026 |
bool operator< (const queue<T, Container>& x, const queue<T, Container>& y);
|
| 5027 |
template <class T, class Container>
|
|
@@ -5056,91 +6193,80 @@ explicit queue(Container&& cont = Container());
|
|
| 5056 |
|
| 5057 |
*Effects:* Initializes `c` with `std::move(cont)`.
|
| 5058 |
|
| 5059 |
#### `queue` constructors with allocators <a id="queue.cons.alloc">[[queue.cons.alloc]]</a>
|
| 5060 |
|
| 5061 |
-
If `
|
| 5062 |
-
|
| 5063 |
-
resolution.
|
| 5064 |
|
| 5065 |
``` cpp
|
| 5066 |
-
template <class Alloc>
|
| 5067 |
-
explicit queue(const Alloc& a);
|
| 5068 |
```
|
| 5069 |
|
| 5070 |
*Effects:* Initializes `c` with `a`.
|
| 5071 |
|
| 5072 |
``` cpp
|
| 5073 |
-
template <class Alloc>
|
| 5074 |
-
queue(const container_type& cont, const Alloc& a);
|
| 5075 |
```
|
| 5076 |
|
| 5077 |
*Effects:* Initializes `c` with `cont` as the first argument and `a` as
|
| 5078 |
the second argument.
|
| 5079 |
|
| 5080 |
``` cpp
|
| 5081 |
-
template <class Alloc>
|
| 5082 |
-
queue(container_type&& cont, const Alloc& a);
|
| 5083 |
```
|
| 5084 |
|
| 5085 |
*Effects:* Initializes `c` with `std::move(cont)` as the first argument
|
| 5086 |
and `a` as the second argument.
|
| 5087 |
|
| 5088 |
``` cpp
|
| 5089 |
-
template <class Alloc>
|
| 5090 |
-
queue(const queue& q, const Alloc& a);
|
| 5091 |
```
|
| 5092 |
|
| 5093 |
*Effects:* Initializes `c` with `q.c` as the first argument and `a` as
|
| 5094 |
the second argument.
|
| 5095 |
|
| 5096 |
``` cpp
|
| 5097 |
-
template <class Alloc>
|
| 5098 |
-
queue(queue&& q, const Alloc& a);
|
| 5099 |
```
|
| 5100 |
|
| 5101 |
*Effects:* Initializes `c` with `std::move(q.c)` as the first argument
|
| 5102 |
and `a` as the second argument.
|
| 5103 |
|
| 5104 |
#### `queue` operators <a id="queue.ops">[[queue.ops]]</a>
|
| 5105 |
|
| 5106 |
``` cpp
|
| 5107 |
template <class T, class Container>
|
| 5108 |
-
|
| 5109 |
-
const queue<T, Container>& y);
|
| 5110 |
```
|
| 5111 |
|
| 5112 |
*Returns:* `x.c == y.c`.
|
| 5113 |
|
| 5114 |
``` cpp
|
| 5115 |
template <class T, class Container>
|
| 5116 |
-
|
| 5117 |
-
const queue<T, Container>& y);
|
| 5118 |
```
|
| 5119 |
|
| 5120 |
*Returns:* `x.c != y.c`.
|
| 5121 |
|
| 5122 |
``` cpp
|
| 5123 |
template <class T, class Container>
|
| 5124 |
-
|
| 5125 |
-
const queue<T, Container>& y);
|
| 5126 |
```
|
| 5127 |
|
| 5128 |
*Returns:* `x.c < y.c`.
|
| 5129 |
|
| 5130 |
``` cpp
|
| 5131 |
template <class T, class Container>
|
| 5132 |
-
|
| 5133 |
-
const queue<T, Container>& y);
|
| 5134 |
```
|
| 5135 |
|
| 5136 |
*Returns:* `x.c <= y.c`.
|
| 5137 |
|
| 5138 |
``` cpp
|
| 5139 |
template <class T, class Container>
|
| 5140 |
-
|
| 5141 |
-
const queue<T, Container>& y);
|
| 5142 |
```
|
| 5143 |
|
| 5144 |
*Returns:* `x.c > y.c`.
|
| 5145 |
|
| 5146 |
``` cpp
|
|
@@ -5156,11 +6282,14 @@ template <class T, class Container>
|
|
| 5156 |
``` cpp
|
| 5157 |
template <class T, class Container>
|
| 5158 |
void swap(queue<T, Container>& x, queue<T, Container>& y) noexcept(noexcept(x.swap(y)));
|
| 5159 |
```
|
| 5160 |
|
| 5161 |
-
*
|
|
|
|
|
|
|
|
|
|
| 5162 |
|
| 5163 |
### Class template `priority_queue` <a id="priority.queue">[[priority.queue]]</a>
|
| 5164 |
|
| 5165 |
Any sequence container with random access iterator and supporting
|
| 5166 |
operations `front()`, `push_back()` and `pop_back()` can be used to
|
|
@@ -5174,15 +6303,17 @@ defines a strict weak ordering ([[alg.sorting]]).
|
|
| 5174 |
namespace std {
|
| 5175 |
template <class T, class Container = vector<T>,
|
| 5176 |
class Compare = less<typename Container::value_type>>
|
| 5177 |
class priority_queue {
|
| 5178 |
public:
|
| 5179 |
-
|
| 5180 |
-
|
| 5181 |
-
|
| 5182 |
-
|
| 5183 |
-
|
|
|
|
|
|
|
| 5184 |
protected:
|
| 5185 |
Container c;
|
| 5186 |
Compare comp;
|
| 5187 |
|
| 5188 |
public:
|
|
@@ -5194,29 +6325,43 @@ namespace std {
|
|
| 5194 |
template <class InputIterator>
|
| 5195 |
priority_queue(InputIterator first, InputIterator last,
|
| 5196 |
const Compare& x = Compare(), Container&& = Container());
|
| 5197 |
template <class Alloc> explicit priority_queue(const Alloc&);
|
| 5198 |
template <class Alloc> priority_queue(const Compare&, const Alloc&);
|
| 5199 |
-
template <class Alloc> priority_queue(const Compare&,
|
| 5200 |
-
|
| 5201 |
-
template <class Alloc> priority_queue(const Compare&,
|
| 5202 |
-
Container&&, const Alloc&);
|
| 5203 |
template <class Alloc> priority_queue(const priority_queue&, const Alloc&);
|
| 5204 |
template <class Alloc> priority_queue(priority_queue&&, const Alloc&);
|
| 5205 |
|
| 5206 |
bool empty() const { return c.empty(); }
|
| 5207 |
size_type size() const { return c.size(); }
|
| 5208 |
const_reference top() const { return c.front(); }
|
| 5209 |
void push(const value_type& x);
|
| 5210 |
void push(value_type&& x);
|
| 5211 |
template <class... Args> void emplace(Args&&... args);
|
| 5212 |
void pop();
|
| 5213 |
-
void swap(priority_queue& q) noexcept(
|
| 5214 |
-
|
| 5215 |
{ using std::swap; swap(c, q.c); swap(comp, q.comp); }
|
| 5216 |
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 5217 |
// no equality is provided
|
|
|
|
| 5218 |
template <class T, class Container, class Compare>
|
| 5219 |
void swap(priority_queue<T, Container, Compare>& x,
|
| 5220 |
priority_queue<T, Container, Compare>& y) noexcept(noexcept(x.swap(y)));
|
| 5221 |
|
| 5222 |
template <class T, class Container, class Compare, class Alloc>
|
|
@@ -5226,14 +6371,12 @@ namespace std {
|
|
| 5226 |
```
|
| 5227 |
|
| 5228 |
#### `priority_queue` constructors <a id="priqueue.cons">[[priqueue.cons]]</a>
|
| 5229 |
|
| 5230 |
``` cpp
|
| 5231 |
-
priority_queue(const Compare& x,
|
| 5232 |
-
|
| 5233 |
-
explicit priority_queue(const Compare& x = Compare(),
|
| 5234 |
-
Container&& y = Container());
|
| 5235 |
```
|
| 5236 |
|
| 5237 |
*Requires:* `x` shall define a strict weak ordering ([[alg.sorting]]).
|
| 5238 |
|
| 5239 |
*Effects:* Initializes `comp` with `x` and `c` with `y` (copy
|
|
@@ -5258,24 +6401,21 @@ constructing or move constructing as appropriate); calls
|
|
| 5258 |
`c.insert(c.end(), first, last)`; and finally calls
|
| 5259 |
`make_heap(c.begin(), c.end(), comp)`.
|
| 5260 |
|
| 5261 |
#### `priority_queue` constructors with allocators <a id="priqueue.cons.alloc">[[priqueue.cons.alloc]]</a>
|
| 5262 |
|
| 5263 |
-
If `
|
| 5264 |
-
|
| 5265 |
-
resolution.
|
| 5266 |
|
| 5267 |
``` cpp
|
| 5268 |
-
template <class Alloc>
|
| 5269 |
-
explicit priority_queue(const Alloc& a);
|
| 5270 |
```
|
| 5271 |
|
| 5272 |
*Effects:* Initializes `c` with `a` and value-initializes `comp`.
|
| 5273 |
|
| 5274 |
``` cpp
|
| 5275 |
-
template <class Alloc>
|
| 5276 |
-
priority_queue(const Compare& compare, const Alloc& a);
|
| 5277 |
```
|
| 5278 |
|
| 5279 |
*Effects:* Initializes `c` with `a` and initializes `comp` with
|
| 5280 |
`compare`.
|
| 5281 |
|
|
@@ -5283,31 +6423,31 @@ template <class Alloc>
|
|
| 5283 |
template <class Alloc>
|
| 5284 |
priority_queue(const Compare& compare, const Container& cont, const Alloc& a);
|
| 5285 |
```
|
| 5286 |
|
| 5287 |
*Effects:* Initializes `c` with `cont` as the first argument and `a` as
|
| 5288 |
-
the second argument, and initializes `comp` with `compare`
|
|
|
|
| 5289 |
|
| 5290 |
``` cpp
|
| 5291 |
template <class Alloc>
|
| 5292 |
priority_queue(const Compare& compare, Container&& cont, const Alloc& a);
|
| 5293 |
```
|
| 5294 |
|
| 5295 |
*Effects:* Initializes `c` with `std::move(cont)` as the first argument
|
| 5296 |
-
and `a` as the second argument, and initializes `comp` with `compare`
|
|
|
|
| 5297 |
|
| 5298 |
``` cpp
|
| 5299 |
-
template <class Alloc>
|
| 5300 |
-
priority_queue(const priority_queue& q, const Alloc& a);
|
| 5301 |
```
|
| 5302 |
|
| 5303 |
*Effects:* Initializes `c` with `q.c` as the first argument and `a` as
|
| 5304 |
the second argument, and initializes `comp` with `q.comp`.
|
| 5305 |
|
| 5306 |
``` cpp
|
| 5307 |
-
template <class Alloc>
|
| 5308 |
-
priority_queue(priority_queue&& q, const Alloc& a);
|
| 5309 |
```
|
| 5310 |
|
| 5311 |
*Effects:* Initializes `c` with `std::move(q.c)` as the first argument
|
| 5312 |
and `a` as the second argument, and initializes `comp` with
|
| 5313 |
`std::move(q.comp)`.
|
|
@@ -5316,104 +6456,84 @@ and `a` as the second argument, and initializes `comp` with
|
|
| 5316 |
|
| 5317 |
``` cpp
|
| 5318 |
void push(const value_type& x);
|
| 5319 |
```
|
| 5320 |
|
| 5321 |
-
*Effects:*
|
| 5322 |
|
| 5323 |
``` cpp
|
| 5324 |
c.push_back(x);
|
| 5325 |
push_heap(c.begin(), c.end(), comp);
|
| 5326 |
```
|
| 5327 |
|
| 5328 |
``` cpp
|
| 5329 |
void push(value_type&& x);
|
| 5330 |
```
|
| 5331 |
|
| 5332 |
-
*Effects:*
|
| 5333 |
|
| 5334 |
``` cpp
|
| 5335 |
c.push_back(std::move(x));
|
| 5336 |
push_heap(c.begin(), c.end(), comp);
|
| 5337 |
```
|
| 5338 |
|
| 5339 |
``` cpp
|
| 5340 |
template <class... Args> void emplace(Args&&... args)
|
| 5341 |
```
|
| 5342 |
|
| 5343 |
-
*Effects:*
|
| 5344 |
|
| 5345 |
``` cpp
|
| 5346 |
c.emplace_back(std::forward<Args>(args)...);
|
| 5347 |
push_heap(c.begin(), c.end(), comp);
|
| 5348 |
```
|
| 5349 |
|
| 5350 |
``` cpp
|
| 5351 |
void pop();
|
| 5352 |
```
|
| 5353 |
|
| 5354 |
-
*Effects:*
|
| 5355 |
|
| 5356 |
``` cpp
|
| 5357 |
pop_heap(c.begin(), c.end(), comp);
|
| 5358 |
c.pop_back();
|
| 5359 |
```
|
| 5360 |
|
| 5361 |
#### `priority_queue` specialized algorithms <a id="priqueue.special">[[priqueue.special]]</a>
|
| 5362 |
|
| 5363 |
``` cpp
|
| 5364 |
-
template <class T, class Container, Compare>
|
| 5365 |
void swap(priority_queue<T, Container, Compare>& x,
|
| 5366 |
priority_queue<T, Container, Compare>& y) noexcept(noexcept(x.swap(y)));
|
| 5367 |
```
|
| 5368 |
|
| 5369 |
-
*
|
|
|
|
|
|
|
|
|
|
|
|
|
| 5370 |
|
| 5371 |
### Class template `stack` <a id="stack">[[stack]]</a>
|
| 5372 |
|
| 5373 |
Any sequence container supporting operations `back()`, `push_back()` and
|
| 5374 |
`pop_back()` can be used to instantiate `stack`. In particular,
|
| 5375 |
`vector` ([[vector]]), `list` ([[list]]) and `deque` ([[deque]]) can
|
| 5376 |
be used.
|
| 5377 |
|
| 5378 |
-
#### Header `<stack>` synopsis <a id="stack.syn">[[stack.syn]]</a>
|
| 5379 |
-
|
| 5380 |
-
``` cpp
|
| 5381 |
-
#include <initializer_list>
|
| 5382 |
-
|
| 5383 |
-
namespace std {
|
| 5384 |
-
|
| 5385 |
-
template <class T, class Container = deque<T> > class stack;
|
| 5386 |
-
template <class T, class Container>
|
| 5387 |
-
bool operator==(const stack<T, Container>& x,const stack<T, Container>& y);
|
| 5388 |
-
template <class T, class Container>
|
| 5389 |
-
bool operator< (const stack<T, Container>& x,const stack<T, Container>& y);
|
| 5390 |
-
template <class T, class Container>
|
| 5391 |
-
bool operator!=(const stack<T, Container>& x,const stack<T, Container>& y);
|
| 5392 |
-
template <class T, class Container>
|
| 5393 |
-
bool operator> (const stack<T, Container>& x,const stack<T, Container>& y);
|
| 5394 |
-
template <class T, class Container>
|
| 5395 |
-
bool operator>=(const stack<T, Container>& x,const stack<T, Container>& y);
|
| 5396 |
-
template <class T, class Container>
|
| 5397 |
-
bool operator<=(const stack<T, Container>& x,const stack<T, Container>& y);
|
| 5398 |
-
template <class T, class Container>
|
| 5399 |
-
void swap(stack<T, Container>& x, stack<T, Container>& y) noexcept(noexcept(x.swap(y)));
|
| 5400 |
-
}
|
| 5401 |
-
```
|
| 5402 |
-
|
| 5403 |
#### `stack` definition <a id="stack.defn">[[stack.defn]]</a>
|
| 5404 |
|
| 5405 |
``` cpp
|
| 5406 |
namespace std {
|
| 5407 |
template <class T, class Container = deque<T>>
|
| 5408 |
class stack {
|
| 5409 |
public:
|
| 5410 |
-
|
| 5411 |
-
|
| 5412 |
-
|
| 5413 |
-
|
| 5414 |
-
|
|
|
|
| 5415 |
protected:
|
| 5416 |
Container c;
|
| 5417 |
|
| 5418 |
public:
|
| 5419 |
explicit stack(const Container&);
|
|
@@ -5428,17 +6548,23 @@ namespace std {
|
|
| 5428 |
size_type size() const { return c.size(); }
|
| 5429 |
reference top() { return c.back(); }
|
| 5430 |
const_reference top() const { return c.back(); }
|
| 5431 |
void push(const value_type& x) { c.push_back(x); }
|
| 5432 |
void push(value_type&& x) { c.push_back(std::move(x)); }
|
| 5433 |
-
template <class... Args>
|
| 5434 |
-
{ c.emplace_back(std::forward<Args>(args)...); }
|
| 5435 |
void pop() { c.pop_back(); }
|
| 5436 |
-
void swap(stack& s) noexcept(
|
| 5437 |
{ using std::swap; swap(c, s.c); }
|
| 5438 |
};
|
| 5439 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 5440 |
template <class T, class Container>
|
| 5441 |
bool operator==(const stack<T, Container>& x, const stack<T, Container>& y);
|
| 5442 |
template <class T, class Container>
|
| 5443 |
bool operator< (const stack<T, Container>& x, const stack<T, Container>& y);
|
| 5444 |
template <class T, class Container>
|
|
@@ -5472,99 +6598,87 @@ explicit stack(Container&& cont = Container());
|
|
| 5472 |
|
| 5473 |
*Effects:* Initializes `c` with `std::move(cont)`.
|
| 5474 |
|
| 5475 |
#### `stack` constructors with allocators <a id="stack.cons.alloc">[[stack.cons.alloc]]</a>
|
| 5476 |
|
| 5477 |
-
If `
|
| 5478 |
-
|
| 5479 |
-
resolution.
|
| 5480 |
|
| 5481 |
``` cpp
|
| 5482 |
-
template <class Alloc>
|
| 5483 |
-
explicit stack(const Alloc& a);
|
| 5484 |
```
|
| 5485 |
|
| 5486 |
*Effects:* Initializes `c` with `a`.
|
| 5487 |
|
| 5488 |
``` cpp
|
| 5489 |
-
template <class Alloc>
|
| 5490 |
-
stack(const container_type& cont, const Alloc& a);
|
| 5491 |
```
|
| 5492 |
|
| 5493 |
*Effects:* Initializes `c` with `cont` as the first argument and `a` as
|
| 5494 |
the second argument.
|
| 5495 |
|
| 5496 |
``` cpp
|
| 5497 |
-
template <class Alloc>
|
| 5498 |
-
stack(container_type&& cont, const Alloc& a);
|
| 5499 |
```
|
| 5500 |
|
| 5501 |
*Effects:* Initializes `c` with `std::move(cont)` as the first argument
|
| 5502 |
and `a` as the second argument.
|
| 5503 |
|
| 5504 |
``` cpp
|
| 5505 |
-
template <class Alloc>
|
| 5506 |
-
stack(const stack& s, const Alloc& a);
|
| 5507 |
```
|
| 5508 |
|
| 5509 |
*Effects:* Initializes `c` with `s.c` as the first argument and `a` as
|
| 5510 |
the second argument.
|
| 5511 |
|
| 5512 |
``` cpp
|
| 5513 |
-
template <class Alloc>
|
| 5514 |
-
stack(stack&& s, const Alloc& a);
|
| 5515 |
```
|
| 5516 |
|
| 5517 |
*Effects:* Initializes `c` with `std::move(s.c)` as the first argument
|
| 5518 |
and `a` as the second argument.
|
| 5519 |
|
| 5520 |
#### `stack` operators <a id="stack.ops">[[stack.ops]]</a>
|
| 5521 |
|
| 5522 |
``` cpp
|
| 5523 |
template <class T, class Container>
|
| 5524 |
-
|
| 5525 |
-
const stack<T, Container>& y);
|
| 5526 |
```
|
| 5527 |
|
| 5528 |
*Returns:* `x.c == y.c`.
|
| 5529 |
|
| 5530 |
``` cpp
|
| 5531 |
template <class T, class Container>
|
| 5532 |
-
|
| 5533 |
-
const stack<T, Container>& y);
|
| 5534 |
```
|
| 5535 |
|
| 5536 |
*Returns:* `x.c != y.c`.
|
| 5537 |
|
| 5538 |
``` cpp
|
| 5539 |
template <class T, class Container>
|
| 5540 |
-
|
| 5541 |
-
const stack<T, Container>& y);
|
| 5542 |
```
|
| 5543 |
|
| 5544 |
*Returns:* `x.c < y.c`.
|
| 5545 |
|
| 5546 |
``` cpp
|
| 5547 |
template <class T, class Container>
|
| 5548 |
-
|
| 5549 |
-
const stack<T, Container>& y);
|
| 5550 |
```
|
| 5551 |
|
| 5552 |
*Returns:* `x.c <= y.c`.
|
| 5553 |
|
| 5554 |
``` cpp
|
| 5555 |
template <class T, class Container>
|
| 5556 |
-
|
| 5557 |
-
const stack<T, Container>& y);
|
| 5558 |
```
|
| 5559 |
|
| 5560 |
*Returns:* `x.c > y.c`.
|
| 5561 |
|
| 5562 |
``` cpp
|
| 5563 |
template <class T, class Container>
|
| 5564 |
-
bool operator>=(const stack<T, Container>& x,
|
| 5565 |
-
const stack<T, Container>& y);
|
| 5566 |
```
|
| 5567 |
|
| 5568 |
*Returns:* `x.c >= y.c`.
|
| 5569 |
|
| 5570 |
#### `stack` specialized algorithms <a id="stack.special">[[stack.special]]</a>
|
|
@@ -5572,26 +6686,31 @@ template <class T, class Container>
|
|
| 5572 |
``` cpp
|
| 5573 |
template <class T, class Container>
|
| 5574 |
void swap(stack<T, Container>& x, stack<T, Container>& y) noexcept(noexcept(x.swap(y)));
|
| 5575 |
```
|
| 5576 |
|
| 5577 |
-
*
|
|
|
|
|
|
|
|
|
|
| 5578 |
|
| 5579 |
<!-- Link reference definitions -->
|
| 5580 |
[alg.sorting]: algorithms.md#alg.sorting
|
| 5581 |
[algorithm.stable]: library.md#algorithm.stable
|
| 5582 |
[algorithms]: algorithms.md#algorithms
|
| 5583 |
[allocator.requirements]: library.md#allocator.requirements
|
|
|
|
| 5584 |
[allocator.traits.members]: utilities.md#allocator.traits.members
|
| 5585 |
[array]: #array
|
| 5586 |
[array.cons]: #array.cons
|
| 5587 |
[array.data]: #array.data
|
| 5588 |
[array.fill]: #array.fill
|
| 5589 |
[array.overview]: #array.overview
|
| 5590 |
[array.size]: #array.size
|
| 5591 |
[array.special]: #array.special
|
| 5592 |
[array.swap]: #array.swap
|
|
|
|
| 5593 |
[array.tuple]: #array.tuple
|
| 5594 |
[array.zero]: #array.zero
|
| 5595 |
[associative]: #associative
|
| 5596 |
[associative.general]: #associative.general
|
| 5597 |
[associative.map.syn]: #associative.map.syn
|
|
@@ -5602,10 +6721,17 @@ template <class T, class Container>
|
|
| 5602 |
[class.copy]: special.md#class.copy
|
| 5603 |
[class.ctor]: special.md#class.ctor
|
| 5604 |
[class.dtor]: special.md#class.dtor
|
| 5605 |
[container.adaptors]: #container.adaptors
|
| 5606 |
[container.adaptors.general]: #container.adaptors.general
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 5607 |
[container.requirements]: #container.requirements
|
| 5608 |
[container.requirements.dataraces]: #container.requirements.dataraces
|
| 5609 |
[container.requirements.general]: #container.requirements.general
|
| 5610 |
[containers]: #containers
|
| 5611 |
[containers.general]: #containers.general
|
|
@@ -5614,28 +6740,32 @@ template <class T, class Container>
|
|
| 5614 |
[deque.capacity]: #deque.capacity
|
| 5615 |
[deque.cons]: #deque.cons
|
| 5616 |
[deque.modifiers]: #deque.modifiers
|
| 5617 |
[deque.overview]: #deque.overview
|
| 5618 |
[deque.special]: #deque.special
|
|
|
|
| 5619 |
[forward.iterators]: iterators.md#forward.iterators
|
|
|
|
| 5620 |
[forwardlist]: #forwardlist
|
| 5621 |
[forwardlist.access]: #forwardlist.access
|
| 5622 |
[forwardlist.cons]: #forwardlist.cons
|
| 5623 |
[forwardlist.iter]: #forwardlist.iter
|
| 5624 |
[forwardlist.modifiers]: #forwardlist.modifiers
|
| 5625 |
[forwardlist.ops]: #forwardlist.ops
|
| 5626 |
[forwardlist.overview]: #forwardlist.overview
|
| 5627 |
[forwardlist.spec]: #forwardlist.spec
|
| 5628 |
[hash.requirements]: library.md#hash.requirements
|
| 5629 |
[iterator.requirements]: iterators.md#iterator.requirements
|
|
|
|
| 5630 |
[list]: #list
|
| 5631 |
[list.capacity]: #list.capacity
|
| 5632 |
[list.cons]: #list.cons
|
| 5633 |
[list.modifiers]: #list.modifiers
|
| 5634 |
[list.ops]: #list.ops
|
| 5635 |
[list.overview]: #list.overview
|
| 5636 |
[list.special]: #list.special
|
|
|
|
| 5637 |
[map]: #map
|
| 5638 |
[map.access]: #map.access
|
| 5639 |
[map.cons]: #map.cons
|
| 5640 |
[map.modifiers]: #map.modifiers
|
| 5641 |
[map.overview]: #map.overview
|
|
@@ -5659,10 +6789,11 @@ template <class T, class Container>
|
|
| 5659 |
[queue.cons.alloc]: #queue.cons.alloc
|
| 5660 |
[queue.defn]: #queue.defn
|
| 5661 |
[queue.ops]: #queue.ops
|
| 5662 |
[queue.special]: #queue.special
|
| 5663 |
[queue.syn]: #queue.syn
|
|
|
|
| 5664 |
[res.on.data.races]: library.md#res.on.data.races
|
| 5665 |
[sequence.reqmts]: #sequence.reqmts
|
| 5666 |
[sequences]: #sequences
|
| 5667 |
[sequences.general]: #sequences.general
|
| 5668 |
[set]: #set
|
|
@@ -5675,15 +6806,17 @@ template <class T, class Container>
|
|
| 5675 |
[stack.defn]: #stack.defn
|
| 5676 |
[stack.ops]: #stack.ops
|
| 5677 |
[stack.special]: #stack.special
|
| 5678 |
[stack.syn]: #stack.syn
|
| 5679 |
[strings]: strings.md#strings
|
|
|
|
| 5680 |
[tab:HashRequirements]: #tab:HashRequirements
|
| 5681 |
[tab:containers.allocatoraware]: #tab:containers.allocatoraware
|
| 5682 |
[tab:containers.associative.requirements]: #tab:containers.associative.requirements
|
| 5683 |
[tab:containers.container.requirements]: #tab:containers.container.requirements
|
| 5684 |
[tab:containers.lib.summary]: #tab:containers.lib.summary
|
|
|
|
| 5685 |
[tab:containers.optional.operations]: #tab:containers.optional.operations
|
| 5686 |
[tab:containers.reversible.requirements]: #tab:containers.reversible.requirements
|
| 5687 |
[tab:containers.sequence.optional]: #tab:containers.sequence.optional
|
| 5688 |
[tab:containers.sequence.requirements]: #tab:containers.sequence.requirements
|
| 5689 |
[temp.deduct]: temp.md#temp.deduct
|
|
@@ -5719,10 +6852,11 @@ template <class T, class Container>
|
|
| 5719 |
[vector.cons]: #vector.cons
|
| 5720 |
[vector.data]: #vector.data
|
| 5721 |
[vector.modifiers]: #vector.modifiers
|
| 5722 |
[vector.overview]: #vector.overview
|
| 5723 |
[vector.special]: #vector.special
|
|
|
|
| 5724 |
|
| 5725 |
[^1]: Equality comparison is a refinement of partitioning if no two
|
| 5726 |
objects that compare equal fall into different partitions.
|
| 5727 |
|
| 5728 |
[^2]: These member functions are only provided by containers whose
|
|
|
|
| 34 |
Containers are objects that store other objects. They control allocation
|
| 35 |
and deallocation of these objects through constructors, destructors,
|
| 36 |
insert and erase operations.
|
| 37 |
|
| 38 |
All of the complexity requirements in this Clause are stated solely in
|
| 39 |
+
terms of the number of operations on the contained objects.
|
| 40 |
+
|
| 41 |
+
[*Example 1*: The copy constructor of type `vector<vector<int>>` has
|
| 42 |
+
linear complexity, even though the complexity of copying each contained
|
| 43 |
+
`vector<int>` is itself linear. — *end example*]
|
| 44 |
|
| 45 |
For the components affected by this subclause that declare an
|
| 46 |
`allocator_type`, objects stored in these components shall be
|
| 47 |
+
constructed using the function
|
| 48 |
+
`allocator_traits<allocator_type>::rebind_traits<U>::{}construct` and
|
| 49 |
+
destroyed using the function
|
| 50 |
+
`allocator_traits<allocator_type>::rebind_traits<U>::{}destroy` (
|
| 51 |
+
[[allocator.traits.members]]), where `U` is either
|
| 52 |
+
`allocator_type::value_type` or an internal type used by the container.
|
| 53 |
+
These functions are called only for the container’s element type, not
|
| 54 |
+
for internal types used by the container.
|
| 55 |
+
|
| 56 |
+
[*Note 1*: This means, for example, that a node-based container might
|
| 57 |
+
need to construct nodes containing aligned buffers and call `construct`
|
| 58 |
+
to place the element into the buffer. — *end note*]
|
| 59 |
|
| 60 |
In Tables [[tab:containers.container.requirements]],
|
| 61 |
[[tab:containers.reversible.requirements]], and
|
| 62 |
[[tab:containers.optional.operations]] `X` denotes a container class
|
| 63 |
containing objects of type `T`, `a` and `b` denote values of type `X`,
|
| 64 |
`u` denotes an identifier, `r` denotes a non-const value of type `X`,
|
| 65 |
and `rv` denotes a non-const rvalue of type `X`.
|
| 66 |
|
|
|
|
| 67 |
Those entries marked “(Note A)” or “(Note B)” have linear complexity for
|
| 68 |
`array` and have constant complexity for all other standard containers.
|
| 69 |
|
| 70 |
+
[*Note 2*: The algorithm `equal()` is defined in Clause
|
| 71 |
+
[[algorithms]]. — *end note*]
|
| 72 |
+
|
| 73 |
The member function `size()` returns the number of elements in the
|
| 74 |
container. The number of elements is defined by the rules of
|
| 75 |
constructors, inserts, and erases.
|
| 76 |
|
| 77 |
`begin()`
|
| 78 |
|
| 79 |
returns an iterator referring to the first element in the container.
|
| 80 |
`end()` returns an iterator which is the past-the-end value for the
|
| 81 |
+
container. If the container is empty, then `begin() == end()`.
|
| 82 |
|
| 83 |
In the expressions
|
| 84 |
|
| 85 |
``` cpp
|
| 86 |
i == j
|
|
|
|
| 96 |
either or both may be replaced by an object of the container’s
|
| 97 |
`const_iterator` type referring to the same element with no change in
|
| 98 |
semantics.
|
| 99 |
|
| 100 |
Unless otherwise specified, all containers defined in this clause obtain
|
| 101 |
+
memory using an allocator (see [[allocator.requirements]]).
|
| 102 |
+
|
| 103 |
+
[*Note 3*: In particular, containers and iterators do not store
|
| 104 |
+
references to allocated elements other than through the allocator’s
|
| 105 |
+
pointer type, i.e., as objects of type `P` or
|
| 106 |
+
`pointer_traits<P>::template rebind<unspecified>`, where `P` is
|
| 107 |
+
`allocator_traits<allocator_type>::pointer`. — *end note*]
|
| 108 |
+
|
| 109 |
+
Copy constructors for these container types obtain an allocator by
|
| 110 |
+
calling
|
| 111 |
`allocator_traits<allocator_type>::select_on_container_copy_construction`
|
| 112 |
on the allocator belonging to the container being copied. Move
|
| 113 |
constructors obtain an allocator by move construction from the allocator
|
| 114 |
belonging to the container being moved. Such move construction of the
|
| 115 |
allocator shall not exit via an exception. All other constructors for
|
| 116 |
+
these container types take a `const allocator_type&` argument.
|
| 117 |
+
|
| 118 |
+
[*Note 4*: If an invocation of a constructor uses the default value of
|
| 119 |
+
an optional allocator argument, then the `Allocator` type must support
|
| 120 |
+
value-initialization. — *end note*]
|
| 121 |
+
|
| 122 |
+
A copy of this allocator is used for any memory allocation and element
|
| 123 |
+
construction performed, by these constructors and by all member
|
| 124 |
+
functions, during the lifetime of each container object or until the
|
| 125 |
+
allocator is replaced. The allocator may be replaced only via assignment
|
| 126 |
+
or `swap()`. Allocator replacement is performed by copy assignment, move
|
| 127 |
+
assignment, or swapping of the allocator only if
|
| 128 |
`allocator_traits<allocator_type>::propagate_on_container_copy_assignment::value`,
|
| 129 |
`allocator_traits<allocator_type>::propagate_on_container_move_assignment::value`,
|
| 130 |
or
|
| 131 |
`allocator_traits<allocator_type>::propagate_on_container_swap::value`
|
| 132 |
+
is `true` within the implementation of the corresponding container
|
| 133 |
+
operation. In all container types defined in this Clause, the member
|
|
|
|
|
|
|
|
|
|
|
|
|
| 134 |
`get_allocator()` returns a copy of the allocator used to construct the
|
| 135 |
container or, if that allocator has been replaced, a copy of the most
|
| 136 |
recent replacement.
|
| 137 |
|
| 138 |
The expression `a.swap(b)`, for containers `a` and `b` of a standard
|
| 139 |
container type other than `array`, shall exchange the values of `a` and
|
| 140 |
`b` without invoking any move, copy, or swap operations on the
|
| 141 |
+
individual container elements. Lvalues of any `Compare`, `Pred`, or
|
| 142 |
+
`Hash` types belonging to `a` and `b` shall be swappable and shall be
|
| 143 |
+
exchanged by calling `swap` as described in [[swappable.requirements]].
|
| 144 |
+
If
|
| 145 |
`allocator_traits<allocator_type>::propagate_on_container_swap::value`
|
| 146 |
+
is `true`, then lvalues of type `allocator_type` shall be swappable and
|
| 147 |
+
the allocators of `a` and `b` shall also be exchanged by calling `swap`
|
| 148 |
+
as described in [[swappable.requirements]]. Otherwise, the allocators
|
| 149 |
+
shall not be swapped, and the behavior is undefined unless
|
| 150 |
`a.get_allocator() == b.get_allocator()`. Every iterator referring to an
|
| 151 |
element in one container before the swap shall refer to the same element
|
| 152 |
in the other container after the swap. It is unspecified whether an
|
| 153 |
iterator with value `a.end()` before the swap will have value `b.end()`
|
| 154 |
after the swap.
|
|
|
|
| 173 |
- no copy constructor or assignment operator of a returned iterator
|
| 174 |
throws an exception.
|
| 175 |
- no `swap()` function throws an exception.
|
| 176 |
- no `swap()` function invalidates any references, pointers, or
|
| 177 |
iterators referring to the elements of the containers being swapped.
|
| 178 |
+
\[*Note 5*: The `end()` iterator does not refer to any element, so it
|
| 179 |
+
may be invalidated. — *end note*]
|
| 180 |
|
| 181 |
Unless otherwise specified (either explicitly or by defining a function
|
| 182 |
in terms of other functions), invoking a container member function or
|
| 183 |
passing a container as an argument to a library function shall not
|
| 184 |
invalidate iterators to, or change the values of, objects within that
|
| 185 |
container.
|
| 186 |
|
| 187 |
+
A *contiguous container* is a container that supports random access
|
| 188 |
+
iterators ([[random.access.iterators]]) and whose member types
|
| 189 |
+
`iterator` and `const_iterator` are contiguous iterators (
|
| 190 |
+
[[iterator.requirements.general]]).
|
| 191 |
+
|
| 192 |
Table [[tab:containers.optional.operations]] lists operations that are
|
| 193 |
provided for some types of containers but not others. Those containers
|
| 194 |
for which the listed operations are provided shall implement the
|
| 195 |
semantics described in Table [[tab:containers.optional.operations]]
|
| 196 |
unless otherwise stated.
|
| 197 |
|
| 198 |
+
[*Note 6*: The algorithm `lexicographical_compare()` is defined in
|
| 199 |
+
Clause [[algorithms]]. — *end note*]
|
| 200 |
|
| 201 |
+
All of the containers defined in this Clause and in [[basic.string]]
|
| 202 |
except `array` meet the additional requirements of an allocator-aware
|
| 203 |
container, as described in Table [[tab:containers.allocatoraware]].
|
| 204 |
|
| 205 |
+
Given an allocator type `A` and given a container type `X` having a
|
| 206 |
+
`value_type` identical to `T` and an `allocator_type` identical to
|
| 207 |
+
`allocator_traits<A>::rebind_alloc<T>` and given an lvalue `m` of type
|
| 208 |
+
`A`, a pointer `p` of type `T*`, an expression `v` of type (possibly
|
| 209 |
+
`const`) `T`, and an rvalue `rv` of type `T`, the following terms are
|
| 210 |
+
defined. If `X` is not allocator-aware, the terms below are defined as
|
| 211 |
+
if `A` were `allocator<T>` — no allocator object needs to be created and
|
| 212 |
+
user specializations of `allocator<T>` are not instantiated:
|
| 213 |
|
| 214 |
- `T` is *`DefaultInsertable` into `X`* means that the following
|
| 215 |
expression is well-formed:
|
| 216 |
``` cpp
|
| 217 |
allocator_traits<A>::construct(m, p)
|
|
|
|
| 230 |
allocator_traits<A>::construct(m, p, rv)
|
| 231 |
```
|
| 232 |
|
| 233 |
and its evaluation causes the following postcondition to hold: The
|
| 234 |
value of `*p` is equivalent to the value of `rv` before the
|
| 235 |
+
evaluation.
|
| 236 |
+
\[*Note 7*: `rv` remains a valid object. Its state is
|
| 237 |
+
unspecified — *end note*]
|
| 238 |
- `T` is *`CopyInsertable` into `X`* means that, in addition to `T`
|
| 239 |
being `MoveInsertable` into `X`, the following expression is
|
| 240 |
well-formed:
|
| 241 |
``` cpp
|
| 242 |
allocator_traits<A>::construct(m, p, v)
|
|
|
|
| 253 |
well-formed:
|
| 254 |
``` cpp
|
| 255 |
allocator_traits<A>::destroy(m, p)
|
| 256 |
```
|
| 257 |
|
| 258 |
+
[*Note 8*: A container calls
|
| 259 |
+
`allocator_traits<A>::construct(m, p, args)` to construct an element at
|
| 260 |
+
`p` using `args`, with `m == get_allocator()`. The default `construct`
|
| 261 |
+
in `allocator` will call `::new((void*)p) T(args)`, but specialized
|
| 262 |
+
allocators may choose a different definition. — *end note*]
|
| 263 |
|
| 264 |
In Table [[tab:containers.allocatoraware]], `X` denotes an
|
| 265 |
allocator-aware container class with a `value_type` of `T` using
|
| 266 |
allocator of type `A`, `u` denotes a variable, `a` and `b` denote
|
| 267 |
non-const lvalues of type `X`, `t` denotes an lvalue or a const rvalue
|
| 268 |
of type `X`, `rv` denotes a non-const rvalue of type `X`, and `m` is a
|
| 269 |
value of type `A`.
|
| 270 |
|
| 271 |
+
The behavior of certain container member functions and deduction guides
|
| 272 |
+
depends on whether types qualify as input iterators or allocators. The
|
| 273 |
+
extent to which an implementation determines that a type cannot be an
|
| 274 |
+
input iterator is unspecified, except that as a minimum integral types
|
| 275 |
+
shall not qualify as input iterators. Likewise, the extent to which an
|
| 276 |
+
implementation determines that a type cannot be an allocator is
|
| 277 |
+
unspecified, except that as a minimum a type `A` shall not qualify as an
|
| 278 |
+
allocator unless it satisfies both of the following conditions:
|
| 279 |
+
|
| 280 |
+
- The *qualified-id* `A::value_type` is valid and denotes a type (
|
| 281 |
+
[[temp.deduct]]).
|
| 282 |
+
- The expression `declval<A&>().allocate(size_t{})` is well-formed when
|
| 283 |
+
treated as an unevaluated operand.
|
| 284 |
+
|
| 285 |
### Container data races <a id="container.requirements.dataraces">[[container.requirements.dataraces]]</a>
|
| 286 |
|
| 287 |
For purposes of avoiding data races ([[res.on.data.races]]),
|
| 288 |
implementations shall consider the following functions to be `const`:
|
| 289 |
`begin`, `end`, `rbegin`, `rend`, `front`, `back`, `data`, `find`,
|
| 290 |
`lower_bound`, `upper_bound`, `equal_range`, `at` and, except in
|
| 291 |
associative or unordered associative containers, `operator[]`.
|
| 292 |
|
| 293 |
+
Notwithstanding [[res.on.data.races]], implementations are required to
|
| 294 |
+
avoid data races when the contents of the contained object in different
|
| 295 |
+
elements in the same container, excepting `vector<bool>`, are modified
|
| 296 |
+
concurrently.
|
| 297 |
|
| 298 |
+
[*Note 1*: For a `vector<int> x` with a size greater than one,
|
| 299 |
+
`x[1] = 5` and `*x.begin() = 10` can be executed concurrently without a
|
| 300 |
+
data race, but `x[0] = 5` and `*x.begin() = 10` executed concurrently
|
| 301 |
+
may result in a data race. As an exception to the general rule, for a
|
| 302 |
+
`vector<bool> y`, `y[0] = true` may race with
|
| 303 |
+
`y[1] = true`. — *end note*]
|
| 304 |
|
| 305 |
### Sequence containers <a id="sequence.reqmts">[[sequence.reqmts]]</a>
|
| 306 |
|
| 307 |
A sequence container organizes a finite set of objects, all of the same
|
| 308 |
type, into a strictly linear arrangement. The library provides four
|
|
|
|
| 322 |
of choice when most insertions and deletions take place at the beginning
|
| 323 |
or at the end of the sequence.
|
| 324 |
|
| 325 |
In Tables [[tab:containers.sequence.requirements]] and
|
| 326 |
[[tab:containers.sequence.optional]], `X` denotes a sequence container
|
| 327 |
+
class, `a` denotes a value of type `X` containing elements of type `T`,
|
| 328 |
+
`u` denotes the name of a variable being declared, `A` denotes
|
| 329 |
+
`X::allocator_type` if the *qualified-id* `X::allocator_type` is valid
|
| 330 |
+
and denotes a type ([[temp.deduct]]) and `allocator<T>` if it doesn’t,
|
| 331 |
+
`i` and `j` denote iterators satisfying input iterator requirements and
|
| 332 |
+
refer to elements implicitly convertible to `value_type`, `[i, j)`
|
| 333 |
+
denotes a valid range, `il` designates an object of type
|
| 334 |
+
`initializer_list<value_type>`, `n` denotes a value of type
|
| 335 |
+
`X::size_type`, `p` denotes a valid constant iterator to `a`, `q`
|
| 336 |
+
denotes a valid dereferenceable constant iterator to `a`, `[q1, q2)`
|
| 337 |
+
denotes a valid range of constant iterators in `a`, `t` denotes an
|
| 338 |
+
lvalue or a const rvalue of `X::value_type`, and `rv` denotes a
|
| 339 |
+
non-const rvalue of `X::value_type`. `Args` denotes a template parameter
|
| 340 |
+
pack; `args` denotes a function parameter pack with the pattern
|
| 341 |
+
`Args&&`.
|
| 342 |
|
| 343 |
The complexities of the expressions are sequence dependent.
|
| 344 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 345 |
The iterator returned from `a.insert(p, t)` points to the copy of `t`
|
| 346 |
inserted into `a`.
|
| 347 |
|
| 348 |
The iterator returned from `a.insert(p, rv)` points to the copy of `rv`
|
| 349 |
inserted into `a`.
|
|
|
|
| 373 |
|
| 374 |
- If the constructor
|
| 375 |
``` cpp
|
| 376 |
template <class InputIterator>
|
| 377 |
X(InputIterator first, InputIterator last,
|
| 378 |
+
const allocator_type& alloc = allocator_type());
|
| 379 |
```
|
| 380 |
|
| 381 |
is called with a type `InputIterator` that does not qualify as an
|
| 382 |
input iterator, then the constructor shall not participate in overload
|
| 383 |
resolution.
|
| 384 |
- If the member functions of the forms:
|
| 385 |
``` cpp
|
| 386 |
+
template <class InputIterator>
|
| 387 |
+
return-type F(const_iterator p,
|
| 388 |
+
InputIterator first, InputIterator last); // such as insert
|
| 389 |
|
| 390 |
+
template <class InputIterator>
|
| 391 |
+
return-type F(InputIterator first, InputIterator last); // such as append, assign
|
| 392 |
|
| 393 |
+
template <class InputIterator>
|
| 394 |
+
return-type F(const_iterator i1, const_iterator i2,
|
| 395 |
+
InputIterator first, InputIterator last); // such as replace
|
| 396 |
```
|
| 397 |
|
| 398 |
are called with a type `InputIterator` that does not qualify as an
|
| 399 |
input iterator, then these functions shall not participate in overload
|
| 400 |
resolution.
|
| 401 |
+
- A deduction guide for a sequence container shall not participate in
|
| 402 |
+
overload resolution if it has an `InputIterator` template parameter
|
| 403 |
+
and a type that does not qualify as an input iterator is deduced for
|
| 404 |
+
that parameter, or if it has an `Allocator` template parameter and a
|
| 405 |
+
type that does not qualify as an allocator is deduced for that
|
| 406 |
+
parameter.
|
| 407 |
|
| 408 |
Table [[tab:containers.sequence.optional]] lists operations that are
|
| 409 |
provided for some types of sequence containers but not others. An
|
| 410 |
implementation shall provide these operations for all container types
|
| 411 |
shown in the “container” column, and shall implement them so as to take
|
| 412 |
amortized constant time.
|
| 413 |
|
| 414 |
The member function `at()` provides bounds-checked access to container
|
| 415 |
elements. `at()` throws `out_of_range` if `n >= a.size()`.
|
| 416 |
|
| 417 |
+
### Node handles <a id="container.node">[[container.node]]</a>
|
| 418 |
+
|
| 419 |
+
#### `node_handle` overview <a id="container.node.overview">[[container.node.overview]]</a>
|
| 420 |
+
|
| 421 |
+
A *node handle* is an object that accepts ownership of a single element
|
| 422 |
+
from an associative container ([[associative.reqmts]]) or an unordered
|
| 423 |
+
associative container ([[unord.req]]). It may be used to transfer that
|
| 424 |
+
ownership to another container with compatible nodes. Containers with
|
| 425 |
+
compatible nodes have the same node handle type. Elements may be
|
| 426 |
+
transferred in either direction between container types in the same row
|
| 427 |
+
of Table [[tab:containers.node.compat]].
|
| 428 |
+
|
| 429 |
+
**Table: Container types with compatible nodes** <a id="tab:containers.node.compat">[tab:containers.node.compat]</a>
|
| 430 |
+
|
| 431 |
+
| | |
|
| 432 |
+
| -------------------------------- | ------------------------------------- |
|
| 433 |
+
| `map<K, T, C1, A>` | `map<K, T, C2, A>` |
|
| 434 |
+
| `map<K, T, C1, A>` | `multimap<K, T, C2, A>` |
|
| 435 |
+
| `set<K, C1, A>` | `set<K, C2, A>` |
|
| 436 |
+
| `set<K, C1, A>` | `multiset<K, C2, A>` |
|
| 437 |
+
| `unordered_map<K, T, H1, E1, A>` | `unordered_map<K, T, H2, E2, A>` |
|
| 438 |
+
| `unordered_map<K, T, H1, E1, A>` | `unordered_multimap<K, T, H2, E2, A>` |
|
| 439 |
+
| `unordered_set<K, H1, E1, A>` | `unordered_set<K, H2, E2, A>` |
|
| 440 |
+
| `unordered_set<K, H1, E1, A>` | `unordered_multiset<K, H2, E2, A>` |
|
| 441 |
+
|
| 442 |
+
|
| 443 |
+
If a node handle is not empty, then it contains an allocator that is
|
| 444 |
+
equal to the allocator of the container when the element was extracted.
|
| 445 |
+
If a node handle is empty, it contains no allocator.
|
| 446 |
+
|
| 447 |
+
Class `node_handle` is for exposition only. An implementation is
|
| 448 |
+
permitted to provide equivalent functionality without providing a class
|
| 449 |
+
with this name.
|
| 450 |
+
|
| 451 |
+
If a user-defined specialization of `pair` exists for
|
| 452 |
+
`pair<const Key, T>` or `pair<Key, T>`, where `Key` is the container’s
|
| 453 |
+
`key_type` and `T` is the container’s `mapped_type`, the behavior of
|
| 454 |
+
operations involving node handles is undefined.
|
| 455 |
+
|
| 456 |
+
``` cpp
|
| 457 |
+
template<unspecified>
|
| 458 |
+
class node_handle {
|
| 459 |
+
public:
|
| 460 |
+
// These type declarations are described in Tables [tab:containers.associative.requirements] and [tab:HashRequirements].
|
| 461 |
+
using value_type = see below; // not present for map containers
|
| 462 |
+
using key_type = see below; // not present for set containers
|
| 463 |
+
using mapped_type = see below; // not present for set containers
|
| 464 |
+
using allocator_type = see below;
|
| 465 |
+
|
| 466 |
+
private:
|
| 467 |
+
using container_node_type = unspecified;
|
| 468 |
+
using ator_traits = allocator_traits<allocator_type>;
|
| 469 |
+
|
| 470 |
+
typename ator_traits::rebind_traits<container_node_type>::pointer ptr_;
|
| 471 |
+
optional<allocator_type> alloc_;
|
| 472 |
+
|
| 473 |
+
public:
|
| 474 |
+
constexpr node_handle() noexcept : ptr_(), alloc_() {}
|
| 475 |
+
~node_handle();
|
| 476 |
+
node_handle(node_handle&&) noexcept;
|
| 477 |
+
node_handle& operator=(node_handle&&);
|
| 478 |
+
|
| 479 |
+
value_type& value() const; // not present for map containers
|
| 480 |
+
key_type& key() const; // not present for set containers
|
| 481 |
+
mapped_type& mapped() const; // not present for set containers
|
| 482 |
+
|
| 483 |
+
allocator_type get_allocator() const;
|
| 484 |
+
explicit operator bool() const noexcept;
|
| 485 |
+
bool empty() const noexcept;
|
| 486 |
+
|
| 487 |
+
void swap(node_handle&)
|
| 488 |
+
noexcept(ator_traits::propagate_on_container_swap::value ||
|
| 489 |
+
ator_traits::is_always_equal::value);
|
| 490 |
+
|
| 491 |
+
friend void swap(node_handle& x, node_handle& y) noexcept(noexcept(x.swap(y))) {
|
| 492 |
+
x.swap(y);
|
| 493 |
+
}
|
| 494 |
+
};
|
| 495 |
+
```
|
| 496 |
+
|
| 497 |
+
#### `node_handle` constructors, copy, and assignment <a id="container.node.cons">[[container.node.cons]]</a>
|
| 498 |
+
|
| 499 |
+
``` cpp
|
| 500 |
+
node_handle(node_handle&& nh) noexcept;
|
| 501 |
+
```
|
| 502 |
+
|
| 503 |
+
*Effects:* Constructs a *`node_handle`* object initializing `ptr_` with
|
| 504 |
+
`nh.ptr_`. Move constructs `alloc_` with `nh.alloc_`. Assigns `nullptr`
|
| 505 |
+
to `nh.ptr_` and assigns `nullopt` to `nh.alloc_`.
|
| 506 |
+
|
| 507 |
+
``` cpp
|
| 508 |
+
node_handle& operator=(node_handle&& nh);
|
| 509 |
+
```
|
| 510 |
+
|
| 511 |
+
*Requires:* Either `!alloc_`, or
|
| 512 |
+
`ator_traits::propagate_on_container_move_assignment` is `true`, or
|
| 513 |
+
`alloc_ == nh.alloc_`.
|
| 514 |
+
|
| 515 |
+
*Effects:*
|
| 516 |
+
|
| 517 |
+
- If `ptr_ != nullptr`, destroys the `value_type` subobject in the
|
| 518 |
+
`container_node_type` object pointed to by `ptr_` by calling
|
| 519 |
+
`ator_traits::destroy`, then deallocates `ptr_` by calling
|
| 520 |
+
`ator_traits::rebind_traits<container_node_type>::deallocate`.
|
| 521 |
+
- Assigns `nh.ptr_` to `ptr_`.
|
| 522 |
+
- If `!alloc` or `ator_traits::propagate_on_container_move_assignment`
|
| 523 |
+
is `true`, move assigns `nh.alloc_` to `alloc_`.
|
| 524 |
+
- Assigns `nullptr` to `nh.ptr_` and assigns `nullopt` to `nh.alloc_`.
|
| 525 |
+
|
| 526 |
+
*Returns:* `*this`.
|
| 527 |
+
|
| 528 |
+
*Throws:* Nothing.
|
| 529 |
+
|
| 530 |
+
#### `node_handle` destructor <a id="container.node.dtor">[[container.node.dtor]]</a>
|
| 531 |
+
|
| 532 |
+
``` cpp
|
| 533 |
+
~node_handle();
|
| 534 |
+
```
|
| 535 |
+
|
| 536 |
+
*Effects:* If `ptr_ != nullptr`, destroys the `value_type` subobject in
|
| 537 |
+
the `container_node_type` object pointed to by `ptr_` by calling
|
| 538 |
+
`ator_traits::destroy`, then deallocates `ptr_` by calling
|
| 539 |
+
`ator_traits::rebind_traits<container_node_type>::deallocate`.
|
| 540 |
+
|
| 541 |
+
#### `node_handle` observers <a id="container.node.observers">[[container.node.observers]]</a>
|
| 542 |
+
|
| 543 |
+
``` cpp
|
| 544 |
+
value_type& value() const;
|
| 545 |
+
```
|
| 546 |
+
|
| 547 |
+
*Requires:* `empty() == false`.
|
| 548 |
+
|
| 549 |
+
*Returns:* A reference to the `value_type` subobject in the
|
| 550 |
+
`container_node_type` object pointed to by `ptr_`.
|
| 551 |
+
|
| 552 |
+
*Throws:* Nothing.
|
| 553 |
+
|
| 554 |
+
``` cpp
|
| 555 |
+
key_type& key() const;
|
| 556 |
+
```
|
| 557 |
+
|
| 558 |
+
*Requires:* `empty() == false`.
|
| 559 |
+
|
| 560 |
+
*Returns:* A non-const reference to the `key_type` member of the
|
| 561 |
+
`value_type` subobject in the `container_node_type` object pointed to by
|
| 562 |
+
`ptr_`.
|
| 563 |
+
|
| 564 |
+
*Throws:* Nothing.
|
| 565 |
+
|
| 566 |
+
*Remarks:* Modifying the key through the returned reference is
|
| 567 |
+
permitted.
|
| 568 |
+
|
| 569 |
+
``` cpp
|
| 570 |
+
mapped_type& mapped() const;
|
| 571 |
+
```
|
| 572 |
+
|
| 573 |
+
*Requires:* `empty() == false`.
|
| 574 |
+
|
| 575 |
+
*Returns:* A reference to the `mapped_type` member of the `value_type`
|
| 576 |
+
subobject in the `container_node_type` object pointed to by `ptr_`.
|
| 577 |
+
|
| 578 |
+
*Throws:* Nothing.
|
| 579 |
+
|
| 580 |
+
``` cpp
|
| 581 |
+
allocator_type get_allocator() const;
|
| 582 |
+
```
|
| 583 |
+
|
| 584 |
+
*Requires:* `empty() == false`.
|
| 585 |
+
|
| 586 |
+
*Returns:* `*alloc_`.
|
| 587 |
+
|
| 588 |
+
*Throws:* Nothing.
|
| 589 |
+
|
| 590 |
+
``` cpp
|
| 591 |
+
explicit operator bool() const noexcept;
|
| 592 |
+
```
|
| 593 |
+
|
| 594 |
+
*Returns:* `ptr_ != nullptr`.
|
| 595 |
+
|
| 596 |
+
``` cpp
|
| 597 |
+
bool empty() const noexcept;
|
| 598 |
+
```
|
| 599 |
+
|
| 600 |
+
*Returns:* `ptr_ == nullptr`.
|
| 601 |
+
|
| 602 |
+
#### `node_handle` modifiers <a id="container.node.modifiers">[[container.node.modifiers]]</a>
|
| 603 |
+
|
| 604 |
+
``` cpp
|
| 605 |
+
void swap(node_handle& nh)
|
| 606 |
+
noexcept(ator_traits::propagate_on_container_swap::value ||
|
| 607 |
+
ator_traits::is_always_equal::value);
|
| 608 |
+
```
|
| 609 |
+
|
| 610 |
+
*Requires:* `!alloc_`, or `!nh.alloc_`, or
|
| 611 |
+
`ator_traits::propagate_on_container_swap` is `true`, or
|
| 612 |
+
`alloc_ == nh.alloc_`.
|
| 613 |
+
|
| 614 |
+
*Effects:* Calls `swap(ptr_, nh.ptr_)`. If `!alloc_`, or `!nh.alloc_`,
|
| 615 |
+
or `ator_traits::propagate_on_container_swap` is `true` calls
|
| 616 |
+
`swap(alloc_, nh.alloc_)`.
|
| 617 |
+
|
| 618 |
+
### Insert return type <a id="container.insert.return">[[container.insert.return]]</a>
|
| 619 |
+
|
| 620 |
+
The associative containers with unique keys and the unordered containers
|
| 621 |
+
with unique keys have a member function `insert` that returns a nested
|
| 622 |
+
type `insert_return_type`. That return type is a specialization of the
|
| 623 |
+
type specified in this subclause.
|
| 624 |
+
|
| 625 |
+
``` cpp
|
| 626 |
+
template <class Iterator, class NodeType>
|
| 627 |
+
struct INSERT_RETURN_TYPE
|
| 628 |
+
{
|
| 629 |
+
Iterator position;
|
| 630 |
+
bool inserted;
|
| 631 |
+
NodeType node;
|
| 632 |
+
};
|
| 633 |
+
```
|
| 634 |
+
|
| 635 |
+
The name `INSERT_RETURN_TYPE` is exposition only. `INSERT_RETURN_TYPE`
|
| 636 |
+
has the template parameters, data members, and special members specified
|
| 637 |
+
above. It has no base classes or members other than those specified.
|
| 638 |
+
|
| 639 |
### Associative containers <a id="associative.reqmts">[[associative.reqmts]]</a>
|
| 640 |
|
| 641 |
Associative containers provide fast retrieval of data based on keys. The
|
| 642 |
library provides four basic kinds of associative containers: `set`,
|
| 643 |
`multiset`, `map` and `multimap`.
|
|
|
|
| 669 |
|
| 670 |
of an associative container is of the bidirectional iterator category.
|
| 671 |
For associative containers where the value type is the same as the key
|
| 672 |
type, both `iterator` and `const_iterator` are constant iterators. It is
|
| 673 |
unspecified whether or not `iterator` and `const_iterator` are the same
|
| 674 |
+
type.
|
| 675 |
+
|
| 676 |
+
[*Note 1*: `iterator` and `const_iterator` have identical semantics in
|
| 677 |
+
this case, and `iterator` is convertible to `const_iterator`. Users can
|
| 678 |
+
avoid violating the one-definition rule by always using `const_iterator`
|
| 679 |
+
in their function parameter lists. — *end note*]
|
| 680 |
|
| 681 |
The associative containers meet all the requirements of Allocator-aware
|
| 682 |
containers ([[container.requirements.general]]), except that for `map`
|
| 683 |
and `multimap`, the requirements placed on `value_type` in Table
|
| 684 |
[[tab:containers.container.requirements]] apply instead to `key_type`
|
| 685 |
+
and `mapped_type`.
|
| 686 |
+
|
| 687 |
+
[*Note 2*: For example, in some cases `key_type` and `mapped_type` are
|
| 688 |
+
required to be `CopyAssignable` even though the associated `value_type`,
|
| 689 |
+
`pair<const key_type, mapped_type>`, is not
|
| 690 |
+
`CopyAssignable`. — *end note*]
|
| 691 |
|
| 692 |
In Table [[tab:containers.associative.requirements]], `X` denotes an
|
| 693 |
+
associative container class, `a` denotes a value of type `X`, `a2`
|
| 694 |
+
denotes a value of a type with nodes compatible with type `X` (Table
|
| 695 |
+
[[tab:containers.node.compat]]), `b` denotes a possibly `const` value of
|
| 696 |
+
type `X`, `u` denotes the name of a variable being declared, `a_uniq`
|
| 697 |
+
denotes a value of type `X` when `X` supports unique keys, `a_eq`
|
| 698 |
+
denotes a value of type `X` when `X` supports multiple keys, `a_tran`
|
| 699 |
+
denotes a possibly `const` value of type `X` when the *qualified-id*
|
| 700 |
+
`X::key_compare::is_transparent` is valid and denotes a type (
|
| 701 |
+
[[temp.deduct]]), `i` and `j` satisfy input iterator requirements and
|
| 702 |
+
refer to elements implicitly convertible to `value_type`, \[`i`, `j`)
|
| 703 |
+
denotes a valid range, `p` denotes a valid constant iterator to `a`, `q`
|
| 704 |
+
denotes a valid dereferenceable constant iterator to `a`, `r` denotes a
|
| 705 |
+
valid dereferenceable iterator to `a`, `[q1, q2)` denotes a valid range
|
| 706 |
+
of constant iterators in `a`, `il` designates an object of type
|
| 707 |
+
`initializer_list<value_type>`, `t` denotes a value of type
|
| 708 |
+
`X::value_type`, `k` denotes a value of type `X::key_type` and `c`
|
| 709 |
+
denotes a possibly `const` value of type `X::key_compare`; `kl` is a
|
| 710 |
+
value such that `a` is partitioned ([[alg.sorting]]) with respect to
|
| 711 |
`c(r, kl)`, with `r` the key value of `e` and `e` in `a`; `ku` is a
|
| 712 |
value such that `a` is partitioned with respect to `!c(ku, r)`; `ke` is
|
| 713 |
a value such that `a` is partitioned with respect to `c(r, ke)` and
|
| 714 |
`!c(ke, r)`, with `c(r, ke)` implying `!c(ke, r)`. `A` denotes the
|
| 715 |
+
storage allocator used by `X`, if any, or `allocator<X::value_type>`
|
| 716 |
+
otherwise, `m` denotes an allocator of a type convertible to `A`, and
|
| 717 |
+
`nh` denotes a non-const rvalue of type `X::node_type`.
|
| 718 |
|
| 719 |
The `insert` and `emplace` members shall not affect the validity of
|
| 720 |
iterators and references to the container, and the `erase` members shall
|
| 721 |
invalidate only iterators and references to the erased elements.
|
| 722 |
|
| 723 |
+
The `extract` members invalidate only iterators to the removed element;
|
| 724 |
+
pointers and references to the removed element remain valid. However,
|
| 725 |
+
accessing the element through such pointers and references while the
|
| 726 |
+
element is owned by a `node_type` is undefined behavior. References and
|
| 727 |
+
pointers to an element obtained while it is owned by a `node_type` are
|
| 728 |
+
invalidated if the element is successfully inserted.
|
| 729 |
+
|
| 730 |
The fundamental property of iterators of associative containers is that
|
| 731 |
they iterate through the containers in the non-descending order of keys
|
| 732 |
where non-descending is defined by the comparison that was used to
|
| 733 |
construct them. For any two dereferenceable iterators `i` and `j` such
|
| 734 |
+
that distance from `i` to `j` is positive, the following condition
|
| 735 |
+
holds:
|
| 736 |
|
| 737 |
``` cpp
|
| 738 |
value_comp(*j, *i) == false
|
| 739 |
```
|
| 740 |
|
| 741 |
For associative containers with unique keys the stronger condition
|
| 742 |
+
holds:
|
| 743 |
|
| 744 |
``` cpp
|
| 745 |
+
value_comp(*i, *j) != false
|
| 746 |
```
|
| 747 |
|
| 748 |
When an associative container is constructed by passing a comparison
|
| 749 |
object the container shall not store a pointer or reference to the
|
| 750 |
passed object, even if that object is passed by reference. When an
|
|
|
|
| 753 |
object from the container being copied, as if that comparison object had
|
| 754 |
been passed to the target container in its constructor.
|
| 755 |
|
| 756 |
The member function templates `find`, `count`, `lower_bound`,
|
| 757 |
`upper_bound`, and `equal_range` shall not participate in overload
|
| 758 |
+
resolution unless the *qualified-id* `Compare::is_transparent` is valid
|
| 759 |
and denotes a type ([[temp.deduct]]).
|
| 760 |
|
| 761 |
+
A deduction guide for an associative container shall not participate in
|
| 762 |
+
overload resolution if any of the following are true:
|
| 763 |
+
|
| 764 |
+
- It has an `InputIterator` template parameter and a type that does not
|
| 765 |
+
qualify as an input iterator is deduced for that parameter.
|
| 766 |
+
- It has an `Allocator` template parameter and a type that does not
|
| 767 |
+
qualify as an allocator is deduced for that parameter.
|
| 768 |
+
- It has a `Compare` template parameter and a type that qualifies as an
|
| 769 |
+
allocator is deduced for that parameter.
|
| 770 |
+
|
| 771 |
#### Exception safety guarantees <a id="associative.reqmts.except">[[associative.reqmts.except]]</a>
|
| 772 |
|
| 773 |
For associative containers, no `clear()` function throws an exception.
|
| 774 |
`erase(k)` does not throw an exception unless that exception is thrown
|
| 775 |
by the container’s `Compare` object (if any).
|
|
|
|
| 809 |
the container.
|
| 810 |
|
| 811 |
Two values `k1` and `k2` of type `Key` are considered equivalent if the
|
| 812 |
container’s key equality predicate returns `true` when passed those
|
| 813 |
values. If `k1` and `k2` are equivalent, the container’s hash function
|
| 814 |
+
shall return the same value for both.
|
| 815 |
+
|
| 816 |
+
[*Note 1*: Thus, when an unordered associative container is
|
| 817 |
+
instantiated with a non-default `Pred` parameter it usually needs a
|
| 818 |
+
non-default `Hash` parameter as well. — *end note*]
|
| 819 |
+
|
| 820 |
+
For any two keys `k1` and `k2` in the same container, calling
|
| 821 |
+
`pred(k1, k2)` shall always return the same value. For any key `k` in a
|
| 822 |
+
container, calling `hash(k)` shall always return the same value.
|
| 823 |
|
| 824 |
An unordered associative container supports *unique keys* if it may
|
| 825 |
contain at most one element for each key. Otherwise, it supports
|
| 826 |
*equivalent keys*. `unordered_set` and `unordered_map` support unique
|
| 827 |
keys. `unordered_multiset` and `unordered_multimap` support equivalent
|
| 828 |
keys. In containers that support equivalent keys, elements with
|
| 829 |
equivalent keys are adjacent to each other in the iteration order of the
|
| 830 |
container. Thus, although the absolute order of elements in an unordered
|
| 831 |
container is not specified, its elements are grouped into
|
| 832 |
+
*equivalent-key groups* such that all elements of each group have
|
| 833 |
equivalent keys. Mutating operations on unordered containers shall
|
| 834 |
preserve the relative order of elements within each equivalent-key group
|
| 835 |
unless otherwise specified.
|
| 836 |
|
| 837 |
For `unordered_set` and `unordered_multiset` the value type is the same
|
| 838 |
as the key type. For `unordered_map` and `unordered_multimap` it is
|
| 839 |
+
`pair<const Key,
|
| 840 |
T>`.
|
| 841 |
|
| 842 |
For unordered containers where the value type is the same as the key
|
| 843 |
type, both `iterator` and `const_iterator` are constant iterators. It is
|
| 844 |
unspecified whether or not `iterator` and `const_iterator` are the same
|
| 845 |
+
type.
|
| 846 |
+
|
| 847 |
+
[*Note 2*: `iterator` and `const_iterator` have identical semantics in
|
| 848 |
+
this case, and `iterator` is convertible to `const_iterator`. Users can
|
| 849 |
+
avoid violating the one-definition rule by always using `const_iterator`
|
| 850 |
+
in their function parameter lists. — *end note*]
|
| 851 |
|
| 852 |
The elements of an unordered associative container are organized into
|
| 853 |
*buckets*. Keys with the same hash code appear in the same bucket. The
|
| 854 |
number of buckets is automatically increased as elements are added to an
|
| 855 |
unordered associative container, so that the average number of elements
|
|
|
|
| 862 |
The unordered associative containers meet all the requirements of
|
| 863 |
Allocator-aware containers ([[container.requirements.general]]), except
|
| 864 |
that for `unordered_map` and `unordered_multimap`, the requirements
|
| 865 |
placed on `value_type` in Table
|
| 866 |
[[tab:containers.container.requirements]] apply instead to `key_type`
|
| 867 |
+
and `mapped_type`.
|
|
|
|
|
|
|
|
|
|
| 868 |
|
| 869 |
+
[*Note 3*: For example, `key_type` and `mapped_type` are sometimes
|
| 870 |
+
required to be `CopyAssignable` even though the associated `value_type`,
|
| 871 |
+
`pair<const key_type, mapped_type>`, is not
|
| 872 |
+
`CopyAssignable`. — *end note*]
|
| 873 |
+
|
| 874 |
+
In Table [[tab:HashRequirements]]: `X` denotes an unordered associative
|
| 875 |
+
container class, `a` denotes a value of type `X`, `a2` denotes a value
|
| 876 |
+
of a type with nodes compatible with type `X` (Table
|
| 877 |
+
[[tab:containers.node.compat]]), `b` denotes a possibly const value of
|
| 878 |
+
type `X`, `a_uniq` denotes a value of type `X` when `X` supports unique
|
| 879 |
+
keys, `a_eq` denotes a value of type `X` when `X` supports equivalent
|
| 880 |
+
keys, `i` and `j` denote input iterators that refer to `value_type`,
|
| 881 |
+
`[i, j)` denotes a valid range, `p` and `q2` denote valid constant
|
| 882 |
+
iterators to `a`, `q` and `q1` denote valid dereferenceable constant
|
| 883 |
+
iterators to `a`, `r` denotes a valid dereferenceable iterator to `a`,
|
| 884 |
+
`[q1, q2)` denotes a valid range in `a`, `il` denotes a value of type
|
| 885 |
+
`initializer_list<value_type>`, `t` denotes a value of type
|
| 886 |
+
`X::value_type`, `k` denotes a value of type `key_type`, `hf` denotes a
|
| 887 |
+
possibly const value of type `hasher`, `eq` denotes a possibly const
|
| 888 |
+
value of type `key_equal`, `n` denotes a value of type `size_type`, `z`
|
| 889 |
+
denotes a value of type `float`, and `nh` denotes a non-const rvalue of
|
| 890 |
+
type `X::node_type`.
|
| 891 |
|
| 892 |
Two unordered containers `a` and `b` compare equal if
|
| 893 |
`a.size() == b.size()` and, for every equivalent-key group \[`Ea1`,
|
| 894 |
`Ea2`) obtained from `a.equal_range(Ea1)`, there exists an
|
| 895 |
equivalent-key group \[`Eb1`, `Eb2`) obtained from `b.equal_range(Ea1)`,
|
| 896 |
such that `is_permutation(Ea1, Ea2, Eb1, Eb2)` returns `true`. For
|
| 897 |
`unordered_set` and `unordered_map`, the complexity of `operator==`
|
| 898 |
(i.e., the number of calls to the `==` operator of the `value_type`, to
|
| 899 |
+
the predicate returned by `key_eq()`, and to the hasher returned by
|
| 900 |
`hash_function()`) is proportional to N in the average case and to N² in
|
| 901 |
the worst case, where N is a.size(). For `unordered_multiset` and
|
| 902 |
`unordered_multimap`, the complexity of `operator==` is proportional to
|
| 903 |
$\sum E_i^2$ in the average case and to N² in the worst case, where N is
|
| 904 |
`a.size()`, and Eᵢ is the size of the iᵗʰ equivalent-key group in `a`.
|
|
|
|
| 909 |
`unordered_multiset` and `unordered_multimap` becomes proportional to N
|
| 910 |
(but worst-case complexity remains 𝑂(N^2), e.g., for a pathologically
|
| 911 |
bad hash function). The behavior of a program that uses `operator==` or
|
| 912 |
`operator!=` on unordered containers is undefined unless the `Hash` and
|
| 913 |
`Pred` function objects respectively have the same behavior for both
|
| 914 |
+
containers and the equality comparison function for `Key` is a
|
| 915 |
refinement[^1] of the partition into equivalent-key groups produced by
|
| 916 |
`Pred`.
|
| 917 |
|
| 918 |
The iterator types `iterator` and `const_iterator` of an unordered
|
| 919 |
associative container are of at least the forward iterator category. For
|
| 920 |
unordered associative containers where the key type and value type are
|
| 921 |
+
the same, both `iterator` and `const_iterator` are constant iterators.
|
| 922 |
|
| 923 |
The `insert` and `emplace` members shall not affect the validity of
|
| 924 |
references to container elements, but may invalidate all iterators to
|
| 925 |
the container. The `erase` members shall invalidate only iterators and
|
| 926 |
references to the erased elements, and preserve the relative order of
|
| 927 |
the elements that are not erased.
|
| 928 |
|
| 929 |
The `insert` and `emplace` members shall not affect the validity of
|
| 930 |
+
iterators if `(N+n) <= z * B`, where `N` is the number of elements in
|
| 931 |
+
the container prior to the insert operation, `n` is the number of
|
| 932 |
+
elements inserted, `B` is the container’s bucket count, and `z` is the
|
| 933 |
container’s maximum load factor.
|
| 934 |
|
| 935 |
+
The `extract` members invalidate only iterators to the removed element,
|
| 936 |
+
and preserve the relative order of the elements that are not erased;
|
| 937 |
+
pointers and references to the removed element remain valid. However,
|
| 938 |
+
accessing the element through such pointers and references while the
|
| 939 |
+
element is owned by a `node_type` is undefined behavior. References and
|
| 940 |
+
pointers to an element obtained while it is owned by a `node_type` are
|
| 941 |
+
invalidated if the element is successfully inserted.
|
| 942 |
+
|
| 943 |
+
A deduction guide for an unordered associative container shall not
|
| 944 |
+
participate in overload resolution if any of the following are true:
|
| 945 |
+
|
| 946 |
+
- It has an `InputIterator` template parameter and a type that does not
|
| 947 |
+
qualify as an input iterator is deduced for that parameter.
|
| 948 |
+
- It has an `Allocator` template parameter and a type that does not
|
| 949 |
+
qualify as an allocator is deduced for that parameter.
|
| 950 |
+
- It has a `Hash` template parameter and an integral type or a type that
|
| 951 |
+
qualifies as an allocator is deduced for that parameter.
|
| 952 |
+
- It has a `Pred` template parameter and a type that qualifies as an
|
| 953 |
+
allocator is deduced for that parameter.
|
| 954 |
+
|
| 955 |
#### Exception safety guarantees <a id="unord.req.except">[[unord.req.except]]</a>
|
| 956 |
|
| 957 |
For unordered associative containers, no `clear()` function throws an
|
| 958 |
exception. `erase(k)` does not throw an exception unless that exception
|
| 959 |
is thrown by the container’s `Hash` or `Pred` object (if any).
|
|
|
|
| 963 |
`insert` or `emplace` function inserting a single element, the insertion
|
| 964 |
has no effect.
|
| 965 |
|
| 966 |
For unordered associative containers, no `swap` function throws an
|
| 967 |
exception unless that exception is thrown by the swap of the container’s
|
| 968 |
+
`Hash` or `Pred` object (if any).
|
| 969 |
|
| 970 |
For unordered associative containers, if an exception is thrown from
|
| 971 |
within a `rehash()` function other than by the container’s hash function
|
| 972 |
or comparison function, the `rehash()` function has no effect.
|
| 973 |
|
| 974 |
## Sequence containers <a id="sequences">[[sequences]]</a>
|
| 975 |
|
| 976 |
### In general <a id="sequences.general">[[sequences.general]]</a>
|
| 977 |
|
| 978 |
The headers `<array>`, `<deque>`, `<forward_list>`, `<list>`, and
|
| 979 |
+
`<vector>` define class templates that meet the requirements for
|
| 980 |
sequence containers.
|
| 981 |
|
| 982 |
+
### Header `<array>` synopsis <a id="array.syn">[[array.syn]]</a>
|
|
|
|
|
|
|
|
|
|
|
|
|
| 983 |
|
| 984 |
``` cpp
|
| 985 |
#include <initializer_list>
|
| 986 |
|
| 987 |
namespace std {
|
| 988 |
+
// [array], class template array
|
| 989 |
template <class T, size_t N> struct array;
|
| 990 |
template <class T, size_t N>
|
| 991 |
bool operator==(const array<T, N>& x, const array<T, N>& y);
|
| 992 |
template <class T, size_t N>
|
| 993 |
bool operator!=(const array<T, N>& x, const array<T, N>& y);
|
|
|
|
| 1012 |
constexpr T& get(array<T, N>&) noexcept;
|
| 1013 |
template <size_t I, class T, size_t N>
|
| 1014 |
constexpr T&& get(array<T, N>&&) noexcept;
|
| 1015 |
template <size_t I, class T, size_t N>
|
| 1016 |
constexpr const T& get(const array<T, N>&) noexcept;
|
| 1017 |
+
template <size_t I, class T, size_t N>
|
| 1018 |
+
constexpr const T&& get(const array<T, N>&&) noexcept;
|
| 1019 |
}
|
| 1020 |
```
|
| 1021 |
|
| 1022 |
+
### Header `<deque>` synopsis <a id="deque.syn">[[deque.syn]]</a>
|
| 1023 |
|
| 1024 |
``` cpp
|
| 1025 |
#include <initializer_list>
|
| 1026 |
|
| 1027 |
namespace std {
|
| 1028 |
+
// [deque], class template deque
|
| 1029 |
template <class T, class Allocator = allocator<T>> class deque;
|
| 1030 |
template <class T, class Allocator>
|
| 1031 |
bool operator==(const deque<T, Allocator>& x, const deque<T, Allocator>& y);
|
| 1032 |
template <class T, class Allocator>
|
| 1033 |
bool operator< (const deque<T, Allocator>& x, const deque<T, Allocator>& y);
|
|
|
|
| 1038 |
template <class T, class Allocator>
|
| 1039 |
bool operator>=(const deque<T, Allocator>& x, const deque<T, Allocator>& y);
|
| 1040 |
template <class T, class Allocator>
|
| 1041 |
bool operator<=(const deque<T, Allocator>& x, const deque<T, Allocator>& y);
|
| 1042 |
template <class T, class Allocator>
|
| 1043 |
+
void swap(deque<T, Allocator>& x, deque<T, Allocator>& y)
|
| 1044 |
+
noexcept(noexcept(x.swap(y)));
|
| 1045 |
+
|
| 1046 |
+
namespace pmr {
|
| 1047 |
+
template <class T>
|
| 1048 |
+
using deque = std::deque<T, polymorphic_allocator<T>>;
|
| 1049 |
+
}
|
| 1050 |
}
|
| 1051 |
```
|
| 1052 |
|
| 1053 |
+
### Header `<forward_list>` synopsis <a id="forward_list.syn">[[forward_list.syn]]</a>
|
| 1054 |
|
| 1055 |
``` cpp
|
| 1056 |
#include <initializer_list>
|
| 1057 |
|
| 1058 |
namespace std {
|
| 1059 |
+
// [forwardlist], class template forward_list
|
| 1060 |
template <class T, class Allocator = allocator<T>> class forward_list;
|
| 1061 |
template <class T, class Allocator>
|
| 1062 |
bool operator==(const forward_list<T, Allocator>& x, const forward_list<T, Allocator>& y);
|
| 1063 |
template <class T, class Allocator>
|
| 1064 |
bool operator< (const forward_list<T, Allocator>& x, const forward_list<T, Allocator>& y);
|
|
|
|
| 1069 |
template <class T, class Allocator>
|
| 1070 |
bool operator>=(const forward_list<T, Allocator>& x, const forward_list<T, Allocator>& y);
|
| 1071 |
template <class T, class Allocator>
|
| 1072 |
bool operator<=(const forward_list<T, Allocator>& x, const forward_list<T, Allocator>& y);
|
| 1073 |
template <class T, class Allocator>
|
| 1074 |
+
void swap(forward_list<T, Allocator>& x, forward_list<T, Allocator>& y)
|
| 1075 |
+
noexcept(noexcept(x.swap(y)));
|
| 1076 |
+
|
| 1077 |
+
namespace pmr {
|
| 1078 |
+
template <class T>
|
| 1079 |
+
using forward_list = std::forward_list<T, polymorphic_allocator<T>>;
|
| 1080 |
+
}
|
| 1081 |
}
|
| 1082 |
```
|
| 1083 |
|
| 1084 |
+
### Header `<list>` synopsis <a id="list.syn">[[list.syn]]</a>
|
| 1085 |
|
| 1086 |
``` cpp
|
| 1087 |
#include <initializer_list>
|
| 1088 |
|
| 1089 |
namespace std {
|
| 1090 |
+
// [list], class template list
|
| 1091 |
template <class T, class Allocator = allocator<T>> class list;
|
| 1092 |
template <class T, class Allocator>
|
| 1093 |
bool operator==(const list<T, Allocator>& x, const list<T, Allocator>& y);
|
| 1094 |
template <class T, class Allocator>
|
| 1095 |
bool operator< (const list<T, Allocator>& x, const list<T, Allocator>& y);
|
|
|
|
| 1100 |
template <class T, class Allocator>
|
| 1101 |
bool operator>=(const list<T, Allocator>& x, const list<T, Allocator>& y);
|
| 1102 |
template <class T, class Allocator>
|
| 1103 |
bool operator<=(const list<T, Allocator>& x, const list<T, Allocator>& y);
|
| 1104 |
template <class T, class Allocator>
|
| 1105 |
+
void swap(list<T, Allocator>& x, list<T, Allocator>& y)
|
| 1106 |
+
noexcept(noexcept(x.swap(y)));
|
| 1107 |
+
|
| 1108 |
+
namespace pmr {
|
| 1109 |
+
template <class T>
|
| 1110 |
+
using list = std::list<T, polymorphic_allocator<T>>;
|
| 1111 |
+
}
|
| 1112 |
}
|
| 1113 |
```
|
| 1114 |
|
| 1115 |
+
### Header `<vector>` synopsis <a id="vector.syn">[[vector.syn]]</a>
|
| 1116 |
|
| 1117 |
``` cpp
|
| 1118 |
#include <initializer_list>
|
| 1119 |
|
| 1120 |
namespace std {
|
| 1121 |
+
// [vector], class template vector
|
| 1122 |
template <class T, class Allocator = allocator<T>> class vector;
|
| 1123 |
template <class T, class Allocator>
|
| 1124 |
bool operator==(const vector<T, Allocator>& x, const vector<T, Allocator>& y);
|
| 1125 |
template <class T, class Allocator>
|
| 1126 |
bool operator< (const vector<T, Allocator>& x, const vector<T, Allocator>& y);
|
|
|
|
| 1131 |
template <class T, class Allocator>
|
| 1132 |
bool operator>=(const vector<T, Allocator>& x, const vector<T, Allocator>& y);
|
| 1133 |
template <class T, class Allocator>
|
| 1134 |
bool operator<=(const vector<T, Allocator>& x, const vector<T, Allocator>& y);
|
| 1135 |
template <class T, class Allocator>
|
| 1136 |
+
void swap(vector<T, Allocator>& x, vector<T, Allocator>& y)
|
| 1137 |
+
noexcept(noexcept(x.swap(y)));
|
| 1138 |
|
| 1139 |
+
// [vector.bool], class vector<bool>
|
| 1140 |
template <class Allocator> class vector<bool, Allocator>;
|
| 1141 |
|
| 1142 |
// hash support
|
| 1143 |
template <class T> struct hash;
|
| 1144 |
template <class Allocator> struct hash<vector<bool, Allocator>>;
|
| 1145 |
+
|
| 1146 |
+
namespace pmr {
|
| 1147 |
+
template <class T>
|
| 1148 |
+
using vector = std::vector<T, polymorphic_allocator<T>>;
|
| 1149 |
+
}
|
| 1150 |
}
|
| 1151 |
```
|
| 1152 |
|
| 1153 |
### Class template `array` <a id="array">[[array]]</a>
|
| 1154 |
|
| 1155 |
#### Class template `array` overview <a id="array.overview">[[array.overview]]</a>
|
| 1156 |
|
| 1157 |
The header `<array>` defines a class template for storing fixed-size
|
| 1158 |
+
sequences of objects. An `array` is a contiguous container (
|
| 1159 |
+
[[container.requirements.general]]). An instance of `array<T, N>` stores
|
| 1160 |
+
`N` elements of type `T`, so that `size() == N` is an invariant.
|
|
|
|
|
|
|
| 1161 |
|
| 1162 |
+
An `array` is an aggregate ([[dcl.init.aggr]]) that can be
|
| 1163 |
+
list-initialized with up to `N` elements whose types are convertible to
|
| 1164 |
+
`T`.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1165 |
|
| 1166 |
An `array` satisfies all of the requirements of a container and of a
|
| 1167 |
reversible container ([[container.requirements]]), except that a
|
| 1168 |
default constructed `array` object is not empty and that `swap` does not
|
| 1169 |
have constant complexity. An `array` satisfies some of the requirements
|
|
|
|
| 1175 |
``` cpp
|
| 1176 |
namespace std {
|
| 1177 |
template <class T, size_t N>
|
| 1178 |
struct array {
|
| 1179 |
// types:
|
| 1180 |
+
using value_type = T;
|
| 1181 |
+
using pointer = T*;
|
| 1182 |
+
using const_pointer = const T*;
|
| 1183 |
+
using reference = T&;
|
| 1184 |
+
using const_reference = const T&;
|
| 1185 |
+
using size_type = size_t;
|
| 1186 |
+
using difference_type = ptrdiff_t;
|
| 1187 |
+
using iterator = implementation-defined // type of array::iterator; // see [container.requirements]
|
| 1188 |
+
using const_iterator = implementation-defined // type of array::const_iterator; // see [container.requirements]
|
| 1189 |
+
using reverse_iterator = std::reverse_iterator<iterator>;
|
| 1190 |
+
using const_reverse_iterator = std::reverse_iterator<const_iterator>;
|
|
|
|
|
|
|
| 1191 |
|
| 1192 |
// no explicit construct/copy/destroy for aggregate type
|
| 1193 |
|
| 1194 |
void fill(const T& u);
|
| 1195 |
+
void swap(array&) noexcept(is_nothrow_swappable_v<T>);
|
| 1196 |
|
| 1197 |
// iterators:
|
| 1198 |
+
constexpr iterator begin() noexcept;
|
| 1199 |
+
constexpr const_iterator begin() const noexcept;
|
| 1200 |
+
constexpr iterator end() noexcept;
|
| 1201 |
+
constexpr const_iterator end() const noexcept;
|
| 1202 |
|
| 1203 |
+
constexpr reverse_iterator rbegin() noexcept;
|
| 1204 |
+
constexpr const_reverse_iterator rbegin() const noexcept;
|
| 1205 |
+
constexpr reverse_iterator rend() noexcept;
|
| 1206 |
+
constexpr const_reverse_iterator rend() const noexcept;
|
| 1207 |
|
| 1208 |
+
constexpr const_iterator cbegin() const noexcept;
|
| 1209 |
+
constexpr const_iterator cend() const noexcept;
|
| 1210 |
+
constexpr const_reverse_iterator crbegin() const noexcept;
|
| 1211 |
+
constexpr const_reverse_iterator crend() const noexcept;
|
| 1212 |
|
| 1213 |
// capacity:
|
| 1214 |
+
constexpr bool empty() const noexcept;
|
| 1215 |
constexpr size_type size() const noexcept;
|
| 1216 |
constexpr size_type max_size() const noexcept;
|
|
|
|
| 1217 |
|
| 1218 |
// element access:
|
| 1219 |
+
constexpr reference operator[](size_type n);
|
| 1220 |
constexpr const_reference operator[](size_type n) const;
|
| 1221 |
+
constexpr reference at(size_type n);
|
| 1222 |
constexpr const_reference at(size_type n) const;
|
| 1223 |
+
constexpr reference front();
|
| 1224 |
constexpr const_reference front() const;
|
| 1225 |
+
constexpr reference back();
|
| 1226 |
constexpr const_reference back() const;
|
| 1227 |
|
| 1228 |
+
constexpr T * data() noexcept;
|
| 1229 |
+
constexpr const T * data() const noexcept;
|
| 1230 |
};
|
| 1231 |
+
|
| 1232 |
+
template<class T, class... U>
|
| 1233 |
+
array(T, U...) -> array<T, 1 + sizeof...(U)>;
|
| 1234 |
}
|
| 1235 |
```
|
| 1236 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1237 |
#### `array` constructors, copy, and assignment <a id="array.cons">[[array.cons]]</a>
|
| 1238 |
|
| 1239 |
The conditions for an aggregate ([[dcl.init.aggr]]) shall be met. Class
|
| 1240 |
`array` relies on the implicitly-declared special member functions (
|
| 1241 |
[[class.ctor]], [[class.dtor]], and [[class.copy]]) to conform to the
|
|
|
|
| 1243 |
to the requirements specified in the container requirements table, the
|
| 1244 |
implicit move constructor and move assignment operator for `array`
|
| 1245 |
require that `T` be `MoveConstructible` or `MoveAssignable`,
|
| 1246 |
respectively.
|
| 1247 |
|
| 1248 |
+
``` cpp
|
| 1249 |
+
template<class T, class... U>
|
| 1250 |
+
array(T, U...) -> array<T, 1 + sizeof...(U)>;
|
| 1251 |
+
```
|
| 1252 |
+
|
| 1253 |
+
*Requires:* `(is_same_v<T, U> && ...)` is `true`. Otherwise the program
|
| 1254 |
+
is ill-formed.
|
| 1255 |
+
|
| 1256 |
#### `array` specialized algorithms <a id="array.special">[[array.special]]</a>
|
| 1257 |
|
| 1258 |
``` cpp
|
| 1259 |
+
template <class T, size_t N>
|
| 1260 |
+
void swap(array<T, N>& x, array<T, N>& y) noexcept(noexcept(x.swap(y)));
|
| 1261 |
```
|
| 1262 |
|
| 1263 |
+
*Remarks:* This function shall not participate in overload resolution
|
| 1264 |
+
unless `N == 0` or `is_swappable_v<T>` is `true`.
|
| 1265 |
|
| 1266 |
+
*Effects:* As if by `x.swap(y)`.
|
|
|
|
|
|
|
| 1267 |
|
| 1268 |
*Complexity:* Linear in `N`.
|
| 1269 |
|
| 1270 |
#### `array::size` <a id="array.size">[[array.size]]</a>
|
| 1271 |
|
| 1272 |
``` cpp
|
| 1273 |
template <class T, size_t N> constexpr size_type array<T, N>::size() const noexcept;
|
| 1274 |
```
|
| 1275 |
|
| 1276 |
+
*Returns:* `N`.
|
| 1277 |
|
| 1278 |
#### `array::data` <a id="array.data">[[array.data]]</a>
|
| 1279 |
|
| 1280 |
``` cpp
|
| 1281 |
+
constexpr T* data() noexcept;
|
| 1282 |
+
constexpr const T* data() const noexcept;
|
| 1283 |
```
|
| 1284 |
|
| 1285 |
+
*Returns:* A pointer such that `data() == addressof(front())`, and
|
| 1286 |
+
\[`data()`, `data() + size()`) is a valid range.
|
| 1287 |
|
| 1288 |
#### `array::fill` <a id="array.fill">[[array.fill]]</a>
|
| 1289 |
|
| 1290 |
``` cpp
|
| 1291 |
void fill(const T& u);
|
| 1292 |
```
|
| 1293 |
|
| 1294 |
+
*Effects:* As if by `fill_n(begin(), N, u)`.
|
| 1295 |
|
| 1296 |
#### `array::swap` <a id="array.swap">[[array.swap]]</a>
|
| 1297 |
|
| 1298 |
``` cpp
|
| 1299 |
+
void swap(array& y) noexcept(is_nothrow_swappable_v<T>);
|
| 1300 |
```
|
| 1301 |
|
| 1302 |
+
*Effects:* Equivalent to `swap_ranges(begin(), end(), y.begin())`.
|
| 1303 |
|
| 1304 |
+
[*Note 1*: Unlike the `swap` function for other containers,
|
| 1305 |
+
`array::swap` takes linear time, may exit via an exception, and does not
|
| 1306 |
+
cause iterators to become associated with the other
|
| 1307 |
+
container. — *end note*]
|
|
|
|
|
|
|
| 1308 |
|
| 1309 |
#### Zero sized arrays <a id="array.zero">[[array.zero]]</a>
|
| 1310 |
|
| 1311 |
`array` shall provide support for the special case `N == 0`.
|
| 1312 |
|
|
|
|
| 1314 |
return value of `data()` is unspecified.
|
| 1315 |
|
| 1316 |
The effect of calling `front()` or `back()` for a zero-sized array is
|
| 1317 |
undefined.
|
| 1318 |
|
| 1319 |
+
Member function `swap()` shall have a non-throwing exception
|
| 1320 |
+
specification.
|
| 1321 |
|
| 1322 |
#### Tuple interface to class template `array` <a id="array.tuple">[[array.tuple]]</a>
|
| 1323 |
|
| 1324 |
``` cpp
|
| 1325 |
template <class T, size_t N>
|
| 1326 |
+
struct tuple_size<array<T, N>> : integral_constant<size_t, N> { };
|
|
|
|
| 1327 |
```
|
| 1328 |
|
| 1329 |
``` cpp
|
| 1330 |
tuple_element<I, array<T, N>>::type
|
| 1331 |
```
|
|
|
|
| 1335 |
*Value:* The type T.
|
| 1336 |
|
| 1337 |
``` cpp
|
| 1338 |
template <size_t I, class T, size_t N>
|
| 1339 |
constexpr T& get(array<T, N>& a) noexcept;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1340 |
template <size_t I, class T, size_t N>
|
| 1341 |
constexpr T&& get(array<T, N>&& a) noexcept;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1342 |
template <size_t I, class T, size_t N>
|
| 1343 |
constexpr const T& get(const array<T, N>& a) noexcept;
|
| 1344 |
+
template <size_t I, class T, size_t N>
|
| 1345 |
+
constexpr const T&& get(const array<T, N>&& a) noexcept;
|
| 1346 |
```
|
| 1347 |
|
| 1348 |
*Requires:* `I < N`. The program is ill-formed if `I` is out of bounds.
|
| 1349 |
|
| 1350 |
+
*Returns:* A reference to the `I`th element of `a`, where indexing is
|
| 1351 |
+
zero-based.
|
| 1352 |
|
| 1353 |
### Class template `deque` <a id="deque">[[deque]]</a>
|
| 1354 |
|
| 1355 |
#### Class template `deque` overview <a id="deque.overview">[[deque.overview]]</a>
|
| 1356 |
|
| 1357 |
+
A `deque` is a sequence container that supports random access iterators
|
| 1358 |
+
([[random.access.iterators]]). In addition, it supports constant time
|
| 1359 |
insert and erase operations at the beginning or the end; insert and
|
| 1360 |
erase in the middle take linear time. That is, a deque is especially
|
| 1361 |
+
optimized for pushing and popping elements at the beginning and end.
|
| 1362 |
+
Storage management is handled automatically.
|
| 1363 |
|
| 1364 |
A `deque` satisfies all of the requirements of a container, of a
|
| 1365 |
reversible container (given in tables in [[container.requirements]]),
|
| 1366 |
of a sequence container, including the optional sequence container
|
| 1367 |
requirements ([[sequence.reqmts]]), and of an allocator-aware container
|
|
|
|
| 1374 |
namespace std {
|
| 1375 |
template <class T, class Allocator = allocator<T>>
|
| 1376 |
class deque {
|
| 1377 |
public:
|
| 1378 |
// types:
|
| 1379 |
+
using value_type = T;
|
| 1380 |
+
using allocator_type = Allocator;
|
| 1381 |
+
using pointer = typename allocator_traits<Allocator>::pointer;
|
| 1382 |
+
using const_pointer = typename allocator_traits<Allocator>::const_pointer;
|
| 1383 |
+
using reference = value_type&;
|
| 1384 |
+
using const_reference = const value_type&;
|
| 1385 |
+
using size_type = implementation-defined; // see [container.requirements]
|
| 1386 |
+
using difference_type = implementation-defined; // see [container.requirements]
|
| 1387 |
+
using iterator = implementation-defined // type of deque::iterator; // see [container.requirements]
|
| 1388 |
+
using const_iterator = implementation-defined // type of deque::const_iterator; // see [container.requirements]
|
| 1389 |
+
using reverse_iterator = std::reverse_iterator<iterator>;
|
| 1390 |
+
using const_reverse_iterator = std::reverse_iterator<const_iterator>;
|
| 1391 |
|
| 1392 |
+
// [deque.cons], construct/copy/destroy
|
| 1393 |
deque() : deque(Allocator()) { }
|
| 1394 |
explicit deque(const Allocator&);
|
| 1395 |
explicit deque(size_type n, const Allocator& = Allocator());
|
| 1396 |
deque(size_type n, const T& value, const Allocator& = Allocator());
|
| 1397 |
template <class InputIterator>
|
|
|
|
| 1402 |
deque(deque&&, const Allocator&);
|
| 1403 |
deque(initializer_list<T>, const Allocator& = Allocator());
|
| 1404 |
|
| 1405 |
~deque();
|
| 1406 |
deque& operator=(const deque& x);
|
| 1407 |
+
deque& operator=(deque&& x)
|
| 1408 |
+
noexcept(allocator_traits<Allocator>::is_always_equal::value);
|
| 1409 |
deque& operator=(initializer_list<T>);
|
| 1410 |
template <class InputIterator>
|
| 1411 |
void assign(InputIterator first, InputIterator last);
|
| 1412 |
void assign(size_type n, const T& t);
|
| 1413 |
void assign(initializer_list<T>);
|
|
|
|
| 1426 |
const_iterator cbegin() const noexcept;
|
| 1427 |
const_iterator cend() const noexcept;
|
| 1428 |
const_reverse_iterator crbegin() const noexcept;
|
| 1429 |
const_reverse_iterator crend() const noexcept;
|
| 1430 |
|
| 1431 |
+
// [deque.capacity], capacity
|
| 1432 |
+
bool empty() const noexcept;
|
| 1433 |
size_type size() const noexcept;
|
| 1434 |
size_type max_size() const noexcept;
|
| 1435 |
void resize(size_type sz);
|
| 1436 |
void resize(size_type sz, const T& c);
|
| 1437 |
void shrink_to_fit();
|
|
|
|
| 1438 |
|
| 1439 |
// element access:
|
| 1440 |
reference operator[](size_type n);
|
| 1441 |
const_reference operator[](size_type n) const;
|
| 1442 |
reference at(size_type n);
|
|
|
|
| 1444 |
reference front();
|
| 1445 |
const_reference front() const;
|
| 1446 |
reference back();
|
| 1447 |
const_reference back() const;
|
| 1448 |
|
| 1449 |
+
// [deque.modifiers], modifiers
|
| 1450 |
+
template <class... Args> reference emplace_front(Args&&... args);
|
| 1451 |
+
template <class... Args> reference emplace_back(Args&&... args);
|
| 1452 |
template <class... Args> iterator emplace(const_iterator position, Args&&... args);
|
| 1453 |
|
| 1454 |
void push_front(const T& x);
|
| 1455 |
void push_front(T&& x);
|
| 1456 |
void push_back(const T& x);
|
|
|
|
| 1466 |
void pop_front();
|
| 1467 |
void pop_back();
|
| 1468 |
|
| 1469 |
iterator erase(const_iterator position);
|
| 1470 |
iterator erase(const_iterator first, const_iterator last);
|
| 1471 |
+
void swap(deque&)
|
| 1472 |
+
noexcept(allocator_traits<Allocator>::is_always_equal::value);
|
| 1473 |
void clear() noexcept;
|
| 1474 |
};
|
| 1475 |
|
| 1476 |
+
template<class InputIterator,
|
| 1477 |
+
class Allocator = allocator<typename iterator_traits<InputIterator>::value_type>>
|
| 1478 |
+
deque(InputIterator, InputIterator, Allocator = Allocator())
|
| 1479 |
+
-> deque<typename iterator_traits<InputIterator>::value_type, Allocator>;
|
| 1480 |
+
|
| 1481 |
template <class T, class Allocator>
|
| 1482 |
bool operator==(const deque<T, Allocator>& x, const deque<T, Allocator>& y);
|
| 1483 |
template <class T, class Allocator>
|
| 1484 |
bool operator< (const deque<T, Allocator>& x, const deque<T, Allocator>& y);
|
| 1485 |
template <class T, class Allocator>
|
|
|
|
| 1489 |
template <class T, class Allocator>
|
| 1490 |
bool operator>=(const deque<T, Allocator>& x, const deque<T, Allocator>& y);
|
| 1491 |
template <class T, class Allocator>
|
| 1492 |
bool operator<=(const deque<T, Allocator>& x, const deque<T, Allocator>& y);
|
| 1493 |
|
| 1494 |
+
// [deque.special], specialized algorithms
|
| 1495 |
template <class T, class Allocator>
|
| 1496 |
+
void swap(deque<T, Allocator>& x, deque<T, Allocator>& y)
|
| 1497 |
+
noexcept(noexcept(x.swap(y)));
|
| 1498 |
}
|
| 1499 |
```
|
| 1500 |
|
| 1501 |
#### `deque` constructors, copy, and assignment <a id="deque.cons">[[deque.cons]]</a>
|
| 1502 |
|
|
|
|
| 1518 |
*Requires:* `T` shall be `DefaultInsertable` into `*this`.
|
| 1519 |
|
| 1520 |
*Complexity:* Linear in `n`.
|
| 1521 |
|
| 1522 |
``` cpp
|
| 1523 |
+
deque(size_type n, const T& value, const Allocator& = Allocator());
|
|
|
|
| 1524 |
```
|
| 1525 |
|
| 1526 |
*Effects:* Constructs a `deque` with `n` copies of `value`, using the
|
| 1527 |
specified allocator.
|
| 1528 |
|
|
|
|
| 1530 |
|
| 1531 |
*Complexity:* Linear in `n`.
|
| 1532 |
|
| 1533 |
``` cpp
|
| 1534 |
template <class InputIterator>
|
| 1535 |
+
deque(InputIterator first, InputIterator last, const Allocator& = Allocator());
|
|
|
|
| 1536 |
```
|
| 1537 |
|
| 1538 |
*Effects:* Constructs a `deque` equal to the range \[`first`, `last`),
|
| 1539 |
using the specified allocator.
|
| 1540 |
|
|
|
|
| 1544 |
|
| 1545 |
``` cpp
|
| 1546 |
void resize(size_type sz);
|
| 1547 |
```
|
| 1548 |
|
| 1549 |
+
*Effects:* If `sz < size()`, erases the last `size() - sz` elements from
|
| 1550 |
+
the sequence. Otherwise, appends `sz - size()` default-inserted elements
|
| 1551 |
+
to the sequence.
|
| 1552 |
|
| 1553 |
*Requires:* `T` shall be `MoveInsertable` and `DefaultInsertable` into
|
| 1554 |
`*this`.
|
| 1555 |
|
| 1556 |
``` cpp
|
| 1557 |
void resize(size_type sz, const T& c);
|
| 1558 |
```
|
| 1559 |
|
| 1560 |
+
*Effects:* If `sz < size()`, erases the last `size() - sz` elements from
|
| 1561 |
+
the sequence. Otherwise, appends `sz - size()` copies of `c` to the
|
| 1562 |
+
sequence.
|
| 1563 |
|
| 1564 |
*Requires:* `T` shall be `CopyInsertable` into `*this`.
|
| 1565 |
|
| 1566 |
``` cpp
|
| 1567 |
void shrink_to_fit();
|
| 1568 |
```
|
| 1569 |
|
| 1570 |
*Requires:* `T` shall be `MoveInsertable` into `*this`.
|
| 1571 |
|
| 1572 |
+
*Effects:* `shrink_to_fit` is a non-binding request to reduce memory use
|
| 1573 |
+
but does not change the size of the sequence.
|
| 1574 |
+
|
| 1575 |
+
[*Note 1*: The request is non-binding to allow latitude for
|
| 1576 |
+
implementation-specific optimizations. — *end note*]
|
| 1577 |
+
|
| 1578 |
+
If an exception is thrown other than by the move constructor of a
|
| 1579 |
+
non-`CopyInsertable` `T` there are no effects.
|
| 1580 |
+
|
| 1581 |
*Complexity:* Linear in the size of the sequence.
|
| 1582 |
|
| 1583 |
+
*Remarks:* `shrink_to_fit` invalidates all the references, pointers, and
|
| 1584 |
+
iterators referring to the elements in the sequence as well as the
|
| 1585 |
+
past-the-end iterator.
|
| 1586 |
|
| 1587 |
#### `deque` modifiers <a id="deque.modifiers">[[deque.modifiers]]</a>
|
| 1588 |
|
| 1589 |
``` cpp
|
| 1590 |
iterator insert(const_iterator position, const T& x);
|
|
|
|
| 1593 |
template <class InputIterator>
|
| 1594 |
iterator insert(const_iterator position,
|
| 1595 |
InputIterator first, InputIterator last);
|
| 1596 |
iterator insert(const_iterator position, initializer_list<T>);
|
| 1597 |
|
| 1598 |
+
template <class... Args> reference emplace_front(Args&&... args);
|
| 1599 |
+
template <class... Args> reference emplace_back(Args&&... args);
|
| 1600 |
template <class... Args> iterator emplace(const_iterator position, Args&&... args);
|
| 1601 |
void push_front(const T& x);
|
| 1602 |
void push_front(T&& x);
|
| 1603 |
void push_back(const T& x);
|
| 1604 |
void push_back(T&& x);
|
|
|
|
| 1623 |
constructor of `T`.
|
| 1624 |
|
| 1625 |
``` cpp
|
| 1626 |
iterator erase(const_iterator position);
|
| 1627 |
iterator erase(const_iterator first, const_iterator last);
|
| 1628 |
+
void pop_front();
|
| 1629 |
+
void pop_back();
|
| 1630 |
```
|
| 1631 |
|
| 1632 |
*Effects:* An erase operation that erases the last element of a deque
|
| 1633 |
invalidates only the past-the-end iterator and all iterators and
|
| 1634 |
references to the erased elements. An erase operation that erases the
|
| 1635 |
+
first element of a deque but not the last element invalidates only
|
| 1636 |
+
iterators and references to the erased elements. An erase operation that
|
| 1637 |
+
erases neither the first element nor the last element of a deque
|
| 1638 |
+
invalidates the past-the-end iterator and all iterators and references
|
| 1639 |
+
to all the elements of the deque.
|
| 1640 |
|
| 1641 |
+
[*Note 1*: `pop_front` and `pop_back` are erase
|
| 1642 |
+
operations. — *end note*]
|
| 1643 |
+
|
| 1644 |
+
*Complexity:* The number of calls to the destructor of `T` is the same
|
| 1645 |
+
as the number of elements erased, but the number of calls to the
|
| 1646 |
+
assignment operator of `T` is no more than the lesser of the number of
|
| 1647 |
+
elements before the erased elements and the number of elements after the
|
| 1648 |
+
erased elements.
|
| 1649 |
|
| 1650 |
*Throws:* Nothing unless an exception is thrown by the copy constructor,
|
| 1651 |
move constructor, assignment operator, or move assignment operator of
|
| 1652 |
`T`.
|
| 1653 |
|
| 1654 |
#### `deque` specialized algorithms <a id="deque.special">[[deque.special]]</a>
|
| 1655 |
|
| 1656 |
``` cpp
|
| 1657 |
template <class T, class Allocator>
|
| 1658 |
+
void swap(deque<T, Allocator>& x, deque<T, Allocator>& y)
|
| 1659 |
+
noexcept(noexcept(x.swap(y)));
|
| 1660 |
```
|
| 1661 |
|
| 1662 |
+
*Effects:* As if by `x.swap(y)`.
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1663 |
|
| 1664 |
### Class template `forward_list` <a id="forwardlist">[[forwardlist]]</a>
|
| 1665 |
|
| 1666 |
#### Class template `forward_list` overview <a id="forwardlist.overview">[[forwardlist.overview]]</a>
|
| 1667 |
|
| 1668 |
A `forward_list` is a container that supports forward iterators and
|
| 1669 |
allows constant time insert and erase operations anywhere within the
|
| 1670 |
sequence, with storage management handled automatically. Fast random
|
| 1671 |
+
access to list elements is not supported.
|
| 1672 |
+
|
| 1673 |
+
[*Note 1*: It is intended that `forward_list` have zero space or time
|
| 1674 |
+
overhead relative to a hand-written C-style singly linked list. Features
|
| 1675 |
+
that would conflict with that goal have been omitted. — *end note*]
|
| 1676 |
|
| 1677 |
A `forward_list` satisfies all of the requirements of a container
|
| 1678 |
(Table [[tab:containers.container.requirements]]), except that the
|
| 1679 |
`size()` member function is not provided and `operator==` has linear
|
| 1680 |
complexity. A `forward_list` also satisfies all of the requirements for
|
|
|
|
| 1684 |
optional container requirements (Table
|
| 1685 |
[[tab:containers.sequence.optional]]). Descriptions are provided here
|
| 1686 |
only for operations on `forward_list` that are not described in that
|
| 1687 |
table or for operations where there is additional semantic information.
|
| 1688 |
|
| 1689 |
+
[*Note 2*: Modifying any list requires access to the element preceding
|
| 1690 |
+
the first element of interest, but in a `forward_list` there is no
|
| 1691 |
+
constant-time way to access a preceding element. For this reason, ranges
|
| 1692 |
+
that are modified, such as those supplied to `erase` and `splice`, must
|
| 1693 |
+
be open at the beginning. — *end note*]
|
| 1694 |
|
| 1695 |
``` cpp
|
| 1696 |
namespace std {
|
| 1697 |
template <class T, class Allocator = allocator<T>>
|
| 1698 |
class forward_list {
|
| 1699 |
public:
|
| 1700 |
// types:
|
| 1701 |
+
using value_type = T;
|
| 1702 |
+
using allocator_type = Allocator;
|
| 1703 |
+
using pointer = typename allocator_traits<Allocator>::pointer;
|
| 1704 |
+
using const_pointer = typename allocator_traits<Allocator>::const_pointer;
|
| 1705 |
+
using reference = value_type&;
|
| 1706 |
+
using const_reference = const value_type&;
|
| 1707 |
+
using size_type = implementation-defined; // see [container.requirements]
|
| 1708 |
+
using difference_type = implementation-defined; // see [container.requirements]
|
| 1709 |
+
using iterator = implementation-defined // type of forward_list::iterator; // see [container.requirements]
|
| 1710 |
+
using const_iterator = implementation-defined // type of forward_list::const_iterator; // see [container.requirements]
|
| 1711 |
|
| 1712 |
+
// [forwardlist.cons], construct/copy/destroy
|
| 1713 |
forward_list() : forward_list(Allocator()) { }
|
| 1714 |
explicit forward_list(const Allocator&);
|
| 1715 |
explicit forward_list(size_type n, const Allocator& = Allocator());
|
| 1716 |
forward_list(size_type n, const T& value,
|
| 1717 |
const Allocator& = Allocator());
|
|
|
|
| 1723 |
forward_list(const forward_list& x, const Allocator&);
|
| 1724 |
forward_list(forward_list&& x, const Allocator&);
|
| 1725 |
forward_list(initializer_list<T>, const Allocator& = Allocator());
|
| 1726 |
~forward_list();
|
| 1727 |
forward_list& operator=(const forward_list& x);
|
| 1728 |
+
forward_list& operator=(forward_list&& x)
|
| 1729 |
+
noexcept(allocator_traits<Allocator>::is_always_equal::value);
|
| 1730 |
forward_list& operator=(initializer_list<T>);
|
| 1731 |
template <class InputIterator>
|
| 1732 |
void assign(InputIterator first, InputIterator last);
|
| 1733 |
void assign(size_type n, const T& t);
|
| 1734 |
void assign(initializer_list<T>);
|
| 1735 |
allocator_type get_allocator() const noexcept;
|
| 1736 |
|
| 1737 |
+
// [forwardlist.iter], iterators
|
| 1738 |
iterator before_begin() noexcept;
|
| 1739 |
const_iterator before_begin() const noexcept;
|
| 1740 |
iterator begin() noexcept;
|
| 1741 |
const_iterator begin() const noexcept;
|
| 1742 |
iterator end() noexcept;
|
|
|
|
| 1748 |
|
| 1749 |
// capacity:
|
| 1750 |
bool empty() const noexcept;
|
| 1751 |
size_type max_size() const noexcept;
|
| 1752 |
|
| 1753 |
+
// [forwardlist.access], element access
|
| 1754 |
reference front();
|
| 1755 |
const_reference front() const;
|
| 1756 |
|
| 1757 |
+
// [forwardlist.modifiers], modifiers
|
| 1758 |
+
template <class... Args> reference emplace_front(Args&&... args);
|
| 1759 |
void push_front(const T& x);
|
| 1760 |
void push_front(T&& x);
|
| 1761 |
void pop_front();
|
| 1762 |
|
| 1763 |
template <class... Args> iterator emplace_after(const_iterator position, Args&&... args);
|
|
|
|
| 1769 |
iterator insert_after(const_iterator position, InputIterator first, InputIterator last);
|
| 1770 |
iterator insert_after(const_iterator position, initializer_list<T> il);
|
| 1771 |
|
| 1772 |
iterator erase_after(const_iterator position);
|
| 1773 |
iterator erase_after(const_iterator position, const_iterator last);
|
| 1774 |
+
void swap(forward_list&)
|
| 1775 |
+
noexcept(allocator_traits<Allocator>::is_always_equal::value);
|
| 1776 |
|
| 1777 |
void resize(size_type sz);
|
| 1778 |
void resize(size_type sz, const value_type& c);
|
| 1779 |
void clear() noexcept;
|
| 1780 |
|
| 1781 |
+
// [forwardlist.ops], forward_list operations
|
| 1782 |
void splice_after(const_iterator position, forward_list& x);
|
| 1783 |
void splice_after(const_iterator position, forward_list&& x);
|
| 1784 |
void splice_after(const_iterator position, forward_list& x,
|
| 1785 |
const_iterator i);
|
| 1786 |
void splice_after(const_iterator position, forward_list&& x,
|
|
|
|
| 1805 |
template <class Compare> void sort(Compare comp);
|
| 1806 |
|
| 1807 |
void reverse() noexcept;
|
| 1808 |
};
|
| 1809 |
|
| 1810 |
+
template<class InputIterator,
|
| 1811 |
+
class Allocator = allocator<typename iterator_traits<InputIterator>::value_type>>
|
| 1812 |
+
forward_list(InputIterator, InputIterator, Allocator = Allocator())
|
| 1813 |
+
-> forward_list<typename iterator_traits<InputIterator>::value_type, Allocator>;
|
| 1814 |
+
|
| 1815 |
template <class T, class Allocator>
|
| 1816 |
bool operator==(const forward_list<T, Allocator>& x, const forward_list<T, Allocator>& y);
|
| 1817 |
template <class T, class Allocator>
|
| 1818 |
bool operator< (const forward_list<T, Allocator>& x, const forward_list<T, Allocator>& y);
|
| 1819 |
template <class T, class Allocator>
|
|
|
|
| 1823 |
template <class T, class Allocator>
|
| 1824 |
bool operator>=(const forward_list<T, Allocator>& x, const forward_list<T, Allocator>& y);
|
| 1825 |
template <class T, class Allocator>
|
| 1826 |
bool operator<=(const forward_list<T, Allocator>& x, const forward_list<T, Allocator>& y);
|
| 1827 |
|
| 1828 |
+
// [forwardlist.spec], specialized algorithms
|
| 1829 |
template <class T, class Allocator>
|
| 1830 |
+
void swap(forward_list<T, Allocator>& x, forward_list<T, Allocator>& y)
|
| 1831 |
+
noexcept(noexcept(x.swap(y)));
|
| 1832 |
}
|
| 1833 |
```
|
| 1834 |
|
| 1835 |
+
An incomplete type `T` may be used when instantiating `forward_list` if
|
| 1836 |
+
the allocator satisfies the allocator completeness requirements (
|
| 1837 |
+
[[allocator.requirements.completeness]]). `T` shall be complete before
|
| 1838 |
+
any member of the resulting specialization of `forward_list` is
|
| 1839 |
+
referenced.
|
| 1840 |
+
|
| 1841 |
#### `forward_list` constructors, copy, assignment <a id="forwardlist.cons">[[forwardlist.cons]]</a>
|
| 1842 |
|
| 1843 |
``` cpp
|
| 1844 |
explicit forward_list(const Allocator&);
|
| 1845 |
```
|
|
|
|
| 1916 |
to the copy or move constructor of `T` is exactly equal to `n`. Erasing
|
| 1917 |
`n` elements from a `forward_list` is linear in `n` and the number of
|
| 1918 |
calls to the destructor of type `T` is exactly equal to `n`.
|
| 1919 |
|
| 1920 |
``` cpp
|
| 1921 |
+
template <class... Args> reference emplace_front(Args&&... args);
|
| 1922 |
```
|
| 1923 |
|
| 1924 |
*Effects:* Inserts an object of type `value_type` constructed with
|
| 1925 |
`value_type(std::forward<Args>(args)...)` at the beginning of the list.
|
| 1926 |
|
|
|
|
| 1933 |
|
| 1934 |
``` cpp
|
| 1935 |
void pop_front();
|
| 1936 |
```
|
| 1937 |
|
| 1938 |
+
*Effects:* As if by `erase_after(before_begin())`.
|
| 1939 |
|
| 1940 |
``` cpp
|
| 1941 |
iterator insert_after(const_iterator position, const T& x);
|
| 1942 |
iterator insert_after(const_iterator position, T&& x);
|
| 1943 |
```
|
|
|
|
| 2040 |
void resize(size_type sz, const value_type& c);
|
| 2041 |
```
|
| 2042 |
|
| 2043 |
*Effects:* If `sz < distance(begin(), end())`, erases the last
|
| 2044 |
`distance(begin(), end()) - sz` elements from the list. Otherwise,
|
| 2045 |
+
inserts `sz - distance(begin(), end())` copies of `c` at the end of the
|
| 2046 |
+
list.
|
|
|
|
|
|
|
| 2047 |
|
| 2048 |
*Requires:* `T` shall be `CopyInsertable` into `*this`.
|
| 2049 |
|
| 2050 |
``` cpp
|
| 2051 |
void clear() noexcept;
|
|
|
|
| 2072 |
the moved elements will continue to refer to their elements, but they
|
| 2073 |
now behave as iterators into `*this`, not into `x`.
|
| 2074 |
|
| 2075 |
*Throws:* Nothing.
|
| 2076 |
|
| 2077 |
+
*Complexity:* 𝑂(`distance(x.begin(), x.end())`)
|
| 2078 |
|
| 2079 |
``` cpp
|
| 2080 |
void splice_after(const_iterator position, forward_list& x, const_iterator i);
|
| 2081 |
void splice_after(const_iterator position, forward_list&& x, const_iterator i);
|
| 2082 |
```
|
|
|
|
| 2115 |
the moved elements of `x` now refer to those same elements but as
|
| 2116 |
members of `*this`. Iterators referring to the moved elements will
|
| 2117 |
continue to refer to their elements, but they now behave as iterators
|
| 2118 |
into `*this`, not into `x`.
|
| 2119 |
|
| 2120 |
+
*Complexity:* 𝑂(`distance(first, last)`)
|
| 2121 |
|
| 2122 |
``` cpp
|
| 2123 |
void remove(const T& value);
|
| 2124 |
template <class Predicate> void remove_if(Predicate pred);
|
| 2125 |
```
|
| 2126 |
|
| 2127 |
*Effects:* Erases all the elements in the list referred by a list
|
| 2128 |
iterator `i` for which the following conditions hold: `*i == value` (for
|
| 2129 |
+
`remove()`), `pred(*i)` is `true` (for `remove_if()`). Invalidates only
|
| 2130 |
the iterators and references to the erased elements.
|
| 2131 |
|
| 2132 |
*Throws:* Nothing unless an exception is thrown by the equality
|
| 2133 |
comparison or the predicate.
|
| 2134 |
|
|
|
|
| 2174 |
but as members of `*this`. Iterators referring to the moved elements
|
| 2175 |
will continue to refer to their elements, but they now behave as
|
| 2176 |
iterators into `*this`, not into `x`.
|
| 2177 |
|
| 2178 |
*Remarks:* Stable ([[algorithm.stable]]). The behavior is undefined if
|
| 2179 |
+
`get_allocator() != x.get_allocator()`.
|
| 2180 |
|
| 2181 |
*Complexity:* At most
|
| 2182 |
`distance(begin(), end()) + distance(x.begin(), x.end()) - 1`
|
| 2183 |
comparisons.
|
| 2184 |
|
|
|
|
| 2190 |
*Requires:* `operator<` (for the version with no arguments) or `comp`
|
| 2191 |
(for the version with a comparison argument) defines a strict weak
|
| 2192 |
ordering ([[alg.sorting]]).
|
| 2193 |
|
| 2194 |
*Effects:* Sorts the list according to the `operator<` or the `comp`
|
| 2195 |
+
function object. If an exception is thrown, the order of the elements in
|
| 2196 |
`*this` is unspecified. Does not affect the validity of iterators and
|
| 2197 |
references.
|
| 2198 |
|
| 2199 |
*Remarks:* Stable ([[algorithm.stable]]).
|
| 2200 |
|
|
|
|
| 2212 |
|
| 2213 |
#### `forward_list` specialized algorithms <a id="forwardlist.spec">[[forwardlist.spec]]</a>
|
| 2214 |
|
| 2215 |
``` cpp
|
| 2216 |
template <class T, class Allocator>
|
| 2217 |
+
void swap(forward_list<T, Allocator>& x, forward_list<T, Allocator>& y)
|
| 2218 |
+
noexcept(noexcept(x.swap(y)));
|
| 2219 |
```
|
| 2220 |
|
| 2221 |
+
*Effects:* As if by `x.swap(y)`.
|
| 2222 |
|
| 2223 |
### Class template `list` <a id="list">[[list]]</a>
|
| 2224 |
|
| 2225 |
#### Class template `list` overview <a id="list.overview">[[list.overview]]</a>
|
| 2226 |
|
|
|
|
| 2246 |
namespace std {
|
| 2247 |
template <class T, class Allocator = allocator<T>>
|
| 2248 |
class list {
|
| 2249 |
public:
|
| 2250 |
// types:
|
| 2251 |
+
using value_type = T;
|
| 2252 |
+
using allocator_type = Allocator;
|
| 2253 |
+
using pointer = typename allocator_traits<Allocator>::pointer;
|
| 2254 |
+
using const_pointer = typename allocator_traits<Allocator>::const_pointer;
|
| 2255 |
+
using reference = value_type&;
|
| 2256 |
+
using const_reference = const value_type&;
|
| 2257 |
+
using size_type = implementation-defined; // see [container.requirements]
|
| 2258 |
+
using difference_type = implementation-defined; // see [container.requirements]
|
| 2259 |
+
using iterator = implementation-defined // type of list::iterator; // see [container.requirements]
|
| 2260 |
+
using const_iterator = implementation-defined // type of list::const_iterator; // see [container.requirements]
|
| 2261 |
+
using reverse_iterator = std::reverse_iterator<iterator>;
|
| 2262 |
+
using const_reverse_iterator = std::reverse_iterator<const_iterator>;
|
| 2263 |
|
| 2264 |
+
// [list.cons], construct/copy/destroy
|
| 2265 |
list() : list(Allocator()) { }
|
| 2266 |
explicit list(const Allocator&);
|
| 2267 |
explicit list(size_type n, const Allocator& = Allocator());
|
| 2268 |
list(size_type n, const T& value, const Allocator& = Allocator());
|
| 2269 |
template <class InputIterator>
|
|
|
|
| 2273 |
list(const list&, const Allocator&);
|
| 2274 |
list(list&&, const Allocator&);
|
| 2275 |
list(initializer_list<T>, const Allocator& = Allocator());
|
| 2276 |
~list();
|
| 2277 |
list& operator=(const list& x);
|
| 2278 |
+
list& operator=(list&& x)
|
| 2279 |
+
noexcept(allocator_traits<Allocator>::is_always_equal::value);
|
| 2280 |
list& operator=(initializer_list<T>);
|
| 2281 |
template <class InputIterator>
|
| 2282 |
void assign(InputIterator first, InputIterator last);
|
| 2283 |
void assign(size_type n, const T& t);
|
| 2284 |
void assign(initializer_list<T>);
|
|
|
|
| 2297 |
const_iterator cbegin() const noexcept;
|
| 2298 |
const_iterator cend() const noexcept;
|
| 2299 |
const_reverse_iterator crbegin() const noexcept;
|
| 2300 |
const_reverse_iterator crend() const noexcept;
|
| 2301 |
|
| 2302 |
+
// [list.capacity], capacity
|
| 2303 |
bool empty() const noexcept;
|
| 2304 |
size_type size() const noexcept;
|
| 2305 |
size_type max_size() const noexcept;
|
| 2306 |
void resize(size_type sz);
|
| 2307 |
void resize(size_type sz, const T& c);
|
|
|
|
| 2310 |
reference front();
|
| 2311 |
const_reference front() const;
|
| 2312 |
reference back();
|
| 2313 |
const_reference back() const;
|
| 2314 |
|
| 2315 |
+
// [list.modifiers], modifiers
|
| 2316 |
+
template <class... Args> reference emplace_front(Args&&... args);
|
| 2317 |
+
template <class... Args> reference emplace_back(Args&&... args);
|
|
|
|
| 2318 |
void push_front(const T& x);
|
| 2319 |
void push_front(T&& x);
|
| 2320 |
+
void pop_front();
|
| 2321 |
void push_back(const T& x);
|
| 2322 |
void push_back(T&& x);
|
| 2323 |
void pop_back();
|
| 2324 |
|
| 2325 |
template <class... Args> iterator emplace(const_iterator position, Args&&... args);
|
|
|
|
| 2331 |
InputIterator last);
|
| 2332 |
iterator insert(const_iterator position, initializer_list<T> il);
|
| 2333 |
|
| 2334 |
iterator erase(const_iterator position);
|
| 2335 |
iterator erase(const_iterator position, const_iterator last);
|
| 2336 |
+
void swap(list&)
|
| 2337 |
+
noexcept(allocator_traits<Allocator>::is_always_equal::value);
|
| 2338 |
void clear() noexcept;
|
| 2339 |
|
| 2340 |
+
// [list.ops], list operations
|
| 2341 |
void splice(const_iterator position, list& x);
|
| 2342 |
void splice(const_iterator position, list&& x);
|
| 2343 |
void splice(const_iterator position, list& x, const_iterator i);
|
| 2344 |
void splice(const_iterator position, list&& x, const_iterator i);
|
| 2345 |
void splice(const_iterator position, list& x,
|
|
|
|
| 2363 |
template <class Compare> void sort(Compare comp);
|
| 2364 |
|
| 2365 |
void reverse() noexcept;
|
| 2366 |
};
|
| 2367 |
|
| 2368 |
+
template<class InputIterator,
|
| 2369 |
+
class Allocator = allocator<typename iterator_traits<InputIterator>::value_type>>
|
| 2370 |
+
list(InputIterator, InputIterator, Allocator = Allocator())
|
| 2371 |
+
-> list<typename iterator_traits<InputIterator>::value_type, Allocator>;
|
| 2372 |
+
|
| 2373 |
template <class T, class Allocator>
|
| 2374 |
bool operator==(const list<T, Allocator>& x, const list<T, Allocator>& y);
|
| 2375 |
template <class T, class Allocator>
|
| 2376 |
bool operator< (const list<T, Allocator>& x, const list<T, Allocator>& y);
|
| 2377 |
template <class T, class Allocator>
|
|
|
|
| 2381 |
template <class T, class Allocator>
|
| 2382 |
bool operator>=(const list<T, Allocator>& x, const list<T, Allocator>& y);
|
| 2383 |
template <class T, class Allocator>
|
| 2384 |
bool operator<=(const list<T, Allocator>& x, const list<T, Allocator>& y);
|
| 2385 |
|
| 2386 |
+
// [list.special], specialized algorithms
|
| 2387 |
template <class T, class Allocator>
|
| 2388 |
+
void swap(list<T, Allocator>& x, list<T, Allocator>& y)
|
| 2389 |
+
noexcept(noexcept(x.swap(y)));
|
| 2390 |
}
|
| 2391 |
```
|
| 2392 |
|
| 2393 |
+
An incomplete type `T` may be used when instantiating `list` if the
|
| 2394 |
+
allocator satisfies the allocator completeness requirements (
|
| 2395 |
+
[[allocator.requirements.completeness]]). `T` shall be complete before
|
| 2396 |
+
any member of the resulting specialization of `list` is referenced.
|
| 2397 |
+
|
| 2398 |
#### `list` constructors, copy, and assignment <a id="list.cons">[[list.cons]]</a>
|
| 2399 |
|
| 2400 |
``` cpp
|
| 2401 |
explicit list(const Allocator&);
|
| 2402 |
```
|
|
|
|
| 2415 |
*Requires:* `T` shall be `DefaultInsertable` into `*this`.
|
| 2416 |
|
| 2417 |
*Complexity:* Linear in `n`.
|
| 2418 |
|
| 2419 |
``` cpp
|
| 2420 |
+
list(size_type n, const T& value, const Allocator& = Allocator());
|
|
|
|
| 2421 |
```
|
| 2422 |
|
| 2423 |
*Effects:* Constructs a `list` with `n` copies of `value`, using the
|
| 2424 |
specified allocator.
|
| 2425 |
|
|
|
|
| 2427 |
|
| 2428 |
*Complexity:* Linear in `n`.
|
| 2429 |
|
| 2430 |
``` cpp
|
| 2431 |
template <class InputIterator>
|
| 2432 |
+
list(InputIterator first, InputIterator last, const Allocator& = Allocator());
|
|
|
|
| 2433 |
```
|
| 2434 |
|
| 2435 |
*Effects:* Constructs a `list` equal to the range \[`first`, `last`).
|
| 2436 |
|
| 2437 |
*Complexity:* Linear in `distance(first, last)`.
|
|
|
|
| 2441 |
``` cpp
|
| 2442 |
void resize(size_type sz);
|
| 2443 |
```
|
| 2444 |
|
| 2445 |
*Effects:* If `size() < sz`, appends `sz - size()` default-inserted
|
| 2446 |
+
elements to the sequence. If `sz <= size()`, equivalent to:
|
| 2447 |
|
| 2448 |
``` cpp
|
| 2449 |
list<T>::iterator it = begin();
|
| 2450 |
advance(it, sz);
|
| 2451 |
erase(it, end());
|
|
|
|
| 2455 |
|
| 2456 |
``` cpp
|
| 2457 |
void resize(size_type sz, const T& c);
|
| 2458 |
```
|
| 2459 |
|
| 2460 |
+
*Effects:* As if by:
|
| 2461 |
|
| 2462 |
``` cpp
|
| 2463 |
if (sz > size())
|
| 2464 |
insert(end(), sz-size(), c);
|
| 2465 |
else if (sz < size()) {
|
|
|
|
| 2482 |
template <class InputIterator>
|
| 2483 |
iterator insert(const_iterator position, InputIterator first,
|
| 2484 |
InputIterator last);
|
| 2485 |
iterator insert(const_iterator position, initializer_list<T>);
|
| 2486 |
|
| 2487 |
+
template <class... Args> reference emplace_front(Args&&... args);
|
| 2488 |
+
template <class... Args> reference emplace_back(Args&&... args);
|
| 2489 |
template <class... Args> iterator emplace(const_iterator position, Args&&... args);
|
| 2490 |
void push_front(const T& x);
|
| 2491 |
void push_front(T&& x);
|
| 2492 |
void push_back(const T& x);
|
| 2493 |
void push_back(T&& x);
|
|
|
|
| 2551 |
``` cpp
|
| 2552 |
void splice(const_iterator position, list& x, const_iterator i);
|
| 2553 |
void splice(const_iterator position, list&& x, const_iterator i);
|
| 2554 |
```
|
| 2555 |
|
| 2556 |
+
*Requires:* `i` is a valid dereferenceable iterator of `x`.
|
| 2557 |
+
|
| 2558 |
*Effects:* Inserts an element pointed to by `i` from list `x` before
|
| 2559 |
`position` and removes the element from `x`. The result is unchanged if
|
| 2560 |
`position == i` or `position == ++i`. Pointers and references to `*i`
|
| 2561 |
continue to refer to this same element but as a member of `*this`.
|
| 2562 |
Iterators to `*i` (including `i` itself) continue to refer to the same
|
| 2563 |
element, but now behave as iterators into `*this`, not into `x`.
|
| 2564 |
|
|
|
|
|
|
|
| 2565 |
*Throws:* Nothing.
|
| 2566 |
|
| 2567 |
*Complexity:* Constant time.
|
| 2568 |
|
| 2569 |
``` cpp
|
|
|
|
| 2571 |
const_iterator last);
|
| 2572 |
void splice(const_iterator position, list&& x, const_iterator first,
|
| 2573 |
const_iterator last);
|
| 2574 |
```
|
| 2575 |
|
| 2576 |
+
*Requires:* `[first, last)` is a valid range in `x`. The program has
|
| 2577 |
+
undefined behavior if `position` is an iterator in the range \[`first`,
|
| 2578 |
+
`last`).
|
| 2579 |
+
|
| 2580 |
*Effects:* Inserts elements in the range \[`first`, `last`) before
|
| 2581 |
+
`position` and removes the elements from `x`. Pointers and references to
|
| 2582 |
+
the moved elements of `x` now refer to those same elements but as
|
| 2583 |
+
members of `*this`. Iterators referring to the moved elements will
|
| 2584 |
+
continue to refer to their elements, but they now behave as iterators
|
| 2585 |
+
into `*this`, not into `x`.
|
|
|
|
|
|
|
|
|
|
| 2586 |
|
| 2587 |
*Throws:* Nothing.
|
| 2588 |
|
| 2589 |
*Complexity:* Constant time if `&x == this`; otherwise, linear time.
|
| 2590 |
|
|
|
|
| 2639 |
*Effects:* If `(&x == this)` does nothing; otherwise, merges the two
|
| 2640 |
sorted ranges `[begin(), end())` and `[x.begin(), x.end())`. The result
|
| 2641 |
is a range in which the elements will be sorted in non-decreasing order
|
| 2642 |
according to the ordering defined by `comp`; that is, for every iterator
|
| 2643 |
`i`, in the range other than the first, the condition
|
| 2644 |
+
`comp(*i, *(i - 1))` will be `false`. Pointers and references to the
|
| 2645 |
+
moved elements of `x` now refer to those same elements but as members of
|
| 2646 |
`*this`. Iterators referring to the moved elements will continue to
|
| 2647 |
refer to their elements, but they now behave as iterators into `*this`,
|
| 2648 |
not into `x`.
|
| 2649 |
|
| 2650 |
*Remarks:* Stable ([[algorithm.stable]]). If `(&x != this)` the range
|
| 2651 |
`[x.begin(), x.end())` is empty after the merge. No elements are copied
|
| 2652 |
by this operation. The behavior is undefined if
|
| 2653 |
+
`get_allocator() != x.get_allocator()`.
|
| 2654 |
|
| 2655 |
*Complexity:* At most `size() + x.size() - 1` applications of `comp` if
|
| 2656 |
`(&x != this)`; otherwise, no applications of `comp` are performed. If
|
| 2657 |
an exception is thrown other than by a comparison there are no effects.
|
| 2658 |
|
|
|
|
| 2672 |
|
| 2673 |
*Requires:* `operator<` (for the first version) or `comp` (for the
|
| 2674 |
second version) shall define a strict weak ordering ([[alg.sorting]]).
|
| 2675 |
|
| 2676 |
*Effects:* Sorts the list according to the `operator<` or a `Compare`
|
| 2677 |
+
function object. If an exception is thrown, the order of the elements in
|
| 2678 |
+
`*this` is unspecified. Does not affect the validity of iterators and
|
| 2679 |
references.
|
| 2680 |
|
| 2681 |
*Remarks:* Stable ([[algorithm.stable]]).
|
| 2682 |
|
| 2683 |
+
*Complexity:* Approximately N log N comparisons, where `N == size()`.
|
| 2684 |
|
| 2685 |
#### `list` specialized algorithms <a id="list.special">[[list.special]]</a>
|
| 2686 |
|
| 2687 |
``` cpp
|
| 2688 |
template <class T, class Allocator>
|
| 2689 |
+
void swap(list<T, Allocator>& x, list<T, Allocator>& y)
|
| 2690 |
+
noexcept(noexcept(x.swap(y)));
|
| 2691 |
```
|
| 2692 |
|
| 2693 |
+
*Effects:* As if by `x.swap(y)`.
|
|
|
|
|
|
|
|
|
|
|
|
|
| 2694 |
|
| 2695 |
### Class template `vector` <a id="vector">[[vector]]</a>
|
| 2696 |
|
| 2697 |
#### Class template `vector` overview <a id="vector.overview">[[vector.overview]]</a>
|
| 2698 |
|
| 2699 |
+
A `vector` is a sequence container that supports (amortized) constant
|
| 2700 |
+
time insert and erase operations at the end; insert and erase in the
|
| 2701 |
+
middle take linear time. Storage management is handled automatically,
|
| 2702 |
+
though hints can be given to improve efficiency.
|
|
|
|
|
|
|
|
|
|
|
|
|
| 2703 |
|
| 2704 |
A `vector` satisfies all of the requirements of a container and of a
|
| 2705 |
reversible container (given in two tables in
|
| 2706 |
[[container.requirements]]), of a sequence container, including most of
|
| 2707 |
+
the optional sequence container requirements ([[sequence.reqmts]]), of
|
| 2708 |
+
an allocator-aware container (Table [[tab:containers.allocatoraware]]),
|
| 2709 |
+
and, for an element type other than `bool`, of a contiguous container (
|
| 2710 |
+
[[container.requirements.general]]). The exceptions are the
|
| 2711 |
+
`push_front`, `pop_front`, and `emplace_front` member functions, which
|
| 2712 |
+
are not provided. Descriptions are provided here only for operations on
|
| 2713 |
+
`vector` that are not described in one of these tables or for operations
|
| 2714 |
+
where there is additional semantic information.
|
| 2715 |
|
| 2716 |
``` cpp
|
| 2717 |
namespace std {
|
| 2718 |
template <class T, class Allocator = allocator<T>>
|
| 2719 |
class vector {
|
| 2720 |
public:
|
| 2721 |
// types:
|
| 2722 |
+
using value_type = T;
|
| 2723 |
+
using allocator_type = Allocator;
|
| 2724 |
+
using pointer = typename allocator_traits<Allocator>::pointer;
|
| 2725 |
+
using const_pointer = typename allocator_traits<Allocator>::const_pointer;
|
| 2726 |
+
using reference = value_type&;
|
| 2727 |
+
using const_reference = const value_type&;
|
| 2728 |
+
using size_type = implementation-defined; // see [container.requirements]
|
| 2729 |
+
using difference_type = implementation-defined; // see [container.requirements]
|
| 2730 |
+
using iterator = implementation-defined // type of vector::iterator; // see [container.requirements]
|
| 2731 |
+
using const_iterator = implementation-defined // type of vector::const_iterator; // see [container.requirements]
|
| 2732 |
+
using reverse_iterator = std::reverse_iterator<iterator>;
|
| 2733 |
+
using const_reverse_iterator = std::reverse_iterator<const_iterator>;
|
| 2734 |
|
| 2735 |
+
// [vector.cons], construct/copy/destroy
|
| 2736 |
+
vector() noexcept(noexcept(Allocator())) : vector(Allocator()) { }
|
| 2737 |
+
explicit vector(const Allocator&) noexcept;
|
| 2738 |
explicit vector(size_type n, const Allocator& = Allocator());
|
| 2739 |
vector(size_type n, const T& value, const Allocator& = Allocator());
|
| 2740 |
template <class InputIterator>
|
| 2741 |
+
vector(InputIterator first, InputIterator last, const Allocator& = Allocator());
|
|
|
|
| 2742 |
vector(const vector& x);
|
| 2743 |
+
vector(vector&&) noexcept;
|
| 2744 |
vector(const vector&, const Allocator&);
|
| 2745 |
vector(vector&&, const Allocator&);
|
| 2746 |
vector(initializer_list<T>, const Allocator& = Allocator());
|
| 2747 |
~vector();
|
| 2748 |
vector& operator=(const vector& x);
|
| 2749 |
+
vector& operator=(vector&& x)
|
| 2750 |
+
noexcept(allocator_traits<Allocator>::propagate_on_container_move_assignment::value ||
|
| 2751 |
+
allocator_traits<Allocator>::is_always_equal::value);
|
| 2752 |
vector& operator=(initializer_list<T>);
|
| 2753 |
template <class InputIterator>
|
| 2754 |
void assign(InputIterator first, InputIterator last);
|
| 2755 |
void assign(size_type n, const T& u);
|
| 2756 |
void assign(initializer_list<T>);
|
|
|
|
| 2769 |
const_iterator cbegin() const noexcept;
|
| 2770 |
const_iterator cend() const noexcept;
|
| 2771 |
const_reverse_iterator crbegin() const noexcept;
|
| 2772 |
const_reverse_iterator crend() const noexcept;
|
| 2773 |
|
| 2774 |
+
// [vector.capacity], capacity
|
| 2775 |
+
bool empty() const noexcept;
|
| 2776 |
size_type size() const noexcept;
|
| 2777 |
size_type max_size() const noexcept;
|
| 2778 |
+
size_type capacity() const noexcept;
|
| 2779 |
void resize(size_type sz);
|
| 2780 |
void resize(size_type sz, const T& c);
|
|
|
|
|
|
|
| 2781 |
void reserve(size_type n);
|
| 2782 |
void shrink_to_fit();
|
| 2783 |
|
| 2784 |
// element access:
|
| 2785 |
reference operator[](size_type n);
|
|
|
|
| 2793 |
|
| 2794 |
// [vector.data], data access
|
| 2795 |
T* data() noexcept;
|
| 2796 |
const T* data() const noexcept;
|
| 2797 |
|
| 2798 |
+
// [vector.modifiers], modifiers
|
| 2799 |
+
template <class... Args> reference emplace_back(Args&&... args);
|
| 2800 |
void push_back(const T& x);
|
| 2801 |
void push_back(T&& x);
|
| 2802 |
void pop_back();
|
| 2803 |
|
| 2804 |
template <class... Args> iterator emplace(const_iterator position, Args&&... args);
|
| 2805 |
iterator insert(const_iterator position, const T& x);
|
| 2806 |
iterator insert(const_iterator position, T&& x);
|
| 2807 |
iterator insert(const_iterator position, size_type n, const T& x);
|
| 2808 |
template <class InputIterator>
|
| 2809 |
+
iterator insert(const_iterator position, InputIterator first, InputIterator last);
|
|
|
|
| 2810 |
iterator insert(const_iterator position, initializer_list<T> il);
|
| 2811 |
iterator erase(const_iterator position);
|
| 2812 |
iterator erase(const_iterator first, const_iterator last);
|
| 2813 |
+
void swap(vector&)
|
| 2814 |
+
noexcept(allocator_traits<Allocator>::propagate_on_container_swap::value ||
|
| 2815 |
+
allocator_traits<Allocator>::is_always_equal::value);
|
| 2816 |
void clear() noexcept;
|
| 2817 |
};
|
| 2818 |
|
| 2819 |
+
template<class InputIterator,
|
| 2820 |
+
class Allocator = allocator<typename iterator_traits<InputIterator>::value_type>>
|
| 2821 |
+
vector(InputIterator, InputIterator, Allocator = Allocator())
|
| 2822 |
+
-> vector<typename iterator_traits<InputIterator>::value_type, Allocator>;
|
| 2823 |
+
|
| 2824 |
template <class T, class Allocator>
|
| 2825 |
bool operator==(const vector<T, Allocator>& x, const vector<T, Allocator>& y);
|
| 2826 |
template <class T, class Allocator>
|
| 2827 |
bool operator< (const vector<T, Allocator>& x, const vector<T, Allocator>& y);
|
| 2828 |
template <class T, class Allocator>
|
|
|
|
| 2832 |
template <class T, class Allocator>
|
| 2833 |
bool operator>=(const vector<T, Allocator>& x, const vector<T, Allocator>& y);
|
| 2834 |
template <class T, class Allocator>
|
| 2835 |
bool operator<=(const vector<T, Allocator>& x, const vector<T, Allocator>& y);
|
| 2836 |
|
| 2837 |
+
// [vector.special], specialized algorithms
|
| 2838 |
template <class T, class Allocator>
|
| 2839 |
+
void swap(vector<T, Allocator>& x, vector<T, Allocator>& y)
|
| 2840 |
+
noexcept(noexcept(x.swap(y)));
|
| 2841 |
}
|
| 2842 |
```
|
| 2843 |
|
| 2844 |
+
An incomplete type `T` may be used when instantiating `vector` if the
|
| 2845 |
+
allocator satisfies the allocator completeness requirements (
|
| 2846 |
+
[[allocator.requirements.completeness]]). `T` shall be complete before
|
| 2847 |
+
any member of the resulting specialization of `vector` is referenced.
|
| 2848 |
+
|
| 2849 |
#### `vector` constructors, copy, and assignment <a id="vector.cons">[[vector.cons]]</a>
|
| 2850 |
|
| 2851 |
``` cpp
|
| 2852 |
explicit vector(const Allocator&);
|
| 2853 |
```
|
|
|
|
| 2888 |
*Effects:* Constructs a `vector` equal to the range \[`first`, `last`),
|
| 2889 |
using the specified allocator.
|
| 2890 |
|
| 2891 |
*Complexity:* Makes only N calls to the copy constructor of `T` (where N
|
| 2892 |
is the distance between `first` and `last`) and no reallocations if
|
| 2893 |
+
iterators `first` and `last` are of forward, bidirectional, or random
|
| 2894 |
+
access categories. It makes order `N` calls to the copy constructor of
|
| 2895 |
+
`T` and order log N reallocations if they are just input iterators.
|
| 2896 |
|
| 2897 |
#### `vector` capacity <a id="vector.capacity">[[vector.capacity]]</a>
|
| 2898 |
|
| 2899 |
``` cpp
|
| 2900 |
size_type capacity() const noexcept;
|
|
|
|
| 2933 |
void shrink_to_fit();
|
| 2934 |
```
|
| 2935 |
|
| 2936 |
*Requires:* `T` shall be `MoveInsertable` into `*this`.
|
| 2937 |
|
| 2938 |
+
*Effects:* `shrink_to_fit` is a non-binding request to reduce
|
| 2939 |
+
`capacity()` to `size()`.
|
| 2940 |
+
|
| 2941 |
+
[*Note 1*: The request is non-binding to allow latitude for
|
| 2942 |
+
implementation-specific optimizations. — *end note*]
|
| 2943 |
+
|
| 2944 |
+
It does not increase `capacity()`, but may reduce `capacity()` by
|
| 2945 |
+
causing reallocation. If an exception is thrown other than by the move
|
| 2946 |
+
constructor of a non-`CopyInsertable` `T` there are no effects.
|
| 2947 |
+
|
| 2948 |
*Complexity:* Linear in the size of the sequence.
|
| 2949 |
|
| 2950 |
+
*Remarks:* Reallocation invalidates all the references, pointers, and
|
| 2951 |
+
iterators referring to the elements in the sequence as well as the
|
| 2952 |
+
past-the-end iterator. If no reallocation happens, they remain valid.
|
|
|
|
|
|
|
| 2953 |
|
| 2954 |
``` cpp
|
| 2955 |
+
void swap(vector& x)
|
| 2956 |
+
noexcept(allocator_traits<Allocator>::propagate_on_container_swap::value ||
|
| 2957 |
+
allocator_traits<Allocator>::is_always_equal::value);
|
| 2958 |
```
|
| 2959 |
|
| 2960 |
*Effects:* Exchanges the contents and `capacity()` of `*this` with that
|
| 2961 |
of `x`.
|
| 2962 |
|
|
|
|
| 2964 |
|
| 2965 |
``` cpp
|
| 2966 |
void resize(size_type sz);
|
| 2967 |
```
|
| 2968 |
|
| 2969 |
+
*Effects:* If `sz < size()`, erases the last `size() - sz` elements from
|
| 2970 |
+
the sequence. Otherwise, appends `sz - size()` default-inserted elements
|
| 2971 |
+
to the sequence.
|
| 2972 |
|
| 2973 |
*Requires:* `T` shall be `MoveInsertable` and `DefaultInsertable` into
|
| 2974 |
`*this`.
|
| 2975 |
|
| 2976 |
*Remarks:* If an exception is thrown other than by the move constructor
|
|
|
|
| 2978 |
|
| 2979 |
``` cpp
|
| 2980 |
void resize(size_type sz, const T& c);
|
| 2981 |
```
|
| 2982 |
|
| 2983 |
+
*Effects:* If `sz < size()`, erases the last `size() - sz` elements from
|
| 2984 |
+
the sequence. Otherwise, appends `sz - size()` copies of `c` to the
|
| 2985 |
+
sequence.
|
| 2986 |
|
| 2987 |
*Requires:* `T` shall be `CopyInsertable` into `*this`.
|
| 2988 |
|
| 2989 |
*Remarks:* If an exception is thrown there are no effects.
|
| 2990 |
|
|
|
|
| 2994 |
T* data() noexcept;
|
| 2995 |
const T* data() const noexcept;
|
| 2996 |
```
|
| 2997 |
|
| 2998 |
*Returns:* A pointer such that \[`data()`, `data() + size()`) is a valid
|
| 2999 |
+
range. For a non-empty vector, `data()` `==` `addressof(front())`.
|
| 3000 |
|
| 3001 |
*Complexity:* Constant time.
|
| 3002 |
|
| 3003 |
#### `vector` modifiers <a id="vector.modifiers">[[vector.modifiers]]</a>
|
| 3004 |
|
|
|
|
| 3008 |
iterator insert(const_iterator position, size_type n, const T& x);
|
| 3009 |
template <class InputIterator>
|
| 3010 |
iterator insert(const_iterator position, InputIterator first, InputIterator last);
|
| 3011 |
iterator insert(const_iterator position, initializer_list<T>);
|
| 3012 |
|
| 3013 |
+
template <class... Args> reference emplace_back(Args&&... args);
|
| 3014 |
template <class... Args> iterator emplace(const_iterator position, Args&&... args);
|
| 3015 |
void push_back(const T& x);
|
| 3016 |
void push_back(T&& x);
|
| 3017 |
```
|
| 3018 |
|
| 3019 |
*Remarks:* Causes reallocation if the new size is greater than the old
|
| 3020 |
+
capacity. Reallocation invalidates all the references, pointers, and
|
| 3021 |
+
iterators referring to the elements in the sequence. If no reallocation
|
| 3022 |
+
happens, all the iterators and references before the insertion point
|
| 3023 |
+
remain valid. If an exception is thrown other than by the copy
|
| 3024 |
+
constructor, move constructor, assignment operator, or move assignment
|
| 3025 |
+
operator of `T` or by any `InputIterator` operation there are no
|
| 3026 |
+
effects. If an exception is thrown while inserting a single element at
|
| 3027 |
+
the end and `T` is `CopyInsertable` or
|
| 3028 |
+
`is_nothrow_move_constructible_v<T>` is `true`, there are no effects.
|
| 3029 |
+
Otherwise, if an exception is thrown by the move constructor of a
|
| 3030 |
+
non-`CopyInsertable` `T`, the effects are unspecified.
|
| 3031 |
|
| 3032 |
*Complexity:* The complexity is linear in the number of elements
|
| 3033 |
inserted plus the distance to the end of the vector.
|
| 3034 |
|
| 3035 |
``` cpp
|
| 3036 |
iterator erase(const_iterator position);
|
| 3037 |
iterator erase(const_iterator first, const_iterator last);
|
| 3038 |
+
void pop_back();
|
| 3039 |
```
|
| 3040 |
|
| 3041 |
*Effects:* Invalidates iterators and references at or after the point of
|
| 3042 |
the erase.
|
| 3043 |
|
| 3044 |
*Complexity:* The destructor of `T` is called the number of times equal
|
| 3045 |
+
to the number of the elements erased, but the assignment operator of `T`
|
| 3046 |
+
is called the number of times equal to the number of elements in the
|
| 3047 |
+
vector after the erased elements.
|
| 3048 |
|
| 3049 |
+
*Throws:* Nothing unless an exception is thrown by the assignment
|
| 3050 |
+
operator or move assignment operator of `T`.
|
|
|
|
| 3051 |
|
| 3052 |
#### `vector` specialized algorithms <a id="vector.special">[[vector.special]]</a>
|
| 3053 |
|
| 3054 |
``` cpp
|
| 3055 |
template <class T, class Allocator>
|
| 3056 |
+
void swap(vector<T, Allocator>& x, vector<T, Allocator>& y)
|
| 3057 |
+
noexcept(noexcept(x.swap(y)));
|
| 3058 |
```
|
| 3059 |
|
| 3060 |
+
*Effects:* As if by `x.swap(y)`.
|
|
|
|
|
|
|
|
|
|
|
|
|
| 3061 |
|
| 3062 |
### Class `vector<bool>` <a id="vector.bool">[[vector.bool]]</a>
|
| 3063 |
|
| 3064 |
To optimize space allocation, a specialization of vector for `bool`
|
| 3065 |
elements is provided:
|
| 3066 |
|
| 3067 |
``` cpp
|
| 3068 |
namespace std {
|
| 3069 |
+
template <class Allocator>
|
| 3070 |
+
class vector<bool, Allocator> {
|
| 3071 |
public:
|
| 3072 |
// types:
|
| 3073 |
+
using value_type = bool;
|
| 3074 |
+
using allocator_type = Allocator;
|
| 3075 |
+
using pointer = implementation-defined;
|
| 3076 |
+
using const_pointer = implementation-defined;
|
| 3077 |
+
using const_reference = bool;
|
| 3078 |
+
using size_type = implementation-defined; // see [container.requirements]
|
| 3079 |
+
using difference_type = implementation-defined; // see [container.requirements]
|
| 3080 |
+
using iterator = implementation-defined // type of vector<bool>::iterator; // see [container.requirements]
|
| 3081 |
+
using const_iterator = implementation-defined // type of vector<bool>::const_iterator; // see [container.requirements]
|
| 3082 |
+
using reverse_iterator = std::reverse_iterator<iterator>;
|
| 3083 |
+
using const_reverse_iterator = std::reverse_iterator<const_iterator>;
|
| 3084 |
|
| 3085 |
// bit reference:
|
| 3086 |
class reference {
|
| 3087 |
friend class vector;
|
| 3088 |
reference() noexcept;
|
|
|
|
| 3132 |
const_iterator cend() const noexcept;
|
| 3133 |
const_reverse_iterator crbegin() const noexcept;
|
| 3134 |
const_reverse_iterator crend() const noexcept;
|
| 3135 |
|
| 3136 |
// capacity:
|
| 3137 |
+
bool empty() const noexcept;
|
| 3138 |
size_type size() const noexcept;
|
| 3139 |
size_type max_size() const noexcept;
|
| 3140 |
+
size_type capacity() const noexcept;
|
| 3141 |
void resize(size_type sz, bool c = false);
|
|
|
|
|
|
|
| 3142 |
void reserve(size_type n);
|
| 3143 |
void shrink_to_fit();
|
| 3144 |
|
| 3145 |
// element access:
|
| 3146 |
reference operator[](size_type n);
|
|
|
|
| 3151 |
const_reference front() const;
|
| 3152 |
reference back();
|
| 3153 |
const_reference back() const;
|
| 3154 |
|
| 3155 |
// modifiers:
|
| 3156 |
+
template <class... Args> reference emplace_back(Args&&... args);
|
| 3157 |
void push_back(const bool& x);
|
| 3158 |
void pop_back();
|
| 3159 |
template <class... Args> iterator emplace(const_iterator position, Args&&... args);
|
| 3160 |
iterator insert(const_iterator position, const bool& x);
|
| 3161 |
iterator insert(const_iterator position, size_type n, const bool& x);
|
|
|
|
| 3175 |
```
|
| 3176 |
|
| 3177 |
Unless described below, all operations have the same requirements and
|
| 3178 |
semantics as the primary `vector` template, except that operations
|
| 3179 |
dealing with the `bool` value type map to bit values in the container
|
| 3180 |
+
storage and `allocator_traits::construct` (
|
| 3181 |
+
[[allocator.traits.members]]) is not used to construct these values.
|
| 3182 |
|
| 3183 |
There is no requirement that the data be stored as a contiguous
|
| 3184 |
allocation of `bool` values. A space-optimized representation of bits is
|
| 3185 |
recommended instead.
|
| 3186 |
|
| 3187 |
`reference`
|
| 3188 |
|
| 3189 |
is a class that simulates the behavior of references of a single bit in
|
| 3190 |
+
`vector<bool>`. The conversion function returns `true` when the bit is
|
| 3191 |
set, and `false` otherwise. The assignment operator sets the bit when
|
| 3192 |
the argument is (convertible to) `true` and clears it otherwise. `flip`
|
| 3193 |
reverses the state of the bit.
|
| 3194 |
|
| 3195 |
``` cpp
|
|
|
|
| 3200 |
|
| 3201 |
``` cpp
|
| 3202 |
static void swap(reference x, reference y) noexcept;
|
| 3203 |
```
|
| 3204 |
|
| 3205 |
+
*Effects:* Exchanges the contents of `x` and `y` as if by:
|
| 3206 |
|
| 3207 |
``` cpp
|
| 3208 |
bool b = x;
|
| 3209 |
x = y;
|
| 3210 |
y = b;
|
|
|
|
| 3212 |
|
| 3213 |
``` cpp
|
| 3214 |
template <class Allocator> struct hash<vector<bool, Allocator>>;
|
| 3215 |
```
|
| 3216 |
|
| 3217 |
+
The specialization is enabled ([[unord.hash]]).
|
|
|
|
| 3218 |
|
| 3219 |
## Associative containers <a id="associative">[[associative]]</a>
|
| 3220 |
|
| 3221 |
### In general <a id="associative.general">[[associative.general]]</a>
|
| 3222 |
|
| 3223 |
The header `<map>` defines the class templates `map` and `multimap`; the
|
| 3224 |
header `<set>` defines the class templates `set` and `multiset`.
|
| 3225 |
|
| 3226 |
+
The following exposition-only alias templates may appear in deduction
|
| 3227 |
+
guides for associative containers:
|
| 3228 |
+
|
| 3229 |
+
``` cpp
|
| 3230 |
+
template<class InputIterator>
|
| 3231 |
+
using iter_key_t = remove_const_t<
|
| 3232 |
+
typename iterator_traits<InputIterator>::value_type::first_type>; // exposition only
|
| 3233 |
+
template<class InputIterator>
|
| 3234 |
+
using iter_val_t
|
| 3235 |
+
= typename iterator_traits<InputIterator>::value_type::second_type; // exposition only
|
| 3236 |
+
template<class InputIterator>
|
| 3237 |
+
using iter_to_alloc_t
|
| 3238 |
+
= pair<add_const_t<typename iterator_traits<InputIterator>::value_type::first_type>,
|
| 3239 |
+
typename iterator_traits<InputIterator>::value_type::second_type>; // exposition only
|
| 3240 |
+
```
|
| 3241 |
+
|
| 3242 |
### Header `<map>` synopsis <a id="associative.map.syn">[[associative.map.syn]]</a>
|
| 3243 |
|
| 3244 |
``` cpp
|
| 3245 |
#include <initializer_list>
|
| 3246 |
|
| 3247 |
namespace std {
|
| 3248 |
+
// [map], class template map
|
| 3249 |
template <class Key, class T, class Compare = less<Key>,
|
| 3250 |
class Allocator = allocator<pair<const Key, T>>>
|
| 3251 |
class map;
|
| 3252 |
template <class Key, class T, class Compare, class Allocator>
|
| 3253 |
bool operator==(const map<Key, T, Compare, Allocator>& x,
|
|
|
|
| 3267 |
template <class Key, class T, class Compare, class Allocator>
|
| 3268 |
bool operator<=(const map<Key, T, Compare, Allocator>& x,
|
| 3269 |
const map<Key, T, Compare, Allocator>& y);
|
| 3270 |
template <class Key, class T, class Compare, class Allocator>
|
| 3271 |
void swap(map<Key, T, Compare, Allocator>& x,
|
| 3272 |
+
map<Key, T, Compare, Allocator>& y)
|
| 3273 |
+
noexcept(noexcept(x.swap(y)));
|
| 3274 |
|
| 3275 |
+
// [multimap], class template multimap
|
| 3276 |
template <class Key, class T, class Compare = less<Key>,
|
| 3277 |
class Allocator = allocator<pair<const Key, T>>>
|
| 3278 |
class multimap;
|
| 3279 |
template <class Key, class T, class Compare, class Allocator>
|
| 3280 |
bool operator==(const multimap<Key, T, Compare, Allocator>& x,
|
|
|
|
| 3294 |
template <class Key, class T, class Compare, class Allocator>
|
| 3295 |
bool operator<=(const multimap<Key, T, Compare, Allocator>& x,
|
| 3296 |
const multimap<Key, T, Compare, Allocator>& y);
|
| 3297 |
template <class Key, class T, class Compare, class Allocator>
|
| 3298 |
void swap(multimap<Key, T, Compare, Allocator>& x,
|
| 3299 |
+
multimap<Key, T, Compare, Allocator>& y)
|
| 3300 |
+
noexcept(noexcept(x.swap(y)));
|
| 3301 |
+
|
| 3302 |
+
namespace pmr {
|
| 3303 |
+
template <class Key, class T, class Compare = less<Key>>
|
| 3304 |
+
using map = std::map<Key, T, Compare,
|
| 3305 |
+
polymorphic_allocator<pair<const Key, T>>>;
|
| 3306 |
+
|
| 3307 |
+
template <class Key, class T, class Compare = less<Key>>
|
| 3308 |
+
using multimap = std::multimap<Key, T, Compare,
|
| 3309 |
+
polymorphic_allocator<pair<const Key, T>>>;
|
| 3310 |
+
}
|
| 3311 |
}
|
| 3312 |
```
|
| 3313 |
|
| 3314 |
### Header `<set>` synopsis <a id="associative.set.syn">[[associative.set.syn]]</a>
|
| 3315 |
|
| 3316 |
``` cpp
|
| 3317 |
#include <initializer_list>
|
| 3318 |
|
| 3319 |
namespace std {
|
| 3320 |
+
// [set], class template set
|
| 3321 |
template <class Key, class Compare = less<Key>,
|
| 3322 |
class Allocator = allocator<Key>>
|
| 3323 |
class set;
|
| 3324 |
template <class Key, class Compare, class Allocator>
|
| 3325 |
bool operator==(const set<Key, Compare, Allocator>& x,
|
|
|
|
| 3339 |
template <class Key, class Compare, class Allocator>
|
| 3340 |
bool operator<=(const set<Key, Compare, Allocator>& x,
|
| 3341 |
const set<Key, Compare, Allocator>& y);
|
| 3342 |
template <class Key, class Compare, class Allocator>
|
| 3343 |
void swap(set<Key, Compare, Allocator>& x,
|
| 3344 |
+
set<Key, Compare, Allocator>& y)
|
| 3345 |
+
noexcept(noexcept(x.swap(y)));
|
| 3346 |
|
| 3347 |
+
// [multiset], class template multiset
|
| 3348 |
template <class Key, class Compare = less<Key>,
|
| 3349 |
class Allocator = allocator<Key>>
|
| 3350 |
class multiset;
|
| 3351 |
template <class Key, class Compare, class Allocator>
|
| 3352 |
bool operator==(const multiset<Key, Compare, Allocator>& x,
|
|
|
|
| 3366 |
template <class Key, class Compare, class Allocator>
|
| 3367 |
bool operator<=(const multiset<Key, Compare, Allocator>& x,
|
| 3368 |
const multiset<Key, Compare, Allocator>& y);
|
| 3369 |
template <class Key, class Compare, class Allocator>
|
| 3370 |
void swap(multiset<Key, Compare, Allocator>& x,
|
| 3371 |
+
multiset<Key, Compare, Allocator>& y)
|
| 3372 |
+
noexcept(noexcept(x.swap(y)));
|
| 3373 |
+
|
| 3374 |
+
namespace pmr {
|
| 3375 |
+
template <class Key, class Compare = less<Key>>
|
| 3376 |
+
using set = std::set<Key, Compare,
|
| 3377 |
+
polymorphic_allocator<Key>>;
|
| 3378 |
+
|
| 3379 |
+
template <class Key, class Compare = less<Key>>
|
| 3380 |
+
using multiset = std::multiset<Key, Compare,
|
| 3381 |
+
polymorphic_allocator<Key>>;
|
| 3382 |
+
}
|
| 3383 |
}
|
| 3384 |
```
|
| 3385 |
|
| 3386 |
### Class template `map` <a id="map">[[map]]</a>
|
| 3387 |
|
|
|
|
| 3394 |
|
| 3395 |
A `map` satisfies all of the requirements of a container, of a
|
| 3396 |
reversible container ([[container.requirements]]), of an associative
|
| 3397 |
container ([[associative.reqmts]]), and of an allocator-aware container
|
| 3398 |
(Table [[tab:containers.allocatoraware]]). A `map` also provides most
|
| 3399 |
+
operations described in [[associative.reqmts]] for unique keys. This
|
| 3400 |
+
means that a `map` supports the `a_uniq` operations in
|
| 3401 |
+
[[associative.reqmts]] but not the `a_eq` operations. For a `map<Key,T>`
|
| 3402 |
+
the `key_type` is `Key` and the `value_type` is `pair<const Key,T>`.
|
| 3403 |
+
Descriptions are provided here only for operations on `map` that are not
|
| 3404 |
+
described in one of those tables or for operations where there is
|
| 3405 |
+
additional semantic information.
|
| 3406 |
|
| 3407 |
``` cpp
|
| 3408 |
namespace std {
|
| 3409 |
template <class Key, class T, class Compare = less<Key>,
|
| 3410 |
class Allocator = allocator<pair<const Key, T>>>
|
| 3411 |
class map {
|
| 3412 |
public:
|
| 3413 |
// types:
|
| 3414 |
+
using key_type = Key;
|
| 3415 |
+
using mapped_type = T;
|
| 3416 |
+
using value_type = pair<const Key, T>;
|
| 3417 |
+
using key_compare = Compare;
|
| 3418 |
+
using allocator_type = Allocator;
|
| 3419 |
+
using pointer = typename allocator_traits<Allocator>::pointer;
|
| 3420 |
+
using const_pointer = typename allocator_traits<Allocator>::const_pointer;
|
| 3421 |
+
using reference = value_type&;
|
| 3422 |
+
using const_reference = const value_type&;
|
| 3423 |
+
using size_type = implementation-defined; // see [container.requirements]
|
| 3424 |
+
using difference_type = implementation-defined; // see [container.requirements]
|
| 3425 |
+
using iterator = implementation-defined // type of map::iterator; // see [container.requirements]
|
| 3426 |
+
using const_iterator = implementation-defined // type of map::const_iterator; // see [container.requirements]
|
| 3427 |
+
using reverse_iterator = std::reverse_iterator<iterator>;
|
| 3428 |
+
using const_reverse_iterator = std::reverse_iterator<const_iterator>;
|
| 3429 |
+
using node_type = unspecified;
|
| 3430 |
+
using insert_return_type = INSERT_RETURN_TYPE<iterator, node_type>;
|
| 3431 |
|
| 3432 |
class value_compare {
|
| 3433 |
friend class map;
|
| 3434 |
protected:
|
| 3435 |
Compare comp;
|
| 3436 |
value_compare(Compare c) : comp(c) {}
|
| 3437 |
public:
|
|
|
|
|
|
|
|
|
|
| 3438 |
bool operator()(const value_type& x, const value_type& y) const {
|
| 3439 |
return comp(x.first, y.first);
|
| 3440 |
}
|
| 3441 |
};
|
| 3442 |
|
| 3443 |
+
// [map.cons], construct/copy/destroy
|
| 3444 |
map() : map(Compare()) { }
|
| 3445 |
+
explicit map(const Compare& comp, const Allocator& = Allocator());
|
|
|
|
| 3446 |
template <class InputIterator>
|
| 3447 |
map(InputIterator first, InputIterator last,
|
| 3448 |
const Compare& comp = Compare(), const Allocator& = Allocator());
|
| 3449 |
map(const map& x);
|
| 3450 |
map(map&& x);
|
|
|
|
| 3459 |
: map(first, last, Compare(), a) { }
|
| 3460 |
map(initializer_list<value_type> il, const Allocator& a)
|
| 3461 |
: map(il, Compare(), a) { }
|
| 3462 |
~map();
|
| 3463 |
map& operator=(const map& x);
|
| 3464 |
+
map& operator=(map&& x)
|
| 3465 |
+
noexcept(allocator_traits<Allocator>::is_always_equal::value &&
|
| 3466 |
+
is_nothrow_move_assignable_v<Compare>);
|
| 3467 |
map& operator=(initializer_list<value_type>);
|
| 3468 |
allocator_type get_allocator() const noexcept;
|
| 3469 |
|
| 3470 |
// iterators:
|
| 3471 |
iterator begin() noexcept;
|
|
|
|
| 3486 |
// capacity:
|
| 3487 |
bool empty() const noexcept;
|
| 3488 |
size_type size() const noexcept;
|
| 3489 |
size_type max_size() const noexcept;
|
| 3490 |
|
| 3491 |
+
// [map.access], element access
|
| 3492 |
T& operator[](const key_type& x);
|
| 3493 |
T& operator[](key_type&& x);
|
| 3494 |
T& at(const key_type& x);
|
| 3495 |
const T& at(const key_type& x) const;
|
| 3496 |
|
| 3497 |
+
// [map.modifiers], modifiers
|
| 3498 |
template <class... Args> pair<iterator, bool> emplace(Args&&... args);
|
| 3499 |
template <class... Args> iterator emplace_hint(const_iterator position, Args&&... args);
|
| 3500 |
pair<iterator, bool> insert(const value_type& x);
|
| 3501 |
+
pair<iterator, bool> insert(value_type&& x);
|
| 3502 |
template <class P> pair<iterator, bool> insert(P&& x);
|
| 3503 |
iterator insert(const_iterator position, const value_type& x);
|
| 3504 |
+
iterator insert(const_iterator position, value_type&& x);
|
| 3505 |
template <class P>
|
| 3506 |
iterator insert(const_iterator position, P&&);
|
| 3507 |
template <class InputIterator>
|
| 3508 |
void insert(InputIterator first, InputIterator last);
|
| 3509 |
void insert(initializer_list<value_type>);
|
| 3510 |
|
| 3511 |
+
node_type extract(const_iterator position);
|
| 3512 |
+
node_type extract(const key_type& x);
|
| 3513 |
+
insert_return_type insert(node_type&& nh);
|
| 3514 |
+
iterator insert(const_iterator hint, node_type&& nh);
|
| 3515 |
+
|
| 3516 |
+
template <class... Args>
|
| 3517 |
+
pair<iterator, bool> try_emplace(const key_type& k, Args&&... args);
|
| 3518 |
+
template <class... Args>
|
| 3519 |
+
pair<iterator, bool> try_emplace(key_type&& k, Args&&... args);
|
| 3520 |
+
template <class... Args>
|
| 3521 |
+
iterator try_emplace(const_iterator hint, const key_type& k, Args&&... args);
|
| 3522 |
+
template <class... Args>
|
| 3523 |
+
iterator try_emplace(const_iterator hint, key_type&& k, Args&&... args);
|
| 3524 |
+
template <class M>
|
| 3525 |
+
pair<iterator, bool> insert_or_assign(const key_type& k, M&& obj);
|
| 3526 |
+
template <class M>
|
| 3527 |
+
pair<iterator, bool> insert_or_assign(key_type&& k, M&& obj);
|
| 3528 |
+
template <class M>
|
| 3529 |
+
iterator insert_or_assign(const_iterator hint, const key_type& k, M&& obj);
|
| 3530 |
+
template <class M>
|
| 3531 |
+
iterator insert_or_assign(const_iterator hint, key_type&& k, M&& obj);
|
| 3532 |
+
|
| 3533 |
+
iterator erase(iterator position);
|
| 3534 |
iterator erase(const_iterator position);
|
| 3535 |
size_type erase(const key_type& x);
|
| 3536 |
iterator erase(const_iterator first, const_iterator last);
|
| 3537 |
+
void swap(map&)
|
| 3538 |
+
noexcept(allocator_traits<Allocator>::is_always_equal::value &&
|
| 3539 |
+
is_nothrow_swappable_v<Compare>);
|
| 3540 |
void clear() noexcept;
|
| 3541 |
|
| 3542 |
+
template<class C2>
|
| 3543 |
+
void merge(map<Key, T, C2, Allocator>& source);
|
| 3544 |
+
template<class C2>
|
| 3545 |
+
void merge(map<Key, T, C2, Allocator>&& source);
|
| 3546 |
+
template<class C2>
|
| 3547 |
+
void merge(multimap<Key, T, C2, Allocator>& source);
|
| 3548 |
+
template<class C2>
|
| 3549 |
+
void merge(multimap<Key, T, C2, Allocator>&& source);
|
| 3550 |
+
|
| 3551 |
// observers:
|
| 3552 |
key_compare key_comp() const;
|
| 3553 |
value_compare value_comp() const;
|
| 3554 |
|
| 3555 |
// map operations:
|
|
|
|
| 3569 |
iterator upper_bound(const key_type& x);
|
| 3570 |
const_iterator upper_bound(const key_type& x) const;
|
| 3571 |
template <class K> iterator upper_bound(const K& x);
|
| 3572 |
template <class K> const_iterator upper_bound(const K& x) const;
|
| 3573 |
|
| 3574 |
+
pair<iterator, iterator> equal_range(const key_type& x);
|
| 3575 |
+
pair<const_iterator, const_iterator> equal_range(const key_type& x) const;
|
|
|
|
|
|
|
| 3576 |
template <class K>
|
| 3577 |
pair<iterator, iterator> equal_range(const K& x);
|
| 3578 |
template <class K>
|
| 3579 |
pair<const_iterator, const_iterator> equal_range(const K& x) const;
|
| 3580 |
};
|
| 3581 |
|
| 3582 |
+
template<class InputIterator, class Compare = less<iter_key_t<InputIterator>>,
|
| 3583 |
+
class Allocator = allocator<iter_to_alloc_t<InputIterator>>>
|
| 3584 |
+
map(InputIterator, InputIterator, Compare = Compare(), Allocator = Allocator())
|
| 3585 |
+
-> map<iter_key_t<InputIterator>, iter_val_t<InputIterator>, Compare, Allocator>;
|
| 3586 |
+
|
| 3587 |
+
template<class Key, class T, class Compare = less<Key>,
|
| 3588 |
+
class Allocator = allocator<pair<const Key, T>>>
|
| 3589 |
+
map(initializer_list<pair<const Key, T>>, Compare = Compare(), Allocator = Allocator())
|
| 3590 |
+
-> map<Key, T, Compare, Allocator>;
|
| 3591 |
+
|
| 3592 |
+
template <class InputIterator, class Allocator>
|
| 3593 |
+
map(InputIterator, InputIterator, Allocator)
|
| 3594 |
+
-> map<iter_key_t<InputIterator>, iter_val_t<InputIterator>,
|
| 3595 |
+
less<iter_key_t<InputIterator>>, Allocator>;
|
| 3596 |
+
|
| 3597 |
+
template<class Key, class T, class Allocator>
|
| 3598 |
+
map(initializer_list<pair<const Key, T>>, Allocator) -> map<Key, T, less<Key>, Allocator>;
|
| 3599 |
+
|
| 3600 |
template <class Key, class T, class Compare, class Allocator>
|
| 3601 |
bool operator==(const map<Key, T, Compare, Allocator>& x,
|
| 3602 |
const map<Key, T, Compare, Allocator>& y);
|
| 3603 |
template <class Key, class T, class Compare, class Allocator>
|
| 3604 |
bool operator< (const map<Key, T, Compare, Allocator>& x,
|
|
|
|
| 3614 |
const map<Key, T, Compare, Allocator>& y);
|
| 3615 |
template <class Key, class T, class Compare, class Allocator>
|
| 3616 |
bool operator<=(const map<Key, T, Compare, Allocator>& x,
|
| 3617 |
const map<Key, T, Compare, Allocator>& y);
|
| 3618 |
|
| 3619 |
+
// [map.special], specialized algorithms
|
| 3620 |
template <class Key, class T, class Compare, class Allocator>
|
| 3621 |
void swap(map<Key, T, Compare, Allocator>& x,
|
| 3622 |
+
map<Key, T, Compare, Allocator>& y)
|
| 3623 |
+
noexcept(noexcept(x.swap(y)));
|
| 3624 |
}
|
| 3625 |
```
|
| 3626 |
|
| 3627 |
#### `map` constructors, copy, and assignment <a id="map.cons">[[map.cons]]</a>
|
| 3628 |
|
| 3629 |
``` cpp
|
| 3630 |
+
explicit map(const Compare& comp, const Allocator& = Allocator());
|
|
|
|
| 3631 |
```
|
| 3632 |
|
| 3633 |
*Effects:* Constructs an empty `map` using the specified comparison
|
| 3634 |
object and allocator.
|
| 3635 |
|
|
|
|
| 3639 |
template <class InputIterator>
|
| 3640 |
map(InputIterator first, InputIterator last,
|
| 3641 |
const Compare& comp = Compare(), const Allocator& = Allocator());
|
| 3642 |
```
|
| 3643 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 3644 |
*Effects:* Constructs an empty `map` using the specified comparison
|
| 3645 |
object and allocator, and inserts elements from the range \[`first`,
|
| 3646 |
`last`).
|
| 3647 |
|
| 3648 |
*Complexity:* Linear in N if the range \[`first`, `last`) is already
|
| 3649 |
+
sorted using `comp` and otherwise N log N, where N is `last - first`.
|
| 3650 |
|
| 3651 |
#### `map` element access <a id="map.access">[[map.access]]</a>
|
| 3652 |
|
| 3653 |
``` cpp
|
| 3654 |
T& operator[](const key_type& x);
|
| 3655 |
```
|
| 3656 |
|
| 3657 |
+
*Effects:* Equivalent to: `return try_emplace(x).first->second;`
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 3658 |
|
| 3659 |
``` cpp
|
| 3660 |
T& operator[](key_type&& x);
|
| 3661 |
```
|
| 3662 |
|
| 3663 |
+
*Effects:* Equivalent to: `return try_emplace(move(x)).first->second;`
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 3664 |
|
| 3665 |
``` cpp
|
| 3666 |
T& at(const key_type& x);
|
| 3667 |
const T& at(const key_type& x) const;
|
| 3668 |
```
|
|
|
|
| 3676 |
*Complexity:* Logarithmic.
|
| 3677 |
|
| 3678 |
#### `map` modifiers <a id="map.modifiers">[[map.modifiers]]</a>
|
| 3679 |
|
| 3680 |
``` cpp
|
| 3681 |
+
template <class P>
|
| 3682 |
+
pair<iterator, bool> insert(P&& x);
|
| 3683 |
+
template <class P>
|
| 3684 |
+
iterator insert(const_iterator position, P&& x);
|
| 3685 |
```
|
| 3686 |
|
| 3687 |
*Effects:* The first form is equivalent to
|
| 3688 |
`return emplace(std::forward<P>(x))`. The second form is equivalent to
|
| 3689 |
`return emplace_hint(position, std::forward<P>(x))`.
|
| 3690 |
|
| 3691 |
*Remarks:* These signatures shall not participate in overload resolution
|
| 3692 |
+
unless `is_constructible_v<value_type, P&&>` is `true`.
|
| 3693 |
+
|
| 3694 |
+
``` cpp
|
| 3695 |
+
template <class... Args>
|
| 3696 |
+
pair<iterator, bool> try_emplace(const key_type& k, Args&&... args);
|
| 3697 |
+
template <class... Args>
|
| 3698 |
+
iterator try_emplace(const_iterator hint, const key_type& k, Args&&... args);
|
| 3699 |
+
```
|
| 3700 |
+
|
| 3701 |
+
*Requires:* `value_type` shall be `EmplaceConstructible` into `map` from
|
| 3702 |
+
`piecewise_construct`, `forward_as_tuple(k)`,
|
| 3703 |
+
`forward_as_tuple(std::forward<Args>(args)...)`.
|
| 3704 |
+
|
| 3705 |
+
*Effects:* If the map already contains an element whose key is
|
| 3706 |
+
equivalent to `k`, there is no effect. Otherwise inserts an object of
|
| 3707 |
+
type `value_type` constructed with `piecewise_construct`,
|
| 3708 |
+
`forward_as_tuple(k)`, `forward_as_tuple(std::forward<Args>(args)...)`.
|
| 3709 |
+
|
| 3710 |
+
*Returns:* In the first overload, the `bool` component of the returned
|
| 3711 |
+
pair is `true` if and only if the insertion took place. The returned
|
| 3712 |
+
iterator points to the map element whose key is equivalent to `k`.
|
| 3713 |
+
|
| 3714 |
+
*Complexity:* The same as `emplace` and `emplace_hint`, respectively.
|
| 3715 |
+
|
| 3716 |
+
``` cpp
|
| 3717 |
+
template <class... Args>
|
| 3718 |
+
pair<iterator, bool> try_emplace(key_type&& k, Args&&... args);
|
| 3719 |
+
template <class... Args>
|
| 3720 |
+
iterator try_emplace(const_iterator hint, key_type&& k, Args&&... args);
|
| 3721 |
+
```
|
| 3722 |
+
|
| 3723 |
+
*Requires:* `value_type` shall be `EmplaceConstructible` into `map` from
|
| 3724 |
+
`piecewise_construct`, `forward_as_tuple(std::move(k))`,
|
| 3725 |
+
`forward_as_tuple(std::forward<Args>(args)...)`.
|
| 3726 |
+
|
| 3727 |
+
*Effects:* If the map already contains an element whose key is
|
| 3728 |
+
equivalent to `k`, there is no effect. Otherwise inserts an object of
|
| 3729 |
+
type `value_type` constructed with `piecewise_construct`,
|
| 3730 |
+
`forward_as_tuple(std::move(k))`,
|
| 3731 |
+
`forward_as_tuple(std::forward<Args>(args)...)`.
|
| 3732 |
+
|
| 3733 |
+
*Returns:* In the first overload, the `bool` component of the returned
|
| 3734 |
+
pair is `true` if and only if the insertion took place. The returned
|
| 3735 |
+
iterator points to the map element whose key is equivalent to `k`.
|
| 3736 |
+
|
| 3737 |
+
*Complexity:* The same as `emplace` and `emplace_hint`, respectively.
|
| 3738 |
+
|
| 3739 |
+
``` cpp
|
| 3740 |
+
template <class M>
|
| 3741 |
+
pair<iterator, bool> insert_or_assign(const key_type& k, M&& obj);
|
| 3742 |
+
template <class M>
|
| 3743 |
+
iterator insert_or_assign(const_iterator hint, const key_type& k, M&& obj);
|
| 3744 |
+
```
|
| 3745 |
+
|
| 3746 |
+
*Requires:* `is_assignable_v<mapped_type&, M&&>` shall be `true`.
|
| 3747 |
+
`value_type` shall be `EmplaceConstructible` into `map` from `k`,
|
| 3748 |
+
`forward<M>(obj)`.
|
| 3749 |
+
|
| 3750 |
+
*Effects:* If the map already contains an element `e` whose key is
|
| 3751 |
+
equivalent to `k`, assigns `std::forward<M>(obj)` to `e.second`.
|
| 3752 |
+
Otherwise inserts an object of type `value_type` constructed with `k`,
|
| 3753 |
+
`std::forward<M>(obj)`.
|
| 3754 |
+
|
| 3755 |
+
*Returns:* In the first overload, the `bool` component of the returned
|
| 3756 |
+
pair is `true` if and only if the insertion took place. The returned
|
| 3757 |
+
iterator points to the map element whose key is equivalent to `k`.
|
| 3758 |
+
|
| 3759 |
+
*Complexity:* The same as `emplace` and `emplace_hint`, respectively.
|
| 3760 |
+
|
| 3761 |
+
``` cpp
|
| 3762 |
+
template <class M>
|
| 3763 |
+
pair<iterator, bool> insert_or_assign(key_type&& k, M&& obj);
|
| 3764 |
+
template <class M>
|
| 3765 |
+
iterator insert_or_assign(const_iterator hint, key_type&& k, M&& obj);
|
| 3766 |
+
```
|
| 3767 |
+
|
| 3768 |
+
*Requires:* `is_assignable_v<mapped_type&, M&&>` shall be `true`.
|
| 3769 |
+
`value_type` shall be `EmplaceConstructible` into `map` from `move(k)`,
|
| 3770 |
+
`forward<M>(obj)`.
|
| 3771 |
+
|
| 3772 |
+
*Effects:* If the map already contains an element `e` whose key is
|
| 3773 |
+
equivalent to `k`, assigns `std::forward<M>(obj)` to `e.second`.
|
| 3774 |
+
Otherwise inserts an object of type `value_type` constructed with
|
| 3775 |
+
`std::move(k)`, `std::forward<M>(obj)`.
|
| 3776 |
+
|
| 3777 |
+
*Returns:* In the first overload, the `bool` component of the returned
|
| 3778 |
+
pair is `true` if and only if the insertion took place. The returned
|
| 3779 |
+
iterator points to the map element whose key is equivalent to `k`.
|
| 3780 |
+
|
| 3781 |
+
*Complexity:* The same as `emplace` and `emplace_hint`, respectively.
|
| 3782 |
|
| 3783 |
#### `map` specialized algorithms <a id="map.special">[[map.special]]</a>
|
| 3784 |
|
| 3785 |
``` cpp
|
| 3786 |
template <class Key, class T, class Compare, class Allocator>
|
| 3787 |
void swap(map<Key, T, Compare, Allocator>& x,
|
| 3788 |
+
map<Key, T, Compare, Allocator>& y)
|
| 3789 |
+
noexcept(noexcept(x.swap(y)));
|
| 3790 |
```
|
| 3791 |
|
| 3792 |
+
*Effects:* As if by `x.swap(y)`.
|
|
|
|
|
|
|
|
|
|
|
|
|
| 3793 |
|
| 3794 |
### Class template `multimap` <a id="multimap">[[multimap]]</a>
|
| 3795 |
|
| 3796 |
#### Class template `multimap` overview <a id="multimap.overview">[[multimap.overview]]</a>
|
| 3797 |
|
|
|
|
| 3802 |
|
| 3803 |
A `multimap` satisfies all of the requirements of a container and of a
|
| 3804 |
reversible container ([[container.requirements]]), of an associative
|
| 3805 |
container ([[associative.reqmts]]), and of an allocator-aware container
|
| 3806 |
(Table [[tab:containers.allocatoraware]]). A `multimap` also provides
|
| 3807 |
+
most operations described in [[associative.reqmts]] for equal keys.
|
| 3808 |
+
This means that a `multimap` supports the `a_eq` operations in
|
| 3809 |
+
[[associative.reqmts]] but not the `a_uniq` operations. For a
|
| 3810 |
`multimap<Key,T>` the `key_type` is `Key` and the `value_type` is
|
| 3811 |
`pair<const Key,T>`. Descriptions are provided here only for operations
|
| 3812 |
on `multimap` that are not described in one of those tables or for
|
| 3813 |
operations where there is additional semantic information.
|
| 3814 |
|
|
|
|
| 3817 |
template <class Key, class T, class Compare = less<Key>,
|
| 3818 |
class Allocator = allocator<pair<const Key, T>>>
|
| 3819 |
class multimap {
|
| 3820 |
public:
|
| 3821 |
// types:
|
| 3822 |
+
using key_type = Key;
|
| 3823 |
+
using mapped_type = T;
|
| 3824 |
+
using value_type = pair<const Key, T>;
|
| 3825 |
+
using key_compare = Compare;
|
| 3826 |
+
using allocator_type = Allocator;
|
| 3827 |
+
using pointer = typename allocator_traits<Allocator>::pointer;
|
| 3828 |
+
using const_pointer = typename allocator_traits<Allocator>::const_pointer;
|
| 3829 |
+
using reference = value_type&;
|
| 3830 |
+
using const_reference = const value_type&;
|
| 3831 |
+
using size_type = implementation-defined; // see [container.requirements]
|
| 3832 |
+
using difference_type = implementation-defined; // see [container.requirements]
|
| 3833 |
+
using iterator = implementation-defined // type of multimap::iterator; // see [container.requirements]
|
| 3834 |
+
using const_iterator = implementation-defined // type of multimap::const_iterator; // see [container.requirements]
|
| 3835 |
+
using reverse_iterator = std::reverse_iterator<iterator>;
|
| 3836 |
+
using const_reverse_iterator = std::reverse_iterator<const_iterator>;
|
| 3837 |
+
using node_type = unspecified;
|
| 3838 |
|
| 3839 |
class value_compare {
|
| 3840 |
friend class multimap;
|
| 3841 |
protected:
|
| 3842 |
Compare comp;
|
| 3843 |
value_compare(Compare c) : comp(c) { }
|
| 3844 |
public:
|
|
|
|
|
|
|
|
|
|
| 3845 |
bool operator()(const value_type& x, const value_type& y) const {
|
| 3846 |
return comp(x.first, y.first);
|
| 3847 |
}
|
| 3848 |
};
|
| 3849 |
|
| 3850 |
+
// [multimap.cons], construct/copy/destroy
|
| 3851 |
multimap() : multimap(Compare()) { }
|
| 3852 |
+
explicit multimap(const Compare& comp, const Allocator& = Allocator());
|
|
|
|
| 3853 |
template <class InputIterator>
|
| 3854 |
multimap(InputIterator first, InputIterator last,
|
| 3855 |
const Compare& comp = Compare(),
|
| 3856 |
const Allocator& = Allocator());
|
| 3857 |
multimap(const multimap& x);
|
|
|
|
| 3867 |
: multimap(first, last, Compare(), a) { }
|
| 3868 |
multimap(initializer_list<value_type> il, const Allocator& a)
|
| 3869 |
: multimap(il, Compare(), a) { }
|
| 3870 |
~multimap();
|
| 3871 |
multimap& operator=(const multimap& x);
|
| 3872 |
+
multimap& operator=(multimap&& x)
|
| 3873 |
+
noexcept(allocator_traits<Allocator>::is_always_equal::value &&
|
| 3874 |
+
is_nothrow_move_assignable_v<Compare>);
|
| 3875 |
multimap& operator=(initializer_list<value_type>);
|
| 3876 |
allocator_type get_allocator() const noexcept;
|
| 3877 |
|
| 3878 |
// iterators:
|
| 3879 |
iterator begin() noexcept;
|
|
|
|
| 3894 |
// capacity:
|
| 3895 |
bool empty() const noexcept;
|
| 3896 |
size_type size() const noexcept;
|
| 3897 |
size_type max_size() const noexcept;
|
| 3898 |
|
| 3899 |
+
// [multimap.modifiers], modifiers
|
| 3900 |
template <class... Args> iterator emplace(Args&&... args);
|
| 3901 |
template <class... Args> iterator emplace_hint(const_iterator position, Args&&... args);
|
| 3902 |
iterator insert(const value_type& x);
|
| 3903 |
+
iterator insert(value_type&& x);
|
| 3904 |
template <class P> iterator insert(P&& x);
|
| 3905 |
iterator insert(const_iterator position, const value_type& x);
|
| 3906 |
+
iterator insert(const_iterator position, value_type&& x);
|
| 3907 |
template <class P> iterator insert(const_iterator position, P&& x);
|
| 3908 |
template <class InputIterator>
|
| 3909 |
void insert(InputIterator first, InputIterator last);
|
| 3910 |
void insert(initializer_list<value_type>);
|
| 3911 |
|
| 3912 |
+
node_type extract(const_iterator position);
|
| 3913 |
+
node_type extract(const key_type& x);
|
| 3914 |
+
iterator insert(node_type&& nh);
|
| 3915 |
+
iterator insert(const_iterator hint, node_type&& nh);
|
| 3916 |
+
|
| 3917 |
+
iterator erase(iterator position);
|
| 3918 |
iterator erase(const_iterator position);
|
| 3919 |
size_type erase(const key_type& x);
|
| 3920 |
iterator erase(const_iterator first, const_iterator last);
|
| 3921 |
+
void swap(multimap&)
|
| 3922 |
+
noexcept(allocator_traits<Allocator>::is_always_equal::value &&
|
| 3923 |
+
is_nothrow_swappable_v<Compare>);
|
| 3924 |
void clear() noexcept;
|
| 3925 |
|
| 3926 |
+
template<class C2>
|
| 3927 |
+
void merge(multimap<Key, T, C2, Allocator>& source);
|
| 3928 |
+
template<class C2>
|
| 3929 |
+
void merge(multimap<Key, T, C2, Allocator>&& source);
|
| 3930 |
+
template<class C2>
|
| 3931 |
+
void merge(map<Key, T, C2, Allocator>& source);
|
| 3932 |
+
template<class C2>
|
| 3933 |
+
void merge(map<Key, T, C2, Allocator>&& source);
|
| 3934 |
+
|
| 3935 |
// observers:
|
| 3936 |
key_compare key_comp() const;
|
| 3937 |
value_compare value_comp() const;
|
| 3938 |
|
| 3939 |
// map operations:
|
|
|
|
| 3953 |
iterator upper_bound(const key_type& x);
|
| 3954 |
const_iterator upper_bound(const key_type& x) const;
|
| 3955 |
template <class K> iterator upper_bound(const K& x);
|
| 3956 |
template <class K> const_iterator upper_bound(const K& x) const;
|
| 3957 |
|
| 3958 |
+
pair<iterator, iterator> equal_range(const key_type& x);
|
| 3959 |
+
pair<const_iterator, const_iterator> equal_range(const key_type& x) const;
|
|
|
|
|
|
|
| 3960 |
template <class K>
|
| 3961 |
pair<iterator, iterator> equal_range(const K& x);
|
| 3962 |
template <class K>
|
| 3963 |
pair<const_iterator, const_iterator> equal_range(const K& x) const;
|
| 3964 |
};
|
| 3965 |
|
| 3966 |
+
template<class InputIterator, class Compare = less<iter_key_t<InputIterator>>,
|
| 3967 |
+
class Allocator = allocator<iter_to_alloc_t<InputIterator>>>
|
| 3968 |
+
multimap(InputIterator, InputIterator, Compare = Compare(), Allocator = Allocator())
|
| 3969 |
+
-> multimap<iter_key_t<InputIterator>, iter_val_t<InputIterator>, Compare, Allocator>;
|
| 3970 |
+
|
| 3971 |
+
template<class Key, class T, class Compare = less<Key>,
|
| 3972 |
+
class Allocator = allocator<pair<const Key, T>>>
|
| 3973 |
+
multimap(initializer_list<pair<const Key, T>>, Compare = Compare(), Allocator = Allocator())
|
| 3974 |
+
-> multimap<Key, T, Compare, Allocator>;
|
| 3975 |
+
|
| 3976 |
+
template<class InputIterator, class Allocator>
|
| 3977 |
+
multimap(InputIterator, InputIterator, Allocator)
|
| 3978 |
+
-> multimap<iter_key_t<InputIterator>, iter_val_t<InputIterator>,
|
| 3979 |
+
less<iter_key_t<InputIterator>>, Allocator>;
|
| 3980 |
+
|
| 3981 |
+
template<class Key, class T, class Allocator>
|
| 3982 |
+
multimap(initializer_list<pair<const Key, T>>, Allocator)
|
| 3983 |
+
-> multimap<Key, T, less<Key>, Allocator>;
|
| 3984 |
+
|
| 3985 |
template <class Key, class T, class Compare, class Allocator>
|
| 3986 |
bool operator==(const multimap<Key, T, Compare, Allocator>& x,
|
| 3987 |
const multimap<Key, T, Compare, Allocator>& y);
|
| 3988 |
template <class Key, class T, class Compare, class Allocator>
|
| 3989 |
bool operator< (const multimap<Key, T, Compare, Allocator>& x,
|
|
|
|
| 3999 |
const multimap<Key, T, Compare, Allocator>& y);
|
| 4000 |
template <class Key, class T, class Compare, class Allocator>
|
| 4001 |
bool operator<=(const multimap<Key, T, Compare, Allocator>& x,
|
| 4002 |
const multimap<Key, T, Compare, Allocator>& y);
|
| 4003 |
|
| 4004 |
+
// [multimap.special], specialized algorithms
|
| 4005 |
template <class Key, class T, class Compare, class Allocator>
|
| 4006 |
void swap(multimap<Key, T, Compare, Allocator>& x,
|
| 4007 |
+
multimap<Key, T, Compare, Allocator>& y)
|
| 4008 |
+
noexcept(noexcept(x.swap(y)));
|
| 4009 |
}
|
| 4010 |
```
|
| 4011 |
|
| 4012 |
#### `multimap` constructors <a id="multimap.cons">[[multimap.cons]]</a>
|
| 4013 |
|
| 4014 |
``` cpp
|
| 4015 |
+
explicit multimap(const Compare& comp, const Allocator& = Allocator());
|
|
|
|
| 4016 |
```
|
| 4017 |
|
| 4018 |
*Effects:* Constructs an empty `multimap` using the specified comparison
|
| 4019 |
object and allocator.
|
| 4020 |
|
|
|
|
| 4025 |
multimap(InputIterator first, InputIterator last,
|
| 4026 |
const Compare& comp = Compare(),
|
| 4027 |
const Allocator& = Allocator());
|
| 4028 |
```
|
| 4029 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 4030 |
*Effects:* Constructs an empty `multimap` using the specified comparison
|
| 4031 |
object and allocator, and inserts elements from the range \[`first`,
|
| 4032 |
`last`).
|
| 4033 |
|
| 4034 |
*Complexity:* Linear in N if the range \[`first`, `last`) is already
|
|
|
|
| 4044 |
*Effects:* The first form is equivalent to
|
| 4045 |
`return emplace(std::forward<P>(x))`. The second form is equivalent to
|
| 4046 |
`return emplace_hint(position, std::forward<P>(x))`.
|
| 4047 |
|
| 4048 |
*Remarks:* These signatures shall not participate in overload resolution
|
| 4049 |
+
unless `is_constructible_v<value_type, P&&>` is `true`.
|
| 4050 |
|
| 4051 |
#### `multimap` specialized algorithms <a id="multimap.special">[[multimap.special]]</a>
|
| 4052 |
|
| 4053 |
``` cpp
|
| 4054 |
template <class Key, class T, class Compare, class Allocator>
|
| 4055 |
void swap(multimap<Key, T, Compare, Allocator>& x,
|
| 4056 |
+
multimap<Key, T, Compare, Allocator>& y)
|
| 4057 |
+
noexcept(noexcept(x.swap(y)));
|
| 4058 |
```
|
| 4059 |
|
| 4060 |
+
*Effects:* As if by `x.swap(y)`.
|
|
|
|
|
|
|
|
|
|
|
|
|
| 4061 |
|
| 4062 |
### Class template `set` <a id="set">[[set]]</a>
|
| 4063 |
|
| 4064 |
#### Class template `set` overview <a id="set.overview">[[set.overview]]</a>
|
| 4065 |
|
|
|
|
| 4069 |
|
| 4070 |
A `set` satisfies all of the requirements of a container, of a
|
| 4071 |
reversible container ([[container.requirements]]), of an associative
|
| 4072 |
container ([[associative.reqmts]]), and of an allocator-aware container
|
| 4073 |
(Table [[tab:containers.allocatoraware]]). A `set` also provides most
|
| 4074 |
+
operations described in [[associative.reqmts]] for unique keys. This
|
| 4075 |
+
means that a `set` supports the `a_uniq` operations in
|
| 4076 |
+
[[associative.reqmts]] but not the `a_eq` operations. For a `set<Key>`
|
| 4077 |
both the `key_type` and `value_type` are `Key`. Descriptions are
|
| 4078 |
provided here only for operations on `set` that are not described in one
|
| 4079 |
of these tables and for operations where there is additional semantic
|
| 4080 |
information.
|
| 4081 |
|
|
|
|
| 4084 |
template <class Key, class Compare = less<Key>,
|
| 4085 |
class Allocator = allocator<Key>>
|
| 4086 |
class set {
|
| 4087 |
public:
|
| 4088 |
// types:
|
| 4089 |
+
using key_type = Key;
|
| 4090 |
+
using key_compare = Compare;
|
| 4091 |
+
using value_type = Key;
|
| 4092 |
+
using value_compare = Compare;
|
| 4093 |
+
using allocator_type = Allocator;
|
| 4094 |
+
using pointer = typename allocator_traits<Allocator>::pointer;
|
| 4095 |
+
using const_pointer = typename allocator_traits<Allocator>::const_pointer;
|
| 4096 |
+
using reference = value_type&;
|
| 4097 |
+
using const_reference = const value_type&;
|
| 4098 |
+
using size_type = implementation-defined; // see [container.requirements]
|
| 4099 |
+
using difference_type = implementation-defined; // see [container.requirements]
|
| 4100 |
+
using iterator = implementation-defined // type of set::iterator; // see [container.requirements]
|
| 4101 |
+
using const_iterator = implementation-defined // type of set::const_iterator; // see [container.requirements]
|
| 4102 |
+
using reverse_iterator = std::reverse_iterator<iterator>;
|
| 4103 |
+
using const_reverse_iterator = std::reverse_iterator<const_iterator>;
|
| 4104 |
+
using node_type = unspecified;
|
| 4105 |
+
using insert_return_type = INSERT_RETURN_TYPE<iterator, node_type>;
|
| 4106 |
|
| 4107 |
+
// [set.cons], construct/copy/destroy
|
| 4108 |
set() : set(Compare()) { }
|
| 4109 |
+
explicit set(const Compare& comp, const Allocator& = Allocator());
|
|
|
|
| 4110 |
template <class InputIterator>
|
| 4111 |
set(InputIterator first, InputIterator last,
|
| 4112 |
const Compare& comp = Compare(), const Allocator& = Allocator());
|
| 4113 |
set(const set& x);
|
| 4114 |
set(set&& x);
|
| 4115 |
explicit set(const Allocator&);
|
| 4116 |
set(const set&, const Allocator&);
|
| 4117 |
set(set&&, const Allocator&);
|
| 4118 |
+
set(initializer_list<value_type>, const Compare& = Compare(),
|
|
|
|
| 4119 |
const Allocator& = Allocator());
|
| 4120 |
template <class InputIterator>
|
| 4121 |
set(InputIterator first, InputIterator last, const Allocator& a)
|
| 4122 |
: set(first, last, Compare(), a) { }
|
| 4123 |
set(initializer_list<value_type> il, const Allocator& a)
|
| 4124 |
: set(il, Compare(), a) { }
|
| 4125 |
~set();
|
| 4126 |
set& operator=(const set& x);
|
| 4127 |
+
set& operator=(set&& x)
|
| 4128 |
+
noexcept(allocator_traits<Allocator>::is_always_equal::value &&
|
| 4129 |
+
is_nothrow_move_assignable_v<Compare>);
|
| 4130 |
set& operator=(initializer_list<value_type>);
|
| 4131 |
allocator_type get_allocator() const noexcept;
|
| 4132 |
|
| 4133 |
// iterators:
|
| 4134 |
iterator begin() noexcept;
|
|
|
|
| 4160 |
iterator insert(const_iterator position, value_type&& x);
|
| 4161 |
template <class InputIterator>
|
| 4162 |
void insert(InputIterator first, InputIterator last);
|
| 4163 |
void insert(initializer_list<value_type>);
|
| 4164 |
|
| 4165 |
+
node_type extract(const_iterator position);
|
| 4166 |
+
node_type extract(const key_type& x);
|
| 4167 |
+
insert_return_type insert(node_type&& nh);
|
| 4168 |
+
iterator insert(const_iterator hint, node_type&& nh);
|
| 4169 |
+
|
| 4170 |
+
iterator erase(iterator position);
|
| 4171 |
iterator erase(const_iterator position);
|
| 4172 |
size_type erase(const key_type& x);
|
| 4173 |
iterator erase(const_iterator first, const_iterator last);
|
| 4174 |
+
void swap(set&)
|
| 4175 |
+
noexcept(allocator_traits<Allocator>::is_always_equal::value &&
|
| 4176 |
+
is_nothrow_swappable_v<Compare>);
|
| 4177 |
void clear() noexcept;
|
| 4178 |
|
| 4179 |
+
template<class C2>
|
| 4180 |
+
void merge(set<Key, C2, Allocator>& source);
|
| 4181 |
+
template<class C2>
|
| 4182 |
+
void merge(set<Key, C2, Allocator>&& source);
|
| 4183 |
+
template<class C2>
|
| 4184 |
+
void merge(multiset<Key, C2, Allocator>& source);
|
| 4185 |
+
template<class C2>
|
| 4186 |
+
void merge(multiset<Key, C2, Allocator>&& source);
|
| 4187 |
+
|
| 4188 |
// observers:
|
| 4189 |
key_compare key_comp() const;
|
| 4190 |
value_compare value_comp() const;
|
| 4191 |
|
| 4192 |
// set operations:
|
|
|
|
| 4214 |
pair<iterator, iterator> equal_range(const K& x);
|
| 4215 |
template <class K>
|
| 4216 |
pair<const_iterator, const_iterator> equal_range(const K& x) const;
|
| 4217 |
};
|
| 4218 |
|
| 4219 |
+
template<class InputIterator,
|
| 4220 |
+
class Compare = less<typename iterator_traits<InputIterator>::value_type>,
|
| 4221 |
+
class Allocator = allocator<typename iterator_traits<InputIterator>::value_type>>
|
| 4222 |
+
set(InputIterator, InputIterator,
|
| 4223 |
+
Compare = Compare(), Allocator = Allocator())
|
| 4224 |
+
-> set<typename iterator_traits<InputIterator>::value_type, Compare, Allocator>;
|
| 4225 |
+
|
| 4226 |
+
template<class Key, class Compare = less<Key>, class Allocator = allocator<Key>>
|
| 4227 |
+
set(initializer_list<Key>, Compare = Compare(), Allocator = Allocator())
|
| 4228 |
+
-> set<Key, Compare, Allocator>;
|
| 4229 |
+
|
| 4230 |
+
template<class InputIterator, class Allocator>
|
| 4231 |
+
set(InputIterator, InputIterator, Allocator)
|
| 4232 |
+
-> set<typename iterator_traits<InputIterator>::value_type,
|
| 4233 |
+
less<typename iterator_traits<InputIterator>::value_type>, Allocator>;
|
| 4234 |
+
|
| 4235 |
+
template<class Key, class Allocator>
|
| 4236 |
+
set(initializer_list<Key>, Allocator) -> set<Key, less<Key>, Allocator>;
|
| 4237 |
+
|
| 4238 |
template <class Key, class Compare, class Allocator>
|
| 4239 |
bool operator==(const set<Key, Compare, Allocator>& x,
|
| 4240 |
const set<Key, Compare, Allocator>& y);
|
| 4241 |
template <class Key, class Compare, class Allocator>
|
| 4242 |
bool operator< (const set<Key, Compare, Allocator>& x,
|
|
|
|
| 4252 |
const set<Key, Compare, Allocator>& y);
|
| 4253 |
template <class Key, class Compare, class Allocator>
|
| 4254 |
bool operator<=(const set<Key, Compare, Allocator>& x,
|
| 4255 |
const set<Key, Compare, Allocator>& y);
|
| 4256 |
|
| 4257 |
+
// [set.special], specialized algorithms
|
| 4258 |
template <class Key, class Compare, class Allocator>
|
| 4259 |
void swap(set<Key, Compare, Allocator>& x,
|
| 4260 |
+
set<Key, Compare, Allocator>& y)
|
| 4261 |
+
noexcept(noexcept(x.swap(y)));
|
| 4262 |
}
|
| 4263 |
```
|
| 4264 |
|
| 4265 |
#### `set` constructors, copy, and assignment <a id="set.cons">[[set.cons]]</a>
|
| 4266 |
|
| 4267 |
``` cpp
|
| 4268 |
+
explicit set(const Compare& comp, const Allocator& = Allocator());
|
|
|
|
| 4269 |
```
|
| 4270 |
|
| 4271 |
+
*Effects:* Constructs an empty `set` using the specified comparison
|
| 4272 |
objects and allocator.
|
| 4273 |
|
| 4274 |
*Complexity:* Constant.
|
| 4275 |
|
| 4276 |
``` cpp
|
|
|
|
| 4281 |
|
| 4282 |
*Effects:* Constructs an empty `set` using the specified comparison
|
| 4283 |
object and allocator, and inserts elements from the range \[`first`,
|
| 4284 |
`last`).
|
| 4285 |
|
|
|
|
|
|
|
|
|
|
| 4286 |
*Complexity:* Linear in N if the range \[`first`, `last`) is already
|
| 4287 |
sorted using `comp` and otherwise N log N, where N is `last - first`.
|
| 4288 |
|
| 4289 |
#### `set` specialized algorithms <a id="set.special">[[set.special]]</a>
|
| 4290 |
|
| 4291 |
``` cpp
|
| 4292 |
template <class Key, class Compare, class Allocator>
|
| 4293 |
void swap(set<Key, Compare, Allocator>& x,
|
| 4294 |
+
set<Key, Compare, Allocator>& y)
|
| 4295 |
+
noexcept(noexcept(x.swap(y)));
|
| 4296 |
```
|
| 4297 |
|
| 4298 |
+
*Effects:* As if by `x.swap(y)`.
|
|
|
|
|
|
|
|
|
|
|
|
|
| 4299 |
|
| 4300 |
### Class template `multiset` <a id="multiset">[[multiset]]</a>
|
| 4301 |
|
| 4302 |
#### Class template `multiset` overview <a id="multiset.overview">[[multiset.overview]]</a>
|
| 4303 |
|
|
|
|
| 4308 |
|
| 4309 |
A `multiset` satisfies all of the requirements of a container, of a
|
| 4310 |
reversible container ([[container.requirements]]), of an associative
|
| 4311 |
container ([[associative.reqmts]]), and of an allocator-aware container
|
| 4312 |
(Table [[tab:containers.allocatoraware]]). `multiset` also provides
|
| 4313 |
+
most operations described in [[associative.reqmts]] for duplicate keys.
|
| 4314 |
+
This means that a `multiset` supports the `a_eq` operations in
|
| 4315 |
+
[[associative.reqmts]] but not the `a_uniq` operations. For a
|
| 4316 |
`multiset<Key>` both the `key_type` and `value_type` are `Key`.
|
| 4317 |
Descriptions are provided here only for operations on `multiset` that
|
| 4318 |
are not described in one of these tables and for operations where there
|
| 4319 |
is additional semantic information.
|
| 4320 |
|
|
|
|
| 4323 |
template <class Key, class Compare = less<Key>,
|
| 4324 |
class Allocator = allocator<Key>>
|
| 4325 |
class multiset {
|
| 4326 |
public:
|
| 4327 |
// types:
|
| 4328 |
+
using key_type = Key;
|
| 4329 |
+
using key_compare = Compare;
|
| 4330 |
+
using value_type = Key;
|
| 4331 |
+
using value_compare = Compare;
|
| 4332 |
+
using allocator_type = Allocator;
|
| 4333 |
+
using pointer = typename allocator_traits<Allocator>::pointer;
|
| 4334 |
+
using const_pointer = typename allocator_traits<Allocator>::const_pointer;
|
| 4335 |
+
using reference = value_type&;
|
| 4336 |
+
using const_reference = const value_type&;
|
| 4337 |
+
using size_type = implementation-defined; // see [container.requirements]
|
| 4338 |
+
using difference_type = implementation-defined; // see [container.requirements]
|
| 4339 |
+
using iterator = implementation-defined // type of multiset::iterator; // see [container.requirements]
|
| 4340 |
+
using const_iterator = implementation-defined // type of multiset::const_iterator; // see [container.requirements]
|
| 4341 |
+
using reverse_iterator = std::reverse_iterator<iterator>;
|
| 4342 |
+
using const_reverse_iterator = std::reverse_iterator<const_iterator>;
|
| 4343 |
+
using node_type = unspecified;
|
| 4344 |
|
| 4345 |
+
// [multiset.cons], construct/copy/destroy
|
| 4346 |
multiset() : multiset(Compare()) { }
|
| 4347 |
+
explicit multiset(const Compare& comp, const Allocator& = Allocator());
|
|
|
|
| 4348 |
template <class InputIterator>
|
| 4349 |
multiset(InputIterator first, InputIterator last,
|
| 4350 |
+
const Compare& comp = Compare(), const Allocator& = Allocator());
|
|
|
|
| 4351 |
multiset(const multiset& x);
|
| 4352 |
multiset(multiset&& x);
|
| 4353 |
explicit multiset(const Allocator&);
|
| 4354 |
multiset(const multiset&, const Allocator&);
|
| 4355 |
multiset(multiset&&, const Allocator&);
|
| 4356 |
+
multiset(initializer_list<value_type>, const Compare& = Compare(),
|
|
|
|
| 4357 |
const Allocator& = Allocator());
|
| 4358 |
template <class InputIterator>
|
| 4359 |
multiset(InputIterator first, InputIterator last, const Allocator& a)
|
| 4360 |
: multiset(first, last, Compare(), a) { }
|
| 4361 |
multiset(initializer_list<value_type> il, const Allocator& a)
|
| 4362 |
: multiset(il, Compare(), a) { }
|
| 4363 |
~multiset();
|
| 4364 |
multiset& operator=(const multiset& x);
|
| 4365 |
+
multiset& operator=(multiset&& x)
|
| 4366 |
+
noexcept(allocator_traits<Allocator>::is_always_equal::value &&
|
| 4367 |
+
is_nothrow_move_assignable_v<Compare>);
|
| 4368 |
multiset& operator=(initializer_list<value_type>);
|
| 4369 |
allocator_type get_allocator() const noexcept;
|
| 4370 |
|
| 4371 |
// iterators:
|
| 4372 |
iterator begin() noexcept;
|
|
|
|
| 4398 |
iterator insert(const_iterator position, value_type&& x);
|
| 4399 |
template <class InputIterator>
|
| 4400 |
void insert(InputIterator first, InputIterator last);
|
| 4401 |
void insert(initializer_list<value_type>);
|
| 4402 |
|
| 4403 |
+
node_type extract(const_iterator position);
|
| 4404 |
+
node_type extract(const key_type& x);
|
| 4405 |
+
iterator insert(node_type&& nh);
|
| 4406 |
+
iterator insert(const_iterator hint, node_type&& nh);
|
| 4407 |
+
|
| 4408 |
+
iterator erase(iterator position);
|
| 4409 |
iterator erase(const_iterator position);
|
| 4410 |
size_type erase(const key_type& x);
|
| 4411 |
iterator erase(const_iterator first, const_iterator last);
|
| 4412 |
+
void swap(multiset&)
|
| 4413 |
+
noexcept(allocator_traits<Allocator>::is_always_equal::value &&
|
| 4414 |
+
is_nothrow_swappable_v<Compare>);
|
| 4415 |
void clear() noexcept;
|
| 4416 |
|
| 4417 |
+
template<class C2>
|
| 4418 |
+
void merge(multiset<Key, C2, Allocator>& source);
|
| 4419 |
+
template<class C2>
|
| 4420 |
+
void merge(multiset<Key, C2, Allocator>&& source);
|
| 4421 |
+
template<class C2>
|
| 4422 |
+
void merge(set<Key, C2, Allocator>& source);
|
| 4423 |
+
template<class C2>
|
| 4424 |
+
void merge(set<Key, C2, Allocator>&& source);
|
| 4425 |
+
|
| 4426 |
// observers:
|
| 4427 |
key_compare key_comp() const;
|
| 4428 |
value_compare value_comp() const;
|
| 4429 |
|
| 4430 |
// set operations:
|
|
|
|
| 4452 |
pair<iterator, iterator> equal_range(const K& x);
|
| 4453 |
template <class K>
|
| 4454 |
pair<const_iterator, const_iterator> equal_range(const K& x) const;
|
| 4455 |
};
|
| 4456 |
|
| 4457 |
+
template<class InputIterator,
|
| 4458 |
+
class Compare = less<typename iterator_traits<InputIterator>::value_type>,
|
| 4459 |
+
class Allocator = allocator<typename iterator_traits<InputIterator>::value_type>>
|
| 4460 |
+
multiset(InputIterator, InputIterator,
|
| 4461 |
+
Compare = Compare(), Allocator = Allocator())
|
| 4462 |
+
-> multiset<typename iterator_traits<InputIterator>::value_type, Compare, Allocator>;
|
| 4463 |
+
|
| 4464 |
+
template<class Key, class Compare = less<Key>, class Allocator = allocator<Key>>
|
| 4465 |
+
multiset(initializer_list<Key>, Compare = Compare(), Allocator = Allocator())
|
| 4466 |
+
-> multiset<Key, Compare, Allocator>;
|
| 4467 |
+
|
| 4468 |
+
template<class InputIterator, class Allocator>
|
| 4469 |
+
multiset(InputIterator, InputIterator, Allocator)
|
| 4470 |
+
-> multiset<typename iterator_traits<InputIterator>::value_type,
|
| 4471 |
+
less<typename iterator_traits<InputIterator>::value_type>, Allocator>;
|
| 4472 |
+
|
| 4473 |
+
template<class Key, class Allocator>
|
| 4474 |
+
multiset(initializer_list<Key>, Allocator) -> multiset<Key, less<Key>, Allocator>;
|
| 4475 |
+
|
| 4476 |
template <class Key, class Compare, class Allocator>
|
| 4477 |
bool operator==(const multiset<Key, Compare, Allocator>& x,
|
| 4478 |
const multiset<Key, Compare, Allocator>& y);
|
| 4479 |
template <class Key, class Compare, class Allocator>
|
| 4480 |
bool operator< (const multiset<Key, Compare, Allocator>& x,
|
|
|
|
| 4490 |
const multiset<Key, Compare, Allocator>& y);
|
| 4491 |
template <class Key, class Compare, class Allocator>
|
| 4492 |
bool operator<=(const multiset<Key, Compare, Allocator>& x,
|
| 4493 |
const multiset<Key, Compare, Allocator>& y);
|
| 4494 |
|
| 4495 |
+
// [multiset.special], specialized algorithms
|
| 4496 |
template <class Key, class Compare, class Allocator>
|
| 4497 |
void swap(multiset<Key, Compare, Allocator>& x,
|
| 4498 |
+
multiset<Key, Compare, Allocator>& y)
|
| 4499 |
+
noexcept(noexcept(x.swap(y)));
|
| 4500 |
}
|
| 4501 |
```
|
| 4502 |
|
| 4503 |
#### `multiset` constructors <a id="multiset.cons">[[multiset.cons]]</a>
|
| 4504 |
|
| 4505 |
``` cpp
|
| 4506 |
+
explicit multiset(const Compare& comp, const Allocator& = Allocator());
|
|
|
|
| 4507 |
```
|
| 4508 |
|
| 4509 |
+
*Effects:* Constructs an empty `multiset` using the specified comparison
|
| 4510 |
+
object and allocator.
|
| 4511 |
|
| 4512 |
*Complexity:* Constant.
|
| 4513 |
|
| 4514 |
``` cpp
|
| 4515 |
template <class InputIterator>
|
| 4516 |
multiset(InputIterator first, InputIterator last,
|
| 4517 |
const Compare& comp = Compare(), const Allocator& = Allocator());
|
| 4518 |
```
|
| 4519 |
|
|
|
|
|
|
|
|
|
|
| 4520 |
*Effects:* Constructs an empty `multiset` using the specified comparison
|
| 4521 |
object and allocator, and inserts elements from the range \[`first`,
|
| 4522 |
`last`).
|
| 4523 |
|
| 4524 |
*Complexity:* Linear in N if the range \[`first`, `last`) is already
|
|
|
|
| 4527 |
#### `multiset` specialized algorithms <a id="multiset.special">[[multiset.special]]</a>
|
| 4528 |
|
| 4529 |
``` cpp
|
| 4530 |
template <class Key, class Compare, class Allocator>
|
| 4531 |
void swap(multiset<Key, Compare, Allocator>& x,
|
| 4532 |
+
multiset<Key, Compare, Allocator>& y)
|
| 4533 |
+
noexcept(noexcept(x.swap(y)));
|
| 4534 |
```
|
| 4535 |
|
| 4536 |
+
*Effects:* As if by `x.swap(y)`.
|
|
|
|
|
|
|
|
|
|
|
|
|
| 4537 |
|
| 4538 |
## Unordered associative containers <a id="unord">[[unord]]</a>
|
| 4539 |
|
| 4540 |
### In general <a id="unord.general">[[unord.general]]</a>
|
| 4541 |
|
| 4542 |
The header `<unordered_map>` defines the class templates `unordered_map`
|
| 4543 |
and `unordered_multimap`; the header `<unordered_set>` defines the class
|
| 4544 |
templates `unordered_set` and `unordered_multiset`.
|
| 4545 |
|
| 4546 |
+
The exposition-only alias templates `iter_key_t`, `iter_val_t`, and
|
| 4547 |
+
`iter_to_alloc_t` defined in [[associative.general]] may appear in
|
| 4548 |
+
deduction guides for unordered containers.
|
| 4549 |
+
|
| 4550 |
### Header `<unordered_map>` synopsis <a id="unord.map.syn">[[unord.map.syn]]</a>
|
| 4551 |
|
| 4552 |
``` cpp
|
| 4553 |
#include <initializer_list>
|
| 4554 |
|
| 4555 |
namespace std {
|
| 4556 |
+
// [unord.map], class template unordered_map
|
|
|
|
| 4557 |
template <class Key,
|
| 4558 |
class T,
|
| 4559 |
class Hash = hash<Key>,
|
| 4560 |
+
class Pred = equal_to<Key>,
|
| 4561 |
+
class Alloc = allocator<pair<const Key, T>>>
|
| 4562 |
class unordered_map;
|
| 4563 |
|
| 4564 |
+
// [unord.multimap], class template unordered_multimap
|
| 4565 |
template <class Key,
|
| 4566 |
class T,
|
| 4567 |
class Hash = hash<Key>,
|
| 4568 |
+
class Pred = equal_to<Key>,
|
| 4569 |
+
class Alloc = allocator<pair<const Key, T>>>
|
| 4570 |
class unordered_multimap;
|
| 4571 |
|
| 4572 |
template <class Key, class T, class Hash, class Pred, class Alloc>
|
| 4573 |
void swap(unordered_map<Key, T, Hash, Pred, Alloc>& x,
|
| 4574 |
+
unordered_map<Key, T, Hash, Pred, Alloc>& y)
|
| 4575 |
+
noexcept(noexcept(x.swap(y)));
|
| 4576 |
|
| 4577 |
template <class Key, class T, class Hash, class Pred, class Alloc>
|
| 4578 |
void swap(unordered_multimap<Key, T, Hash, Pred, Alloc>& x,
|
| 4579 |
+
unordered_multimap<Key, T, Hash, Pred, Alloc>& y)
|
| 4580 |
+
noexcept(noexcept(x.swap(y)));
|
| 4581 |
|
| 4582 |
template <class Key, class T, class Hash, class Pred, class Alloc>
|
| 4583 |
bool operator==(const unordered_map<Key, T, Hash, Pred, Alloc>& a,
|
| 4584 |
const unordered_map<Key, T, Hash, Pred, Alloc>& b);
|
| 4585 |
template <class Key, class T, class Hash, class Pred, class Alloc>
|
|
|
|
| 4589 |
bool operator==(const unordered_multimap<Key, T, Hash, Pred, Alloc>& a,
|
| 4590 |
const unordered_multimap<Key, T, Hash, Pred, Alloc>& b);
|
| 4591 |
template <class Key, class T, class Hash, class Pred, class Alloc>
|
| 4592 |
bool operator!=(const unordered_multimap<Key, T, Hash, Pred, Alloc>& a,
|
| 4593 |
const unordered_multimap<Key, T, Hash, Pred, Alloc>& b);
|
| 4594 |
+
|
| 4595 |
+
namespace pmr {
|
| 4596 |
+
template <class Key,
|
| 4597 |
+
class T,
|
| 4598 |
+
class Hash = hash<Key>,
|
| 4599 |
+
class Pred = equal_to<Key>>
|
| 4600 |
+
using unordered_map =
|
| 4601 |
+
std::unordered_map<Key, T, Hash, Pred,
|
| 4602 |
+
polymorphic_allocator<pair<const Key, T>>>;
|
| 4603 |
+
template <class Key,
|
| 4604 |
+
class T,
|
| 4605 |
+
class Hash = hash<Key>,
|
| 4606 |
+
class Pred = equal_to<Key>>
|
| 4607 |
+
using unordered_multimap =
|
| 4608 |
+
std::unordered_multimap<Key, T, Hash, Pred,
|
| 4609 |
+
polymorphic_allocator<pair<const Key, T>>>;
|
| 4610 |
+
|
| 4611 |
+
}
|
| 4612 |
+
}
|
| 4613 |
```
|
| 4614 |
|
| 4615 |
### Header `<unordered_set>` synopsis <a id="unord.set.syn">[[unord.set.syn]]</a>
|
| 4616 |
|
| 4617 |
``` cpp
|
| 4618 |
#include <initializer_list>
|
| 4619 |
|
| 4620 |
namespace std {
|
| 4621 |
+
// [unord.set], class template unordered_set
|
|
|
|
| 4622 |
template <class Key,
|
| 4623 |
class Hash = hash<Key>,
|
| 4624 |
+
class Pred = equal_to<Key>,
|
| 4625 |
+
class Alloc = allocator<Key>>
|
| 4626 |
class unordered_set;
|
| 4627 |
|
| 4628 |
+
// [unord.multiset], class template unordered_multiset
|
| 4629 |
template <class Key,
|
| 4630 |
class Hash = hash<Key>,
|
| 4631 |
+
class Pred = equal_to<Key>,
|
| 4632 |
+
class Alloc = allocator<Key>>
|
| 4633 |
class unordered_multiset;
|
| 4634 |
|
| 4635 |
template <class Key, class Hash, class Pred, class Alloc>
|
| 4636 |
void swap(unordered_set<Key, Hash, Pred, Alloc>& x,
|
| 4637 |
+
unordered_set<Key, Hash, Pred, Alloc>& y)
|
| 4638 |
+
noexcept(noexcept(x.swap(y)));
|
| 4639 |
|
| 4640 |
template <class Key, class Hash, class Pred, class Alloc>
|
| 4641 |
void swap(unordered_multiset<Key, Hash, Pred, Alloc>& x,
|
| 4642 |
+
unordered_multiset<Key, Hash, Pred, Alloc>& y)
|
| 4643 |
+
noexcept(noexcept(x.swap(y)));
|
| 4644 |
|
| 4645 |
template <class Key, class Hash, class Pred, class Alloc>
|
| 4646 |
bool operator==(const unordered_set<Key, Hash, Pred, Alloc>& a,
|
| 4647 |
const unordered_set<Key, Hash, Pred, Alloc>& b);
|
| 4648 |
template <class Key, class Hash, class Pred, class Alloc>
|
|
|
|
| 4652 |
bool operator==(const unordered_multiset<Key, Hash, Pred, Alloc>& a,
|
| 4653 |
const unordered_multiset<Key, Hash, Pred, Alloc>& b);
|
| 4654 |
template <class Key, class Hash, class Pred, class Alloc>
|
| 4655 |
bool operator!=(const unordered_multiset<Key, Hash, Pred, Alloc>& a,
|
| 4656 |
const unordered_multiset<Key, Hash, Pred, Alloc>& b);
|
| 4657 |
+
|
| 4658 |
+
namespace pmr {
|
| 4659 |
+
template <class Key,
|
| 4660 |
+
class Hash = hash<Key>,
|
| 4661 |
+
class Pred = equal_to<Key>>
|
| 4662 |
+
using unordered_set = std::unordered_set<Key, Hash, Pred,
|
| 4663 |
+
polymorphic_allocator<Key>>;
|
| 4664 |
+
|
| 4665 |
+
template <class Key,
|
| 4666 |
+
class Hash = hash<Key>,
|
| 4667 |
+
class Pred = equal_to<Key>>
|
| 4668 |
+
using unordered_multiset = std::unordered_multiset<Key, Hash, Pred,
|
| 4669 |
+
polymorphic_allocator<Key>>;
|
| 4670 |
+
}
|
| 4671 |
+
}
|
| 4672 |
```
|
| 4673 |
|
| 4674 |
### Class template `unordered_map` <a id="unord.map">[[unord.map]]</a>
|
| 4675 |
|
| 4676 |
#### Class template `unordered_map` overview <a id="unord.map.overview">[[unord.map.overview]]</a>
|
|
|
|
| 4685 |
(Table [[tab:containers.allocatoraware]]). It provides the operations
|
| 4686 |
described in the preceding requirements table for unique keys; that is,
|
| 4687 |
an `unordered_map` supports the `a_uniq` operations in that table, not
|
| 4688 |
the `a_eq` operations. For an `unordered_map<Key, T>` the `key type` is
|
| 4689 |
`Key`, the mapped type is `T`, and the value type is
|
| 4690 |
+
`pair<const Key, T>`.
|
| 4691 |
|
| 4692 |
This section only describes operations on `unordered_map` that are not
|
| 4693 |
described in one of the requirement tables, or for which there is
|
| 4694 |
additional semantic information.
|
| 4695 |
|
| 4696 |
``` cpp
|
| 4697 |
namespace std {
|
| 4698 |
template <class Key,
|
| 4699 |
class T,
|
| 4700 |
class Hash = hash<Key>,
|
| 4701 |
+
class Pred = equal_to<Key>,
|
| 4702 |
+
class Allocator = allocator<pair<const Key, T>>>
|
| 4703 |
+
class unordered_map {
|
|
|
|
| 4704 |
public:
|
| 4705 |
+
// types:
|
| 4706 |
+
using key_type = Key;
|
| 4707 |
+
using mapped_type = T;
|
| 4708 |
+
using value_type = pair<const Key, T>;
|
| 4709 |
+
using hasher = Hash;
|
| 4710 |
+
using key_equal = Pred;
|
| 4711 |
+
using allocator_type = Allocator;
|
| 4712 |
+
using pointer = typename allocator_traits<Allocator>::pointer;
|
| 4713 |
+
using const_pointer = typename allocator_traits<Allocator>::const_pointer;
|
| 4714 |
+
using reference = value_type&;
|
| 4715 |
+
using const_reference = const value_type&;
|
| 4716 |
+
using size_type = implementation-defined; // see [container.requirements]
|
| 4717 |
+
using difference_type = implementation-defined; // see [container.requirements]
|
| 4718 |
|
| 4719 |
+
using iterator = implementation-defined // type of unordered_map::iterator; // see [container.requirements]
|
| 4720 |
+
using const_iterator = implementation-defined // type of unordered_map::const_iterator; // see [container.requirements]
|
| 4721 |
+
using local_iterator = implementation-defined // type of unordered_map::local_iterator; // see [container.requirements]
|
| 4722 |
+
using const_local_iterator = implementation-defined // type of unordered_map::const_local_iterator; // see [container.requirements]
|
| 4723 |
+
using node_type = unspecified;
|
| 4724 |
+
using insert_return_type = INSERT_RETURN_TYPE<iterator, node_type>;
|
| 4725 |
|
| 4726 |
+
// [unord.map.cnstr], construct/copy/destroy
|
| 4727 |
unordered_map();
|
| 4728 |
explicit unordered_map(size_type n,
|
| 4729 |
const hasher& hf = hasher(),
|
| 4730 |
const key_equal& eql = key_equal(),
|
| 4731 |
const allocator_type& a = allocator_type());
|
|
|
|
| 4738 |
unordered_map(const unordered_map&);
|
| 4739 |
unordered_map(unordered_map&&);
|
| 4740 |
explicit unordered_map(const Allocator&);
|
| 4741 |
unordered_map(const unordered_map&, const Allocator&);
|
| 4742 |
unordered_map(unordered_map&&, const Allocator&);
|
| 4743 |
+
unordered_map(initializer_list<value_type> il,
|
| 4744 |
+
size_type n = see below,
|
| 4745 |
const hasher& hf = hasher(),
|
| 4746 |
const key_equal& eql = key_equal(),
|
| 4747 |
const allocator_type& a = allocator_type());
|
| 4748 |
unordered_map(size_type n, const allocator_type& a)
|
| 4749 |
: unordered_map(n, hasher(), key_equal(), a) { }
|
|
|
|
| 4761 |
unordered_map(initializer_list<value_type> il, size_type n, const hasher& hf,
|
| 4762 |
const allocator_type& a)
|
| 4763 |
: unordered_map(il, n, hf, key_equal(), a) { }
|
| 4764 |
~unordered_map();
|
| 4765 |
unordered_map& operator=(const unordered_map&);
|
| 4766 |
+
unordered_map& operator=(unordered_map&&)
|
| 4767 |
+
noexcept(allocator_traits<Allocator>::is_always_equal::value &&
|
| 4768 |
+
is_nothrow_move_assignable_v<Hash> &&
|
| 4769 |
+
is_nothrow_move_assignable_v<Pred>);
|
| 4770 |
unordered_map& operator=(initializer_list<value_type>);
|
| 4771 |
allocator_type get_allocator() const noexcept;
|
| 4772 |
|
| 4773 |
+
// iterators:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 4774 |
iterator begin() noexcept;
|
| 4775 |
const_iterator begin() const noexcept;
|
| 4776 |
iterator end() noexcept;
|
| 4777 |
const_iterator end() const noexcept;
|
| 4778 |
const_iterator cbegin() const noexcept;
|
| 4779 |
const_iterator cend() const noexcept;
|
| 4780 |
|
| 4781 |
+
// capacity:
|
| 4782 |
+
bool empty() const noexcept;
|
| 4783 |
+
size_type size() const noexcept;
|
| 4784 |
+
size_type max_size() const noexcept;
|
| 4785 |
+
|
| 4786 |
+
// [unord.map.modifiers], modifiers
|
| 4787 |
template <class... Args> pair<iterator, bool> emplace(Args&&... args);
|
| 4788 |
template <class... Args> iterator emplace_hint(const_iterator position, Args&&... args);
|
| 4789 |
pair<iterator, bool> insert(const value_type& obj);
|
| 4790 |
+
pair<iterator, bool> insert(value_type&& obj);
|
| 4791 |
template <class P> pair<iterator, bool> insert(P&& obj);
|
| 4792 |
iterator insert(const_iterator hint, const value_type& obj);
|
| 4793 |
+
iterator insert(const_iterator hint, value_type&& obj);
|
| 4794 |
template <class P> iterator insert(const_iterator hint, P&& obj);
|
| 4795 |
template <class InputIterator> void insert(InputIterator first, InputIterator last);
|
| 4796 |
void insert(initializer_list<value_type>);
|
| 4797 |
|
| 4798 |
+
node_type extract(const_iterator position);
|
| 4799 |
+
node_type extract(const key_type& x);
|
| 4800 |
+
insert_return_type insert(node_type&& nh);
|
| 4801 |
+
iterator insert(const_iterator hint, node_type&& nh);
|
| 4802 |
+
|
| 4803 |
+
template <class... Args>
|
| 4804 |
+
pair<iterator, bool> try_emplace(const key_type& k, Args&&... args);
|
| 4805 |
+
template <class... Args>
|
| 4806 |
+
pair<iterator, bool> try_emplace(key_type&& k, Args&&... args);
|
| 4807 |
+
template <class... Args>
|
| 4808 |
+
iterator try_emplace(const_iterator hint, const key_type& k, Args&&... args);
|
| 4809 |
+
template <class... Args>
|
| 4810 |
+
iterator try_emplace(const_iterator hint, key_type&& k, Args&&... args);
|
| 4811 |
+
template <class M>
|
| 4812 |
+
pair<iterator, bool> insert_or_assign(const key_type& k, M&& obj);
|
| 4813 |
+
template <class M>
|
| 4814 |
+
pair<iterator, bool> insert_or_assign(key_type&& k, M&& obj);
|
| 4815 |
+
template <class M>
|
| 4816 |
+
iterator insert_or_assign(const_iterator hint, const key_type& k, M&& obj);
|
| 4817 |
+
template <class M>
|
| 4818 |
+
iterator insert_or_assign(const_iterator hint, key_type&& k, M&& obj);
|
| 4819 |
+
|
| 4820 |
+
iterator erase(iterator position);
|
| 4821 |
iterator erase(const_iterator position);
|
| 4822 |
size_type erase(const key_type& k);
|
| 4823 |
iterator erase(const_iterator first, const_iterator last);
|
| 4824 |
+
void swap(unordered_map&)
|
| 4825 |
+
noexcept(allocator_traits<Allocator>::is_always_equal::value &&
|
| 4826 |
+
is_nothrow_swappable_v<Hash> &&
|
| 4827 |
+
is_nothrow_swappable_v<Pred>);
|
| 4828 |
void clear() noexcept;
|
| 4829 |
|
| 4830 |
+
template<class H2, class P2>
|
| 4831 |
+
void merge(unordered_map<Key, T, H2, P2, Allocator>& source);
|
| 4832 |
+
template<class H2, class P2>
|
| 4833 |
+
void merge(unordered_map<Key, T, H2, P2, Allocator>&& source);
|
| 4834 |
+
template<class H2, class P2>
|
| 4835 |
+
void merge(unordered_multimap<Key, T, H2, P2, Allocator>& source);
|
| 4836 |
+
template<class H2, class P2>
|
| 4837 |
+
void merge(unordered_multimap<Key, T, H2, P2, Allocator>&& source);
|
| 4838 |
|
| 4839 |
+
// observers:
|
| 4840 |
hasher hash_function() const;
|
| 4841 |
key_equal key_eq() const;
|
| 4842 |
|
| 4843 |
+
// map operations:
|
| 4844 |
iterator find(const key_type& k);
|
| 4845 |
const_iterator find(const key_type& k) const;
|
| 4846 |
size_type count(const key_type& k) const;
|
| 4847 |
+
pair<iterator, iterator> equal_range(const key_type& k);
|
| 4848 |
+
pair<const_iterator, const_iterator> equal_range(const key_type& k) const;
|
| 4849 |
|
| 4850 |
+
// [unord.map.elem], element access
|
| 4851 |
mapped_type& operator[](const key_type& k);
|
| 4852 |
mapped_type& operator[](key_type&& k);
|
| 4853 |
mapped_type& at(const key_type& k);
|
| 4854 |
const mapped_type& at(const key_type& k) const;
|
| 4855 |
|
| 4856 |
+
// bucket interface:
|
| 4857 |
size_type bucket_count() const noexcept;
|
| 4858 |
size_type max_bucket_count() const noexcept;
|
| 4859 |
size_type bucket_size(size_type n) const;
|
| 4860 |
size_type bucket(const key_type& k) const;
|
| 4861 |
local_iterator begin(size_type n);
|
|
|
|
| 4863 |
local_iterator end(size_type n);
|
| 4864 |
const_local_iterator end(size_type n) const;
|
| 4865 |
const_local_iterator cbegin(size_type n) const;
|
| 4866 |
const_local_iterator cend(size_type n) const;
|
| 4867 |
|
| 4868 |
+
// hash policy:
|
| 4869 |
float load_factor() const noexcept;
|
| 4870 |
float max_load_factor() const noexcept;
|
| 4871 |
void max_load_factor(float z);
|
| 4872 |
void rehash(size_type n);
|
| 4873 |
void reserve(size_type n);
|
| 4874 |
};
|
| 4875 |
|
| 4876 |
+
template<class InputIterator,
|
| 4877 |
+
class Hash = hash<iter_key_t<InputIterator>>,
|
| 4878 |
+
class Pred = equal_to<iter_key_t<InputIterator>>,
|
| 4879 |
+
class Allocator = allocator<iter_to_alloc_t<InputIterator>>>
|
| 4880 |
+
unordered_map(InputIterator, InputIterator, typename see below::size_type = see below,
|
| 4881 |
+
Hash = Hash(), Pred = Pred(), Allocator = Allocator())
|
| 4882 |
+
-> unordered_map<iter_key_t<InputIterator>, iter_value_t<InputIterator>, Hash, Pred,
|
| 4883 |
+
Allocator>;
|
| 4884 |
+
|
| 4885 |
+
template<class Key, class T, class Hash = hash<Key>,
|
| 4886 |
+
class Pred = equal_to<Key>, class Allocator = allocator<pair<const Key, T>>>
|
| 4887 |
+
unordered_map(initializer_list<pair<const Key, T>>,
|
| 4888 |
+
typename see below::size_type = see below, Hash = Hash(),
|
| 4889 |
+
Pred = Pred(), Allocator = Allocator())
|
| 4890 |
+
-> unordered_map<Key, T, Hash, Pred, Allocator>;
|
| 4891 |
+
|
| 4892 |
+
template<class InputIterator, class Allocator>
|
| 4893 |
+
unordered_map(InputIterator, InputIterator, typename see below::size_type, Allocator)
|
| 4894 |
+
-> unordered_map<iter_key_t<InputIterator>, iter_val_t<InputIterator>,
|
| 4895 |
+
hash<iter_key_t<InputIterator>>, equal_to<iter_key_t<InputIterator>>,
|
| 4896 |
+
Allocator>;
|
| 4897 |
+
|
| 4898 |
+
template<class InputIterator, class Allocator>
|
| 4899 |
+
unordered_map(InputIterator, InputIterator, Allocator)
|
| 4900 |
+
-> unordered_map<iter_key_t<InputIterator>, iter_val_t<InputIterator>,
|
| 4901 |
+
hash<iter_key_t<InputIterator>>, equal_to<iter_key_t<InputIterator>>,
|
| 4902 |
+
Allocator>;
|
| 4903 |
+
|
| 4904 |
+
template<class InputIterator, class Hash, class Allocator>
|
| 4905 |
+
unordered_map(InputIterator, InputIterator, typename see below::size_type, Hash, Allocator)
|
| 4906 |
+
-> unordered_map<iter_key_t<InputIterator>, iter_val_t<InputIterator>, Hash,
|
| 4907 |
+
equal_to<iter_key_t<InputIterator>>, Allocator>;
|
| 4908 |
+
|
| 4909 |
+
template<class Key, class T, typename Allocator>
|
| 4910 |
+
unordered_map(initializer_list<pair<const Key, T>>, typename see below::size_type,
|
| 4911 |
+
Allocator)
|
| 4912 |
+
-> unordered_map<Key, T, hash<Key>, equal_to<Key>, Allocator>;
|
| 4913 |
+
|
| 4914 |
+
template<class Key, class T, typename Allocator>
|
| 4915 |
+
unordered_map(initializer_list<pair<const Key, T>>, Allocator)
|
| 4916 |
+
-> unordered_map<Key, T, hash<Key>, equal_to<Key>, Allocator>;
|
| 4917 |
+
|
| 4918 |
+
template<class Key, class T, class Hash, class Allocator>
|
| 4919 |
+
unordered_map(initializer_list<pair<const Key, T>>, typename see below::size_type, Hash,
|
| 4920 |
+
Allocator)
|
| 4921 |
+
-> unordered_map<Key, T, Hash, equal_to<Key>, Allocator>;
|
| 4922 |
|
| 4923 |
template <class Key, class T, class Hash, class Pred, class Alloc>
|
| 4924 |
bool operator==(const unordered_map<Key, T, Hash, Pred, Alloc>& a,
|
| 4925 |
const unordered_map<Key, T, Hash, Pred, Alloc>& b);
|
| 4926 |
template <class Key, class T, class Hash, class Pred, class Alloc>
|
| 4927 |
bool operator!=(const unordered_map<Key, T, Hash, Pred, Alloc>& a,
|
| 4928 |
const unordered_map<Key, T, Hash, Pred, Alloc>& b);
|
| 4929 |
+
|
| 4930 |
+
// [unord.map.swap], swap
|
| 4931 |
+
template <class Key, class T, class Hash, class Pred, class Alloc>
|
| 4932 |
+
void swap(unordered_map<Key, T, Hash, Pred, Alloc>& x,
|
| 4933 |
+
unordered_map<Key, T, Hash, Pred, Alloc>& y)
|
| 4934 |
+
noexcept(noexcept(x.swap(y)));
|
| 4935 |
}
|
| 4936 |
```
|
| 4937 |
|
| 4938 |
+
A `size_type` parameter type in an `unordered_map` deduction guide
|
| 4939 |
+
refers to the `size_type` member type of the type deduced by the
|
| 4940 |
+
deduction guide.
|
| 4941 |
+
|
| 4942 |
#### `unordered_map` constructors <a id="unord.map.cnstr">[[unord.map.cnstr]]</a>
|
| 4943 |
|
| 4944 |
``` cpp
|
| 4945 |
unordered_map() : unordered_map(size_type(see below)) { }
|
| 4946 |
explicit unordered_map(size_type n,
|
|
|
|
| 4948 |
const key_equal& eql = key_equal(),
|
| 4949 |
const allocator_type& a = allocator_type());
|
| 4950 |
```
|
| 4951 |
|
| 4952 |
*Effects:* Constructs an empty `unordered_map` using the specified hash
|
| 4953 |
+
function, key equality predicate, and allocator, and using at least `n`
|
| 4954 |
buckets. For the default constructor, the number of buckets is
|
| 4955 |
+
*implementation-defined*. `max_load_factor()` returns `1.0`.
|
| 4956 |
|
| 4957 |
*Complexity:* Constant.
|
| 4958 |
|
| 4959 |
``` cpp
|
| 4960 |
template <class InputIterator>
|
| 4961 |
unordered_map(InputIterator f, InputIterator l,
|
| 4962 |
size_type n = see below,
|
| 4963 |
const hasher& hf = hasher(),
|
| 4964 |
const key_equal& eql = key_equal(),
|
| 4965 |
const allocator_type& a = allocator_type());
|
| 4966 |
+
unordered_map(initializer_list<value_type> il,
|
| 4967 |
+
size_type n = see below,
|
| 4968 |
+
const hasher& hf = hasher(),
|
| 4969 |
+
const key_equal& eql = key_equal(),
|
| 4970 |
+
const allocator_type& a = allocator_type());
|
| 4971 |
```
|
| 4972 |
|
| 4973 |
*Effects:* Constructs an empty `unordered_map` using the specified hash
|
| 4974 |
+
function, key equality predicate, and allocator, and using at least `n`
|
| 4975 |
+
buckets. If `n` is not provided, the number of buckets is
|
| 4976 |
+
*implementation-defined*. Then inserts elements from the range \[`f`,
|
| 4977 |
+
`l`) for the first form, or from the range \[`il.begin()`, `il.end()`)
|
| 4978 |
+
for the second form. `max_load_factor()` returns `1.0`.
|
| 4979 |
|
| 4980 |
*Complexity:* Average case linear, worst case quadratic.
|
| 4981 |
|
| 4982 |
#### `unordered_map` element access <a id="unord.map.elem">[[unord.map.elem]]</a>
|
| 4983 |
|
| 4984 |
``` cpp
|
| 4985 |
mapped_type& operator[](const key_type& k);
|
| 4986 |
+
```
|
| 4987 |
+
|
| 4988 |
+
*Effects:* Equivalent to: `return try_emplace(k).first->second;`
|
| 4989 |
+
|
| 4990 |
+
``` cpp
|
| 4991 |
mapped_type& operator[](key_type&& k);
|
| 4992 |
```
|
| 4993 |
|
| 4994 |
+
*Effects:* Equivalent to: `return try_emplace(move(k)).first->second;`
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 4995 |
|
| 4996 |
``` cpp
|
| 4997 |
mapped_type& at(const key_type& k);
|
| 4998 |
const mapped_type& at(const key_type& k) const;
|
| 4999 |
```
|
|
|
|
| 5009 |
``` cpp
|
| 5010 |
template <class P>
|
| 5011 |
pair<iterator, bool> insert(P&& obj);
|
| 5012 |
```
|
| 5013 |
|
| 5014 |
+
*Effects:* Equivalent to: `return emplace(std::forward<P>(obj));`
|
| 5015 |
|
| 5016 |
*Remarks:* This signature shall not participate in overload resolution
|
| 5017 |
+
unless `is_constructible_v<value_type, P&&>` is `true`.
|
| 5018 |
|
| 5019 |
``` cpp
|
| 5020 |
template <class P>
|
| 5021 |
iterator insert(const_iterator hint, P&& obj);
|
| 5022 |
```
|
| 5023 |
|
| 5024 |
+
*Effects:* Equivalent to:
|
| 5025 |
+
`return emplace_hint(hint, std::forward<P>(obj));`
|
| 5026 |
|
| 5027 |
*Remarks:* This signature shall not participate in overload resolution
|
| 5028 |
+
unless `is_constructible_v<value_type, P&&>` is `true`.
|
| 5029 |
+
|
| 5030 |
+
``` cpp
|
| 5031 |
+
template <class... Args>
|
| 5032 |
+
pair<iterator, bool> try_emplace(const key_type& k, Args&&... args);
|
| 5033 |
+
template <class... Args>
|
| 5034 |
+
iterator try_emplace(const_iterator hint, const key_type& k, Args&&... args);
|
| 5035 |
+
```
|
| 5036 |
+
|
| 5037 |
+
*Requires:* `value_type` shall be `EmplaceConstructible` into
|
| 5038 |
+
`unordered_map` from `piecewise_construct`, `forward_as_tuple(k)`,
|
| 5039 |
+
`forward_as_tuple(std::forward<Args>(args)...)`.
|
| 5040 |
+
|
| 5041 |
+
*Effects:* If the map already contains an element whose key is
|
| 5042 |
+
equivalent to `k`, there is no effect. Otherwise inserts an object of
|
| 5043 |
+
type `value_type` constructed with `piecewise_construct`,
|
| 5044 |
+
`forward_as_tuple(k)`, `forward_as_tuple(std::forward<Args>(args)...)`.
|
| 5045 |
+
|
| 5046 |
+
*Returns:* In the first overload, the `bool` component of the returned
|
| 5047 |
+
pair is `true` if and only if the insertion took place. The returned
|
| 5048 |
+
iterator points to the map element whose key is equivalent to `k`.
|
| 5049 |
+
|
| 5050 |
+
*Complexity:* The same as `emplace` and `emplace_hint`, respectively.
|
| 5051 |
+
|
| 5052 |
+
``` cpp
|
| 5053 |
+
template <class... Args>
|
| 5054 |
+
pair<iterator, bool> try_emplace(key_type&& k, Args&&... args);
|
| 5055 |
+
template <class... Args>
|
| 5056 |
+
iterator try_emplace(const_iterator hint, key_type&& k, Args&&... args);
|
| 5057 |
+
```
|
| 5058 |
+
|
| 5059 |
+
*Requires:* `value_type` shall be `EmplaceConstructible` into
|
| 5060 |
+
`unordered_map` from `piecewise_construct`,
|
| 5061 |
+
`forward_as_tuple(std::move(k))`,
|
| 5062 |
+
`forward_as_tuple(std::forward<Args>(args)...)`.
|
| 5063 |
+
|
| 5064 |
+
*Effects:* If the map already contains an element whose key is
|
| 5065 |
+
equivalent to `k`, there is no effect. Otherwise inserts an object of
|
| 5066 |
+
type `value_type` constructed with `piecewise_construct`,
|
| 5067 |
+
`forward_as_tuple(std::move(k))`,
|
| 5068 |
+
`forward_as_tuple(std::forward<Args>(args)...)`.
|
| 5069 |
+
|
| 5070 |
+
*Returns:* In the first overload, the `bool` component of the returned
|
| 5071 |
+
pair is `true` if and only if the insertion took place. The returned
|
| 5072 |
+
iterator points to the map element whose key is equivalent to `k`.
|
| 5073 |
+
|
| 5074 |
+
*Complexity:* The same as `emplace` and `emplace_hint`, respectively.
|
| 5075 |
+
|
| 5076 |
+
``` cpp
|
| 5077 |
+
template <class M>
|
| 5078 |
+
pair<iterator, bool> insert_or_assign(const key_type& k, M&& obj);
|
| 5079 |
+
template <class M>
|
| 5080 |
+
iterator insert_or_assign(const_iterator hint, const key_type& k, M&& obj);
|
| 5081 |
+
```
|
| 5082 |
+
|
| 5083 |
+
*Requires:* `is_assignable_v<mapped_type&, M&&>` shall be `true`.
|
| 5084 |
+
`value_type` shall be `EmplaceConstructible` into `unordered_map` from
|
| 5085 |
+
`k`, `std::forward<M>(obj)`.
|
| 5086 |
+
|
| 5087 |
+
*Effects:* If the map already contains an element `e` whose key is
|
| 5088 |
+
equivalent to `k`, assigns `std::forward<M>(obj)` to `e.second`.
|
| 5089 |
+
Otherwise inserts an object of type `value_type` constructed with `k`,
|
| 5090 |
+
`std::forward<M>(obj)`.
|
| 5091 |
+
|
| 5092 |
+
*Returns:* In the first overload, the `bool` component of the returned
|
| 5093 |
+
pair is `true` if and only if the insertion took place. The returned
|
| 5094 |
+
iterator points to the map element whose key is equivalent to `k`.
|
| 5095 |
+
|
| 5096 |
+
*Complexity:* The same as `emplace` and `emplace_hint`, respectively.
|
| 5097 |
+
|
| 5098 |
+
``` cpp
|
| 5099 |
+
template <class M>
|
| 5100 |
+
pair<iterator, bool> insert_or_assign(key_type&& k, M&& obj);
|
| 5101 |
+
template <class M>
|
| 5102 |
+
iterator insert_or_assign(const_iterator hint, key_type&& k, M&& obj);
|
| 5103 |
+
```
|
| 5104 |
+
|
| 5105 |
+
*Requires:* `is_assignable_v<mapped_type&, M&&>` shall be `true`.
|
| 5106 |
+
`value_type` shall be `EmplaceConstructible` into `unordered_map` from
|
| 5107 |
+
`std::move(k)`, `std::forward<M>(obj)`.
|
| 5108 |
+
|
| 5109 |
+
*Effects:* If the map already contains an element `e` whose key is
|
| 5110 |
+
equivalent to `k`, assigns `std::forward<M>(obj)` to `e.second`.
|
| 5111 |
+
Otherwise inserts an object of type `value_type` constructed with
|
| 5112 |
+
`std::move(k)`, `std::forward<M>(obj)`.
|
| 5113 |
+
|
| 5114 |
+
*Returns:* In the first overload, the `bool` component of the returned
|
| 5115 |
+
pair is `true` if and only if the insertion took place. The returned
|
| 5116 |
+
iterator points to the map element whose key is equivalent to `k`.
|
| 5117 |
+
|
| 5118 |
+
*Complexity:* The same as `emplace` and `emplace_hint`, respectively.
|
| 5119 |
|
| 5120 |
#### `unordered_map` swap <a id="unord.map.swap">[[unord.map.swap]]</a>
|
| 5121 |
|
| 5122 |
``` cpp
|
| 5123 |
template <class Key, class T, class Hash, class Pred, class Alloc>
|
| 5124 |
void swap(unordered_map<Key, T, Hash, Pred, Alloc>& x,
|
| 5125 |
+
unordered_map<Key, T, Hash, Pred, Alloc>& y)
|
| 5126 |
+
noexcept(noexcept(x.swap(y)));
|
| 5127 |
```
|
| 5128 |
|
| 5129 |
+
*Effects:* As if by `x.swap(y)`.
|
| 5130 |
|
| 5131 |
### Class template `unordered_multimap` <a id="unord.multimap">[[unord.multimap]]</a>
|
| 5132 |
|
| 5133 |
#### Class template `unordered_multimap` overview <a id="unord.multimap.overview">[[unord.multimap.overview]]</a>
|
| 5134 |
|
|
|
|
| 5143 |
allocator-aware container (Table [[tab:containers.allocatoraware]]). It
|
| 5144 |
provides the operations described in the preceding requirements table
|
| 5145 |
for equivalent keys; that is, an `unordered_multimap` supports the
|
| 5146 |
`a_eq` operations in that table, not the `a_uniq` operations. For an
|
| 5147 |
`unordered_multimap<Key, T>` the `key type` is `Key`, the mapped type is
|
| 5148 |
+
`T`, and the value type is `pair<const Key, T>`.
|
| 5149 |
|
| 5150 |
This section only describes operations on `unordered_multimap` that are
|
| 5151 |
not described in one of the requirement tables, or for which there is
|
| 5152 |
additional semantic information.
|
| 5153 |
|
| 5154 |
``` cpp
|
| 5155 |
namespace std {
|
| 5156 |
template <class Key,
|
| 5157 |
class T,
|
| 5158 |
class Hash = hash<Key>,
|
| 5159 |
+
class Pred = equal_to<Key>,
|
| 5160 |
+
class Allocator = allocator<pair<const Key, T>>>
|
| 5161 |
+
class unordered_multimap {
|
|
|
|
| 5162 |
public:
|
| 5163 |
+
// types:
|
| 5164 |
+
using key_type = Key;
|
| 5165 |
+
using mapped_type = T;
|
| 5166 |
+
using value_type = pair<const Key, T>;
|
| 5167 |
+
using hasher = Hash;
|
| 5168 |
+
using key_equal = Pred;
|
| 5169 |
+
using allocator_type = Allocator;
|
| 5170 |
+
using pointer = typename allocator_traits<Allocator>::pointer;
|
| 5171 |
+
using const_pointer = typename allocator_traits<Allocator>::const_pointer;
|
| 5172 |
+
using reference = value_type&;
|
| 5173 |
+
using const_reference = const value_type&;
|
| 5174 |
+
using size_type = implementation-defined; // see [container.requirements]
|
| 5175 |
+
using difference_type = implementation-defined; // see [container.requirements]
|
| 5176 |
|
| 5177 |
+
using iterator = implementation-defined // type of unordered_multimap::iterator; // see [container.requirements]
|
| 5178 |
+
using const_iterator = implementation-defined // type of unordered_multimap::const_iterator; // see [container.requirements]
|
| 5179 |
+
using local_iterator = implementation-defined // type of unordered_multimap::local_iterator; // see [container.requirements]
|
| 5180 |
+
using const_local_iterator = implementation-defined // type of unordered_multimap::const_local_iterator; // see [container.requirements]
|
| 5181 |
+
using node_type = unspecified;
|
| 5182 |
|
| 5183 |
+
// [unord.multimap.cnstr], construct/copy/destroy
|
| 5184 |
unordered_multimap();
|
| 5185 |
explicit unordered_multimap(size_type n,
|
| 5186 |
const hasher& hf = hasher(),
|
| 5187 |
const key_equal& eql = key_equal(),
|
| 5188 |
const allocator_type& a = allocator_type());
|
|
|
|
| 5195 |
unordered_multimap(const unordered_multimap&);
|
| 5196 |
unordered_multimap(unordered_multimap&&);
|
| 5197 |
explicit unordered_multimap(const Allocator&);
|
| 5198 |
unordered_multimap(const unordered_multimap&, const Allocator&);
|
| 5199 |
unordered_multimap(unordered_multimap&&, const Allocator&);
|
| 5200 |
+
unordered_multimap(initializer_list<value_type> il,
|
| 5201 |
+
size_type n = see below,
|
| 5202 |
const hasher& hf = hasher(),
|
| 5203 |
const key_equal& eql = key_equal(),
|
| 5204 |
const allocator_type& a = allocator_type());
|
| 5205 |
unordered_multimap(size_type n, const allocator_type& a)
|
| 5206 |
: unordered_multimap(n, hasher(), key_equal(), a) { }
|
|
|
|
| 5218 |
unordered_multimap(initializer_list<value_type> il, size_type n, const hasher& hf,
|
| 5219 |
const allocator_type& a)
|
| 5220 |
: unordered_multimap(il, n, hf, key_equal(), a) { }
|
| 5221 |
~unordered_multimap();
|
| 5222 |
unordered_multimap& operator=(const unordered_multimap&);
|
| 5223 |
+
unordered_multimap& operator=(unordered_multimap&&)
|
| 5224 |
+
noexcept(allocator_traits<Allocator>::is_always_equal::value &&
|
| 5225 |
+
is_nothrow_move_assignable_v<Hash> &&
|
| 5226 |
+
is_nothrow_move_assignable_v<Pred>);
|
| 5227 |
unordered_multimap& operator=(initializer_list<value_type>);
|
| 5228 |
allocator_type get_allocator() const noexcept;
|
| 5229 |
|
| 5230 |
+
// iterators:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 5231 |
iterator begin() noexcept;
|
| 5232 |
const_iterator begin() const noexcept;
|
| 5233 |
iterator end() noexcept;
|
| 5234 |
const_iterator end() const noexcept;
|
| 5235 |
const_iterator cbegin() const noexcept;
|
| 5236 |
const_iterator cend() const noexcept;
|
| 5237 |
|
| 5238 |
+
// capacity:
|
| 5239 |
+
bool empty() const noexcept;
|
| 5240 |
+
size_type size() const noexcept;
|
| 5241 |
+
size_type max_size() const noexcept;
|
| 5242 |
+
|
| 5243 |
+
// [unord.multimap.modifiers], modifiers
|
| 5244 |
template <class... Args> iterator emplace(Args&&... args);
|
| 5245 |
template <class... Args> iterator emplace_hint(const_iterator position, Args&&... args);
|
| 5246 |
iterator insert(const value_type& obj);
|
| 5247 |
+
iterator insert(value_type&& obj);
|
| 5248 |
template <class P> iterator insert(P&& obj);
|
| 5249 |
iterator insert(const_iterator hint, const value_type& obj);
|
| 5250 |
+
iterator insert(const_iterator hint, value_type&& obj);
|
| 5251 |
template <class P> iterator insert(const_iterator hint, P&& obj);
|
| 5252 |
template <class InputIterator> void insert(InputIterator first, InputIterator last);
|
| 5253 |
void insert(initializer_list<value_type>);
|
| 5254 |
|
| 5255 |
+
node_type extract(const_iterator position);
|
| 5256 |
+
node_type extract(const key_type& x);
|
| 5257 |
+
iterator insert(node_type&& nh);
|
| 5258 |
+
iterator insert(const_iterator hint, node_type&& nh);
|
| 5259 |
+
|
| 5260 |
+
iterator erase(iterator position);
|
| 5261 |
iterator erase(const_iterator position);
|
| 5262 |
size_type erase(const key_type& k);
|
| 5263 |
iterator erase(const_iterator first, const_iterator last);
|
| 5264 |
+
void swap(unordered_multimap&)
|
| 5265 |
+
noexcept(allocator_traits<Allocator>::is_always_equal::value &&
|
| 5266 |
+
is_nothrow_swappable_v<Hash> &&
|
| 5267 |
+
is_nothrow_swappable_v<Pred>);
|
| 5268 |
void clear() noexcept;
|
| 5269 |
|
| 5270 |
+
template<class H2, class P2>
|
| 5271 |
+
void merge(unordered_multimap<Key, T, H2, P2, Allocator>& source);
|
| 5272 |
+
template<class H2, class P2>
|
| 5273 |
+
void merge(unordered_multimap<Key, T, H2, P2, Allocator>&& source);
|
| 5274 |
+
template<class H2, class P2>
|
| 5275 |
+
void merge(unordered_map<Key, T, H2, P2, Allocator>& source);
|
| 5276 |
+
template<class H2, class P2>
|
| 5277 |
+
void merge(unordered_map<Key, T, H2, P2, Allocator>&& source);
|
| 5278 |
|
| 5279 |
+
// observers:
|
| 5280 |
hasher hash_function() const;
|
| 5281 |
key_equal key_eq() const;
|
| 5282 |
|
| 5283 |
+
// map operations:
|
| 5284 |
iterator find(const key_type& k);
|
| 5285 |
const_iterator find(const key_type& k) const;
|
| 5286 |
size_type count(const key_type& k) const;
|
| 5287 |
+
pair<iterator, iterator> equal_range(const key_type& k);
|
| 5288 |
+
pair<const_iterator, const_iterator> equal_range(const key_type& k) const;
|
| 5289 |
|
| 5290 |
+
// bucket interface:
|
| 5291 |
size_type bucket_count() const noexcept;
|
| 5292 |
size_type max_bucket_count() const noexcept;
|
| 5293 |
size_type bucket_size(size_type n) const;
|
| 5294 |
size_type bucket(const key_type& k) const;
|
| 5295 |
local_iterator begin(size_type n);
|
|
|
|
| 5305 |
void max_load_factor(float z);
|
| 5306 |
void rehash(size_type n);
|
| 5307 |
void reserve(size_type n);
|
| 5308 |
};
|
| 5309 |
|
| 5310 |
+
template<class InputIterator,
|
| 5311 |
+
class Hash = hash<iter_key_t<InputIterator>>,
|
| 5312 |
+
class Pred = equal_to<iter_key_t<InputIterator>>,
|
| 5313 |
+
class Allocator = allocator<iter_to_alloc_t<InputIterator>>>
|
| 5314 |
+
unordered_multimap(InputIterator, InputIterator,
|
| 5315 |
+
typename see below::size_type = see below,
|
| 5316 |
+
Hash = Hash(), Pred = Pred(), Allocator = Allocator())
|
| 5317 |
+
-> unordered_multimap<iter_key_t<InputIterator>, iter_value_t<InputIterator>, Hash, Pred,
|
| 5318 |
+
Allocator>;
|
| 5319 |
+
|
| 5320 |
+
template<class Key, class T, class Hash = hash<Key>,
|
| 5321 |
+
class Pred = equal_to<Key>, class Allocator = allocator<pair<const Key, T>>>
|
| 5322 |
+
unordered_multimap(initializer_list<pair<const Key, T>>,
|
| 5323 |
+
typename see below::size_type = see below,
|
| 5324 |
+
Hash = Hash(), Pred = Pred(), Allocator = Allocator())
|
| 5325 |
+
-> unordered_multimap<Key, T, Hash, Pred, Allocator>;
|
| 5326 |
+
|
| 5327 |
+
template<class InputIterator, class Allocator>
|
| 5328 |
+
unordered_multimap(InputIterator, InputIterator, typename see below::size_type, Allocator)
|
| 5329 |
+
-> unordered_multimap<iter_key_t<InputIterator>, iter_val_t<InputIterator>,
|
| 5330 |
+
hash<iter_key_t<InputIterator>>,
|
| 5331 |
+
equal_to<iter_key_t<InputIterator>>, Allocator>;
|
| 5332 |
+
|
| 5333 |
+
template<class InputIterator, class Allocator>
|
| 5334 |
+
unordered_multimap(InputIterator, InputIterator, Allocator)
|
| 5335 |
+
-> unordered_multimap<iter_key_t<InputIterator>, iter_val_t<InputIterator>,
|
| 5336 |
+
hash<iter_key_t<InputIterator>>,
|
| 5337 |
+
equal_to<iter_key_t<InputIterator>>, Allocator>;
|
| 5338 |
+
|
| 5339 |
+
template<class InputIterator, class Hash, class Allocator>
|
| 5340 |
+
unordered_multimap(InputIterator, InputIterator, typename see below::size_type, Hash,
|
| 5341 |
+
Allocator)
|
| 5342 |
+
-> unordered_multimap<iter_key_t<InputIterator>, iter_val_t<InputIterator>, Hash,
|
| 5343 |
+
equal_to<iter_key_t<InputIterator>>, Allocator>;
|
| 5344 |
+
|
| 5345 |
+
template<class Key, class T, typename Allocator>
|
| 5346 |
+
unordered_multimap(initializer_list<pair<const Key, T>>, typename see below::size_type,
|
| 5347 |
+
Allocator)
|
| 5348 |
+
-> unordered_multimap<Key, T, hash<Key>, equal_to<Key>, Allocator>;
|
| 5349 |
+
|
| 5350 |
+
template<class Key, class T, typename Allocator>
|
| 5351 |
+
unordered_multimap(initializer_list<pair<const Key, T>>, Allocator)
|
| 5352 |
+
-> unordered_multimap<Key, T, hash<Key>, equal_to<Key>, Allocator>;
|
| 5353 |
+
|
| 5354 |
+
template<class Key, class T, class Hash, class Allocator>
|
| 5355 |
+
unordered_multimap(initializer_list<pair<const Key, T>>, typename see below::size_type,
|
| 5356 |
+
Hash, Allocator)
|
| 5357 |
+
-> unordered_multimap<Key, T, Hash, equal_to<Key>, Allocator>;
|
| 5358 |
|
| 5359 |
template <class Key, class T, class Hash, class Pred, class Alloc>
|
| 5360 |
bool operator==(const unordered_multimap<Key, T, Hash, Pred, Alloc>& a,
|
| 5361 |
const unordered_multimap<Key, T, Hash, Pred, Alloc>& b);
|
| 5362 |
template <class Key, class T, class Hash, class Pred, class Alloc>
|
| 5363 |
bool operator!=(const unordered_multimap<Key, T, Hash, Pred, Alloc>& a,
|
| 5364 |
const unordered_multimap<Key, T, Hash, Pred, Alloc>& b);
|
| 5365 |
+
|
| 5366 |
+
// [unord.multimap.swap], swap
|
| 5367 |
+
template <class Key, class T, class Hash, class Pred, class Alloc>
|
| 5368 |
+
void swap(unordered_multimap<Key, T, Hash, Pred, Alloc>& x,
|
| 5369 |
+
unordered_multimap<Key, T, Hash, Pred, Alloc>& y)
|
| 5370 |
+
noexcept(noexcept(x.swap(y)));
|
| 5371 |
}
|
| 5372 |
```
|
| 5373 |
|
| 5374 |
+
A `size_type` parameter type in an `unordered_multimap` deduction guide
|
| 5375 |
+
refers to the `size_type` member type of the type deduced by the
|
| 5376 |
+
deduction guide.
|
| 5377 |
+
|
| 5378 |
#### `unordered_multimap` constructors <a id="unord.multimap.cnstr">[[unord.multimap.cnstr]]</a>
|
| 5379 |
|
| 5380 |
``` cpp
|
| 5381 |
unordered_multimap() : unordered_multimap(size_type(see below)) { }
|
| 5382 |
explicit unordered_multimap(size_type n,
|
|
|
|
| 5384 |
const key_equal& eql = key_equal(),
|
| 5385 |
const allocator_type& a = allocator_type());
|
| 5386 |
```
|
| 5387 |
|
| 5388 |
*Effects:* Constructs an empty `unordered_multimap` using the specified
|
| 5389 |
+
hash function, key equality predicate, and allocator, and using at least
|
| 5390 |
+
`n` buckets. For the default constructor, the number of buckets is
|
| 5391 |
+
*implementation-defined*. `max_load_factor()` returns `1.0`.
|
| 5392 |
|
| 5393 |
*Complexity:* Constant.
|
| 5394 |
|
| 5395 |
``` cpp
|
| 5396 |
template <class InputIterator>
|
| 5397 |
unordered_multimap(InputIterator f, InputIterator l,
|
| 5398 |
size_type n = see below,
|
| 5399 |
const hasher& hf = hasher(),
|
| 5400 |
const key_equal& eql = key_equal(),
|
| 5401 |
const allocator_type& a = allocator_type());
|
| 5402 |
+
unordered_multimap(initializer_list<value_type> il,
|
| 5403 |
+
size_type n = see below,
|
| 5404 |
+
const hasher& hf = hasher(),
|
| 5405 |
+
const key_equal& eql = key_equal(),
|
| 5406 |
+
const allocator_type& a = allocator_type());
|
| 5407 |
```
|
| 5408 |
|
| 5409 |
*Effects:* Constructs an empty `unordered_multimap` using the specified
|
| 5410 |
+
hash function, key equality predicate, and allocator, and using at least
|
| 5411 |
+
`n` buckets. If `n` is not provided, the number of buckets is
|
| 5412 |
+
*implementation-defined*. Then inserts elements from the range \[`f`,
|
| 5413 |
+
`l`) for the first form, or from the range \[`il.begin()`, `il.end()`)
|
| 5414 |
+
for the second form. `max_load_factor()` returns `1.0`.
|
| 5415 |
|
| 5416 |
*Complexity:* Average case linear, worst case quadratic.
|
| 5417 |
|
| 5418 |
#### `unordered_multimap` modifiers <a id="unord.multimap.modifiers">[[unord.multimap.modifiers]]</a>
|
| 5419 |
|
| 5420 |
``` cpp
|
| 5421 |
template <class P>
|
| 5422 |
iterator insert(P&& obj);
|
| 5423 |
```
|
| 5424 |
|
| 5425 |
+
*Effects:* Equivalent to: `return emplace(std::forward<P>(obj));`
|
| 5426 |
|
| 5427 |
*Remarks:* This signature shall not participate in overload resolution
|
| 5428 |
+
unless `is_constructible_v<value_type, P&&>` is `true`.
|
| 5429 |
|
| 5430 |
``` cpp
|
| 5431 |
template <class P>
|
| 5432 |
iterator insert(const_iterator hint, P&& obj);
|
| 5433 |
```
|
| 5434 |
|
| 5435 |
+
*Effects:* Equivalent to:
|
| 5436 |
+
`return emplace_hint(hint, std::forward<P>(obj));`
|
| 5437 |
|
| 5438 |
*Remarks:* This signature shall not participate in overload resolution
|
| 5439 |
+
unless `is_constructible_v<value_type, P&&>` is `true`.
|
| 5440 |
|
| 5441 |
#### `unordered_multimap` swap <a id="unord.multimap.swap">[[unord.multimap.swap]]</a>
|
| 5442 |
|
| 5443 |
``` cpp
|
| 5444 |
template <class Key, class T, class Hash, class Pred, class Alloc>
|
| 5445 |
void swap(unordered_multimap<Key, T, Hash, Pred, Alloc>& x,
|
| 5446 |
+
unordered_multimap<Key, T, Hash, Pred, Alloc>& y)
|
| 5447 |
+
noexcept(noexcept(x.swap(y)));
|
| 5448 |
```
|
| 5449 |
|
| 5450 |
+
*Effects:* As if by `x.swap(y)`.
|
| 5451 |
|
| 5452 |
### Class template `unordered_set` <a id="unord.set">[[unord.set]]</a>
|
| 5453 |
|
| 5454 |
#### Class template `unordered_set` overview <a id="unord.set.overview">[[unord.set.overview]]</a>
|
| 5455 |
|
|
|
|
| 5463 |
(Table [[tab:containers.allocatoraware]]). It provides the operations
|
| 5464 |
described in the preceding requirements table for unique keys; that is,
|
| 5465 |
an `unordered_set` supports the `a_uniq` operations in that table, not
|
| 5466 |
the `a_eq` operations. For an `unordered_set<Key>` the `key type` and
|
| 5467 |
the value type are both `Key`. The `iterator` and `const_iterator` types
|
| 5468 |
+
are both constant iterator types. It is unspecified whether they are the
|
| 5469 |
same type.
|
| 5470 |
|
| 5471 |
This section only describes operations on `unordered_set` that are not
|
| 5472 |
described in one of the requirement tables, or for which there is
|
| 5473 |
additional semantic information.
|
| 5474 |
|
| 5475 |
``` cpp
|
| 5476 |
namespace std {
|
| 5477 |
template <class Key,
|
| 5478 |
class Hash = hash<Key>,
|
| 5479 |
+
class Pred = equal_to<Key>,
|
| 5480 |
+
class Allocator = allocator<Key>>
|
| 5481 |
+
class unordered_set {
|
|
|
|
| 5482 |
public:
|
| 5483 |
+
// types:
|
| 5484 |
+
using key_type = Key;
|
| 5485 |
+
using value_type = Key;
|
| 5486 |
+
using hasher = Hash;
|
| 5487 |
+
using key_equal = Pred;
|
| 5488 |
+
using allocator_type = Allocator;
|
| 5489 |
+
using pointer = typename allocator_traits<Allocator>::pointer;
|
| 5490 |
+
using const_pointer = typename allocator_traits<Allocator>::const_pointer;
|
| 5491 |
+
using reference = value_type&;
|
| 5492 |
+
using const_reference = const value_type&;
|
| 5493 |
+
using size_type = implementation-defined; // see [container.requirements]
|
| 5494 |
+
using difference_type = implementation-defined; // see [container.requirements]
|
| 5495 |
|
| 5496 |
+
using iterator = implementation-defined // type of unordered_set::iterator; // see [container.requirements]
|
| 5497 |
+
using const_iterator = implementation-defined // type of unordered_set::const_iterator; // see [container.requirements]
|
| 5498 |
+
using local_iterator = implementation-defined // type of unordered_set::local_iterator; // see [container.requirements]
|
| 5499 |
+
using const_local_iterator = implementation-defined // type of unordered_set::const_local_iterator; // see [container.requirements]
|
| 5500 |
+
using node_type = unspecified;
|
| 5501 |
+
using insert_return_type = INSERT_RETURN_TYPE<iterator, node_type>;
|
| 5502 |
|
| 5503 |
+
// [unord.set.cnstr], construct/copy/destroy
|
| 5504 |
unordered_set();
|
| 5505 |
explicit unordered_set(size_type n,
|
| 5506 |
const hasher& hf = hasher(),
|
| 5507 |
const key_equal& eql = key_equal(),
|
| 5508 |
const allocator_type& a = allocator_type());
|
|
|
|
| 5515 |
unordered_set(const unordered_set&);
|
| 5516 |
unordered_set(unordered_set&&);
|
| 5517 |
explicit unordered_set(const Allocator&);
|
| 5518 |
unordered_set(const unordered_set&, const Allocator&);
|
| 5519 |
unordered_set(unordered_set&&, const Allocator&);
|
| 5520 |
+
unordered_set(initializer_list<value_type> il,
|
| 5521 |
+
size_type n = see below,
|
| 5522 |
const hasher& hf = hasher(),
|
| 5523 |
const key_equal& eql = key_equal(),
|
| 5524 |
const allocator_type& a = allocator_type());
|
| 5525 |
unordered_set(size_type n, const allocator_type& a)
|
| 5526 |
: unordered_set(n, hasher(), key_equal(), a) { }
|
|
|
|
| 5538 |
unordered_set(initializer_list<value_type> il, size_type n, const hasher& hf,
|
| 5539 |
const allocator_type& a)
|
| 5540 |
: unordered_set(il, n, hf, key_equal(), a) { }
|
| 5541 |
~unordered_set();
|
| 5542 |
unordered_set& operator=(const unordered_set&);
|
| 5543 |
+
unordered_set& operator=(unordered_set&&)
|
| 5544 |
+
noexcept(allocator_traits<Allocator>::is_always_equal::value &&
|
| 5545 |
+
is_nothrow_move_assignable_v<Hash> &&
|
| 5546 |
+
is_nothrow_move_assignable_v<Pred>);
|
| 5547 |
unordered_set& operator=(initializer_list<value_type>);
|
| 5548 |
allocator_type get_allocator() const noexcept;
|
| 5549 |
|
| 5550 |
+
// iterators:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 5551 |
iterator begin() noexcept;
|
| 5552 |
const_iterator begin() const noexcept;
|
| 5553 |
iterator end() noexcept;
|
| 5554 |
const_iterator end() const noexcept;
|
| 5555 |
const_iterator cbegin() const noexcept;
|
| 5556 |
const_iterator cend() const noexcept;
|
| 5557 |
|
| 5558 |
+
// capacity:
|
| 5559 |
+
bool empty() const noexcept;
|
| 5560 |
+
size_type size() const noexcept;
|
| 5561 |
+
size_type max_size() const noexcept;
|
| 5562 |
+
|
| 5563 |
+
// modifiers:
|
| 5564 |
template <class... Args> pair<iterator, bool> emplace(Args&&... args);
|
| 5565 |
template <class... Args> iterator emplace_hint(const_iterator position, Args&&... args);
|
| 5566 |
pair<iterator, bool> insert(const value_type& obj);
|
| 5567 |
pair<iterator, bool> insert(value_type&& obj);
|
| 5568 |
iterator insert(const_iterator hint, const value_type& obj);
|
| 5569 |
iterator insert(const_iterator hint, value_type&& obj);
|
| 5570 |
template <class InputIterator> void insert(InputIterator first, InputIterator last);
|
| 5571 |
void insert(initializer_list<value_type>);
|
| 5572 |
|
| 5573 |
+
node_type extract(const_iterator position);
|
| 5574 |
+
node_type extract(const key_type& x);
|
| 5575 |
+
insert_return_type insert(node_type&& nh);
|
| 5576 |
+
iterator insert(const_iterator hint, node_type&& nh);
|
| 5577 |
+
|
| 5578 |
+
iterator erase(iterator position);
|
| 5579 |
iterator erase(const_iterator position);
|
| 5580 |
size_type erase(const key_type& k);
|
| 5581 |
iterator erase(const_iterator first, const_iterator last);
|
| 5582 |
+
void swap(unordered_set&)
|
| 5583 |
+
noexcept(allocator_traits<Allocator>::is_always_equal::value &&
|
| 5584 |
+
is_nothrow_swappable_v<Hash> &&
|
| 5585 |
+
is_nothrow_swappable_v<Pred>);
|
| 5586 |
void clear() noexcept;
|
| 5587 |
|
| 5588 |
+
template<class H2, class P2>
|
| 5589 |
+
void merge(unordered_set<Key, H2, P2, Allocator>& source);
|
| 5590 |
+
template<class H2, class P2>
|
| 5591 |
+
void merge(unordered_set<Key, H2, P2, Allocator>&& source);
|
| 5592 |
+
template<class H2, class P2>
|
| 5593 |
+
void merge(unordered_multiset<Key, H2, P2, Allocator>& source);
|
| 5594 |
+
template<class H2, class P2>
|
| 5595 |
+
void merge(unordered_multiset<Key, H2, P2, Allocator>&& source);
|
| 5596 |
|
| 5597 |
+
// observers:
|
| 5598 |
hasher hash_function() const;
|
| 5599 |
key_equal key_eq() const;
|
| 5600 |
|
| 5601 |
+
// set operations:
|
| 5602 |
iterator find(const key_type& k);
|
| 5603 |
const_iterator find(const key_type& k) const;
|
| 5604 |
size_type count(const key_type& k) const;
|
| 5605 |
+
pair<iterator, iterator> equal_range(const key_type& k);
|
| 5606 |
+
pair<const_iterator, const_iterator> equal_range(const key_type& k) const;
|
| 5607 |
|
| 5608 |
+
// bucket interface:
|
| 5609 |
size_type bucket_count() const noexcept;
|
| 5610 |
size_type max_bucket_count() const noexcept;
|
| 5611 |
size_type bucket_size(size_type n) const;
|
| 5612 |
size_type bucket(const key_type& k) const;
|
| 5613 |
local_iterator begin(size_type n);
|
|
|
|
| 5615 |
local_iterator end(size_type n);
|
| 5616 |
const_local_iterator end(size_type n) const;
|
| 5617 |
const_local_iterator cbegin(size_type n) const;
|
| 5618 |
const_local_iterator cend(size_type n) const;
|
| 5619 |
|
| 5620 |
+
// hash policy:
|
| 5621 |
float load_factor() const noexcept;
|
| 5622 |
float max_load_factor() const noexcept;
|
| 5623 |
void max_load_factor(float z);
|
| 5624 |
void rehash(size_type n);
|
| 5625 |
void reserve(size_type n);
|
| 5626 |
};
|
| 5627 |
|
| 5628 |
+
template<class InputIterator,
|
| 5629 |
+
class Hash = hash<typename iterator_traits<InputIterator>::value_type>,
|
| 5630 |
+
class Pred = equal_to<typename iterator_traits<InputIterator>::value_type>,
|
| 5631 |
+
class Allocator = allocator<typename iterator_traits<InputIterator>::value_type>>
|
| 5632 |
+
unordered_set(InputIterator, InputIterator, typename see below::size_type = see below,
|
| 5633 |
+
Hash = Hash(), Pred = Pred(), Allocator = Allocator())
|
| 5634 |
+
-> unordered_set<typename iterator_traits<InputIterator>::value_type,
|
| 5635 |
+
Hash, Pred, Allocator>;
|
| 5636 |
+
|
| 5637 |
+
template<class T, class Hash = hash<T>,
|
| 5638 |
+
class Pred = equal_to<T>, class Allocator = allocator<T>>
|
| 5639 |
+
unordered_set(initializer_list<T>, typename see below::size_type = see below,
|
| 5640 |
+
Hash = Hash(), Pred = Pred(), Allocator = Allocator())
|
| 5641 |
+
-> unordered_set<T, Hash, Pred, Allocator>;
|
| 5642 |
+
|
| 5643 |
+
template<class InputIterator, class Allocator>
|
| 5644 |
+
unordered_set(InputIterator, InputIterator, typename see below::size_type, Allocator)
|
| 5645 |
+
-> unordered_set<typename iterator_traits<InputIterator>::value_type,
|
| 5646 |
+
hash<typename iterator_traits<InputIterator>::value_type>,
|
| 5647 |
+
equal_to<typename iterator_traits<InputIterator>::value_type>,
|
| 5648 |
+
Allocator>;
|
| 5649 |
+
|
| 5650 |
+
template<class InputIterator, class Hash, class Allocator>
|
| 5651 |
+
unordered_set(InputIterator, InputIterator, typename see below::size_type,
|
| 5652 |
+
Hash, Allocator)
|
| 5653 |
+
-> unordered_set<typename iterator_traits<InputIterator>::value_type, Hash,
|
| 5654 |
+
equal_to<typename iterator_traits<InputIterator>::value_type>,
|
| 5655 |
+
Allocator>;
|
| 5656 |
+
|
| 5657 |
+
template<class T, class Allocator>
|
| 5658 |
+
unordered_set(initializer_list<T>, typename see below::size_type, Allocator)
|
| 5659 |
+
-> unordered_set<T, hash<T>, equal_to<T>, Allocator>;
|
| 5660 |
+
|
| 5661 |
+
template<class T, class Hash, class Allocator>
|
| 5662 |
+
unordered_set(initializer_list<T>, typename see below::size_type, Hash, Allocator)
|
| 5663 |
+
-> unordered_set<T, Hash, equal_to<T>, Allocator>;
|
| 5664 |
|
| 5665 |
template <class Key, class Hash, class Pred, class Alloc>
|
| 5666 |
bool operator==(const unordered_set<Key, Hash, Pred, Alloc>& a,
|
| 5667 |
const unordered_set<Key, Hash, Pred, Alloc>& b);
|
| 5668 |
template <class Key, class Hash, class Pred, class Alloc>
|
| 5669 |
bool operator!=(const unordered_set<Key, Hash, Pred, Alloc>& a,
|
| 5670 |
const unordered_set<Key, Hash, Pred, Alloc>& b);
|
| 5671 |
+
|
| 5672 |
+
// [unord.set.swap], swap
|
| 5673 |
+
template <class Key, class Hash, class Pred, class Alloc>
|
| 5674 |
+
void swap(unordered_set<Key, Hash, Pred, Alloc>& x,
|
| 5675 |
+
unordered_set<Key, Hash, Pred, Alloc>& y)
|
| 5676 |
+
noexcept(noexcept(x.swap(y)));
|
| 5677 |
}
|
| 5678 |
```
|
| 5679 |
|
| 5680 |
+
A `size_type` parameter type in an `unordered_set` deduction guide
|
| 5681 |
+
refers to the `size_type` member type of the primary `unordered_set`
|
| 5682 |
+
template.
|
| 5683 |
+
|
| 5684 |
#### `unordered_set` constructors <a id="unord.set.cnstr">[[unord.set.cnstr]]</a>
|
| 5685 |
|
| 5686 |
``` cpp
|
| 5687 |
unordered_set() : unordered_set(size_type(see below)) { }
|
| 5688 |
explicit unordered_set(size_type n,
|
|
|
|
| 5690 |
const key_equal& eql = key_equal(),
|
| 5691 |
const allocator_type& a = allocator_type());
|
| 5692 |
```
|
| 5693 |
|
| 5694 |
*Effects:* Constructs an empty `unordered_set` using the specified hash
|
| 5695 |
+
function, key equality predicate, and allocator, and using at least `n`
|
| 5696 |
buckets. For the default constructor, the number of buckets is
|
| 5697 |
+
*implementation-defined*. `max_load_factor()` returns `1.0`.
|
| 5698 |
|
| 5699 |
*Complexity:* Constant.
|
| 5700 |
|
| 5701 |
``` cpp
|
| 5702 |
template <class InputIterator>
|
| 5703 |
unordered_set(InputIterator f, InputIterator l,
|
| 5704 |
size_type n = see below,
|
| 5705 |
const hasher& hf = hasher(),
|
| 5706 |
const key_equal& eql = key_equal(),
|
| 5707 |
const allocator_type& a = allocator_type());
|
| 5708 |
+
unordered_set(initializer_list<value_type> il,
|
| 5709 |
+
size_type n = see below,
|
| 5710 |
+
const hasher& hf = hasher(),
|
| 5711 |
+
const key_equal& eql = key_equal(),
|
| 5712 |
+
const allocator_type& a = allocator_type());
|
| 5713 |
```
|
| 5714 |
|
| 5715 |
*Effects:* Constructs an empty `unordered_set` using the specified hash
|
| 5716 |
+
function, key equality predicate, and allocator, and using at least `n`
|
| 5717 |
+
buckets. If `n` is not provided, the number of buckets is
|
| 5718 |
+
*implementation-defined*. Then inserts elements from the range \[`f`,
|
| 5719 |
+
`l`) for the first form, or from the range \[`il.begin()`, `il.end()`)
|
| 5720 |
+
for the second form. `max_load_factor()` returns `1.0`.
|
| 5721 |
|
| 5722 |
*Complexity:* Average case linear, worst case quadratic.
|
| 5723 |
|
| 5724 |
#### `unordered_set` swap <a id="unord.set.swap">[[unord.set.swap]]</a>
|
| 5725 |
|
| 5726 |
``` cpp
|
| 5727 |
template <class Key, class Hash, class Pred, class Alloc>
|
| 5728 |
void swap(unordered_set<Key, Hash, Pred, Alloc>& x,
|
| 5729 |
+
unordered_set<Key, Hash, Pred, Alloc>& y)
|
| 5730 |
+
noexcept(noexcept(x.swap(y)));
|
| 5731 |
```
|
| 5732 |
|
| 5733 |
+
*Effects:* As if by `x.swap(y)`.
|
| 5734 |
|
| 5735 |
### Class template `unordered_multiset` <a id="unord.multiset">[[unord.multiset]]</a>
|
| 5736 |
|
| 5737 |
#### Class template `unordered_multiset` overview <a id="unord.multiset.overview">[[unord.multiset.overview]]</a>
|
| 5738 |
|
|
|
|
| 5747 |
allocator-aware container (Table [[tab:containers.allocatoraware]]). It
|
| 5748 |
provides the operations described in the preceding requirements table
|
| 5749 |
for equivalent keys; that is, an `unordered_multiset` supports the
|
| 5750 |
`a_eq` operations in that table, not the `a_uniq` operations. For an
|
| 5751 |
`unordered_multiset<Key>` the `key type` and the value type are both
|
| 5752 |
+
`Key`. The `iterator` and `const_iterator` types are both constant
|
| 5753 |
+
iterator types. It is unspecified whether they are the same type.
|
| 5754 |
|
| 5755 |
This section only describes operations on `unordered_multiset` that are
|
| 5756 |
not described in one of the requirement tables, or for which there is
|
| 5757 |
additional semantic information.
|
| 5758 |
|
| 5759 |
``` cpp
|
| 5760 |
namespace std {
|
| 5761 |
template <class Key,
|
| 5762 |
class Hash = hash<Key>,
|
| 5763 |
+
class Pred = equal_to<Key>,
|
| 5764 |
+
class Allocator = allocator<Key>>
|
| 5765 |
+
class unordered_multiset {
|
|
|
|
| 5766 |
public:
|
| 5767 |
+
// types:
|
| 5768 |
+
using key_type = Key;
|
| 5769 |
+
using value_type = Key;
|
| 5770 |
+
using hasher = Hash;
|
| 5771 |
+
using key_equal = Pred;
|
| 5772 |
+
using allocator_type = Allocator;
|
| 5773 |
+
using pointer = typename allocator_traits<Allocator>::pointer;
|
| 5774 |
+
using const_pointer = typename allocator_traits<Allocator>::const_pointer;
|
| 5775 |
+
using reference = value_type&;
|
| 5776 |
+
using const_reference = const value_type&;
|
| 5777 |
+
using size_type = implementation-defined; // see [container.requirements]
|
| 5778 |
+
using difference_type = implementation-defined; // see [container.requirements]
|
| 5779 |
|
| 5780 |
+
using iterator = implementation-defined // type of unordered_multiset::iterator; // see [container.requirements]
|
| 5781 |
+
using const_iterator = implementation-defined // type of unordered_multiset::const_iterator; // see [container.requirements]
|
| 5782 |
+
using local_iterator = implementation-defined // type of unordered_multiset::local_iterator; // see [container.requirements]
|
| 5783 |
+
using const_local_iterator = implementation-defined // type of unordered_multiset::const_local_iterator; // see [container.requirements]
|
| 5784 |
+
using node_type = unspecified;
|
| 5785 |
|
| 5786 |
+
// [unord.multiset.cnstr], construct/copy/destroy
|
| 5787 |
unordered_multiset();
|
| 5788 |
explicit unordered_multiset(size_type n,
|
| 5789 |
const hasher& hf = hasher(),
|
| 5790 |
const key_equal& eql = key_equal(),
|
| 5791 |
const allocator_type& a = allocator_type());
|
|
|
|
| 5798 |
unordered_multiset(const unordered_multiset&);
|
| 5799 |
unordered_multiset(unordered_multiset&&);
|
| 5800 |
explicit unordered_multiset(const Allocator&);
|
| 5801 |
unordered_multiset(const unordered_multiset&, const Allocator&);
|
| 5802 |
unordered_multiset(unordered_multiset&&, const Allocator&);
|
| 5803 |
+
unordered_multiset(initializer_list<value_type> il,
|
| 5804 |
+
size_type n = see below,
|
| 5805 |
const hasher& hf = hasher(),
|
| 5806 |
const key_equal& eql = key_equal(),
|
| 5807 |
const allocator_type& a = allocator_type());
|
| 5808 |
unordered_multiset(size_type n, const allocator_type& a)
|
| 5809 |
: unordered_multiset(n, hasher(), key_equal(), a) { }
|
|
|
|
| 5821 |
unordered_multiset(initializer_list<value_type> il, size_type n, const hasher& hf,
|
| 5822 |
const allocator_type& a)
|
| 5823 |
: unordered_multiset(il, n, hf, key_equal(), a) { }
|
| 5824 |
~unordered_multiset();
|
| 5825 |
unordered_multiset& operator=(const unordered_multiset&);
|
| 5826 |
+
unordered_multiset& operator=(unordered_multiset&&)
|
| 5827 |
+
noexcept(allocator_traits<Allocator>::is_always_equal::value &&
|
| 5828 |
+
is_nothrow_move_assignable_v<Hash> &&
|
| 5829 |
+
is_nothrow_move_assignable_v<Pred>);
|
| 5830 |
unordered_multiset& operator=(initializer_list<value_type>);
|
| 5831 |
allocator_type get_allocator() const noexcept;
|
| 5832 |
|
| 5833 |
+
// iterators:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 5834 |
iterator begin() noexcept;
|
| 5835 |
const_iterator begin() const noexcept;
|
| 5836 |
iterator end() noexcept;
|
| 5837 |
const_iterator end() const noexcept;
|
| 5838 |
const_iterator cbegin() const noexcept;
|
| 5839 |
const_iterator cend() const noexcept;
|
| 5840 |
|
| 5841 |
+
// capacity:
|
| 5842 |
+
bool empty() const noexcept;
|
| 5843 |
+
size_type size() const noexcept;
|
| 5844 |
+
size_type max_size() const noexcept;
|
| 5845 |
+
|
| 5846 |
+
// modifiers:
|
| 5847 |
template <class... Args> iterator emplace(Args&&... args);
|
| 5848 |
template <class... Args> iterator emplace_hint(const_iterator position, Args&&... args);
|
| 5849 |
iterator insert(const value_type& obj);
|
| 5850 |
iterator insert(value_type&& obj);
|
| 5851 |
iterator insert(const_iterator hint, const value_type& obj);
|
| 5852 |
iterator insert(const_iterator hint, value_type&& obj);
|
| 5853 |
template <class InputIterator> void insert(InputIterator first, InputIterator last);
|
| 5854 |
void insert(initializer_list<value_type>);
|
| 5855 |
|
| 5856 |
+
node_type extract(const_iterator position);
|
| 5857 |
+
node_type extract(const key_type& x);
|
| 5858 |
+
iterator insert(node_type&& nh);
|
| 5859 |
+
iterator insert(const_iterator hint, node_type&& nh);
|
| 5860 |
+
|
| 5861 |
+
iterator erase(iterator position);
|
| 5862 |
iterator erase(const_iterator position);
|
| 5863 |
size_type erase(const key_type& k);
|
| 5864 |
iterator erase(const_iterator first, const_iterator last);
|
| 5865 |
+
void swap(unordered_multiset&)
|
| 5866 |
+
noexcept(allocator_traits<Allocator>::is_always_equal::value &&
|
| 5867 |
+
is_nothrow_swappable_v<Hash> &&
|
| 5868 |
+
is_nothrow_swappable_v<Pred>);
|
| 5869 |
void clear() noexcept;
|
| 5870 |
|
| 5871 |
+
template<class H2, class P2>
|
| 5872 |
+
void merge(unordered_multiset<Key, H2, P2, Allocator>& source);
|
| 5873 |
+
template<class H2, class P2>
|
| 5874 |
+
void merge(unordered_multiset<Key, H2, P2, Allocator>&& source);
|
| 5875 |
+
template<class H2, class P2>
|
| 5876 |
+
void merge(unordered_set<Key, H2, P2, Allocator>& source);
|
| 5877 |
+
template<class H2, class P2>
|
| 5878 |
+
void merge(unordered_set<Key, H2, P2, Allocator>&& source);
|
| 5879 |
|
| 5880 |
+
// observers:
|
| 5881 |
hasher hash_function() const;
|
| 5882 |
key_equal key_eq() const;
|
| 5883 |
|
| 5884 |
+
// set operations:
|
| 5885 |
iterator find(const key_type& k);
|
| 5886 |
const_iterator find(const key_type& k) const;
|
| 5887 |
size_type count(const key_type& k) const;
|
| 5888 |
+
pair<iterator, iterator> equal_range(const key_type& k);
|
| 5889 |
+
pair<const_iterator, const_iterator> equal_range(const key_type& k) const;
|
| 5890 |
|
| 5891 |
+
// bucket interface:
|
| 5892 |
size_type bucket_count() const noexcept;
|
| 5893 |
size_type max_bucket_count() const noexcept;
|
| 5894 |
size_type bucket_size(size_type n) const;
|
| 5895 |
size_type bucket(const key_type& k) const;
|
| 5896 |
local_iterator begin(size_type n);
|
|
|
|
| 5898 |
local_iterator end(size_type n);
|
| 5899 |
const_local_iterator end(size_type n) const;
|
| 5900 |
const_local_iterator cbegin(size_type n) const;
|
| 5901 |
const_local_iterator cend(size_type n) const;
|
| 5902 |
|
| 5903 |
+
// hash policy:
|
| 5904 |
float load_factor() const noexcept;
|
| 5905 |
float max_load_factor() const noexcept;
|
| 5906 |
void max_load_factor(float z);
|
| 5907 |
void rehash(size_type n);
|
| 5908 |
void reserve(size_type n);
|
| 5909 |
};
|
| 5910 |
|
| 5911 |
+
template<class InputIterator,
|
| 5912 |
+
class Hash = hash<typename iterator_traits<InputIterator>::value_type>,
|
| 5913 |
+
class Pred = equal_to<typename iterator_traits<InputIterator>::value_type>,
|
| 5914 |
+
class Allocator = allocator<typename iterator_traits<InputIterator>::value_type>>
|
| 5915 |
+
unordered_multiset(InputIterator, InputIterator, see below::size_type = see below,
|
| 5916 |
+
Hash = Hash(), Pred = Pred(), Allocator = Allocator())
|
| 5917 |
+
-> unordered_multiset<typename iterator_traits<InputIterator>::value_type,
|
| 5918 |
+
Hash, Pred, Allocator>;
|
| 5919 |
+
|
| 5920 |
+
template<class T, class Hash = hash<T>,
|
| 5921 |
+
class Pred = equal_to<T>, class Allocator = allocator<T>>
|
| 5922 |
+
unordered_multiset(initializer_list<T>, typename see below::size_type = see below,
|
| 5923 |
+
Hash = Hash(), Pred = Pred(), Allocator = Allocator())
|
| 5924 |
+
-> unordered_multiset<T, Hash, Pred, Allocator>;
|
| 5925 |
+
|
| 5926 |
+
template<class InputIterator, class Allocator>
|
| 5927 |
+
unordered_multiset(InputIterator, InputIterator, typename see below::size_type, Allocator)
|
| 5928 |
+
-> unordered_multiset<typename iterator_traits<InputIterator>::value_type,
|
| 5929 |
+
hash<typename iterator_traits<InputIterator>::value_type>,
|
| 5930 |
+
equal_to<typename iterator_traits<InputIterator>::value_type>,
|
| 5931 |
+
Allocator>;
|
| 5932 |
+
|
| 5933 |
+
template<class InputIterator, class Hash, class Allocator>
|
| 5934 |
+
unordered_multiset(InputIterator, InputIterator, typename see below::size_type,
|
| 5935 |
+
Hash, Allocator)
|
| 5936 |
+
-> unordered_multiset<typename iterator_traits<InputIterator>::value_type, Hash,
|
| 5937 |
+
equal_to<typename iterator_traits<InputIterator>::value_type>,
|
| 5938 |
+
Allocator>;
|
| 5939 |
+
|
| 5940 |
+
template<class T, class Allocator>
|
| 5941 |
+
unordered_multiset(initializer_list<T>, typename see below::size_type, Allocator)
|
| 5942 |
+
-> unordered_multiset<T, hash<T>, equal_to<T>, Allocator>;
|
| 5943 |
+
|
| 5944 |
+
template<class T, class Hash, class Allocator>
|
| 5945 |
+
unordered_multiset(initializer_list<T>, typename see below::size_type, Hash, Allocator)
|
| 5946 |
+
-> unordered_multiset<T, Hash, equal_to<T>, Allocator>;
|
| 5947 |
+
|
| 5948 |
template <class Key, class Hash, class Pred, class Alloc>
|
| 5949 |
bool operator==(const unordered_multiset<Key, Hash, Pred, Alloc>& a,
|
| 5950 |
const unordered_multiset<Key, Hash, Pred, Alloc>& b);
|
| 5951 |
template <class Key, class Hash, class Pred, class Alloc>
|
| 5952 |
bool operator!=(const unordered_multiset<Key, Hash, Pred, Alloc>& a,
|
| 5953 |
const unordered_multiset<Key, Hash, Pred, Alloc>& b);
|
| 5954 |
+
|
| 5955 |
+
// [unord.multiset.swap], swap
|
| 5956 |
+
template <class Key, class Hash, class Pred, class Alloc>
|
| 5957 |
+
void swap(unordered_multiset<Key, Hash, Pred, Alloc>& x,
|
| 5958 |
+
unordered_multiset<Key, Hash, Pred, Alloc>& y)
|
| 5959 |
+
noexcept(noexcept(x.swap(y)));
|
| 5960 |
}
|
| 5961 |
```
|
| 5962 |
|
| 5963 |
+
A `size_type` parameter type in an `unordered_multiset` deduction guide
|
| 5964 |
+
refers to the `size_type` member type of the primary
|
| 5965 |
+
`unordered_multiset` template.
|
| 5966 |
+
|
| 5967 |
#### `unordered_multiset` constructors <a id="unord.multiset.cnstr">[[unord.multiset.cnstr]]</a>
|
| 5968 |
|
| 5969 |
``` cpp
|
| 5970 |
unordered_multiset() : unordered_multiset(size_type(see below)) { }
|
| 5971 |
explicit unordered_multiset(size_type n,
|
|
|
|
| 5973 |
const key_equal& eql = key_equal(),
|
| 5974 |
const allocator_type& a = allocator_type());
|
| 5975 |
```
|
| 5976 |
|
| 5977 |
*Effects:* Constructs an empty `unordered_multiset` using the specified
|
| 5978 |
+
hash function, key equality predicate, and allocator, and using at least
|
| 5979 |
+
`n` buckets. For the default constructor, the number of buckets is
|
| 5980 |
+
*implementation-defined*. `max_load_factor()` returns `1.0`.
|
| 5981 |
|
| 5982 |
*Complexity:* Constant.
|
| 5983 |
|
| 5984 |
``` cpp
|
| 5985 |
template <class InputIterator>
|
| 5986 |
unordered_multiset(InputIterator f, InputIterator l,
|
| 5987 |
size_type n = see below,
|
| 5988 |
const hasher& hf = hasher(),
|
| 5989 |
const key_equal& eql = key_equal(),
|
| 5990 |
const allocator_type& a = allocator_type());
|
| 5991 |
+
unordered_multiset(initializer_list<value_type> il,
|
| 5992 |
+
size_type n = see below,
|
| 5993 |
+
const hasher& hf = hasher(),
|
| 5994 |
+
const key_equal& eql = key_equal(),
|
| 5995 |
+
const allocator_type& a = allocator_type());
|
| 5996 |
```
|
| 5997 |
|
| 5998 |
*Effects:* Constructs an empty `unordered_multiset` using the specified
|
| 5999 |
+
hash function, key equality predicate, and allocator, and using at least
|
| 6000 |
+
`n` buckets. If `n` is not provided, the number of buckets is
|
| 6001 |
+
*implementation-defined*. Then inserts elements from the range \[`f`,
|
| 6002 |
+
`l`) for the first form, or from the range \[`il.begin()`, `il.end()`)
|
| 6003 |
+
for the second form. `max_load_factor()` returns `1.0`.
|
| 6004 |
|
| 6005 |
*Complexity:* Average case linear, worst case quadratic.
|
| 6006 |
|
| 6007 |
#### `unordered_multiset` swap <a id="unord.multiset.swap">[[unord.multiset.swap]]</a>
|
| 6008 |
|
| 6009 |
``` cpp
|
| 6010 |
template <class Key, class Hash, class Pred, class Alloc>
|
| 6011 |
void swap(unordered_multiset<Key, Hash, Pred, Alloc>& x,
|
| 6012 |
+
unordered_multiset<Key, Hash, Pred, Alloc>& y)
|
| 6013 |
+
noexcept(noexcept(x.swap(y)));
|
| 6014 |
```
|
| 6015 |
|
| 6016 |
+
*Effects:* As if by `x.swap(y)`.
|
| 6017 |
|
| 6018 |
## Container adaptors <a id="container.adaptors">[[container.adaptors]]</a>
|
| 6019 |
|
| 6020 |
### In general <a id="container.adaptors.general">[[container.adaptors.general]]</a>
|
| 6021 |
|
|
|
|
| 6025 |
The container adaptors each take a `Container` template parameter, and
|
| 6026 |
each constructor takes a `Container` reference argument. This container
|
| 6027 |
is copied into the `Container` member of each adaptor. If the container
|
| 6028 |
takes an allocator, then a compatible allocator may be passed in to the
|
| 6029 |
adaptor’s constructor. Otherwise, normal copy or move construction is
|
| 6030 |
+
used for the container argument. The first template parameter `T` of the
|
| 6031 |
+
container adaptors shall denote the same type as
|
| 6032 |
+
`Container::value_type`.
|
| 6033 |
|
| 6034 |
For container adaptors, no `swap` function throws an exception unless
|
| 6035 |
that exception is thrown by the swap of the adaptor’s `Container` or
|
| 6036 |
`Compare` object (if any).
|
| 6037 |
|
| 6038 |
+
A deduction guide for a container adaptor shall not participate in
|
| 6039 |
+
overload resolution if any of the following are true:
|
| 6040 |
+
|
| 6041 |
+
- It has an `InputIterator` template parameter and a type that does not
|
| 6042 |
+
qualify as an input iterator is deduced for that parameter.
|
| 6043 |
+
- It has a `Compare` template parameter and a type that qualifies as an
|
| 6044 |
+
allocator is deduced for that parameter.
|
| 6045 |
+
- It has a `Container` template parameter and a type that qualifies as
|
| 6046 |
+
an allocator is deduced for that parameter.
|
| 6047 |
+
- It has an `Allocator` template parameter and a type that does not
|
| 6048 |
+
qualify as an allocator is deduced for that parameter.
|
| 6049 |
+
- It has both `Container` and `Allocator` template parameters, and
|
| 6050 |
+
`uses_allocator_v<Container, Allocator>` is `false`.
|
| 6051 |
+
|
| 6052 |
### Header `<queue>` synopsis <a id="queue.syn">[[queue.syn]]</a>
|
| 6053 |
|
| 6054 |
``` cpp
|
| 6055 |
#include <initializer_list>
|
| 6056 |
|
| 6057 |
namespace std {
|
|
|
|
| 6058 |
template <class T, class Container = deque<T>> class queue;
|
| 6059 |
template <class T, class Container = vector<T>,
|
| 6060 |
class Compare = less<typename Container::value_type>>
|
| 6061 |
class priority_queue;
|
| 6062 |
|
|
|
|
| 6079 |
void swap(priority_queue<T, Container, Compare>& x,
|
| 6080 |
priority_queue<T, Container, Compare>& y) noexcept(noexcept(x.swap(y)));
|
| 6081 |
}
|
| 6082 |
```
|
| 6083 |
|
| 6084 |
+
### Header `<stack>` synopsis <a id="stack.syn">[[stack.syn]]</a>
|
| 6085 |
+
|
| 6086 |
+
``` cpp
|
| 6087 |
+
#include <initializer_list>
|
| 6088 |
+
|
| 6089 |
+
namespace std {
|
| 6090 |
+
template <class T, class Container = deque<T>> class stack;
|
| 6091 |
+
template <class T, class Container>
|
| 6092 |
+
bool operator==(const stack<T, Container>& x, const stack<T, Container>& y);
|
| 6093 |
+
template <class T, class Container>
|
| 6094 |
+
bool operator< (const stack<T, Container>& x, const stack<T, Container>& y);
|
| 6095 |
+
template <class T, class Container>
|
| 6096 |
+
bool operator!=(const stack<T, Container>& x, const stack<T, Container>& y);
|
| 6097 |
+
template <class T, class Container>
|
| 6098 |
+
bool operator> (const stack<T, Container>& x, const stack<T, Container>& y);
|
| 6099 |
+
template <class T, class Container>
|
| 6100 |
+
bool operator>=(const stack<T, Container>& x, const stack<T, Container>& y);
|
| 6101 |
+
template <class T, class Container>
|
| 6102 |
+
bool operator<=(const stack<T, Container>& x, const stack<T, Container>& y);
|
| 6103 |
+
template <class T, class Container>
|
| 6104 |
+
void swap(stack<T, Container>& x, stack<T, Container>& y) noexcept(noexcept(x.swap(y)));
|
| 6105 |
+
}
|
| 6106 |
+
```
|
| 6107 |
+
|
| 6108 |
### Class template `queue` <a id="queue">[[queue]]</a>
|
| 6109 |
|
| 6110 |
#### `queue` definition <a id="queue.defn">[[queue.defn]]</a>
|
| 6111 |
|
| 6112 |
Any sequence container supporting operations `front()`, `back()`,
|
|
|
|
| 6116 |
``` cpp
|
| 6117 |
namespace std {
|
| 6118 |
template <class T, class Container = deque<T>>
|
| 6119 |
class queue {
|
| 6120 |
public:
|
| 6121 |
+
using value_type = typename Container::value_type;
|
| 6122 |
+
using reference = typename Container::reference;
|
| 6123 |
+
using const_reference = typename Container::const_reference;
|
| 6124 |
+
using size_type = typename Container::size_type;
|
| 6125 |
+
using container_type = Container;
|
| 6126 |
+
|
| 6127 |
protected:
|
| 6128 |
Container c;
|
| 6129 |
|
| 6130 |
public:
|
| 6131 |
explicit queue(const Container&);
|
|
|
|
| 6142 |
const_reference front() const { return c.front(); }
|
| 6143 |
reference back() { return c.back(); }
|
| 6144 |
const_reference back() const { return c.back(); }
|
| 6145 |
void push(const value_type& x) { c.push_back(x); }
|
| 6146 |
void push(value_type&& x) { c.push_back(std::move(x)); }
|
| 6147 |
+
template <class... Args>
|
| 6148 |
+
reference emplace(Args&&... args) { return c.emplace_back(std::forward<Args>(args)...); }
|
| 6149 |
void pop() { c.pop_front(); }
|
| 6150 |
+
void swap(queue& q) noexcept(is_nothrow_swappable_v<Container>)
|
| 6151 |
{ using std::swap; swap(c, q.c); }
|
| 6152 |
};
|
| 6153 |
|
| 6154 |
+
template<class Container>
|
| 6155 |
+
queue(Container) -> queue<typename Container::value_type, Container>;
|
| 6156 |
+
|
| 6157 |
+
template<class Container, class Allocator>
|
| 6158 |
+
queue(Container, Allocator) -> queue<typename Container::value_type, Container>;
|
| 6159 |
+
|
| 6160 |
template <class T, class Container>
|
| 6161 |
bool operator==(const queue<T, Container>& x, const queue<T, Container>& y);
|
| 6162 |
template <class T, class Container>
|
| 6163 |
bool operator< (const queue<T, Container>& x, const queue<T, Container>& y);
|
| 6164 |
template <class T, class Container>
|
|
|
|
| 6193 |
|
| 6194 |
*Effects:* Initializes `c` with `std::move(cont)`.
|
| 6195 |
|
| 6196 |
#### `queue` constructors with allocators <a id="queue.cons.alloc">[[queue.cons.alloc]]</a>
|
| 6197 |
|
| 6198 |
+
If `uses_allocator_v<container_type, Alloc>` is `false` the constructors
|
| 6199 |
+
in this subclause shall not participate in overload resolution.
|
|
|
|
| 6200 |
|
| 6201 |
``` cpp
|
| 6202 |
+
template <class Alloc> explicit queue(const Alloc& a);
|
|
|
|
| 6203 |
```
|
| 6204 |
|
| 6205 |
*Effects:* Initializes `c` with `a`.
|
| 6206 |
|
| 6207 |
``` cpp
|
| 6208 |
+
template <class Alloc> queue(const container_type& cont, const Alloc& a);
|
|
|
|
| 6209 |
```
|
| 6210 |
|
| 6211 |
*Effects:* Initializes `c` with `cont` as the first argument and `a` as
|
| 6212 |
the second argument.
|
| 6213 |
|
| 6214 |
``` cpp
|
| 6215 |
+
template <class Alloc> queue(container_type&& cont, const Alloc& a);
|
|
|
|
| 6216 |
```
|
| 6217 |
|
| 6218 |
*Effects:* Initializes `c` with `std::move(cont)` as the first argument
|
| 6219 |
and `a` as the second argument.
|
| 6220 |
|
| 6221 |
``` cpp
|
| 6222 |
+
template <class Alloc> queue(const queue& q, const Alloc& a);
|
|
|
|
| 6223 |
```
|
| 6224 |
|
| 6225 |
*Effects:* Initializes `c` with `q.c` as the first argument and `a` as
|
| 6226 |
the second argument.
|
| 6227 |
|
| 6228 |
``` cpp
|
| 6229 |
+
template <class Alloc> queue(queue&& q, const Alloc& a);
|
|
|
|
| 6230 |
```
|
| 6231 |
|
| 6232 |
*Effects:* Initializes `c` with `std::move(q.c)` as the first argument
|
| 6233 |
and `a` as the second argument.
|
| 6234 |
|
| 6235 |
#### `queue` operators <a id="queue.ops">[[queue.ops]]</a>
|
| 6236 |
|
| 6237 |
``` cpp
|
| 6238 |
template <class T, class Container>
|
| 6239 |
+
bool operator==(const queue<T, Container>& x, const queue<T, Container>& y);
|
|
|
|
| 6240 |
```
|
| 6241 |
|
| 6242 |
*Returns:* `x.c == y.c`.
|
| 6243 |
|
| 6244 |
``` cpp
|
| 6245 |
template <class T, class Container>
|
| 6246 |
+
bool operator!=(const queue<T, Container>& x, const queue<T, Container>& y);
|
|
|
|
| 6247 |
```
|
| 6248 |
|
| 6249 |
*Returns:* `x.c != y.c`.
|
| 6250 |
|
| 6251 |
``` cpp
|
| 6252 |
template <class T, class Container>
|
| 6253 |
+
bool operator< (const queue<T, Container>& x, const queue<T, Container>& y);
|
|
|
|
| 6254 |
```
|
| 6255 |
|
| 6256 |
*Returns:* `x.c < y.c`.
|
| 6257 |
|
| 6258 |
``` cpp
|
| 6259 |
template <class T, class Container>
|
| 6260 |
+
bool operator<=(const queue<T, Container>& x, const queue<T, Container>& y);
|
|
|
|
| 6261 |
```
|
| 6262 |
|
| 6263 |
*Returns:* `x.c <= y.c`.
|
| 6264 |
|
| 6265 |
``` cpp
|
| 6266 |
template <class T, class Container>
|
| 6267 |
+
bool operator> (const queue<T, Container>& x, const queue<T, Container>& y);
|
|
|
|
| 6268 |
```
|
| 6269 |
|
| 6270 |
*Returns:* `x.c > y.c`.
|
| 6271 |
|
| 6272 |
``` cpp
|
|
|
|
| 6282 |
``` cpp
|
| 6283 |
template <class T, class Container>
|
| 6284 |
void swap(queue<T, Container>& x, queue<T, Container>& y) noexcept(noexcept(x.swap(y)));
|
| 6285 |
```
|
| 6286 |
|
| 6287 |
+
*Remarks:* This function shall not participate in overload resolution
|
| 6288 |
+
unless `is_swappable_v<Container>` is `true`.
|
| 6289 |
+
|
| 6290 |
+
*Effects:* As if by `x.swap(y)`.
|
| 6291 |
|
| 6292 |
### Class template `priority_queue` <a id="priority.queue">[[priority.queue]]</a>
|
| 6293 |
|
| 6294 |
Any sequence container with random access iterator and supporting
|
| 6295 |
operations `front()`, `push_back()` and `pop_back()` can be used to
|
|
|
|
| 6303 |
namespace std {
|
| 6304 |
template <class T, class Container = vector<T>,
|
| 6305 |
class Compare = less<typename Container::value_type>>
|
| 6306 |
class priority_queue {
|
| 6307 |
public:
|
| 6308 |
+
using value_type = typename Container::value_type;
|
| 6309 |
+
using reference = typename Container::reference;
|
| 6310 |
+
using const_reference = typename Container::const_reference;
|
| 6311 |
+
using size_type = typename Container::size_type;
|
| 6312 |
+
using container_type = Container;
|
| 6313 |
+
using value_compare = Compare;
|
| 6314 |
+
|
| 6315 |
protected:
|
| 6316 |
Container c;
|
| 6317 |
Compare comp;
|
| 6318 |
|
| 6319 |
public:
|
|
|
|
| 6325 |
template <class InputIterator>
|
| 6326 |
priority_queue(InputIterator first, InputIterator last,
|
| 6327 |
const Compare& x = Compare(), Container&& = Container());
|
| 6328 |
template <class Alloc> explicit priority_queue(const Alloc&);
|
| 6329 |
template <class Alloc> priority_queue(const Compare&, const Alloc&);
|
| 6330 |
+
template <class Alloc> priority_queue(const Compare&, const Container&, const Alloc&);
|
| 6331 |
+
template <class Alloc> priority_queue(const Compare&, Container&&, const Alloc&);
|
|
|
|
|
|
|
| 6332 |
template <class Alloc> priority_queue(const priority_queue&, const Alloc&);
|
| 6333 |
template <class Alloc> priority_queue(priority_queue&&, const Alloc&);
|
| 6334 |
|
| 6335 |
bool empty() const { return c.empty(); }
|
| 6336 |
size_type size() const { return c.size(); }
|
| 6337 |
const_reference top() const { return c.front(); }
|
| 6338 |
void push(const value_type& x);
|
| 6339 |
void push(value_type&& x);
|
| 6340 |
template <class... Args> void emplace(Args&&... args);
|
| 6341 |
void pop();
|
| 6342 |
+
void swap(priority_queue& q) noexcept(is_nothrow_swappable_v<Container> &&
|
| 6343 |
+
is_nothrow_swappable_v<Compare>)
|
| 6344 |
{ using std::swap; swap(c, q.c); swap(comp, q.comp); }
|
| 6345 |
};
|
| 6346 |
+
|
| 6347 |
+
template<class Compare, class Container>
|
| 6348 |
+
priority_queue(Compare, Container)
|
| 6349 |
+
-> priority_queue<typename Container::value_type, Container, Compare>;
|
| 6350 |
+
|
| 6351 |
+
template<class InputIterator,
|
| 6352 |
+
class Compare = less<typename iterator_traits<InputIterator>::value_type>,
|
| 6353 |
+
class Container = vector<typename iterator_traits<InputIterator>::value_type>>
|
| 6354 |
+
priority_queue(InputIterator, InputIterator, Compare = Compare(), Container = Container())
|
| 6355 |
+
-> priority_queue<typename iterator_traits<InputIterator>::value_type, Container, Compare>;
|
| 6356 |
+
|
| 6357 |
+
template<class Compare, class Container, class Allocator>
|
| 6358 |
+
priority_queue(Compare, Container, Allocator)
|
| 6359 |
+
-> priority_queue<typename Container::value_type, Container, Compare>;
|
| 6360 |
+
|
| 6361 |
// no equality is provided
|
| 6362 |
+
|
| 6363 |
template <class T, class Container, class Compare>
|
| 6364 |
void swap(priority_queue<T, Container, Compare>& x,
|
| 6365 |
priority_queue<T, Container, Compare>& y) noexcept(noexcept(x.swap(y)));
|
| 6366 |
|
| 6367 |
template <class T, class Container, class Compare, class Alloc>
|
|
|
|
| 6371 |
```
|
| 6372 |
|
| 6373 |
#### `priority_queue` constructors <a id="priqueue.cons">[[priqueue.cons]]</a>
|
| 6374 |
|
| 6375 |
``` cpp
|
| 6376 |
+
priority_queue(const Compare& x, const Container& y);
|
| 6377 |
+
explicit priority_queue(const Compare& x = Compare(), Container&& y = Container());
|
|
|
|
|
|
|
| 6378 |
```
|
| 6379 |
|
| 6380 |
*Requires:* `x` shall define a strict weak ordering ([[alg.sorting]]).
|
| 6381 |
|
| 6382 |
*Effects:* Initializes `comp` with `x` and `c` with `y` (copy
|
|
|
|
| 6401 |
`c.insert(c.end(), first, last)`; and finally calls
|
| 6402 |
`make_heap(c.begin(), c.end(), comp)`.
|
| 6403 |
|
| 6404 |
#### `priority_queue` constructors with allocators <a id="priqueue.cons.alloc">[[priqueue.cons.alloc]]</a>
|
| 6405 |
|
| 6406 |
+
If `uses_allocator_v<container_type, Alloc>` is `false` the constructors
|
| 6407 |
+
in this subclause shall not participate in overload resolution.
|
|
|
|
| 6408 |
|
| 6409 |
``` cpp
|
| 6410 |
+
template <class Alloc> explicit priority_queue(const Alloc& a);
|
|
|
|
| 6411 |
```
|
| 6412 |
|
| 6413 |
*Effects:* Initializes `c` with `a` and value-initializes `comp`.
|
| 6414 |
|
| 6415 |
``` cpp
|
| 6416 |
+
template <class Alloc> priority_queue(const Compare& compare, const Alloc& a);
|
|
|
|
| 6417 |
```
|
| 6418 |
|
| 6419 |
*Effects:* Initializes `c` with `a` and initializes `comp` with
|
| 6420 |
`compare`.
|
| 6421 |
|
|
|
|
| 6423 |
template <class Alloc>
|
| 6424 |
priority_queue(const Compare& compare, const Container& cont, const Alloc& a);
|
| 6425 |
```
|
| 6426 |
|
| 6427 |
*Effects:* Initializes `c` with `cont` as the first argument and `a` as
|
| 6428 |
+
the second argument, and initializes `comp` with `compare`; calls
|
| 6429 |
+
`make_heap(c.begin(), c.end(), comp)`.
|
| 6430 |
|
| 6431 |
``` cpp
|
| 6432 |
template <class Alloc>
|
| 6433 |
priority_queue(const Compare& compare, Container&& cont, const Alloc& a);
|
| 6434 |
```
|
| 6435 |
|
| 6436 |
*Effects:* Initializes `c` with `std::move(cont)` as the first argument
|
| 6437 |
+
and `a` as the second argument, and initializes `comp` with `compare`;
|
| 6438 |
+
calls `make_heap(c.begin(), c.end(), comp)`.
|
| 6439 |
|
| 6440 |
``` cpp
|
| 6441 |
+
template <class Alloc> priority_queue(const priority_queue& q, const Alloc& a);
|
|
|
|
| 6442 |
```
|
| 6443 |
|
| 6444 |
*Effects:* Initializes `c` with `q.c` as the first argument and `a` as
|
| 6445 |
the second argument, and initializes `comp` with `q.comp`.
|
| 6446 |
|
| 6447 |
``` cpp
|
| 6448 |
+
template <class Alloc> priority_queue(priority_queue&& q, const Alloc& a);
|
|
|
|
| 6449 |
```
|
| 6450 |
|
| 6451 |
*Effects:* Initializes `c` with `std::move(q.c)` as the first argument
|
| 6452 |
and `a` as the second argument, and initializes `comp` with
|
| 6453 |
`std::move(q.comp)`.
|
|
|
|
| 6456 |
|
| 6457 |
``` cpp
|
| 6458 |
void push(const value_type& x);
|
| 6459 |
```
|
| 6460 |
|
| 6461 |
+
*Effects:* As if by:
|
| 6462 |
|
| 6463 |
``` cpp
|
| 6464 |
c.push_back(x);
|
| 6465 |
push_heap(c.begin(), c.end(), comp);
|
| 6466 |
```
|
| 6467 |
|
| 6468 |
``` cpp
|
| 6469 |
void push(value_type&& x);
|
| 6470 |
```
|
| 6471 |
|
| 6472 |
+
*Effects:* As if by:
|
| 6473 |
|
| 6474 |
``` cpp
|
| 6475 |
c.push_back(std::move(x));
|
| 6476 |
push_heap(c.begin(), c.end(), comp);
|
| 6477 |
```
|
| 6478 |
|
| 6479 |
``` cpp
|
| 6480 |
template <class... Args> void emplace(Args&&... args)
|
| 6481 |
```
|
| 6482 |
|
| 6483 |
+
*Effects:* As if by:
|
| 6484 |
|
| 6485 |
``` cpp
|
| 6486 |
c.emplace_back(std::forward<Args>(args)...);
|
| 6487 |
push_heap(c.begin(), c.end(), comp);
|
| 6488 |
```
|
| 6489 |
|
| 6490 |
``` cpp
|
| 6491 |
void pop();
|
| 6492 |
```
|
| 6493 |
|
| 6494 |
+
*Effects:* As if by:
|
| 6495 |
|
| 6496 |
``` cpp
|
| 6497 |
pop_heap(c.begin(), c.end(), comp);
|
| 6498 |
c.pop_back();
|
| 6499 |
```
|
| 6500 |
|
| 6501 |
#### `priority_queue` specialized algorithms <a id="priqueue.special">[[priqueue.special]]</a>
|
| 6502 |
|
| 6503 |
``` cpp
|
| 6504 |
+
template <class T, class Container, class Compare>
|
| 6505 |
void swap(priority_queue<T, Container, Compare>& x,
|
| 6506 |
priority_queue<T, Container, Compare>& y) noexcept(noexcept(x.swap(y)));
|
| 6507 |
```
|
| 6508 |
|
| 6509 |
+
*Remarks:* This function shall not participate in overload resolution
|
| 6510 |
+
unless `is_swappable_v<Container>` is `true` and
|
| 6511 |
+
`is_swappable_v<Compare>` is `true`.
|
| 6512 |
+
|
| 6513 |
+
*Effects:* As if by `x.swap(y)`.
|
| 6514 |
|
| 6515 |
### Class template `stack` <a id="stack">[[stack]]</a>
|
| 6516 |
|
| 6517 |
Any sequence container supporting operations `back()`, `push_back()` and
|
| 6518 |
`pop_back()` can be used to instantiate `stack`. In particular,
|
| 6519 |
`vector` ([[vector]]), `list` ([[list]]) and `deque` ([[deque]]) can
|
| 6520 |
be used.
|
| 6521 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 6522 |
#### `stack` definition <a id="stack.defn">[[stack.defn]]</a>
|
| 6523 |
|
| 6524 |
``` cpp
|
| 6525 |
namespace std {
|
| 6526 |
template <class T, class Container = deque<T>>
|
| 6527 |
class stack {
|
| 6528 |
public:
|
| 6529 |
+
using value_type = typename Container::value_type;
|
| 6530 |
+
using reference = typename Container::reference;
|
| 6531 |
+
using const_reference = typename Container::const_reference;
|
| 6532 |
+
using size_type = typename Container::size_type;
|
| 6533 |
+
using container_type = Container;
|
| 6534 |
+
|
| 6535 |
protected:
|
| 6536 |
Container c;
|
| 6537 |
|
| 6538 |
public:
|
| 6539 |
explicit stack(const Container&);
|
|
|
|
| 6548 |
size_type size() const { return c.size(); }
|
| 6549 |
reference top() { return c.back(); }
|
| 6550 |
const_reference top() const { return c.back(); }
|
| 6551 |
void push(const value_type& x) { c.push_back(x); }
|
| 6552 |
void push(value_type&& x) { c.push_back(std::move(x)); }
|
| 6553 |
+
template <class... Args>
|
| 6554 |
+
reference emplace(Args&&... args) { return c.emplace_back(std::forward<Args>(args)...); }
|
| 6555 |
void pop() { c.pop_back(); }
|
| 6556 |
+
void swap(stack& s) noexcept(is_nothrow_swappable_v<Container>)
|
| 6557 |
{ using std::swap; swap(c, s.c); }
|
| 6558 |
};
|
| 6559 |
|
| 6560 |
+
template<class Container>
|
| 6561 |
+
stack(Container) -> stack<typename Container::value_type, Container>;
|
| 6562 |
+
|
| 6563 |
+
template<class Container, class Allocator>
|
| 6564 |
+
stack(Container, Allocator) -> stack<typename Container::value_type, Container>;
|
| 6565 |
+
|
| 6566 |
template <class T, class Container>
|
| 6567 |
bool operator==(const stack<T, Container>& x, const stack<T, Container>& y);
|
| 6568 |
template <class T, class Container>
|
| 6569 |
bool operator< (const stack<T, Container>& x, const stack<T, Container>& y);
|
| 6570 |
template <class T, class Container>
|
|
|
|
| 6598 |
|
| 6599 |
*Effects:* Initializes `c` with `std::move(cont)`.
|
| 6600 |
|
| 6601 |
#### `stack` constructors with allocators <a id="stack.cons.alloc">[[stack.cons.alloc]]</a>
|
| 6602 |
|
| 6603 |
+
If `uses_allocator_v<container_type, Alloc>` is `false` the constructors
|
| 6604 |
+
in this subclause shall not participate in overload resolution.
|
|
|
|
| 6605 |
|
| 6606 |
``` cpp
|
| 6607 |
+
template <class Alloc> explicit stack(const Alloc& a);
|
|
|
|
| 6608 |
```
|
| 6609 |
|
| 6610 |
*Effects:* Initializes `c` with `a`.
|
| 6611 |
|
| 6612 |
``` cpp
|
| 6613 |
+
template <class Alloc> stack(const container_type& cont, const Alloc& a);
|
|
|
|
| 6614 |
```
|
| 6615 |
|
| 6616 |
*Effects:* Initializes `c` with `cont` as the first argument and `a` as
|
| 6617 |
the second argument.
|
| 6618 |
|
| 6619 |
``` cpp
|
| 6620 |
+
template <class Alloc> stack(container_type&& cont, const Alloc& a);
|
|
|
|
| 6621 |
```
|
| 6622 |
|
| 6623 |
*Effects:* Initializes `c` with `std::move(cont)` as the first argument
|
| 6624 |
and `a` as the second argument.
|
| 6625 |
|
| 6626 |
``` cpp
|
| 6627 |
+
template <class Alloc> stack(const stack& s, const Alloc& a);
|
|
|
|
| 6628 |
```
|
| 6629 |
|
| 6630 |
*Effects:* Initializes `c` with `s.c` as the first argument and `a` as
|
| 6631 |
the second argument.
|
| 6632 |
|
| 6633 |
``` cpp
|
| 6634 |
+
template <class Alloc> stack(stack&& s, const Alloc& a);
|
|
|
|
| 6635 |
```
|
| 6636 |
|
| 6637 |
*Effects:* Initializes `c` with `std::move(s.c)` as the first argument
|
| 6638 |
and `a` as the second argument.
|
| 6639 |
|
| 6640 |
#### `stack` operators <a id="stack.ops">[[stack.ops]]</a>
|
| 6641 |
|
| 6642 |
``` cpp
|
| 6643 |
template <class T, class Container>
|
| 6644 |
+
bool operator==(const stack<T, Container>& x, const stack<T, Container>& y);
|
|
|
|
| 6645 |
```
|
| 6646 |
|
| 6647 |
*Returns:* `x.c == y.c`.
|
| 6648 |
|
| 6649 |
``` cpp
|
| 6650 |
template <class T, class Container>
|
| 6651 |
+
bool operator!=(const stack<T, Container>& x, const stack<T, Container>& y);
|
|
|
|
| 6652 |
```
|
| 6653 |
|
| 6654 |
*Returns:* `x.c != y.c`.
|
| 6655 |
|
| 6656 |
``` cpp
|
| 6657 |
template <class T, class Container>
|
| 6658 |
+
bool operator< (const stack<T, Container>& x, const stack<T, Container>& y);
|
|
|
|
| 6659 |
```
|
| 6660 |
|
| 6661 |
*Returns:* `x.c < y.c`.
|
| 6662 |
|
| 6663 |
``` cpp
|
| 6664 |
template <class T, class Container>
|
| 6665 |
+
bool operator<=(const stack<T, Container>& x, const stack<T, Container>& y);
|
|
|
|
| 6666 |
```
|
| 6667 |
|
| 6668 |
*Returns:* `x.c <= y.c`.
|
| 6669 |
|
| 6670 |
``` cpp
|
| 6671 |
template <class T, class Container>
|
| 6672 |
+
bool operator> (const stack<T, Container>& x, const stack<T, Container>& y);
|
|
|
|
| 6673 |
```
|
| 6674 |
|
| 6675 |
*Returns:* `x.c > y.c`.
|
| 6676 |
|
| 6677 |
``` cpp
|
| 6678 |
template <class T, class Container>
|
| 6679 |
+
bool operator>=(const stack<T, Container>& x, const stack<T, Container>& y);
|
|
|
|
| 6680 |
```
|
| 6681 |
|
| 6682 |
*Returns:* `x.c >= y.c`.
|
| 6683 |
|
| 6684 |
#### `stack` specialized algorithms <a id="stack.special">[[stack.special]]</a>
|
|
|
|
| 6686 |
``` cpp
|
| 6687 |
template <class T, class Container>
|
| 6688 |
void swap(stack<T, Container>& x, stack<T, Container>& y) noexcept(noexcept(x.swap(y)));
|
| 6689 |
```
|
| 6690 |
|
| 6691 |
+
*Remarks:* This function shall not participate in overload resolution
|
| 6692 |
+
unless `is_swappable_v<Container>` is `true`.
|
| 6693 |
+
|
| 6694 |
+
*Effects:* As if by `x.swap(y)`.
|
| 6695 |
|
| 6696 |
<!-- Link reference definitions -->
|
| 6697 |
[alg.sorting]: algorithms.md#alg.sorting
|
| 6698 |
[algorithm.stable]: library.md#algorithm.stable
|
| 6699 |
[algorithms]: algorithms.md#algorithms
|
| 6700 |
[allocator.requirements]: library.md#allocator.requirements
|
| 6701 |
+
[allocator.requirements.completeness]: library.md#allocator.requirements.completeness
|
| 6702 |
[allocator.traits.members]: utilities.md#allocator.traits.members
|
| 6703 |
[array]: #array
|
| 6704 |
[array.cons]: #array.cons
|
| 6705 |
[array.data]: #array.data
|
| 6706 |
[array.fill]: #array.fill
|
| 6707 |
[array.overview]: #array.overview
|
| 6708 |
[array.size]: #array.size
|
| 6709 |
[array.special]: #array.special
|
| 6710 |
[array.swap]: #array.swap
|
| 6711 |
+
[array.syn]: #array.syn
|
| 6712 |
[array.tuple]: #array.tuple
|
| 6713 |
[array.zero]: #array.zero
|
| 6714 |
[associative]: #associative
|
| 6715 |
[associative.general]: #associative.general
|
| 6716 |
[associative.map.syn]: #associative.map.syn
|
|
|
|
| 6721 |
[class.copy]: special.md#class.copy
|
| 6722 |
[class.ctor]: special.md#class.ctor
|
| 6723 |
[class.dtor]: special.md#class.dtor
|
| 6724 |
[container.adaptors]: #container.adaptors
|
| 6725 |
[container.adaptors.general]: #container.adaptors.general
|
| 6726 |
+
[container.insert.return]: #container.insert.return
|
| 6727 |
+
[container.node]: #container.node
|
| 6728 |
+
[container.node.cons]: #container.node.cons
|
| 6729 |
+
[container.node.dtor]: #container.node.dtor
|
| 6730 |
+
[container.node.modifiers]: #container.node.modifiers
|
| 6731 |
+
[container.node.observers]: #container.node.observers
|
| 6732 |
+
[container.node.overview]: #container.node.overview
|
| 6733 |
[container.requirements]: #container.requirements
|
| 6734 |
[container.requirements.dataraces]: #container.requirements.dataraces
|
| 6735 |
[container.requirements.general]: #container.requirements.general
|
| 6736 |
[containers]: #containers
|
| 6737 |
[containers.general]: #containers.general
|
|
|
|
| 6740 |
[deque.capacity]: #deque.capacity
|
| 6741 |
[deque.cons]: #deque.cons
|
| 6742 |
[deque.modifiers]: #deque.modifiers
|
| 6743 |
[deque.overview]: #deque.overview
|
| 6744 |
[deque.special]: #deque.special
|
| 6745 |
+
[deque.syn]: #deque.syn
|
| 6746 |
[forward.iterators]: iterators.md#forward.iterators
|
| 6747 |
+
[forward_list.syn]: #forward_list.syn
|
| 6748 |
[forwardlist]: #forwardlist
|
| 6749 |
[forwardlist.access]: #forwardlist.access
|
| 6750 |
[forwardlist.cons]: #forwardlist.cons
|
| 6751 |
[forwardlist.iter]: #forwardlist.iter
|
| 6752 |
[forwardlist.modifiers]: #forwardlist.modifiers
|
| 6753 |
[forwardlist.ops]: #forwardlist.ops
|
| 6754 |
[forwardlist.overview]: #forwardlist.overview
|
| 6755 |
[forwardlist.spec]: #forwardlist.spec
|
| 6756 |
[hash.requirements]: library.md#hash.requirements
|
| 6757 |
[iterator.requirements]: iterators.md#iterator.requirements
|
| 6758 |
+
[iterator.requirements.general]: iterators.md#iterator.requirements.general
|
| 6759 |
[list]: #list
|
| 6760 |
[list.capacity]: #list.capacity
|
| 6761 |
[list.cons]: #list.cons
|
| 6762 |
[list.modifiers]: #list.modifiers
|
| 6763 |
[list.ops]: #list.ops
|
| 6764 |
[list.overview]: #list.overview
|
| 6765 |
[list.special]: #list.special
|
| 6766 |
+
[list.syn]: #list.syn
|
| 6767 |
[map]: #map
|
| 6768 |
[map.access]: #map.access
|
| 6769 |
[map.cons]: #map.cons
|
| 6770 |
[map.modifiers]: #map.modifiers
|
| 6771 |
[map.overview]: #map.overview
|
|
|
|
| 6789 |
[queue.cons.alloc]: #queue.cons.alloc
|
| 6790 |
[queue.defn]: #queue.defn
|
| 6791 |
[queue.ops]: #queue.ops
|
| 6792 |
[queue.special]: #queue.special
|
| 6793 |
[queue.syn]: #queue.syn
|
| 6794 |
+
[random.access.iterators]: iterators.md#random.access.iterators
|
| 6795 |
[res.on.data.races]: library.md#res.on.data.races
|
| 6796 |
[sequence.reqmts]: #sequence.reqmts
|
| 6797 |
[sequences]: #sequences
|
| 6798 |
[sequences.general]: #sequences.general
|
| 6799 |
[set]: #set
|
|
|
|
| 6806 |
[stack.defn]: #stack.defn
|
| 6807 |
[stack.ops]: #stack.ops
|
| 6808 |
[stack.special]: #stack.special
|
| 6809 |
[stack.syn]: #stack.syn
|
| 6810 |
[strings]: strings.md#strings
|
| 6811 |
+
[swappable.requirements]: library.md#swappable.requirements
|
| 6812 |
[tab:HashRequirements]: #tab:HashRequirements
|
| 6813 |
[tab:containers.allocatoraware]: #tab:containers.allocatoraware
|
| 6814 |
[tab:containers.associative.requirements]: #tab:containers.associative.requirements
|
| 6815 |
[tab:containers.container.requirements]: #tab:containers.container.requirements
|
| 6816 |
[tab:containers.lib.summary]: #tab:containers.lib.summary
|
| 6817 |
+
[tab:containers.node.compat]: #tab:containers.node.compat
|
| 6818 |
[tab:containers.optional.operations]: #tab:containers.optional.operations
|
| 6819 |
[tab:containers.reversible.requirements]: #tab:containers.reversible.requirements
|
| 6820 |
[tab:containers.sequence.optional]: #tab:containers.sequence.optional
|
| 6821 |
[tab:containers.sequence.requirements]: #tab:containers.sequence.requirements
|
| 6822 |
[temp.deduct]: temp.md#temp.deduct
|
|
|
|
| 6852 |
[vector.cons]: #vector.cons
|
| 6853 |
[vector.data]: #vector.data
|
| 6854 |
[vector.modifiers]: #vector.modifiers
|
| 6855 |
[vector.overview]: #vector.overview
|
| 6856 |
[vector.special]: #vector.special
|
| 6857 |
+
[vector.syn]: #vector.syn
|
| 6858 |
|
| 6859 |
[^1]: Equality comparison is a refinement of partitioning if no two
|
| 6860 |
objects that compare equal fall into different partitions.
|
| 6861 |
|
| 6862 |
[^2]: These member functions are only provided by containers whose
|