- tmp/tmp9l4jhjm7/{from.md → to.md} +477 -155
tmp/tmp9l4jhjm7/{from.md → to.md}
RENAMED
|
@@ -5,46 +5,53 @@
|
|
| 5 |
Containers are objects that store other objects. They control allocation
|
| 6 |
and deallocation of these objects through constructors, destructors,
|
| 7 |
insert and erase operations.
|
| 8 |
|
| 9 |
All of the complexity requirements in this Clause are stated solely in
|
| 10 |
-
terms of the number of operations on the contained objects.
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
linear
|
|
|
|
| 14 |
|
| 15 |
For the components affected by this subclause that declare an
|
| 16 |
`allocator_type`, objects stored in these components shall be
|
| 17 |
-
constructed using the
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 25 |
|
| 26 |
In Tables [[tab:containers.container.requirements]],
|
| 27 |
[[tab:containers.reversible.requirements]], and
|
| 28 |
[[tab:containers.optional.operations]] `X` denotes a container class
|
| 29 |
containing objects of type `T`, `a` and `b` denote values of type `X`,
|
| 30 |
`u` denotes an identifier, `r` denotes a non-const value of type `X`,
|
| 31 |
and `rv` denotes a non-const rvalue of type `X`.
|
| 32 |
|
| 33 |
-
Notes: the algorithm `equal()` is defined in Clause [[algorithms]].
|
| 34 |
Those entries marked “(Note A)” or “(Note B)” have linear complexity for
|
| 35 |
`array` and have constant complexity for all other standard containers.
|
| 36 |
|
|
|
|
|
|
|
|
|
|
| 37 |
The member function `size()` returns the number of elements in the
|
| 38 |
container. The number of elements is defined by the rules of
|
| 39 |
constructors, inserts, and erases.
|
| 40 |
|
| 41 |
`begin()`
|
| 42 |
|
| 43 |
returns an iterator referring to the first element in the container.
|
| 44 |
`end()` returns an iterator which is the past-the-end value for the
|
| 45 |
-
container. If the container is empty, then `begin() == end()`
|
| 46 |
|
| 47 |
In the expressions
|
| 48 |
|
| 49 |
``` cpp
|
| 50 |
i == j
|
|
@@ -60,50 +67,59 @@ where `i` and `j` denote objects of a container’s `iterator` type,
|
|
| 60 |
either or both may be replaced by an object of the container’s
|
| 61 |
`const_iterator` type referring to the same element with no change in
|
| 62 |
semantics.
|
| 63 |
|
| 64 |
Unless otherwise specified, all containers defined in this clause obtain
|
| 65 |
-
memory using an allocator (see [[allocator.requirements]]).
|
| 66 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 67 |
`allocator_traits<allocator_type>::select_on_container_copy_construction`
|
| 68 |
on the allocator belonging to the container being copied. Move
|
| 69 |
constructors obtain an allocator by move construction from the allocator
|
| 70 |
belonging to the container being moved. Such move construction of the
|
| 71 |
allocator shall not exit via an exception. All other constructors for
|
| 72 |
-
these container types take a `const allocator_type&` argument.
|
| 73 |
-
|
| 74 |
-
|
| 75 |
-
|
| 76 |
-
|
| 77 |
-
|
| 78 |
-
|
| 79 |
-
|
| 80 |
-
|
|
|
|
|
|
|
|
|
|
| 81 |
`allocator_traits<allocator_type>::propagate_on_container_copy_assignment::value`,
|
| 82 |
`allocator_traits<allocator_type>::propagate_on_container_move_assignment::value`,
|
| 83 |
or
|
| 84 |
`allocator_traits<allocator_type>::propagate_on_container_swap::value`
|
| 85 |
-
is true within the implementation of the corresponding container
|
| 86 |
-
operation.
|
| 87 |
-
undefined unless the objects being swapped have allocators that compare
|
| 88 |
-
equal or
|
| 89 |
-
`allocator_traits<allocator_type>::propagate_on_container_swap::value`
|
| 90 |
-
is true. In all container types defined in this Clause, the member
|
| 91 |
`get_allocator()` returns a copy of the allocator used to construct the
|
| 92 |
container or, if that allocator has been replaced, a copy of the most
|
| 93 |
recent replacement.
|
| 94 |
|
| 95 |
The expression `a.swap(b)`, for containers `a` and `b` of a standard
|
| 96 |
container type other than `array`, shall exchange the values of `a` and
|
| 97 |
`b` without invoking any move, copy, or swap operations on the
|
| 98 |
-
individual container elements.
|
| 99 |
-
belonging to `a` and `b` shall be swappable and shall be
|
| 100 |
-
|
|
|
|
| 101 |
`allocator_traits<allocator_type>::propagate_on_container_swap::value`
|
| 102 |
-
is `true`, then
|
| 103 |
-
|
| 104 |
-
|
|
|
|
| 105 |
`a.get_allocator() == b.get_allocator()`. Every iterator referring to an
|
| 106 |
element in one container before the swap shall refer to the same element
|
| 107 |
in the other container after the swap. It is unspecified whether an
|
| 108 |
iterator with value `a.end()` before the swap will have value `b.end()`
|
| 109 |
after the swap.
|
|
@@ -128,39 +144,45 @@ requirements:
|
|
| 128 |
- no copy constructor or assignment operator of a returned iterator
|
| 129 |
throws an exception.
|
| 130 |
- no `swap()` function throws an exception.
|
| 131 |
- no `swap()` function invalidates any references, pointers, or
|
| 132 |
iterators referring to the elements of the containers being swapped.
|
| 133 |
-
The `end()` iterator does not refer to any element, so it
|
| 134 |
-
invalidated.
|
| 135 |
|
| 136 |
Unless otherwise specified (either explicitly or by defining a function
|
| 137 |
in terms of other functions), invoking a container member function or
|
| 138 |
passing a container as an argument to a library function shall not
|
| 139 |
invalidate iterators to, or change the values of, objects within that
|
| 140 |
container.
|
| 141 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 142 |
Table [[tab:containers.optional.operations]] lists operations that are
|
| 143 |
provided for some types of containers but not others. Those containers
|
| 144 |
for which the listed operations are provided shall implement the
|
| 145 |
semantics described in Table [[tab:containers.optional.operations]]
|
| 146 |
unless otherwise stated.
|
| 147 |
|
| 148 |
-
Note:
|
| 149 |
-
[[algorithms]].
|
| 150 |
|
| 151 |
-
All of the containers defined in this Clause and in
|
| 152 |
except `array` meet the additional requirements of an allocator-aware
|
| 153 |
container, as described in Table [[tab:containers.allocatoraware]].
|
| 154 |
|
| 155 |
-
Given
|
| 156 |
-
|
| 157 |
-
|
| 158 |
-
`
|
| 159 |
-
`
|
| 160 |
-
`
|
| 161 |
-
|
|
|
|
| 162 |
|
| 163 |
- `T` is *`DefaultInsertable` into `X`* means that the following
|
| 164 |
expression is well-formed:
|
| 165 |
``` cpp
|
| 166 |
allocator_traits<A>::construct(m, p)
|
|
@@ -179,11 +201,13 @@ specializations of `std::allocator<T>` are not instantiated:
|
|
| 179 |
allocator_traits<A>::construct(m, p, rv)
|
| 180 |
```
|
| 181 |
|
| 182 |
and its evaluation causes the following postcondition to hold: The
|
| 183 |
value of `*p` is equivalent to the value of `rv` before the
|
| 184 |
-
evaluation.
|
|
|
|
|
|
|
| 185 |
- `T` is *`CopyInsertable` into `X`* means that, in addition to `T`
|
| 186 |
being `MoveInsertable` into `X`, the following expression is
|
| 187 |
well-formed:
|
| 188 |
``` cpp
|
| 189 |
allocator_traits<A>::construct(m, p, v)
|
|
@@ -200,40 +224,56 @@ specializations of `std::allocator<T>` are not instantiated:
|
|
| 200 |
well-formed:
|
| 201 |
``` cpp
|
| 202 |
allocator_traits<A>::destroy(m, p)
|
| 203 |
```
|
| 204 |
|
| 205 |
-
|
| 206 |
-
construct
|
| 207 |
-
`
|
| 208 |
-
|
|
|
|
| 209 |
|
| 210 |
In Table [[tab:containers.allocatoraware]], `X` denotes an
|
| 211 |
allocator-aware container class with a `value_type` of `T` using
|
| 212 |
allocator of type `A`, `u` denotes a variable, `a` and `b` denote
|
| 213 |
non-const lvalues of type `X`, `t` denotes an lvalue or a const rvalue
|
| 214 |
of type `X`, `rv` denotes a non-const rvalue of type `X`, and `m` is a
|
| 215 |
value of type `A`.
|
| 216 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 217 |
### Container data races <a id="container.requirements.dataraces">[[container.requirements.dataraces]]</a>
|
| 218 |
|
| 219 |
For purposes of avoiding data races ([[res.on.data.races]]),
|
| 220 |
implementations shall consider the following functions to be `const`:
|
| 221 |
`begin`, `end`, `rbegin`, `rend`, `front`, `back`, `data`, `find`,
|
| 222 |
`lower_bound`, `upper_bound`, `equal_range`, `at` and, except in
|
| 223 |
associative or unordered associative containers, `operator[]`.
|
| 224 |
|
| 225 |
-
Notwithstanding
|
| 226 |
-
|
| 227 |
-
|
| 228 |
-
|
| 229 |
|
| 230 |
-
For a `vector<int> x` with a size greater than one,
|
| 231 |
-
`*x.begin() = 10` can be executed concurrently without a
|
| 232 |
-
`x[0] = 5` and `*x.begin() = 10` executed concurrently
|
| 233 |
-
data race. As an exception to the general rule, for a
|
| 234 |
-
`y[0] = true` may race with
|
|
|
|
| 235 |
|
| 236 |
### Sequence containers <a id="sequence.reqmts">[[sequence.reqmts]]</a>
|
| 237 |
|
| 238 |
A sequence container organizes a finite set of objects, all of the same
|
| 239 |
type, into a strictly linear arrangement. The library provides four
|
|
@@ -253,30 +293,28 @@ deletions from the middle of the sequence. `deque` is the data structure
|
|
| 253 |
of choice when most insertions and deletions take place at the beginning
|
| 254 |
or at the end of the sequence.
|
| 255 |
|
| 256 |
In Tables [[tab:containers.sequence.requirements]] and
|
| 257 |
[[tab:containers.sequence.optional]], `X` denotes a sequence container
|
| 258 |
-
class, `a` denotes a value of `X` containing elements of type `T`,
|
| 259 |
-
|
| 260 |
-
|
| 261 |
-
|
| 262 |
-
`
|
| 263 |
-
|
| 264 |
-
|
| 265 |
-
|
| 266 |
-
|
| 267 |
-
|
| 268 |
-
|
| 269 |
-
|
|
|
|
|
|
|
|
|
|
| 270 |
|
| 271 |
The complexities of the expressions are sequence dependent.
|
| 272 |
|
| 273 |
-
`iterator`
|
| 274 |
-
|
| 275 |
-
and `const_iterator` types for sequence containers shall be at least of
|
| 276 |
-
the forward iterator category.
|
| 277 |
-
|
| 278 |
The iterator returned from `a.insert(p, t)` points to the copy of `t`
|
| 279 |
inserted into `a`.
|
| 280 |
|
| 281 |
The iterator returned from `a.insert(p, rv)` points to the copy of `rv`
|
| 282 |
inserted into `a`.
|
|
@@ -306,45 +344,271 @@ For every sequence container defined in this Clause and in Clause
|
|
| 306 |
|
| 307 |
- If the constructor
|
| 308 |
``` cpp
|
| 309 |
template <class InputIterator>
|
| 310 |
X(InputIterator first, InputIterator last,
|
| 311 |
-
|
| 312 |
```
|
| 313 |
|
| 314 |
is called with a type `InputIterator` that does not qualify as an
|
| 315 |
input iterator, then the constructor shall not participate in overload
|
| 316 |
resolution.
|
| 317 |
- If the member functions of the forms:
|
| 318 |
``` cpp
|
| 319 |
-
template <class InputIterator>
|
| 320 |
-
|
|
|
|
| 321 |
|
| 322 |
-
template <class InputIterator>
|
| 323 |
-
|
| 324 |
|
| 325 |
-
template <class InputIterator>
|
| 326 |
-
|
|
|
|
| 327 |
```
|
| 328 |
|
| 329 |
are called with a type `InputIterator` that does not qualify as an
|
| 330 |
input iterator, then these functions shall not participate in overload
|
| 331 |
resolution.
|
| 332 |
-
|
| 333 |
-
|
| 334 |
-
|
| 335 |
-
|
|
|
|
|
|
|
| 336 |
|
| 337 |
Table [[tab:containers.sequence.optional]] lists operations that are
|
| 338 |
provided for some types of sequence containers but not others. An
|
| 339 |
implementation shall provide these operations for all container types
|
| 340 |
shown in the “container” column, and shall implement them so as to take
|
| 341 |
amortized constant time.
|
| 342 |
|
| 343 |
The member function `at()` provides bounds-checked access to container
|
| 344 |
elements. `at()` throws `out_of_range` if `n >= a.size()`.
|
| 345 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 346 |
### Associative containers <a id="associative.reqmts">[[associative.reqmts]]</a>
|
| 347 |
|
| 348 |
Associative containers provide fast retrieval of data based on keys. The
|
| 349 |
library provides four basic kinds of associative containers: `set`,
|
| 350 |
`multiset`, `map` and `multimap`.
|
|
@@ -376,65 +640,82 @@ For `set` and `multiset` the value type is the same as the key type. For
|
|
| 376 |
|
| 377 |
of an associative container is of the bidirectional iterator category.
|
| 378 |
For associative containers where the value type is the same as the key
|
| 379 |
type, both `iterator` and `const_iterator` are constant iterators. It is
|
| 380 |
unspecified whether or not `iterator` and `const_iterator` are the same
|
| 381 |
-
type.
|
| 382 |
-
|
| 383 |
-
|
| 384 |
-
|
|
|
|
|
|
|
| 385 |
|
| 386 |
The associative containers meet all the requirements of Allocator-aware
|
| 387 |
containers ([[container.requirements.general]]), except that for `map`
|
| 388 |
and `multimap`, the requirements placed on `value_type` in Table
|
| 389 |
[[tab:containers.container.requirements]] apply instead to `key_type`
|
| 390 |
-
and `mapped_type`.
|
| 391 |
-
|
| 392 |
-
|
| 393 |
-
`CopyAssignable`
|
|
|
|
|
|
|
| 394 |
|
| 395 |
In Table [[tab:containers.associative.requirements]], `X` denotes an
|
| 396 |
-
associative container class, `a` denotes a value of `X`, `
|
| 397 |
-
denotes a value of
|
| 398 |
-
|
| 399 |
-
|
| 400 |
-
|
| 401 |
-
|
| 402 |
-
|
| 403 |
-
|
| 404 |
-
|
| 405 |
-
|
| 406 |
-
|
| 407 |
-
|
| 408 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 409 |
`c(r, kl)`, with `r` the key value of `e` and `e` in `a`; `ku` is a
|
| 410 |
value such that `a` is partitioned with respect to `!c(ku, r)`; `ke` is
|
| 411 |
a value such that `a` is partitioned with respect to `c(r, ke)` and
|
| 412 |
`!c(ke, r)`, with `c(r, ke)` implying `!c(ke, r)`. `A` denotes the
|
| 413 |
-
storage allocator used by `X`, if any, or
|
| 414 |
-
|
| 415 |
-
|
| 416 |
|
| 417 |
The `insert` and `emplace` members shall not affect the validity of
|
| 418 |
iterators and references to the container, and the `erase` members shall
|
| 419 |
invalidate only iterators and references to the erased elements.
|
| 420 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 421 |
The fundamental property of iterators of associative containers is that
|
| 422 |
they iterate through the containers in the non-descending order of keys
|
| 423 |
where non-descending is defined by the comparison that was used to
|
| 424 |
construct them. For any two dereferenceable iterators `i` and `j` such
|
| 425 |
-
that distance from `i` to `j` is positive,
|
|
|
|
| 426 |
|
| 427 |
``` cpp
|
| 428 |
value_comp(*j, *i) == false
|
| 429 |
```
|
| 430 |
|
| 431 |
For associative containers with unique keys the stronger condition
|
| 432 |
-
holds
|
| 433 |
|
| 434 |
``` cpp
|
| 435 |
-
value_comp(*i, *j) != false
|
| 436 |
```
|
| 437 |
|
| 438 |
When an associative container is constructed by passing a comparison
|
| 439 |
object the container shall not store a pointer or reference to the
|
| 440 |
passed object, even if that object is passed by reference. When an
|
|
@@ -443,13 +724,23 @@ assignment operator, the target container shall then use the comparison
|
|
| 443 |
object from the container being copied, as if that comparison object had
|
| 444 |
been passed to the target container in its constructor.
|
| 445 |
|
| 446 |
The member function templates `find`, `count`, `lower_bound`,
|
| 447 |
`upper_bound`, and `equal_range` shall not participate in overload
|
| 448 |
-
resolution unless the qualified-id `Compare::is_transparent` is valid
|
| 449 |
and denotes a type ([[temp.deduct]]).
|
| 450 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 451 |
#### Exception safety guarantees <a id="associative.reqmts.except">[[associative.reqmts.except]]</a>
|
| 452 |
|
| 453 |
For associative containers, no `clear()` function throws an exception.
|
| 454 |
`erase(k)` does not throw an exception unless that exception is thrown
|
| 455 |
by the container’s `Compare` object (if any).
|
|
@@ -489,42 +780,47 @@ the *hash function* of the container. The container’s object of type
|
|
| 489 |
the container.
|
| 490 |
|
| 491 |
Two values `k1` and `k2` of type `Key` are considered equivalent if the
|
| 492 |
container’s key equality predicate returns `true` when passed those
|
| 493 |
values. If `k1` and `k2` are equivalent, the container’s hash function
|
| 494 |
-
shall return the same value for both.
|
| 495 |
-
|
| 496 |
-
|
| 497 |
-
|
| 498 |
-
|
| 499 |
-
|
|
|
|
|
|
|
|
|
|
| 500 |
|
| 501 |
An unordered associative container supports *unique keys* if it may
|
| 502 |
contain at most one element for each key. Otherwise, it supports
|
| 503 |
*equivalent keys*. `unordered_set` and `unordered_map` support unique
|
| 504 |
keys. `unordered_multiset` and `unordered_multimap` support equivalent
|
| 505 |
keys. In containers that support equivalent keys, elements with
|
| 506 |
equivalent keys are adjacent to each other in the iteration order of the
|
| 507 |
container. Thus, although the absolute order of elements in an unordered
|
| 508 |
container is not specified, its elements are grouped into
|
| 509 |
-
*equivalent-key
|
| 510 |
equivalent keys. Mutating operations on unordered containers shall
|
| 511 |
preserve the relative order of elements within each equivalent-key group
|
| 512 |
unless otherwise specified.
|
| 513 |
|
| 514 |
For `unordered_set` and `unordered_multiset` the value type is the same
|
| 515 |
as the key type. For `unordered_map` and `unordered_multimap` it is
|
| 516 |
-
`
|
| 517 |
T>`.
|
| 518 |
|
| 519 |
For unordered containers where the value type is the same as the key
|
| 520 |
type, both `iterator` and `const_iterator` are constant iterators. It is
|
| 521 |
unspecified whether or not `iterator` and `const_iterator` are the same
|
| 522 |
-
type.
|
| 523 |
-
|
| 524 |
-
|
| 525 |
-
|
|
|
|
|
|
|
| 526 |
|
| 527 |
The elements of an unordered associative container are organized into
|
| 528 |
*buckets*. Keys with the same hash code appear in the same bucket. The
|
| 529 |
number of buckets is automatically increased as elements are added to an
|
| 530 |
unordered associative container, so that the average number of elements
|
|
@@ -537,37 +833,43 @@ the relative ordering of equivalent elements.
|
|
| 537 |
The unordered associative containers meet all the requirements of
|
| 538 |
Allocator-aware containers ([[container.requirements.general]]), except
|
| 539 |
that for `unordered_map` and `unordered_multimap`, the requirements
|
| 540 |
placed on `value_type` in Table
|
| 541 |
[[tab:containers.container.requirements]] apply instead to `key_type`
|
| 542 |
-
and `mapped_type`.
|
| 543 |
-
sometimes required to be `CopyAssignable` even though the associated
|
| 544 |
-
`value_type`, `pair<const key_type, mapped_type>`, is not
|
| 545 |
-
`CopyAssignable`.
|
| 546 |
|
| 547 |
-
|
| 548 |
-
|
| 549 |
-
|
| 550 |
-
|
| 551 |
-
|
| 552 |
-
|
| 553 |
-
|
| 554 |
-
|
| 555 |
-
|
| 556 |
-
`X
|
| 557 |
-
|
| 558 |
-
|
| 559 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 560 |
|
| 561 |
Two unordered containers `a` and `b` compare equal if
|
| 562 |
`a.size() == b.size()` and, for every equivalent-key group \[`Ea1`,
|
| 563 |
`Ea2`) obtained from `a.equal_range(Ea1)`, there exists an
|
| 564 |
equivalent-key group \[`Eb1`, `Eb2`) obtained from `b.equal_range(Ea1)`,
|
| 565 |
such that `is_permutation(Ea1, Ea2, Eb1, Eb2)` returns `true`. For
|
| 566 |
`unordered_set` and `unordered_map`, the complexity of `operator==`
|
| 567 |
(i.e., the number of calls to the `==` operator of the `value_type`, to
|
| 568 |
-
the predicate returned by `
|
| 569 |
`hash_function()`) is proportional to N in the average case and to N² in
|
| 570 |
the worst case, where N is a.size(). For `unordered_multiset` and
|
| 571 |
`unordered_multimap`, the complexity of `operator==` is proportional to
|
| 572 |
$\sum E_i^2$ in the average case and to N² in the worst case, where N is
|
| 573 |
`a.size()`, and Eᵢ is the size of the iᵗʰ equivalent-key group in `a`.
|
|
@@ -578,31 +880,51 @@ same container), then the average-case complexity for
|
|
| 578 |
`unordered_multiset` and `unordered_multimap` becomes proportional to N
|
| 579 |
(but worst-case complexity remains 𝑂(N^2), e.g., for a pathologically
|
| 580 |
bad hash function). The behavior of a program that uses `operator==` or
|
| 581 |
`operator!=` on unordered containers is undefined unless the `Hash` and
|
| 582 |
`Pred` function objects respectively have the same behavior for both
|
| 583 |
-
containers and the equality comparison
|
| 584 |
refinement[^1] of the partition into equivalent-key groups produced by
|
| 585 |
`Pred`.
|
| 586 |
|
| 587 |
The iterator types `iterator` and `const_iterator` of an unordered
|
| 588 |
associative container are of at least the forward iterator category. For
|
| 589 |
unordered associative containers where the key type and value type are
|
| 590 |
-
the same, both `iterator` and `const_iterator` are
|
| 591 |
|
| 592 |
The `insert` and `emplace` members shall not affect the validity of
|
| 593 |
references to container elements, but may invalidate all iterators to
|
| 594 |
the container. The `erase` members shall invalidate only iterators and
|
| 595 |
references to the erased elements, and preserve the relative order of
|
| 596 |
the elements that are not erased.
|
| 597 |
|
| 598 |
The `insert` and `emplace` members shall not affect the validity of
|
| 599 |
-
iterators if `(N+n) < z * B`, where `N` is the number of elements in
|
| 600 |
-
container prior to the insert operation, `n` is the number of
|
| 601 |
-
inserted, `B` is the container’s bucket count, and `z` is the
|
| 602 |
container’s maximum load factor.
|
| 603 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 604 |
#### Exception safety guarantees <a id="unord.req.except">[[unord.req.except]]</a>
|
| 605 |
|
| 606 |
For unordered associative containers, no `clear()` function throws an
|
| 607 |
exception. `erase(k)` does not throw an exception unless that exception
|
| 608 |
is thrown by the container’s `Hash` or `Pred` object (if any).
|
|
@@ -612,11 +934,11 @@ operation other than the container’s hash function from within an
|
|
| 612 |
`insert` or `emplace` function inserting a single element, the insertion
|
| 613 |
has no effect.
|
| 614 |
|
| 615 |
For unordered associative containers, no `swap` function throws an
|
| 616 |
exception unless that exception is thrown by the swap of the container’s
|
| 617 |
-
Hash or Pred object (if any).
|
| 618 |
|
| 619 |
For unordered associative containers, if an exception is thrown from
|
| 620 |
within a `rehash()` function other than by the container’s hash function
|
| 621 |
or comparison function, the `rehash()` function has no effect.
|
| 622 |
|
|
|
|
| 5 |
Containers are objects that store other objects. They control allocation
|
| 6 |
and deallocation of these objects through constructors, destructors,
|
| 7 |
insert and erase operations.
|
| 8 |
|
| 9 |
All of the complexity requirements in this Clause are stated solely in
|
| 10 |
+
terms of the number of operations on the contained objects.
|
| 11 |
+
|
| 12 |
+
[*Example 1*: The copy constructor of type `vector<vector<int>>` has
|
| 13 |
+
linear complexity, even though the complexity of copying each contained
|
| 14 |
+
`vector<int>` is itself linear. — *end example*]
|
| 15 |
|
| 16 |
For the components affected by this subclause that declare an
|
| 17 |
`allocator_type`, objects stored in these components shall be
|
| 18 |
+
constructed using the function
|
| 19 |
+
`allocator_traits<allocator_type>::rebind_traits<U>::{}construct` and
|
| 20 |
+
destroyed using the function
|
| 21 |
+
`allocator_traits<allocator_type>::rebind_traits<U>::{}destroy` (
|
| 22 |
+
[[allocator.traits.members]]), where `U` is either
|
| 23 |
+
`allocator_type::value_type` or an internal type used by the container.
|
| 24 |
+
These functions are called only for the container’s element type, not
|
| 25 |
+
for internal types used by the container.
|
| 26 |
+
|
| 27 |
+
[*Note 1*: This means, for example, that a node-based container might
|
| 28 |
+
need to construct nodes containing aligned buffers and call `construct`
|
| 29 |
+
to place the element into the buffer. — *end note*]
|
| 30 |
|
| 31 |
In Tables [[tab:containers.container.requirements]],
|
| 32 |
[[tab:containers.reversible.requirements]], and
|
| 33 |
[[tab:containers.optional.operations]] `X` denotes a container class
|
| 34 |
containing objects of type `T`, `a` and `b` denote values of type `X`,
|
| 35 |
`u` denotes an identifier, `r` denotes a non-const value of type `X`,
|
| 36 |
and `rv` denotes a non-const rvalue of type `X`.
|
| 37 |
|
|
|
|
| 38 |
Those entries marked “(Note A)” or “(Note B)” have linear complexity for
|
| 39 |
`array` and have constant complexity for all other standard containers.
|
| 40 |
|
| 41 |
+
[*Note 2*: The algorithm `equal()` is defined in Clause
|
| 42 |
+
[[algorithms]]. — *end note*]
|
| 43 |
+
|
| 44 |
The member function `size()` returns the number of elements in the
|
| 45 |
container. The number of elements is defined by the rules of
|
| 46 |
constructors, inserts, and erases.
|
| 47 |
|
| 48 |
`begin()`
|
| 49 |
|
| 50 |
returns an iterator referring to the first element in the container.
|
| 51 |
`end()` returns an iterator which is the past-the-end value for the
|
| 52 |
+
container. If the container is empty, then `begin() == end()`.
|
| 53 |
|
| 54 |
In the expressions
|
| 55 |
|
| 56 |
``` cpp
|
| 57 |
i == j
|
|
|
|
| 67 |
either or both may be replaced by an object of the container’s
|
| 68 |
`const_iterator` type referring to the same element with no change in
|
| 69 |
semantics.
|
| 70 |
|
| 71 |
Unless otherwise specified, all containers defined in this clause obtain
|
| 72 |
+
memory using an allocator (see [[allocator.requirements]]).
|
| 73 |
+
|
| 74 |
+
[*Note 3*: In particular, containers and iterators do not store
|
| 75 |
+
references to allocated elements other than through the allocator’s
|
| 76 |
+
pointer type, i.e., as objects of type `P` or
|
| 77 |
+
`pointer_traits<P>::template rebind<unspecified>`, where `P` is
|
| 78 |
+
`allocator_traits<allocator_type>::pointer`. — *end note*]
|
| 79 |
+
|
| 80 |
+
Copy constructors for these container types obtain an allocator by
|
| 81 |
+
calling
|
| 82 |
`allocator_traits<allocator_type>::select_on_container_copy_construction`
|
| 83 |
on the allocator belonging to the container being copied. Move
|
| 84 |
constructors obtain an allocator by move construction from the allocator
|
| 85 |
belonging to the container being moved. Such move construction of the
|
| 86 |
allocator shall not exit via an exception. All other constructors for
|
| 87 |
+
these container types take a `const allocator_type&` argument.
|
| 88 |
+
|
| 89 |
+
[*Note 4*: If an invocation of a constructor uses the default value of
|
| 90 |
+
an optional allocator argument, then the `Allocator` type must support
|
| 91 |
+
value-initialization. — *end note*]
|
| 92 |
+
|
| 93 |
+
A copy of this allocator is used for any memory allocation and element
|
| 94 |
+
construction performed, by these constructors and by all member
|
| 95 |
+
functions, during the lifetime of each container object or until the
|
| 96 |
+
allocator is replaced. The allocator may be replaced only via assignment
|
| 97 |
+
or `swap()`. Allocator replacement is performed by copy assignment, move
|
| 98 |
+
assignment, or swapping of the allocator only if
|
| 99 |
`allocator_traits<allocator_type>::propagate_on_container_copy_assignment::value`,
|
| 100 |
`allocator_traits<allocator_type>::propagate_on_container_move_assignment::value`,
|
| 101 |
or
|
| 102 |
`allocator_traits<allocator_type>::propagate_on_container_swap::value`
|
| 103 |
+
is `true` within the implementation of the corresponding container
|
| 104 |
+
operation. In all container types defined in this Clause, the member
|
|
|
|
|
|
|
|
|
|
|
|
|
| 105 |
`get_allocator()` returns a copy of the allocator used to construct the
|
| 106 |
container or, if that allocator has been replaced, a copy of the most
|
| 107 |
recent replacement.
|
| 108 |
|
| 109 |
The expression `a.swap(b)`, for containers `a` and `b` of a standard
|
| 110 |
container type other than `array`, shall exchange the values of `a` and
|
| 111 |
`b` without invoking any move, copy, or swap operations on the
|
| 112 |
+
individual container elements. Lvalues of any `Compare`, `Pred`, or
|
| 113 |
+
`Hash` types belonging to `a` and `b` shall be swappable and shall be
|
| 114 |
+
exchanged by calling `swap` as described in [[swappable.requirements]].
|
| 115 |
+
If
|
| 116 |
`allocator_traits<allocator_type>::propagate_on_container_swap::value`
|
| 117 |
+
is `true`, then lvalues of type `allocator_type` shall be swappable and
|
| 118 |
+
the allocators of `a` and `b` shall also be exchanged by calling `swap`
|
| 119 |
+
as described in [[swappable.requirements]]. Otherwise, the allocators
|
| 120 |
+
shall not be swapped, and the behavior is undefined unless
|
| 121 |
`a.get_allocator() == b.get_allocator()`. Every iterator referring to an
|
| 122 |
element in one container before the swap shall refer to the same element
|
| 123 |
in the other container after the swap. It is unspecified whether an
|
| 124 |
iterator with value `a.end()` before the swap will have value `b.end()`
|
| 125 |
after the swap.
|
|
|
|
| 144 |
- no copy constructor or assignment operator of a returned iterator
|
| 145 |
throws an exception.
|
| 146 |
- no `swap()` function throws an exception.
|
| 147 |
- no `swap()` function invalidates any references, pointers, or
|
| 148 |
iterators referring to the elements of the containers being swapped.
|
| 149 |
+
\[*Note 5*: The `end()` iterator does not refer to any element, so it
|
| 150 |
+
may be invalidated. — *end note*]
|
| 151 |
|
| 152 |
Unless otherwise specified (either explicitly or by defining a function
|
| 153 |
in terms of other functions), invoking a container member function or
|
| 154 |
passing a container as an argument to a library function shall not
|
| 155 |
invalidate iterators to, or change the values of, objects within that
|
| 156 |
container.
|
| 157 |
|
| 158 |
+
A *contiguous container* is a container that supports random access
|
| 159 |
+
iterators ([[random.access.iterators]]) and whose member types
|
| 160 |
+
`iterator` and `const_iterator` are contiguous iterators (
|
| 161 |
+
[[iterator.requirements.general]]).
|
| 162 |
+
|
| 163 |
Table [[tab:containers.optional.operations]] lists operations that are
|
| 164 |
provided for some types of containers but not others. Those containers
|
| 165 |
for which the listed operations are provided shall implement the
|
| 166 |
semantics described in Table [[tab:containers.optional.operations]]
|
| 167 |
unless otherwise stated.
|
| 168 |
|
| 169 |
+
[*Note 6*: The algorithm `lexicographical_compare()` is defined in
|
| 170 |
+
Clause [[algorithms]]. — *end note*]
|
| 171 |
|
| 172 |
+
All of the containers defined in this Clause and in [[basic.string]]
|
| 173 |
except `array` meet the additional requirements of an allocator-aware
|
| 174 |
container, as described in Table [[tab:containers.allocatoraware]].
|
| 175 |
|
| 176 |
+
Given an allocator type `A` and given a container type `X` having a
|
| 177 |
+
`value_type` identical to `T` and an `allocator_type` identical to
|
| 178 |
+
`allocator_traits<A>::rebind_alloc<T>` and given an lvalue `m` of type
|
| 179 |
+
`A`, a pointer `p` of type `T*`, an expression `v` of type (possibly
|
| 180 |
+
`const`) `T`, and an rvalue `rv` of type `T`, the following terms are
|
| 181 |
+
defined. If `X` is not allocator-aware, the terms below are defined as
|
| 182 |
+
if `A` were `allocator<T>` — no allocator object needs to be created and
|
| 183 |
+
user specializations of `allocator<T>` are not instantiated:
|
| 184 |
|
| 185 |
- `T` is *`DefaultInsertable` into `X`* means that the following
|
| 186 |
expression is well-formed:
|
| 187 |
``` cpp
|
| 188 |
allocator_traits<A>::construct(m, p)
|
|
|
|
| 201 |
allocator_traits<A>::construct(m, p, rv)
|
| 202 |
```
|
| 203 |
|
| 204 |
and its evaluation causes the following postcondition to hold: The
|
| 205 |
value of `*p` is equivalent to the value of `rv` before the
|
| 206 |
+
evaluation.
|
| 207 |
+
\[*Note 7*: `rv` remains a valid object. Its state is
|
| 208 |
+
unspecified — *end note*]
|
| 209 |
- `T` is *`CopyInsertable` into `X`* means that, in addition to `T`
|
| 210 |
being `MoveInsertable` into `X`, the following expression is
|
| 211 |
well-formed:
|
| 212 |
``` cpp
|
| 213 |
allocator_traits<A>::construct(m, p, v)
|
|
|
|
| 224 |
well-formed:
|
| 225 |
``` cpp
|
| 226 |
allocator_traits<A>::destroy(m, p)
|
| 227 |
```
|
| 228 |
|
| 229 |
+
[*Note 8*: A container calls
|
| 230 |
+
`allocator_traits<A>::construct(m, p, args)` to construct an element at
|
| 231 |
+
`p` using `args`, with `m == get_allocator()`. The default `construct`
|
| 232 |
+
in `allocator` will call `::new((void*)p) T(args)`, but specialized
|
| 233 |
+
allocators may choose a different definition. — *end note*]
|
| 234 |
|
| 235 |
In Table [[tab:containers.allocatoraware]], `X` denotes an
|
| 236 |
allocator-aware container class with a `value_type` of `T` using
|
| 237 |
allocator of type `A`, `u` denotes a variable, `a` and `b` denote
|
| 238 |
non-const lvalues of type `X`, `t` denotes an lvalue or a const rvalue
|
| 239 |
of type `X`, `rv` denotes a non-const rvalue of type `X`, and `m` is a
|
| 240 |
value of type `A`.
|
| 241 |
|
| 242 |
+
The behavior of certain container member functions and deduction guides
|
| 243 |
+
depends on whether types qualify as input iterators or allocators. The
|
| 244 |
+
extent to which an implementation determines that a type cannot be an
|
| 245 |
+
input iterator is unspecified, except that as a minimum integral types
|
| 246 |
+
shall not qualify as input iterators. Likewise, the extent to which an
|
| 247 |
+
implementation determines that a type cannot be an allocator is
|
| 248 |
+
unspecified, except that as a minimum a type `A` shall not qualify as an
|
| 249 |
+
allocator unless it satisfies both of the following conditions:
|
| 250 |
+
|
| 251 |
+
- The *qualified-id* `A::value_type` is valid and denotes a type (
|
| 252 |
+
[[temp.deduct]]).
|
| 253 |
+
- The expression `declval<A&>().allocate(size_t{})` is well-formed when
|
| 254 |
+
treated as an unevaluated operand.
|
| 255 |
+
|
| 256 |
### Container data races <a id="container.requirements.dataraces">[[container.requirements.dataraces]]</a>
|
| 257 |
|
| 258 |
For purposes of avoiding data races ([[res.on.data.races]]),
|
| 259 |
implementations shall consider the following functions to be `const`:
|
| 260 |
`begin`, `end`, `rbegin`, `rend`, `front`, `back`, `data`, `find`,
|
| 261 |
`lower_bound`, `upper_bound`, `equal_range`, `at` and, except in
|
| 262 |
associative or unordered associative containers, `operator[]`.
|
| 263 |
|
| 264 |
+
Notwithstanding [[res.on.data.races]], implementations are required to
|
| 265 |
+
avoid data races when the contents of the contained object in different
|
| 266 |
+
elements in the same container, excepting `vector<bool>`, are modified
|
| 267 |
+
concurrently.
|
| 268 |
|
| 269 |
+
[*Note 1*: For a `vector<int> x` with a size greater than one,
|
| 270 |
+
`x[1] = 5` and `*x.begin() = 10` can be executed concurrently without a
|
| 271 |
+
data race, but `x[0] = 5` and `*x.begin() = 10` executed concurrently
|
| 272 |
+
may result in a data race. As an exception to the general rule, for a
|
| 273 |
+
`vector<bool> y`, `y[0] = true` may race with
|
| 274 |
+
`y[1] = true`. — *end note*]
|
| 275 |
|
| 276 |
### Sequence containers <a id="sequence.reqmts">[[sequence.reqmts]]</a>
|
| 277 |
|
| 278 |
A sequence container organizes a finite set of objects, all of the same
|
| 279 |
type, into a strictly linear arrangement. The library provides four
|
|
|
|
| 293 |
of choice when most insertions and deletions take place at the beginning
|
| 294 |
or at the end of the sequence.
|
| 295 |
|
| 296 |
In Tables [[tab:containers.sequence.requirements]] and
|
| 297 |
[[tab:containers.sequence.optional]], `X` denotes a sequence container
|
| 298 |
+
class, `a` denotes a value of type `X` containing elements of type `T`,
|
| 299 |
+
`u` denotes the name of a variable being declared, `A` denotes
|
| 300 |
+
`X::allocator_type` if the *qualified-id* `X::allocator_type` is valid
|
| 301 |
+
and denotes a type ([[temp.deduct]]) and `allocator<T>` if it doesn’t,
|
| 302 |
+
`i` and `j` denote iterators satisfying input iterator requirements and
|
| 303 |
+
refer to elements implicitly convertible to `value_type`, `[i, j)`
|
| 304 |
+
denotes a valid range, `il` designates an object of type
|
| 305 |
+
`initializer_list<value_type>`, `n` denotes a value of type
|
| 306 |
+
`X::size_type`, `p` denotes a valid constant iterator to `a`, `q`
|
| 307 |
+
denotes a valid dereferenceable constant iterator to `a`, `[q1, q2)`
|
| 308 |
+
denotes a valid range of constant iterators in `a`, `t` denotes an
|
| 309 |
+
lvalue or a const rvalue of `X::value_type`, and `rv` denotes a
|
| 310 |
+
non-const rvalue of `X::value_type`. `Args` denotes a template parameter
|
| 311 |
+
pack; `args` denotes a function parameter pack with the pattern
|
| 312 |
+
`Args&&`.
|
| 313 |
|
| 314 |
The complexities of the expressions are sequence dependent.
|
| 315 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 316 |
The iterator returned from `a.insert(p, t)` points to the copy of `t`
|
| 317 |
inserted into `a`.
|
| 318 |
|
| 319 |
The iterator returned from `a.insert(p, rv)` points to the copy of `rv`
|
| 320 |
inserted into `a`.
|
|
|
|
| 344 |
|
| 345 |
- If the constructor
|
| 346 |
``` cpp
|
| 347 |
template <class InputIterator>
|
| 348 |
X(InputIterator first, InputIterator last,
|
| 349 |
+
const allocator_type& alloc = allocator_type());
|
| 350 |
```
|
| 351 |
|
| 352 |
is called with a type `InputIterator` that does not qualify as an
|
| 353 |
input iterator, then the constructor shall not participate in overload
|
| 354 |
resolution.
|
| 355 |
- If the member functions of the forms:
|
| 356 |
``` cpp
|
| 357 |
+
template <class InputIterator>
|
| 358 |
+
return-type F(const_iterator p,
|
| 359 |
+
InputIterator first, InputIterator last); // such as insert
|
| 360 |
|
| 361 |
+
template <class InputIterator>
|
| 362 |
+
return-type F(InputIterator first, InputIterator last); // such as append, assign
|
| 363 |
|
| 364 |
+
template <class InputIterator>
|
| 365 |
+
return-type F(const_iterator i1, const_iterator i2,
|
| 366 |
+
InputIterator first, InputIterator last); // such as replace
|
| 367 |
```
|
| 368 |
|
| 369 |
are called with a type `InputIterator` that does not qualify as an
|
| 370 |
input iterator, then these functions shall not participate in overload
|
| 371 |
resolution.
|
| 372 |
+
- A deduction guide for a sequence container shall not participate in
|
| 373 |
+
overload resolution if it has an `InputIterator` template parameter
|
| 374 |
+
and a type that does not qualify as an input iterator is deduced for
|
| 375 |
+
that parameter, or if it has an `Allocator` template parameter and a
|
| 376 |
+
type that does not qualify as an allocator is deduced for that
|
| 377 |
+
parameter.
|
| 378 |
|
| 379 |
Table [[tab:containers.sequence.optional]] lists operations that are
|
| 380 |
provided for some types of sequence containers but not others. An
|
| 381 |
implementation shall provide these operations for all container types
|
| 382 |
shown in the “container” column, and shall implement them so as to take
|
| 383 |
amortized constant time.
|
| 384 |
|
| 385 |
The member function `at()` provides bounds-checked access to container
|
| 386 |
elements. `at()` throws `out_of_range` if `n >= a.size()`.
|
| 387 |
|
| 388 |
+
### Node handles <a id="container.node">[[container.node]]</a>
|
| 389 |
+
|
| 390 |
+
#### `node_handle` overview <a id="container.node.overview">[[container.node.overview]]</a>
|
| 391 |
+
|
| 392 |
+
A *node handle* is an object that accepts ownership of a single element
|
| 393 |
+
from an associative container ([[associative.reqmts]]) or an unordered
|
| 394 |
+
associative container ([[unord.req]]). It may be used to transfer that
|
| 395 |
+
ownership to another container with compatible nodes. Containers with
|
| 396 |
+
compatible nodes have the same node handle type. Elements may be
|
| 397 |
+
transferred in either direction between container types in the same row
|
| 398 |
+
of Table [[tab:containers.node.compat]].
|
| 399 |
+
|
| 400 |
+
**Table: Container types with compatible nodes** <a id="tab:containers.node.compat">[tab:containers.node.compat]</a>
|
| 401 |
+
|
| 402 |
+
| | |
|
| 403 |
+
| -------------------------------- | ------------------------------------- |
|
| 404 |
+
| `map<K, T, C1, A>` | `map<K, T, C2, A>` |
|
| 405 |
+
| `map<K, T, C1, A>` | `multimap<K, T, C2, A>` |
|
| 406 |
+
| `set<K, C1, A>` | `set<K, C2, A>` |
|
| 407 |
+
| `set<K, C1, A>` | `multiset<K, C2, A>` |
|
| 408 |
+
| `unordered_map<K, T, H1, E1, A>` | `unordered_map<K, T, H2, E2, A>` |
|
| 409 |
+
| `unordered_map<K, T, H1, E1, A>` | `unordered_multimap<K, T, H2, E2, A>` |
|
| 410 |
+
| `unordered_set<K, H1, E1, A>` | `unordered_set<K, H2, E2, A>` |
|
| 411 |
+
| `unordered_set<K, H1, E1, A>` | `unordered_multiset<K, H2, E2, A>` |
|
| 412 |
+
|
| 413 |
+
|
| 414 |
+
If a node handle is not empty, then it contains an allocator that is
|
| 415 |
+
equal to the allocator of the container when the element was extracted.
|
| 416 |
+
If a node handle is empty, it contains no allocator.
|
| 417 |
+
|
| 418 |
+
Class `node_handle` is for exposition only. An implementation is
|
| 419 |
+
permitted to provide equivalent functionality without providing a class
|
| 420 |
+
with this name.
|
| 421 |
+
|
| 422 |
+
If a user-defined specialization of `pair` exists for
|
| 423 |
+
`pair<const Key, T>` or `pair<Key, T>`, where `Key` is the container’s
|
| 424 |
+
`key_type` and `T` is the container’s `mapped_type`, the behavior of
|
| 425 |
+
operations involving node handles is undefined.
|
| 426 |
+
|
| 427 |
+
``` cpp
|
| 428 |
+
template<unspecified>
|
| 429 |
+
class node_handle {
|
| 430 |
+
public:
|
| 431 |
+
// These type declarations are described in Tables [tab:containers.associative.requirements] and [tab:HashRequirements].
|
| 432 |
+
using value_type = see below; // not present for map containers
|
| 433 |
+
using key_type = see below; // not present for set containers
|
| 434 |
+
using mapped_type = see below; // not present for set containers
|
| 435 |
+
using allocator_type = see below;
|
| 436 |
+
|
| 437 |
+
private:
|
| 438 |
+
using container_node_type = unspecified;
|
| 439 |
+
using ator_traits = allocator_traits<allocator_type>;
|
| 440 |
+
|
| 441 |
+
typename ator_traits::rebind_traits<container_node_type>::pointer ptr_;
|
| 442 |
+
optional<allocator_type> alloc_;
|
| 443 |
+
|
| 444 |
+
public:
|
| 445 |
+
constexpr node_handle() noexcept : ptr_(), alloc_() {}
|
| 446 |
+
~node_handle();
|
| 447 |
+
node_handle(node_handle&&) noexcept;
|
| 448 |
+
node_handle& operator=(node_handle&&);
|
| 449 |
+
|
| 450 |
+
value_type& value() const; // not present for map containers
|
| 451 |
+
key_type& key() const; // not present for set containers
|
| 452 |
+
mapped_type& mapped() const; // not present for set containers
|
| 453 |
+
|
| 454 |
+
allocator_type get_allocator() const;
|
| 455 |
+
explicit operator bool() const noexcept;
|
| 456 |
+
bool empty() const noexcept;
|
| 457 |
+
|
| 458 |
+
void swap(node_handle&)
|
| 459 |
+
noexcept(ator_traits::propagate_on_container_swap::value ||
|
| 460 |
+
ator_traits::is_always_equal::value);
|
| 461 |
+
|
| 462 |
+
friend void swap(node_handle& x, node_handle& y) noexcept(noexcept(x.swap(y))) {
|
| 463 |
+
x.swap(y);
|
| 464 |
+
}
|
| 465 |
+
};
|
| 466 |
+
```
|
| 467 |
+
|
| 468 |
+
#### `node_handle` constructors, copy, and assignment <a id="container.node.cons">[[container.node.cons]]</a>
|
| 469 |
+
|
| 470 |
+
``` cpp
|
| 471 |
+
node_handle(node_handle&& nh) noexcept;
|
| 472 |
+
```
|
| 473 |
+
|
| 474 |
+
*Effects:* Constructs a *`node_handle`* object initializing `ptr_` with
|
| 475 |
+
`nh.ptr_`. Move constructs `alloc_` with `nh.alloc_`. Assigns `nullptr`
|
| 476 |
+
to `nh.ptr_` and assigns `nullopt` to `nh.alloc_`.
|
| 477 |
+
|
| 478 |
+
``` cpp
|
| 479 |
+
node_handle& operator=(node_handle&& nh);
|
| 480 |
+
```
|
| 481 |
+
|
| 482 |
+
*Requires:* Either `!alloc_`, or
|
| 483 |
+
`ator_traits::propagate_on_container_move_assignment` is `true`, or
|
| 484 |
+
`alloc_ == nh.alloc_`.
|
| 485 |
+
|
| 486 |
+
*Effects:*
|
| 487 |
+
|
| 488 |
+
- If `ptr_ != nullptr`, destroys the `value_type` subobject in the
|
| 489 |
+
`container_node_type` object pointed to by `ptr_` by calling
|
| 490 |
+
`ator_traits::destroy`, then deallocates `ptr_` by calling
|
| 491 |
+
`ator_traits::rebind_traits<container_node_type>::deallocate`.
|
| 492 |
+
- Assigns `nh.ptr_` to `ptr_`.
|
| 493 |
+
- If `!alloc` or `ator_traits::propagate_on_container_move_assignment`
|
| 494 |
+
is `true`, move assigns `nh.alloc_` to `alloc_`.
|
| 495 |
+
- Assigns `nullptr` to `nh.ptr_` and assigns `nullopt` to `nh.alloc_`.
|
| 496 |
+
|
| 497 |
+
*Returns:* `*this`.
|
| 498 |
+
|
| 499 |
+
*Throws:* Nothing.
|
| 500 |
+
|
| 501 |
+
#### `node_handle` destructor <a id="container.node.dtor">[[container.node.dtor]]</a>
|
| 502 |
+
|
| 503 |
+
``` cpp
|
| 504 |
+
~node_handle();
|
| 505 |
+
```
|
| 506 |
+
|
| 507 |
+
*Effects:* If `ptr_ != nullptr`, destroys the `value_type` subobject in
|
| 508 |
+
the `container_node_type` object pointed to by `ptr_` by calling
|
| 509 |
+
`ator_traits::destroy`, then deallocates `ptr_` by calling
|
| 510 |
+
`ator_traits::rebind_traits<container_node_type>::deallocate`.
|
| 511 |
+
|
| 512 |
+
#### `node_handle` observers <a id="container.node.observers">[[container.node.observers]]</a>
|
| 513 |
+
|
| 514 |
+
``` cpp
|
| 515 |
+
value_type& value() const;
|
| 516 |
+
```
|
| 517 |
+
|
| 518 |
+
*Requires:* `empty() == false`.
|
| 519 |
+
|
| 520 |
+
*Returns:* A reference to the `value_type` subobject in the
|
| 521 |
+
`container_node_type` object pointed to by `ptr_`.
|
| 522 |
+
|
| 523 |
+
*Throws:* Nothing.
|
| 524 |
+
|
| 525 |
+
``` cpp
|
| 526 |
+
key_type& key() const;
|
| 527 |
+
```
|
| 528 |
+
|
| 529 |
+
*Requires:* `empty() == false`.
|
| 530 |
+
|
| 531 |
+
*Returns:* A non-const reference to the `key_type` member of the
|
| 532 |
+
`value_type` subobject in the `container_node_type` object pointed to by
|
| 533 |
+
`ptr_`.
|
| 534 |
+
|
| 535 |
+
*Throws:* Nothing.
|
| 536 |
+
|
| 537 |
+
*Remarks:* Modifying the key through the returned reference is
|
| 538 |
+
permitted.
|
| 539 |
+
|
| 540 |
+
``` cpp
|
| 541 |
+
mapped_type& mapped() const;
|
| 542 |
+
```
|
| 543 |
+
|
| 544 |
+
*Requires:* `empty() == false`.
|
| 545 |
+
|
| 546 |
+
*Returns:* A reference to the `mapped_type` member of the `value_type`
|
| 547 |
+
subobject in the `container_node_type` object pointed to by `ptr_`.
|
| 548 |
+
|
| 549 |
+
*Throws:* Nothing.
|
| 550 |
+
|
| 551 |
+
``` cpp
|
| 552 |
+
allocator_type get_allocator() const;
|
| 553 |
+
```
|
| 554 |
+
|
| 555 |
+
*Requires:* `empty() == false`.
|
| 556 |
+
|
| 557 |
+
*Returns:* `*alloc_`.
|
| 558 |
+
|
| 559 |
+
*Throws:* Nothing.
|
| 560 |
+
|
| 561 |
+
``` cpp
|
| 562 |
+
explicit operator bool() const noexcept;
|
| 563 |
+
```
|
| 564 |
+
|
| 565 |
+
*Returns:* `ptr_ != nullptr`.
|
| 566 |
+
|
| 567 |
+
``` cpp
|
| 568 |
+
bool empty() const noexcept;
|
| 569 |
+
```
|
| 570 |
+
|
| 571 |
+
*Returns:* `ptr_ == nullptr`.
|
| 572 |
+
|
| 573 |
+
#### `node_handle` modifiers <a id="container.node.modifiers">[[container.node.modifiers]]</a>
|
| 574 |
+
|
| 575 |
+
``` cpp
|
| 576 |
+
void swap(node_handle& nh)
|
| 577 |
+
noexcept(ator_traits::propagate_on_container_swap::value ||
|
| 578 |
+
ator_traits::is_always_equal::value);
|
| 579 |
+
```
|
| 580 |
+
|
| 581 |
+
*Requires:* `!alloc_`, or `!nh.alloc_`, or
|
| 582 |
+
`ator_traits::propagate_on_container_swap` is `true`, or
|
| 583 |
+
`alloc_ == nh.alloc_`.
|
| 584 |
+
|
| 585 |
+
*Effects:* Calls `swap(ptr_, nh.ptr_)`. If `!alloc_`, or `!nh.alloc_`,
|
| 586 |
+
or `ator_traits::propagate_on_container_swap` is `true` calls
|
| 587 |
+
`swap(alloc_, nh.alloc_)`.
|
| 588 |
+
|
| 589 |
+
### Insert return type <a id="container.insert.return">[[container.insert.return]]</a>
|
| 590 |
+
|
| 591 |
+
The associative containers with unique keys and the unordered containers
|
| 592 |
+
with unique keys have a member function `insert` that returns a nested
|
| 593 |
+
type `insert_return_type`. That return type is a specialization of the
|
| 594 |
+
type specified in this subclause.
|
| 595 |
+
|
| 596 |
+
``` cpp
|
| 597 |
+
template <class Iterator, class NodeType>
|
| 598 |
+
struct INSERT_RETURN_TYPE
|
| 599 |
+
{
|
| 600 |
+
Iterator position;
|
| 601 |
+
bool inserted;
|
| 602 |
+
NodeType node;
|
| 603 |
+
};
|
| 604 |
+
```
|
| 605 |
+
|
| 606 |
+
The name `INSERT_RETURN_TYPE` is exposition only. `INSERT_RETURN_TYPE`
|
| 607 |
+
has the template parameters, data members, and special members specified
|
| 608 |
+
above. It has no base classes or members other than those specified.
|
| 609 |
+
|
| 610 |
### Associative containers <a id="associative.reqmts">[[associative.reqmts]]</a>
|
| 611 |
|
| 612 |
Associative containers provide fast retrieval of data based on keys. The
|
| 613 |
library provides four basic kinds of associative containers: `set`,
|
| 614 |
`multiset`, `map` and `multimap`.
|
|
|
|
| 640 |
|
| 641 |
of an associative container is of the bidirectional iterator category.
|
| 642 |
For associative containers where the value type is the same as the key
|
| 643 |
type, both `iterator` and `const_iterator` are constant iterators. It is
|
| 644 |
unspecified whether or not `iterator` and `const_iterator` are the same
|
| 645 |
+
type.
|
| 646 |
+
|
| 647 |
+
[*Note 1*: `iterator` and `const_iterator` have identical semantics in
|
| 648 |
+
this case, and `iterator` is convertible to `const_iterator`. Users can
|
| 649 |
+
avoid violating the one-definition rule by always using `const_iterator`
|
| 650 |
+
in their function parameter lists. — *end note*]
|
| 651 |
|
| 652 |
The associative containers meet all the requirements of Allocator-aware
|
| 653 |
containers ([[container.requirements.general]]), except that for `map`
|
| 654 |
and `multimap`, the requirements placed on `value_type` in Table
|
| 655 |
[[tab:containers.container.requirements]] apply instead to `key_type`
|
| 656 |
+
and `mapped_type`.
|
| 657 |
+
|
| 658 |
+
[*Note 2*: For example, in some cases `key_type` and `mapped_type` are
|
| 659 |
+
required to be `CopyAssignable` even though the associated `value_type`,
|
| 660 |
+
`pair<const key_type, mapped_type>`, is not
|
| 661 |
+
`CopyAssignable`. — *end note*]
|
| 662 |
|
| 663 |
In Table [[tab:containers.associative.requirements]], `X` denotes an
|
| 664 |
+
associative container class, `a` denotes a value of type `X`, `a2`
|
| 665 |
+
denotes a value of a type with nodes compatible with type `X` (Table
|
| 666 |
+
[[tab:containers.node.compat]]), `b` denotes a possibly `const` value of
|
| 667 |
+
type `X`, `u` denotes the name of a variable being declared, `a_uniq`
|
| 668 |
+
denotes a value of type `X` when `X` supports unique keys, `a_eq`
|
| 669 |
+
denotes a value of type `X` when `X` supports multiple keys, `a_tran`
|
| 670 |
+
denotes a possibly `const` value of type `X` when the *qualified-id*
|
| 671 |
+
`X::key_compare::is_transparent` is valid and denotes a type (
|
| 672 |
+
[[temp.deduct]]), `i` and `j` satisfy input iterator requirements and
|
| 673 |
+
refer to elements implicitly convertible to `value_type`, \[`i`, `j`)
|
| 674 |
+
denotes a valid range, `p` denotes a valid constant iterator to `a`, `q`
|
| 675 |
+
denotes a valid dereferenceable constant iterator to `a`, `r` denotes a
|
| 676 |
+
valid dereferenceable iterator to `a`, `[q1, q2)` denotes a valid range
|
| 677 |
+
of constant iterators in `a`, `il` designates an object of type
|
| 678 |
+
`initializer_list<value_type>`, `t` denotes a value of type
|
| 679 |
+
`X::value_type`, `k` denotes a value of type `X::key_type` and `c`
|
| 680 |
+
denotes a possibly `const` value of type `X::key_compare`; `kl` is a
|
| 681 |
+
value such that `a` is partitioned ([[alg.sorting]]) with respect to
|
| 682 |
`c(r, kl)`, with `r` the key value of `e` and `e` in `a`; `ku` is a
|
| 683 |
value such that `a` is partitioned with respect to `!c(ku, r)`; `ke` is
|
| 684 |
a value such that `a` is partitioned with respect to `c(r, ke)` and
|
| 685 |
`!c(ke, r)`, with `c(r, ke)` implying `!c(ke, r)`. `A` denotes the
|
| 686 |
+
storage allocator used by `X`, if any, or `allocator<X::value_type>`
|
| 687 |
+
otherwise, `m` denotes an allocator of a type convertible to `A`, and
|
| 688 |
+
`nh` denotes a non-const rvalue of type `X::node_type`.
|
| 689 |
|
| 690 |
The `insert` and `emplace` members shall not affect the validity of
|
| 691 |
iterators and references to the container, and the `erase` members shall
|
| 692 |
invalidate only iterators and references to the erased elements.
|
| 693 |
|
| 694 |
+
The `extract` members invalidate only iterators to the removed element;
|
| 695 |
+
pointers and references to the removed element remain valid. However,
|
| 696 |
+
accessing the element through such pointers and references while the
|
| 697 |
+
element is owned by a `node_type` is undefined behavior. References and
|
| 698 |
+
pointers to an element obtained while it is owned by a `node_type` are
|
| 699 |
+
invalidated if the element is successfully inserted.
|
| 700 |
+
|
| 701 |
The fundamental property of iterators of associative containers is that
|
| 702 |
they iterate through the containers in the non-descending order of keys
|
| 703 |
where non-descending is defined by the comparison that was used to
|
| 704 |
construct them. For any two dereferenceable iterators `i` and `j` such
|
| 705 |
+
that distance from `i` to `j` is positive, the following condition
|
| 706 |
+
holds:
|
| 707 |
|
| 708 |
``` cpp
|
| 709 |
value_comp(*j, *i) == false
|
| 710 |
```
|
| 711 |
|
| 712 |
For associative containers with unique keys the stronger condition
|
| 713 |
+
holds:
|
| 714 |
|
| 715 |
``` cpp
|
| 716 |
+
value_comp(*i, *j) != false
|
| 717 |
```
|
| 718 |
|
| 719 |
When an associative container is constructed by passing a comparison
|
| 720 |
object the container shall not store a pointer or reference to the
|
| 721 |
passed object, even if that object is passed by reference. When an
|
|
|
|
| 724 |
object from the container being copied, as if that comparison object had
|
| 725 |
been passed to the target container in its constructor.
|
| 726 |
|
| 727 |
The member function templates `find`, `count`, `lower_bound`,
|
| 728 |
`upper_bound`, and `equal_range` shall not participate in overload
|
| 729 |
+
resolution unless the *qualified-id* `Compare::is_transparent` is valid
|
| 730 |
and denotes a type ([[temp.deduct]]).
|
| 731 |
|
| 732 |
+
A deduction guide for an associative container shall not participate in
|
| 733 |
+
overload resolution if any of the following are true:
|
| 734 |
+
|
| 735 |
+
- It has an `InputIterator` template parameter and a type that does not
|
| 736 |
+
qualify as an input iterator is deduced for that parameter.
|
| 737 |
+
- It has an `Allocator` template parameter and a type that does not
|
| 738 |
+
qualify as an allocator is deduced for that parameter.
|
| 739 |
+
- It has a `Compare` template parameter and a type that qualifies as an
|
| 740 |
+
allocator is deduced for that parameter.
|
| 741 |
+
|
| 742 |
#### Exception safety guarantees <a id="associative.reqmts.except">[[associative.reqmts.except]]</a>
|
| 743 |
|
| 744 |
For associative containers, no `clear()` function throws an exception.
|
| 745 |
`erase(k)` does not throw an exception unless that exception is thrown
|
| 746 |
by the container’s `Compare` object (if any).
|
|
|
|
| 780 |
the container.
|
| 781 |
|
| 782 |
Two values `k1` and `k2` of type `Key` are considered equivalent if the
|
| 783 |
container’s key equality predicate returns `true` when passed those
|
| 784 |
values. If `k1` and `k2` are equivalent, the container’s hash function
|
| 785 |
+
shall return the same value for both.
|
| 786 |
+
|
| 787 |
+
[*Note 1*: Thus, when an unordered associative container is
|
| 788 |
+
instantiated with a non-default `Pred` parameter it usually needs a
|
| 789 |
+
non-default `Hash` parameter as well. — *end note*]
|
| 790 |
+
|
| 791 |
+
For any two keys `k1` and `k2` in the same container, calling
|
| 792 |
+
`pred(k1, k2)` shall always return the same value. For any key `k` in a
|
| 793 |
+
container, calling `hash(k)` shall always return the same value.
|
| 794 |
|
| 795 |
An unordered associative container supports *unique keys* if it may
|
| 796 |
contain at most one element for each key. Otherwise, it supports
|
| 797 |
*equivalent keys*. `unordered_set` and `unordered_map` support unique
|
| 798 |
keys. `unordered_multiset` and `unordered_multimap` support equivalent
|
| 799 |
keys. In containers that support equivalent keys, elements with
|
| 800 |
equivalent keys are adjacent to each other in the iteration order of the
|
| 801 |
container. Thus, although the absolute order of elements in an unordered
|
| 802 |
container is not specified, its elements are grouped into
|
| 803 |
+
*equivalent-key groups* such that all elements of each group have
|
| 804 |
equivalent keys. Mutating operations on unordered containers shall
|
| 805 |
preserve the relative order of elements within each equivalent-key group
|
| 806 |
unless otherwise specified.
|
| 807 |
|
| 808 |
For `unordered_set` and `unordered_multiset` the value type is the same
|
| 809 |
as the key type. For `unordered_map` and `unordered_multimap` it is
|
| 810 |
+
`pair<const Key,
|
| 811 |
T>`.
|
| 812 |
|
| 813 |
For unordered containers where the value type is the same as the key
|
| 814 |
type, both `iterator` and `const_iterator` are constant iterators. It is
|
| 815 |
unspecified whether or not `iterator` and `const_iterator` are the same
|
| 816 |
+
type.
|
| 817 |
+
|
| 818 |
+
[*Note 2*: `iterator` and `const_iterator` have identical semantics in
|
| 819 |
+
this case, and `iterator` is convertible to `const_iterator`. Users can
|
| 820 |
+
avoid violating the one-definition rule by always using `const_iterator`
|
| 821 |
+
in their function parameter lists. — *end note*]
|
| 822 |
|
| 823 |
The elements of an unordered associative container are organized into
|
| 824 |
*buckets*. Keys with the same hash code appear in the same bucket. The
|
| 825 |
number of buckets is automatically increased as elements are added to an
|
| 826 |
unordered associative container, so that the average number of elements
|
|
|
|
| 833 |
The unordered associative containers meet all the requirements of
|
| 834 |
Allocator-aware containers ([[container.requirements.general]]), except
|
| 835 |
that for `unordered_map` and `unordered_multimap`, the requirements
|
| 836 |
placed on `value_type` in Table
|
| 837 |
[[tab:containers.container.requirements]] apply instead to `key_type`
|
| 838 |
+
and `mapped_type`.
|
|
|
|
|
|
|
|
|
|
| 839 |
|
| 840 |
+
[*Note 3*: For example, `key_type` and `mapped_type` are sometimes
|
| 841 |
+
required to be `CopyAssignable` even though the associated `value_type`,
|
| 842 |
+
`pair<const key_type, mapped_type>`, is not
|
| 843 |
+
`CopyAssignable`. — *end note*]
|
| 844 |
+
|
| 845 |
+
In Table [[tab:HashRequirements]]: `X` denotes an unordered associative
|
| 846 |
+
container class, `a` denotes a value of type `X`, `a2` denotes a value
|
| 847 |
+
of a type with nodes compatible with type `X` (Table
|
| 848 |
+
[[tab:containers.node.compat]]), `b` denotes a possibly const value of
|
| 849 |
+
type `X`, `a_uniq` denotes a value of type `X` when `X` supports unique
|
| 850 |
+
keys, `a_eq` denotes a value of type `X` when `X` supports equivalent
|
| 851 |
+
keys, `i` and `j` denote input iterators that refer to `value_type`,
|
| 852 |
+
`[i, j)` denotes a valid range, `p` and `q2` denote valid constant
|
| 853 |
+
iterators to `a`, `q` and `q1` denote valid dereferenceable constant
|
| 854 |
+
iterators to `a`, `r` denotes a valid dereferenceable iterator to `a`,
|
| 855 |
+
`[q1, q2)` denotes a valid range in `a`, `il` denotes a value of type
|
| 856 |
+
`initializer_list<value_type>`, `t` denotes a value of type
|
| 857 |
+
`X::value_type`, `k` denotes a value of type `key_type`, `hf` denotes a
|
| 858 |
+
possibly const value of type `hasher`, `eq` denotes a possibly const
|
| 859 |
+
value of type `key_equal`, `n` denotes a value of type `size_type`, `z`
|
| 860 |
+
denotes a value of type `float`, and `nh` denotes a non-const rvalue of
|
| 861 |
+
type `X::node_type`.
|
| 862 |
|
| 863 |
Two unordered containers `a` and `b` compare equal if
|
| 864 |
`a.size() == b.size()` and, for every equivalent-key group \[`Ea1`,
|
| 865 |
`Ea2`) obtained from `a.equal_range(Ea1)`, there exists an
|
| 866 |
equivalent-key group \[`Eb1`, `Eb2`) obtained from `b.equal_range(Ea1)`,
|
| 867 |
such that `is_permutation(Ea1, Ea2, Eb1, Eb2)` returns `true`. For
|
| 868 |
`unordered_set` and `unordered_map`, the complexity of `operator==`
|
| 869 |
(i.e., the number of calls to the `==` operator of the `value_type`, to
|
| 870 |
+
the predicate returned by `key_eq()`, and to the hasher returned by
|
| 871 |
`hash_function()`) is proportional to N in the average case and to N² in
|
| 872 |
the worst case, where N is a.size(). For `unordered_multiset` and
|
| 873 |
`unordered_multimap`, the complexity of `operator==` is proportional to
|
| 874 |
$\sum E_i^2$ in the average case and to N² in the worst case, where N is
|
| 875 |
`a.size()`, and Eᵢ is the size of the iᵗʰ equivalent-key group in `a`.
|
|
|
|
| 880 |
`unordered_multiset` and `unordered_multimap` becomes proportional to N
|
| 881 |
(but worst-case complexity remains 𝑂(N^2), e.g., for a pathologically
|
| 882 |
bad hash function). The behavior of a program that uses `operator==` or
|
| 883 |
`operator!=` on unordered containers is undefined unless the `Hash` and
|
| 884 |
`Pred` function objects respectively have the same behavior for both
|
| 885 |
+
containers and the equality comparison function for `Key` is a
|
| 886 |
refinement[^1] of the partition into equivalent-key groups produced by
|
| 887 |
`Pred`.
|
| 888 |
|
| 889 |
The iterator types `iterator` and `const_iterator` of an unordered
|
| 890 |
associative container are of at least the forward iterator category. For
|
| 891 |
unordered associative containers where the key type and value type are
|
| 892 |
+
the same, both `iterator` and `const_iterator` are constant iterators.
|
| 893 |
|
| 894 |
The `insert` and `emplace` members shall not affect the validity of
|
| 895 |
references to container elements, but may invalidate all iterators to
|
| 896 |
the container. The `erase` members shall invalidate only iterators and
|
| 897 |
references to the erased elements, and preserve the relative order of
|
| 898 |
the elements that are not erased.
|
| 899 |
|
| 900 |
The `insert` and `emplace` members shall not affect the validity of
|
| 901 |
+
iterators if `(N+n) <= z * B`, where `N` is the number of elements in
|
| 902 |
+
the container prior to the insert operation, `n` is the number of
|
| 903 |
+
elements inserted, `B` is the container’s bucket count, and `z` is the
|
| 904 |
container’s maximum load factor.
|
| 905 |
|
| 906 |
+
The `extract` members invalidate only iterators to the removed element,
|
| 907 |
+
and preserve the relative order of the elements that are not erased;
|
| 908 |
+
pointers and references to the removed element remain valid. However,
|
| 909 |
+
accessing the element through such pointers and references while the
|
| 910 |
+
element is owned by a `node_type` is undefined behavior. References and
|
| 911 |
+
pointers to an element obtained while it is owned by a `node_type` are
|
| 912 |
+
invalidated if the element is successfully inserted.
|
| 913 |
+
|
| 914 |
+
A deduction guide for an unordered associative container shall not
|
| 915 |
+
participate in overload resolution if any of the following are true:
|
| 916 |
+
|
| 917 |
+
- It has an `InputIterator` template parameter and a type that does not
|
| 918 |
+
qualify as an input iterator is deduced for that parameter.
|
| 919 |
+
- It has an `Allocator` template parameter and a type that does not
|
| 920 |
+
qualify as an allocator is deduced for that parameter.
|
| 921 |
+
- It has a `Hash` template parameter and an integral type or a type that
|
| 922 |
+
qualifies as an allocator is deduced for that parameter.
|
| 923 |
+
- It has a `Pred` template parameter and a type that qualifies as an
|
| 924 |
+
allocator is deduced for that parameter.
|
| 925 |
+
|
| 926 |
#### Exception safety guarantees <a id="unord.req.except">[[unord.req.except]]</a>
|
| 927 |
|
| 928 |
For unordered associative containers, no `clear()` function throws an
|
| 929 |
exception. `erase(k)` does not throw an exception unless that exception
|
| 930 |
is thrown by the container’s `Hash` or `Pred` object (if any).
|
|
|
|
| 934 |
`insert` or `emplace` function inserting a single element, the insertion
|
| 935 |
has no effect.
|
| 936 |
|
| 937 |
For unordered associative containers, no `swap` function throws an
|
| 938 |
exception unless that exception is thrown by the swap of the container’s
|
| 939 |
+
`Hash` or `Pred` object (if any).
|
| 940 |
|
| 941 |
For unordered associative containers, if an exception is thrown from
|
| 942 |
within a `rehash()` function other than by the container’s hash function
|
| 943 |
or comparison function, the `rehash()` function has no effect.
|
| 944 |
|