- tmp/tmp0xvk2od7/{from.md → to.md} +2700 -226
tmp/tmp0xvk2od7/{from.md → to.md}
RENAMED
|
@@ -1,8 +1,8 @@
|
|
| 1 |
-
##
|
| 2 |
|
| 3 |
-
###
|
| 4 |
|
| 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 |
|
|
@@ -11,47 +11,299 @@ 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 |
-
|
| 17 |
-
`
|
| 18 |
-
constructed using the function
|
| 19 |
`allocator_traits<allocator_type>::rebind_traits<U>::{}construct` and
|
| 20 |
-
|
| 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
|
| 28 |
need to construct nodes containing aligned buffers and call `construct`
|
| 29 |
to place the element into the buffer. — *end note*]
|
| 30 |
|
| 31 |
-
|
| 32 |
-
[[tab:container.opt]] `X` denotes a container class containing objects
|
| 33 |
-
of type `T`, `a` and `b` denote values of type `X`, `i` and `j` denote
|
| 34 |
-
values of type (possibly const) `X::iterator`, `u` denotes an
|
| 35 |
-
identifier, `r` denotes a non-const value of type `X`, and `rv` denotes
|
| 36 |
-
a non-const rvalue of type `X`.
|
| 37 |
|
| 38 |
-
|
| 39 |
-
`array` and have constant complexity for all other standard containers.
|
| 40 |
|
| 41 |
-
|
| 42 |
-
[[algorithms]]. — *end note*]
|
| 43 |
|
| 44 |
-
|
| 45 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 46 |
constructors, inserts, and erases.
|
| 47 |
|
| 48 |
-
`
|
|
|
|
|
|
|
| 49 |
|
| 50 |
-
|
| 51 |
-
|
| 52 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 53 |
|
| 54 |
In the expressions
|
| 55 |
|
| 56 |
``` cpp
|
| 57 |
i == j
|
|
@@ -67,14 +319,14 @@ i - j
|
|
| 67 |
where `i` and `j` denote objects of a container’s `iterator` type,
|
| 68 |
either or both may be replaced by an object of the container’s
|
| 69 |
`const_iterator` type referring to the same element with no change in
|
| 70 |
semantics.
|
| 71 |
|
| 72 |
-
Unless otherwise specified, all containers defined in this
|
| 73 |
memory using an allocator (see [[allocator.requirements]]).
|
| 74 |
|
| 75 |
-
[*Note
|
| 76 |
references to allocated elements other than through the allocator’s
|
| 77 |
pointer type, i.e., as objects of type `P` or
|
| 78 |
`pointer_traits<P>::template rebind<unspecified>`, where `P` is
|
| 79 |
`allocator_traits<allocator_type>::pointer`. — *end note*]
|
| 80 |
|
|
@@ -85,72 +337,69 @@ on the allocator belonging to the container being copied. Move
|
|
| 85 |
constructors obtain an allocator by move construction from the allocator
|
| 86 |
belonging to the container being moved. Such move construction of the
|
| 87 |
allocator shall not exit via an exception. All other constructors for
|
| 88 |
these container types take a `const allocator_type&` argument.
|
| 89 |
|
| 90 |
-
[*Note
|
| 91 |
an optional allocator argument, then the allocator type must support
|
| 92 |
value-initialization. — *end note*]
|
| 93 |
|
| 94 |
A copy of this allocator is used for any memory allocation and element
|
| 95 |
construction performed, by these constructors and by all member
|
| 96 |
functions, during the lifetime of each container object or until the
|
| 97 |
allocator is replaced. The allocator may be replaced only via assignment
|
| 98 |
or `swap()`. Allocator replacement is performed by copy assignment, move
|
| 99 |
assignment, or swapping of the allocator only if
|
| 100 |
-
|
| 101 |
-
`allocator_traits<allocator_type>::
|
|
|
|
| 102 |
or
|
| 103 |
-
`allocator_traits<allocator_type>::propagate_on_container_swap::value`
|
|
|
|
| 104 |
is `true` within the implementation of the corresponding container
|
| 105 |
operation. In all container types defined in this Clause, the member
|
| 106 |
`get_allocator()` returns a copy of the allocator used to construct the
|
| 107 |
container or, if that allocator has been replaced, a copy of the most
|
| 108 |
recent replacement.
|
| 109 |
|
| 110 |
The expression `a.swap(b)`, for containers `a` and `b` of a standard
|
| 111 |
container type other than `array`, shall exchange the values of `a` and
|
| 112 |
`b` without invoking any move, copy, or swap operations on the
|
| 113 |
-
individual container elements.
|
| 114 |
-
|
| 115 |
-
exchanged by calling `swap` as described in
|
| 116 |
-
If
|
| 117 |
`allocator_traits<allocator_type>::propagate_on_container_swap::value`
|
| 118 |
-
is `true`, then
|
| 119 |
-
the allocators of `a` and `b` shall also be exchanged
|
| 120 |
-
as described in [[swappable.requirements]].
|
| 121 |
-
shall not be swapped, and the behavior is
|
| 122 |
-
`a.get_allocator() == b.get_allocator()`. Every
|
| 123 |
-
element in one container before the swap shall
|
| 124 |
-
in the other container after the swap. It is
|
| 125 |
-
iterator with value `a.end()` before the swap
|
| 126 |
-
after the swap.
|
| 127 |
-
|
| 128 |
-
If the iterator type of a container belongs to the bidirectional or
|
| 129 |
-
random access iterator categories [[iterator.requirements]], the
|
| 130 |
-
container is called *reversible* and meets the additional requirements
|
| 131 |
-
in [[container.rev.req]].
|
| 132 |
|
| 133 |
Unless otherwise specified (see [[associative.reqmts.except]],
|
| 134 |
[[unord.req.except]], [[deque.modifiers]], and [[vector.modifiers]]) all
|
| 135 |
container types defined in this Clause meet the following additional
|
| 136 |
requirements:
|
| 137 |
|
| 138 |
-
-
|
| 139 |
while inserting a single element, that function has no effects.
|
| 140 |
-
-
|
| 141 |
`emplace_back()`, or `emplace_front()` function, that function has no
|
| 142 |
effects.
|
| 143 |
-
-
|
| 144 |
an exception.
|
| 145 |
-
-
|
| 146 |
throws an exception.
|
| 147 |
-
-
|
| 148 |
-
-
|
| 149 |
iterators referring to the elements of the containers being swapped.
|
| 150 |
-
\[*Note
|
| 151 |
-
|
| 152 |
|
| 153 |
Unless otherwise specified (either explicitly or by defining a function
|
| 154 |
in terms of other functions), invoking a container member function or
|
| 155 |
passing a container as an argument to a library function shall not
|
| 156 |
invalidate iterators to, or change the values of, objects within that
|
|
@@ -159,33 +408,129 @@ container.
|
|
| 159 |
A *contiguous container* is a container whose member types `iterator`
|
| 160 |
and `const_iterator` meet the *Cpp17RandomAccessIterator* requirements
|
| 161 |
[[random.access.iterators]] and model `contiguous_iterator`
|
| 162 |
[[iterator.concept.contiguous]].
|
| 163 |
|
| 164 |
-
|
| 165 |
-
|
| 166 |
-
|
| 167 |
-
|
| 168 |
-
|
| 169 |
-
|
| 170 |
-
|
| 171 |
-
|
| 172 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 173 |
in [[algorithms]]. — *end note*]
|
| 174 |
|
| 175 |
-
|
| 176 |
-
|
| 177 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 178 |
|
| 179 |
Given an allocator type `A` and given a container type `X` having a
|
| 180 |
`value_type` identical to `T` and an `allocator_type` identical to
|
| 181 |
`allocator_traits<A>::rebind_alloc<T>` and given an lvalue `m` of type
|
| 182 |
-
`A`, a pointer `p` of type `T*`, an expression `v` of type
|
| 183 |
-
`const
|
| 184 |
-
defined. If `X` is not allocator-aware
|
| 185 |
-
|
| 186 |
-
|
|
|
|
| 187 |
|
| 188 |
- `T` is **Cpp17DefaultInsertable* into `X`* means that the following
|
| 189 |
expression is well-formed:
|
| 190 |
``` cpp
|
| 191 |
allocator_traits<A>::construct(m, p)
|
|
@@ -205,11 +550,11 @@ user specializations of `allocator<T>` are not instantiated:
|
|
| 205 |
```
|
| 206 |
|
| 207 |
and its evaluation causes the following postcondition to hold: The
|
| 208 |
value of `*p` is equivalent to the value of `rv` before the
|
| 209 |
evaluation.
|
| 210 |
-
\[*Note
|
| 211 |
unspecified — *end note*]
|
| 212 |
- `T` is **Cpp17CopyInsertable* into `X`* means that, in addition to `T`
|
| 213 |
being *Cpp17MoveInsertable* into `X`, the following expression is
|
| 214 |
well-formed:
|
| 215 |
``` cpp
|
|
@@ -228,35 +573,138 @@ user specializations of `allocator<T>` are not instantiated:
|
|
| 228 |
is well-formed:
|
| 229 |
``` cpp
|
| 230 |
allocator_traits<A>::destroy(m, p)
|
| 231 |
```
|
| 232 |
|
| 233 |
-
[*Note
|
| 234 |
`allocator_traits<A>::construct(m, p, args)` to construct an element at
|
| 235 |
`p` using `args`, with `m == get_allocator()`. The default `construct`
|
| 236 |
in `allocator` will call `::new((void*)p) T(args)`, but specialized
|
| 237 |
-
allocators
|
| 238 |
-
|
| 239 |
-
In
|
| 240 |
-
|
| 241 |
-
|
| 242 |
-
`
|
| 243 |
-
|
| 244 |
-
|
| 245 |
-
|
| 246 |
-
|
| 247 |
-
|
| 248 |
-
|
| 249 |
-
|
| 250 |
-
|
| 251 |
-
|
| 252 |
-
|
| 253 |
-
|
| 254 |
-
|
| 255 |
-
|
| 256 |
-
|
| 257 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 258 |
|
| 259 |
### Container data races <a id="container.requirements.dataraces">[[container.requirements.dataraces]]</a>
|
| 260 |
|
| 261 |
For purposes of avoiding data races [[res.on.data.races]],
|
| 262 |
implementations shall consider the following functions to be `const`:
|
|
@@ -270,84 +718,324 @@ elements in the same container, excepting `vector<bool>`, are modified
|
|
| 270 |
concurrently.
|
| 271 |
|
| 272 |
[*Note 1*: For a `vector<int> x` with a size greater than one,
|
| 273 |
`x[1] = 5` and `*x.begin() = 10` can be executed concurrently without a
|
| 274 |
data race, but `x[0] = 5` and `*x.begin() = 10` executed concurrently
|
| 275 |
-
|
| 276 |
-
`vector<bool> y`, `y[0] = true`
|
| 277 |
`y[1] = true`. — *end note*]
|
| 278 |
|
| 279 |
### Sequence containers <a id="sequence.reqmts">[[sequence.reqmts]]</a>
|
| 280 |
|
| 281 |
A sequence container organizes a finite set of objects, all of the same
|
| 282 |
type, into a strictly linear arrangement. The library provides four
|
| 283 |
basic kinds of sequence containers: `vector`, `forward_list`, `list`,
|
| 284 |
and `deque`. In addition, `array` is provided as a sequence container
|
| 285 |
which provides limited sequence operations because it has a fixed number
|
| 286 |
of elements. The library also provides container adaptors that make it
|
| 287 |
-
easy to construct abstract data types, such as `stack`s
|
| 288 |
-
|
| 289 |
-
|
|
|
|
| 290 |
|
| 291 |
[*Note 1*: The sequence containers offer the programmer different
|
| 292 |
-
complexity trade-offs
|
| 293 |
-
|
| 294 |
-
|
| 295 |
-
|
| 296 |
-
|
| 297 |
-
|
| 298 |
-
deletions take place at the beginning or at the end of the sequence.
|
| 299 |
-
When choosing a container, remember `vector` is best; leave a comment to
|
| 300 |
explain if you choose from the rest! — *end note*]
|
| 301 |
|
| 302 |
-
In
|
| 303 |
-
|
| 304 |
-
|
| 305 |
-
|
|
|
|
|
|
|
| 306 |
`X::allocator_type` is valid and denotes a type [[temp.deduct]] and
|
| 307 |
-
`allocator<T>` if it doesn’t,
|
| 308 |
-
|
| 309 |
-
|
| 310 |
-
|
| 311 |
-
|
| 312 |
-
|
| 313 |
-
`
|
| 314 |
-
|
| 315 |
-
|
| 316 |
-
|
| 317 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 318 |
|
| 319 |
The complexities of the expressions are sequence dependent.
|
| 320 |
|
| 321 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 322 |
`a`. — *end note*]
|
| 323 |
|
| 324 |
-
|
| 325 |
-
|
| 326 |
|
| 327 |
-
|
| 328 |
-
|
|
|
|
| 329 |
|
| 330 |
-
|
| 331 |
-
first element inserted into `a`, or `p` if `n == 0`.
|
| 332 |
|
| 333 |
-
|
| 334 |
-
|
| 335 |
|
| 336 |
-
|
| 337 |
-
first element inserted into `a`, or `p` if `il` is empty.
|
| 338 |
|
| 339 |
-
|
| 340 |
-
element constructed from `args` into `a`.
|
| 341 |
|
| 342 |
-
|
| 343 |
-
|
| 344 |
-
|
| 345 |
|
| 346 |
-
|
| 347 |
-
|
| 348 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 349 |
|
| 350 |
For every sequence container defined in this Clause and in [[strings]]:
|
| 351 |
|
| 352 |
- If the constructor
|
| 353 |
``` cpp
|
|
@@ -381,17 +1069,202 @@ For every sequence container defined in this Clause and in [[strings]]:
|
|
| 381 |
and a type that does not qualify as an input iterator is deduced for
|
| 382 |
that parameter, or if it has an `Allocator` template parameter and a
|
| 383 |
type that does not qualify as an allocator is deduced for that
|
| 384 |
parameter.
|
| 385 |
|
| 386 |
-
|
| 387 |
-
|
| 388 |
-
|
| 389 |
-
column, and shall implement them so as to take amortized constant time.
|
| 390 |
|
| 391 |
-
|
| 392 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 393 |
|
| 394 |
### Node handles <a id="container.node">[[container.node]]</a>
|
| 395 |
|
| 396 |
#### Overview <a id="container.node.overview">[[container.node.overview]]</a>
|
| 397 |
|
|
@@ -430,22 +1303,23 @@ operations involving node handles is undefined.
|
|
| 430 |
|
| 431 |
``` cpp
|
| 432 |
template<unspecified>
|
| 433 |
class node-handle {
|
| 434 |
public:
|
| 435 |
-
// These type declarations are described in
|
| 436 |
using value_type = see below; // not present for map containers
|
| 437 |
using key_type = see below; // not present for set containers
|
| 438 |
using mapped_type = see below; // not present for set containers
|
| 439 |
using allocator_type = see below;
|
| 440 |
|
| 441 |
private:
|
| 442 |
-
using container_node_type = unspecified;
|
| 443 |
-
using ator_traits = allocator_traits<allocator_type>;
|
| 444 |
|
| 445 |
-
typename ator_traits::template
|
| 446 |
-
|
|
|
|
| 447 |
|
| 448 |
public:
|
| 449 |
// [container.node.cons], constructors, copy, and assignment
|
| 450 |
constexpr node-handle() noexcept : ptr_(), alloc_() {}
|
| 451 |
node-handle(node-handle&&) noexcept;
|
|
@@ -618,13 +1492,19 @@ The name *`insert-return-type`* is exposition only.
|
|
| 618 |
special members specified above. It has no base classes or members other
|
| 619 |
than those specified.
|
| 620 |
|
| 621 |
### Associative containers <a id="associative.reqmts">[[associative.reqmts]]</a>
|
| 622 |
|
|
|
|
|
|
|
| 623 |
Associative containers provide fast retrieval of data based on keys. The
|
| 624 |
library provides four basic kinds of associative containers: `set`,
|
| 625 |
-
`multiset`, `map` and `multimap`.
|
|
|
|
|
|
|
|
|
|
|
|
|
| 626 |
|
| 627 |
Each associative container is parameterized on `Key` and an ordering
|
| 628 |
relation `Compare` that induces a strict weak ordering [[alg.sorting]]
|
| 629 |
on elements of `Key`. In addition, `map` and `multimap` associate an
|
| 630 |
arbitrary *mapped type* `T` with the `Key`. The object of type `Compare`
|
|
@@ -662,50 +1542,729 @@ type.
|
|
| 662 |
[*Note 2*: `iterator` and `const_iterator` have identical semantics in
|
| 663 |
this case, and `iterator` is convertible to `const_iterator`. Users can
|
| 664 |
avoid violating the one-definition rule by always using `const_iterator`
|
| 665 |
in their function parameter lists. — *end note*]
|
| 666 |
|
| 667 |
-
|
| 668 |
-
|
| 669 |
-
`
|
| 670 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 671 |
|
| 672 |
[*Note 3*: For example, in some cases `key_type` and `mapped_type` are
|
| 673 |
required to be *Cpp17CopyAssignable* even though the associated
|
| 674 |
`value_type`, `pair<const key_type, mapped_type>`, is not
|
| 675 |
*Cpp17CopyAssignable*. — *end note*]
|
| 676 |
|
| 677 |
-
|
| 678 |
-
|
| 679 |
-
|
| 680 |
-
|
| 681 |
-
|
| 682 |
-
|
| 683 |
-
|
| 684 |
-
|
| 685 |
-
|
| 686 |
-
|
| 687 |
-
|
| 688 |
-
|
| 689 |
-
|
| 690 |
-
|
| 691 |
-
|
| 692 |
-
|
| 693 |
-
`
|
| 694 |
-
|
| 695 |
-
|
| 696 |
-
`
|
| 697 |
-
|
| 698 |
-
|
| 699 |
-
|
| 700 |
-
|
| 701 |
-
|
| 702 |
-
`
|
| 703 |
-
|
| 704 |
-
|
| 705 |
-
|
| 706 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 707 |
|
| 708 |
The `extract` members invalidate only iterators to the removed element;
|
| 709 |
pointers and references to the removed element remain valid. However,
|
| 710 |
accessing the element through such pointers and references while the
|
| 711 |
element is owned by a `node_type` is undefined behavior. References and
|
|
@@ -737,13 +2296,18 @@ associative container is copied, through either a copy constructor or an
|
|
| 737 |
assignment operator, the target container shall then use the comparison
|
| 738 |
object from the container being copied, as if that comparison object had
|
| 739 |
been passed to the target container in its constructor.
|
| 740 |
|
| 741 |
The member function templates `find`, `count`, `contains`,
|
| 742 |
-
`lower_bound`, `upper_bound`,
|
| 743 |
-
overload resolution unless the *qualified-id*
|
| 744 |
-
is valid and denotes a type [[temp.deduct]].
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 745 |
|
| 746 |
A deduction guide for an associative container shall not participate in
|
| 747 |
overload resolution if any of the following are true:
|
| 748 |
|
| 749 |
- It has an `InputIterator` template parameter and a type that does not
|
|
@@ -767,10 +2331,12 @@ For associative containers, no `swap` function throws an exception
|
|
| 767 |
unless that exception is thrown by the swap of the container’s `Compare`
|
| 768 |
object (if any).
|
| 769 |
|
| 770 |
### Unordered associative containers <a id="unord.req">[[unord.req]]</a>
|
| 771 |
|
|
|
|
|
|
|
| 772 |
Unordered associative containers provide an ability for fast retrieval
|
| 773 |
of data based on keys. The worst-case complexity for most operations is
|
| 774 |
linear, but the average case is much faster. The library provides four
|
| 775 |
unordered associative containers: `unordered_set`, `unordered_map`,
|
| 776 |
`unordered_multiset`, and `unordered_multimap`.
|
|
@@ -842,54 +2408,956 @@ per bucket is kept below a bound. Rehashing invalidates iterators,
|
|
| 842 |
changes ordering between elements, and changes which buckets elements
|
| 843 |
appear in, but does not invalidate pointers or references to elements.
|
| 844 |
For `unordered_multiset` and `unordered_multimap`, rehashing preserves
|
| 845 |
the relative ordering of equivalent elements.
|
| 846 |
|
| 847 |
-
|
| 848 |
-
Allocator-aware containers [[container.requirements.general]], except
|
| 849 |
-
that for `unordered_map` and `unordered_multimap`, the requirements
|
| 850 |
-
placed on `value_type` in [[container.alloc.req]] apply instead to
|
| 851 |
-
`key_type` and `mapped_type`.
|
| 852 |
-
|
| 853 |
-
[*Note 3*: For example, `key_type` and `mapped_type` are sometimes
|
| 854 |
-
required to be *Cpp17CopyAssignable* even though the associated
|
| 855 |
-
`value_type`, `pair<const key_type, mapped_type>`, is not
|
| 856 |
-
*Cpp17CopyAssignable*. — *end note*]
|
| 857 |
-
|
| 858 |
-
In [[container.hash.req]]:
|
| 859 |
|
| 860 |
- `X` denotes an unordered associative container class,
|
| 861 |
- `a` denotes a value of type `X`,
|
| 862 |
- `a2` denotes a value of a type with nodes compatible with type `X` (
|
| 863 |
[[container.node.compat]]),
|
| 864 |
-
- `b` denotes a
|
| 865 |
- `a_uniq` denotes a value of type `X` when `X` supports unique keys,
|
| 866 |
- `a_eq` denotes a value of type `X` when `X` supports equivalent keys,
|
| 867 |
-
- `a_tran` denotes a
|
| 868 |
*qualified-id*s `X::key_equal::is_transparent` and
|
| 869 |
`X::hasher::is_transparent` are both valid and denote types
|
| 870 |
[[temp.deduct]],
|
| 871 |
- `i` and `j` denote input iterators that refer to `value_type`,
|
| 872 |
- `[i, j)` denotes a valid range,
|
|
|
|
|
|
|
| 873 |
- `p` and `q2` denote valid constant iterators to `a`,
|
| 874 |
- `q` and `q1` denote valid dereferenceable constant iterators to `a`,
|
| 875 |
- `r` denotes a valid dereferenceable iterator to `a`,
|
| 876 |
- `[q1, q2)` denotes a valid range in `a`,
|
| 877 |
- `il` denotes a value of type `initializer_list<value_type>`,
|
| 878 |
- `t` denotes a value of type `X::value_type`,
|
| 879 |
- `k` denotes a value of type `key_type`,
|
| 880 |
-
- `hf` denotes a
|
| 881 |
-
- `eq` denotes a
|
| 882 |
- `ke` is a value such that
|
| 883 |
-
- `eq(r1, ke) == eq(ke, r1)`
|
| 884 |
- `hf(r1) == hf(ke)` if `eq(r1, ke)` is `true`, and
|
| 885 |
-
- `
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 886 |
|
| 887 |
where `r1` and `r2` are keys of elements in `a_tran`,
|
| 888 |
- `n` denotes a value of type `size_type`,
|
| 889 |
- `z` denotes a value of type `float`, and
|
| 890 |
-
- `nh` denotes
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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)`,
|
|
@@ -909,42 +3377,48 @@ same container), then the average-case complexity for
|
|
| 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 `Pred`
|
| 913 |
function object has the same behavior for both containers and the
|
| 914 |
-
equality comparison function for `Key` is a refinement[^1]
|
| 915 |
-
|
|
|
|
| 916 |
|
| 917 |
The iterator types `iterator` and `const_iterator` of an unordered
|
| 918 |
associative container are of at least the forward iterator category. For
|
| 919 |
unordered associative containers where the key type and value type are
|
| 920 |
the same, both `iterator` and `const_iterator` are constant iterators.
|
| 921 |
|
| 922 |
-
The `insert` and `emplace` members shall not affect the
|
| 923 |
-
references to container elements, but may invalidate all
|
| 924 |
-
the container. The `erase` members shall invalidate only
|
| 925 |
-
references to the erased elements, and preserve the
|
| 926 |
-
the elements that are not erased.
|
| 927 |
|
| 928 |
-
The `insert` and `emplace` members shall not affect the
|
| 929 |
-
iterators if `(N+n) <= z * B`, where `N` is the number of
|
| 930 |
-
the container prior to the insert operation, `n` is the
|
| 931 |
-
elements inserted, `B` is the container’s bucket count, and
|
| 932 |
-
container’s maximum load factor.
|
| 933 |
|
| 934 |
The `extract` members invalidate only iterators to the removed element,
|
| 935 |
and preserve the relative order of the elements that are not erased;
|
| 936 |
pointers and references to the removed element remain valid. However,
|
| 937 |
accessing the element through such pointers and references while the
|
| 938 |
element is owned by a `node_type` is undefined behavior. References and
|
| 939 |
pointers to an element obtained while it is owned by a `node_type` are
|
| 940 |
invalidated if the element is successfully inserted.
|
| 941 |
|
| 942 |
-
The member function templates `find`, `count`, `equal_range`,
|
| 943 |
-
`contains` shall not participate in overload
|
| 944 |
-
*qualified-id*s `Pred::is_transparent` and
|
| 945 |
-
both valid and denote types [[temp.deduct]].
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 946 |
|
| 947 |
A deduction guide for an unordered associative container shall not
|
| 948 |
participate in overload resolution if any of the following are true:
|
| 949 |
|
| 950 |
- It has an `InputIterator` template parameter and a type that does not
|
|
|
|
| 1 |
+
## Requirements <a id="container.requirements">[[container.requirements]]</a>
|
| 2 |
|
| 3 |
+
### Preamble <a id="container.requirements.pre">[[container.requirements.pre]]</a>
|
| 4 |
|
| 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 |
|
|
|
|
| 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 |
+
Allocator-aware containers [[container.alloc.reqmts]] other than
|
| 17 |
+
`basic_string` construct elements using the function
|
|
|
|
| 18 |
`allocator_traits<allocator_type>::rebind_traits<U>::{}construct` and
|
| 19 |
+
destroy elements using the function
|
| 20 |
`allocator_traits<allocator_type>::rebind_traits<U>::{}destroy`
|
| 21 |
[[allocator.traits.members]], where `U` is either
|
| 22 |
`allocator_type::value_type` or an internal type used by the container.
|
| 23 |
These functions are called only for the container’s element type, not
|
| 24 |
for internal types used by the container.
|
| 25 |
|
| 26 |
+
[*Note 1*: This means, for example, that a node-based container would
|
| 27 |
need to construct nodes containing aligned buffers and call `construct`
|
| 28 |
to place the element into the buffer. — *end note*]
|
| 29 |
|
| 30 |
+
### General containers <a id="container.gen.reqmts">[[container.gen.reqmts]]</a>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 31 |
|
| 32 |
+
#### General <a id="container.requirements.general">[[container.requirements.general]]</a>
|
|
|
|
| 33 |
|
| 34 |
+
In subclause [[container.gen.reqmts]],
|
|
|
|
| 35 |
|
| 36 |
+
- `X` denotes a container class containing objects of type `T`,
|
| 37 |
+
- `a` denotes a value of type `X`,
|
| 38 |
+
- `b` and `c` denote values of type (possibly const) `X`,
|
| 39 |
+
- `i` and `j` denote values of type (possibly const) `X::iterator`,
|
| 40 |
+
- `u` denotes an identifier,
|
| 41 |
+
- `v` denotes an lvalue of type (possibly const) `X` or an rvalue of
|
| 42 |
+
type `const X`,
|
| 43 |
+
- `s` and `t` denote non-const lvalues of type `X`, and
|
| 44 |
+
- `rv` denotes a non-const rvalue of type `X`.
|
| 45 |
+
|
| 46 |
+
The following exposition-only concept is used in the definition of
|
| 47 |
+
containers:
|
| 48 |
+
|
| 49 |
+
``` cpp
|
| 50 |
+
template<class R, class T>
|
| 51 |
+
concept container-compatible-range = // exposition only
|
| 52 |
+
ranges::input_range<R> && convertible_to<ranges::range_reference_t<R>, T>;
|
| 53 |
+
```
|
| 54 |
+
|
| 55 |
+
#### Containers <a id="container.reqmts">[[container.reqmts]]</a>
|
| 56 |
+
|
| 57 |
+
A type `X` meets the *container* requirements if the following types,
|
| 58 |
+
statements, and expressions are well-formed and have the specified
|
| 59 |
+
semantics.
|
| 60 |
+
|
| 61 |
+
``` cpp
|
| 62 |
+
typename X::value_type
|
| 63 |
+
```
|
| 64 |
+
|
| 65 |
+
*Result:* `T`
|
| 66 |
+
|
| 67 |
+
*Preconditions:* `T` is *Cpp17Erasable* from `X`
|
| 68 |
+
(see [[container.alloc.reqmts]], below).
|
| 69 |
+
|
| 70 |
+
``` cpp
|
| 71 |
+
typename X::reference
|
| 72 |
+
```
|
| 73 |
+
|
| 74 |
+
*Result:* `T&`
|
| 75 |
+
|
| 76 |
+
``` cpp
|
| 77 |
+
typename X::const_reference
|
| 78 |
+
```
|
| 79 |
+
|
| 80 |
+
*Result:* `const T&`
|
| 81 |
+
|
| 82 |
+
``` cpp
|
| 83 |
+
typename X::iterator
|
| 84 |
+
```
|
| 85 |
+
|
| 86 |
+
*Result:* A type that meets the forward iterator
|
| 87 |
+
requirements [[forward.iterators]] with value type `T`. The type
|
| 88 |
+
`X::iterator` is convertible to `X::const_iterator`.
|
| 89 |
+
|
| 90 |
+
``` cpp
|
| 91 |
+
typename X::const_iterator
|
| 92 |
+
```
|
| 93 |
+
|
| 94 |
+
*Result:* A type that meets the requirements of a constant iterator and
|
| 95 |
+
those of a forward iterator with value type `T`.
|
| 96 |
+
|
| 97 |
+
``` cpp
|
| 98 |
+
typename X::difference_type
|
| 99 |
+
```
|
| 100 |
+
|
| 101 |
+
*Result:* A signed integer type, identical to the difference type of
|
| 102 |
+
`X::iterator` and `X::const_iterator`.
|
| 103 |
+
|
| 104 |
+
``` cpp
|
| 105 |
+
typename X::size_type
|
| 106 |
+
```
|
| 107 |
+
|
| 108 |
+
*Result:* An unsigned integer type that can represent any non-negative
|
| 109 |
+
value of `X::difference_type`.
|
| 110 |
+
|
| 111 |
+
``` cpp
|
| 112 |
+
X u;
|
| 113 |
+
X u = X();
|
| 114 |
+
```
|
| 115 |
+
|
| 116 |
+
*Ensures:* `u.empty()`
|
| 117 |
+
|
| 118 |
+
*Complexity:* Constant.
|
| 119 |
+
|
| 120 |
+
``` cpp
|
| 121 |
+
X u(v);
|
| 122 |
+
X u = v;
|
| 123 |
+
```
|
| 124 |
+
|
| 125 |
+
*Preconditions:* `T` is *Cpp17CopyInsertable* into `X` (see below).
|
| 126 |
+
|
| 127 |
+
*Ensures:* `u == v`.
|
| 128 |
+
|
| 129 |
+
*Complexity:* Linear.
|
| 130 |
+
|
| 131 |
+
``` cpp
|
| 132 |
+
X u(rv);
|
| 133 |
+
X u = rv;
|
| 134 |
+
```
|
| 135 |
+
|
| 136 |
+
*Ensures:* `u` is equal to the value that `rv` had before this
|
| 137 |
+
construction.
|
| 138 |
+
|
| 139 |
+
*Complexity:* Linear for `array` and constant for all other standard
|
| 140 |
+
containers.
|
| 141 |
+
|
| 142 |
+
``` cpp
|
| 143 |
+
t = v;
|
| 144 |
+
```
|
| 145 |
+
|
| 146 |
+
*Result:* `X&`.
|
| 147 |
+
|
| 148 |
+
*Ensures:* `t == v`.
|
| 149 |
+
|
| 150 |
+
*Complexity:* Linear.
|
| 151 |
+
|
| 152 |
+
``` cpp
|
| 153 |
+
t = rv
|
| 154 |
+
```
|
| 155 |
+
|
| 156 |
+
*Result:* `X&`.
|
| 157 |
+
|
| 158 |
+
*Effects:* All existing elements of `t` are either move assigned to or
|
| 159 |
+
destroyed.
|
| 160 |
+
|
| 161 |
+
*Ensures:* If `t` and `rv` do not refer to the same object, `t` is equal
|
| 162 |
+
to the value that `rv` had before this assignment.
|
| 163 |
+
|
| 164 |
+
*Complexity:* Linear.
|
| 165 |
+
|
| 166 |
+
``` cpp
|
| 167 |
+
a.~X()
|
| 168 |
+
```
|
| 169 |
+
|
| 170 |
+
*Result:* `void`.
|
| 171 |
+
|
| 172 |
+
*Effects:* Destroys every element of `a`; any memory obtained is
|
| 173 |
+
deallocated.
|
| 174 |
+
|
| 175 |
+
*Complexity:* Linear.
|
| 176 |
+
|
| 177 |
+
``` cpp
|
| 178 |
+
b.begin()
|
| 179 |
+
```
|
| 180 |
+
|
| 181 |
+
*Result:* `iterator`; `const_iterator` for constant `b`.
|
| 182 |
+
|
| 183 |
+
*Returns:* An iterator referring to the first element in the container.
|
| 184 |
+
|
| 185 |
+
*Complexity:* Constant.
|
| 186 |
+
|
| 187 |
+
``` cpp
|
| 188 |
+
b.end()
|
| 189 |
+
```
|
| 190 |
+
|
| 191 |
+
*Result:* `iterator`; `const_iterator` for constant `b`.
|
| 192 |
+
|
| 193 |
+
*Returns:* An iterator which is the past-the-end value for the
|
| 194 |
+
container.
|
| 195 |
+
|
| 196 |
+
*Complexity:* Constant.
|
| 197 |
+
|
| 198 |
+
``` cpp
|
| 199 |
+
b.cbegin()
|
| 200 |
+
```
|
| 201 |
+
|
| 202 |
+
*Result:* `const_iterator`.
|
| 203 |
+
|
| 204 |
+
*Returns:* `const_cast<X const&>(b).begin()`
|
| 205 |
+
|
| 206 |
+
*Complexity:* Constant.
|
| 207 |
+
|
| 208 |
+
``` cpp
|
| 209 |
+
b.cend()
|
| 210 |
+
```
|
| 211 |
+
|
| 212 |
+
*Result:* `const_iterator`.
|
| 213 |
+
|
| 214 |
+
*Returns:* `const_cast<X const&>(b).end()`
|
| 215 |
+
|
| 216 |
+
*Complexity:* Constant.
|
| 217 |
+
|
| 218 |
+
``` cpp
|
| 219 |
+
i <=> j
|
| 220 |
+
```
|
| 221 |
+
|
| 222 |
+
*Result:* `strong_ordering`.
|
| 223 |
+
|
| 224 |
+
*Constraints:* `X::iterator` meets the random access iterator
|
| 225 |
+
requirements.
|
| 226 |
+
|
| 227 |
+
*Complexity:* Constant.
|
| 228 |
+
|
| 229 |
+
``` cpp
|
| 230 |
+
c == b
|
| 231 |
+
```
|
| 232 |
+
|
| 233 |
+
*Preconditions:* `T` meets the *Cpp17EqualityComparable* requirements.
|
| 234 |
+
|
| 235 |
+
*Result:* `bool`.
|
| 236 |
+
|
| 237 |
+
*Returns:* `equal(c.begin(), c.end(), b.begin(), b.end())`
|
| 238 |
+
|
| 239 |
+
[*Note 1*: The algorithm `equal` is defined in
|
| 240 |
+
[[alg.equal]]. — *end note*]
|
| 241 |
+
|
| 242 |
+
*Complexity:* Constant if `c.size() != b.size()`, linear otherwise.
|
| 243 |
+
|
| 244 |
+
*Remarks:* `==` is an equivalence relation.
|
| 245 |
+
|
| 246 |
+
``` cpp
|
| 247 |
+
c != b
|
| 248 |
+
```
|
| 249 |
+
|
| 250 |
+
*Effects:* Equivalent to `!(c == b)`.
|
| 251 |
+
|
| 252 |
+
``` cpp
|
| 253 |
+
t.swap(s)
|
| 254 |
+
```
|
| 255 |
+
|
| 256 |
+
*Result:* `void`.
|
| 257 |
+
|
| 258 |
+
*Effects:* Exchanges the contents of `t` and `s`.
|
| 259 |
+
|
| 260 |
+
*Complexity:* Linear for `array` and constant for all other standard
|
| 261 |
+
containers.
|
| 262 |
+
|
| 263 |
+
``` cpp
|
| 264 |
+
swap(t, s)
|
| 265 |
+
```
|
| 266 |
+
|
| 267 |
+
*Effects:* Equivalent to `t.swap(s)`.
|
| 268 |
+
|
| 269 |
+
``` cpp
|
| 270 |
+
c.size()
|
| 271 |
+
```
|
| 272 |
+
|
| 273 |
+
*Result:* `size_type`.
|
| 274 |
+
|
| 275 |
+
*Returns:* `distance(c.begin(), c.end())`, i.e., the number of elements
|
| 276 |
+
in the container.
|
| 277 |
+
|
| 278 |
+
*Complexity:* Constant.
|
| 279 |
+
|
| 280 |
+
*Remarks:* The number of elements is defined by the rules of
|
| 281 |
constructors, inserts, and erases.
|
| 282 |
|
| 283 |
+
``` cpp
|
| 284 |
+
c.max_size()
|
| 285 |
+
```
|
| 286 |
|
| 287 |
+
*Result:* `size_type`.
|
| 288 |
+
|
| 289 |
+
*Returns:* `distance(begin(), end())` for the largest possible
|
| 290 |
+
container.
|
| 291 |
+
|
| 292 |
+
*Complexity:* Constant.
|
| 293 |
+
|
| 294 |
+
``` cpp
|
| 295 |
+
c.empty()
|
| 296 |
+
```
|
| 297 |
+
|
| 298 |
+
*Result:* `bool`.
|
| 299 |
+
|
| 300 |
+
*Returns:* `c.begin() == c.end()`
|
| 301 |
+
|
| 302 |
+
*Complexity:* Constant.
|
| 303 |
+
|
| 304 |
+
*Remarks:* If the container is empty, then `c.empty()` is `true`.
|
| 305 |
|
| 306 |
In the expressions
|
| 307 |
|
| 308 |
``` cpp
|
| 309 |
i == j
|
|
|
|
| 319 |
where `i` and `j` denote objects of a container’s `iterator` type,
|
| 320 |
either or both may be replaced by an object of the container’s
|
| 321 |
`const_iterator` type referring to the same element with no change in
|
| 322 |
semantics.
|
| 323 |
|
| 324 |
+
Unless otherwise specified, all containers defined in this Clause obtain
|
| 325 |
memory using an allocator (see [[allocator.requirements]]).
|
| 326 |
|
| 327 |
+
[*Note 1*: In particular, containers and iterators do not store
|
| 328 |
references to allocated elements other than through the allocator’s
|
| 329 |
pointer type, i.e., as objects of type `P` or
|
| 330 |
`pointer_traits<P>::template rebind<unspecified>`, where `P` is
|
| 331 |
`allocator_traits<allocator_type>::pointer`. — *end note*]
|
| 332 |
|
|
|
|
| 337 |
constructors obtain an allocator by move construction from the allocator
|
| 338 |
belonging to the container being moved. Such move construction of the
|
| 339 |
allocator shall not exit via an exception. All other constructors for
|
| 340 |
these container types take a `const allocator_type&` argument.
|
| 341 |
|
| 342 |
+
[*Note 2*: If an invocation of a constructor uses the default value of
|
| 343 |
an optional allocator argument, then the allocator type must support
|
| 344 |
value-initialization. — *end note*]
|
| 345 |
|
| 346 |
A copy of this allocator is used for any memory allocation and element
|
| 347 |
construction performed, by these constructors and by all member
|
| 348 |
functions, during the lifetime of each container object or until the
|
| 349 |
allocator is replaced. The allocator may be replaced only via assignment
|
| 350 |
or `swap()`. Allocator replacement is performed by copy assignment, move
|
| 351 |
assignment, or swapping of the allocator only if
|
| 352 |
+
|
| 353 |
+
- `allocator_traits<allocator_type>::propagate_on_container_copy_assignment::value`,
|
| 354 |
+
- `allocator_traits<allocator_type>::propagate_on_container_move_assignment::value`,
|
| 355 |
or
|
| 356 |
+
- `allocator_traits<allocator_type>::propagate_on_container_swap::value`
|
| 357 |
+
|
| 358 |
is `true` within the implementation of the corresponding container
|
| 359 |
operation. In all container types defined in this Clause, the member
|
| 360 |
`get_allocator()` returns a copy of the allocator used to construct the
|
| 361 |
container or, if that allocator has been replaced, a copy of the most
|
| 362 |
recent replacement.
|
| 363 |
|
| 364 |
The expression `a.swap(b)`, for containers `a` and `b` of a standard
|
| 365 |
container type other than `array`, shall exchange the values of `a` and
|
| 366 |
`b` without invoking any move, copy, or swap operations on the
|
| 367 |
+
individual container elements. Any `Compare`, `Pred`, or `Hash` types
|
| 368 |
+
belonging to `a` and `b` shall meet the *Cpp17Swappable* requirements
|
| 369 |
+
and shall be exchanged by calling `swap` as described in
|
| 370 |
+
[[swappable.requirements]]. If
|
| 371 |
`allocator_traits<allocator_type>::propagate_on_container_swap::value`
|
| 372 |
+
is `true`, then `allocator_type` shall meet the *Cpp17Swappable*
|
| 373 |
+
requirements and the allocators of `a` and `b` shall also be exchanged
|
| 374 |
+
by calling `swap` as described in [[swappable.requirements]].
|
| 375 |
+
Otherwise, the allocators shall not be swapped, and the behavior is
|
| 376 |
+
undefined unless `a.get_allocator() == b.get_allocator()`. Every
|
| 377 |
+
iterator referring to an element in one container before the swap shall
|
| 378 |
+
refer to the same element in the other container after the swap. It is
|
| 379 |
+
unspecified whether an iterator with value `a.end()` before the swap
|
| 380 |
+
will have value `b.end()` after the swap.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 381 |
|
| 382 |
Unless otherwise specified (see [[associative.reqmts.except]],
|
| 383 |
[[unord.req.except]], [[deque.modifiers]], and [[vector.modifiers]]) all
|
| 384 |
container types defined in this Clause meet the following additional
|
| 385 |
requirements:
|
| 386 |
|
| 387 |
+
- If an exception is thrown by an `insert()` or `emplace()` function
|
| 388 |
while inserting a single element, that function has no effects.
|
| 389 |
+
- If an exception is thrown by a `push_back()`, `push_front()`,
|
| 390 |
`emplace_back()`, or `emplace_front()` function, that function has no
|
| 391 |
effects.
|
| 392 |
+
- No `erase()`, `clear()`, `pop_back()` or `pop_front()` function throws
|
| 393 |
an exception.
|
| 394 |
+
- No copy constructor or assignment operator of a returned iterator
|
| 395 |
throws an exception.
|
| 396 |
+
- No `swap()` function throws an exception.
|
| 397 |
+
- No `swap()` function invalidates any references, pointers, or
|
| 398 |
iterators referring to the elements of the containers being swapped.
|
| 399 |
+
\[*Note 3*: The `end()` iterator does not refer to any element, so it
|
| 400 |
+
can be invalidated. — *end note*]
|
| 401 |
|
| 402 |
Unless otherwise specified (either explicitly or by defining a function
|
| 403 |
in terms of other functions), invoking a container member function or
|
| 404 |
passing a container as an argument to a library function shall not
|
| 405 |
invalidate iterators to, or change the values of, objects within that
|
|
|
|
| 408 |
A *contiguous container* is a container whose member types `iterator`
|
| 409 |
and `const_iterator` meet the *Cpp17RandomAccessIterator* requirements
|
| 410 |
[[random.access.iterators]] and model `contiguous_iterator`
|
| 411 |
[[iterator.concept.contiguous]].
|
| 412 |
|
| 413 |
+
The behavior of certain container member functions and deduction guides
|
| 414 |
+
depends on whether types qualify as input iterators or allocators. The
|
| 415 |
+
extent to which an implementation determines that a type cannot be an
|
| 416 |
+
input iterator is unspecified, except that as a minimum integral types
|
| 417 |
+
shall not qualify as input iterators. Likewise, the extent to which an
|
| 418 |
+
implementation determines that a type cannot be an allocator is
|
| 419 |
+
unspecified, except that as a minimum a type `A` shall not qualify as an
|
| 420 |
+
allocator unless it meets both of the following conditions:
|
| 421 |
+
|
| 422 |
+
- The *qualified-id* `A::value_type` is valid and denotes a type
|
| 423 |
+
[[temp.deduct]].
|
| 424 |
+
- The expression `declval<A&>().allocate(size_t{})` is well-formed when
|
| 425 |
+
treated as an unevaluated operand.
|
| 426 |
+
|
| 427 |
+
#### Reversible container requirements <a id="container.rev.reqmts">[[container.rev.reqmts]]</a>
|
| 428 |
+
|
| 429 |
+
A type `X` meets the *reversible container* requirements if `X` meets
|
| 430 |
+
the container requirements, the iterator type of `X` belongs to the
|
| 431 |
+
bidirectional or random access iterator categories
|
| 432 |
+
[[iterator.requirements]], and the following types and expressions are
|
| 433 |
+
well-formed and have the specified semantics.
|
| 434 |
+
|
| 435 |
+
``` cpp
|
| 436 |
+
typename X::reverse_iterator
|
| 437 |
+
```
|
| 438 |
+
|
| 439 |
+
*Result:* The type `reverse_iterator<X::iterator>`, an iterator type
|
| 440 |
+
whose value type is `T`.
|
| 441 |
+
|
| 442 |
+
``` cpp
|
| 443 |
+
typename X::const_reverse_iterator
|
| 444 |
+
```
|
| 445 |
+
|
| 446 |
+
*Result:* The type `reverse_iterator<X::const_iterator>`, a constant
|
| 447 |
+
iterator type whose value type is `T`.
|
| 448 |
+
|
| 449 |
+
``` cpp
|
| 450 |
+
a.rbegin()
|
| 451 |
+
```
|
| 452 |
+
|
| 453 |
+
*Result:* `reverse_iterator`; `const_reverse_iterator` for constant `a`.
|
| 454 |
+
|
| 455 |
+
*Returns:* `reverse_iterator(end())`
|
| 456 |
+
|
| 457 |
+
*Complexity:* Constant.
|
| 458 |
+
|
| 459 |
+
``` cpp
|
| 460 |
+
a.rend()
|
| 461 |
+
```
|
| 462 |
+
|
| 463 |
+
*Result:* `reverse_iterator`; `const_reverse_iterator` for constant `a`.
|
| 464 |
+
|
| 465 |
+
*Returns:* `reverse_iterator(begin())`
|
| 466 |
+
|
| 467 |
+
*Complexity:* Constant.
|
| 468 |
+
|
| 469 |
+
``` cpp
|
| 470 |
+
a.crbegin()
|
| 471 |
+
```
|
| 472 |
+
|
| 473 |
+
*Result:* `const_reverse_iterator`.
|
| 474 |
+
|
| 475 |
+
*Returns:* `const_cast<X const&>(a).rbegin()`
|
| 476 |
+
|
| 477 |
+
*Complexity:* Constant.
|
| 478 |
+
|
| 479 |
+
``` cpp
|
| 480 |
+
a.crend()
|
| 481 |
+
```
|
| 482 |
+
|
| 483 |
+
*Result:* `const_reverse_iterator`.
|
| 484 |
+
|
| 485 |
+
*Returns:* `const_cast<X const&>(a).rend()`
|
| 486 |
+
|
| 487 |
+
*Complexity:* Constant.
|
| 488 |
+
|
| 489 |
+
#### Optional container requirements <a id="container.opt.reqmts">[[container.opt.reqmts]]</a>
|
| 490 |
+
|
| 491 |
+
The following operations are provided for some types of containers but
|
| 492 |
+
not others. Those containers for which the listed operations are
|
| 493 |
+
provided shall implement the semantics as described unless otherwise
|
| 494 |
+
stated. If the iterators passed to `lexicographical_compare_three_way`
|
| 495 |
+
meet the constexpr iterator requirements
|
| 496 |
+
[[iterator.requirements.general]] then the operations described below
|
| 497 |
+
are implemented by constexpr functions.
|
| 498 |
+
|
| 499 |
+
``` cpp
|
| 500 |
+
a <=> b
|
| 501 |
+
```
|
| 502 |
+
|
| 503 |
+
*Result:* *`synth-three-way-result`*`<X::value_type>`.
|
| 504 |
+
|
| 505 |
+
*Preconditions:* Either `<=>` is defined for values of type (possibly
|
| 506 |
+
const) `T`, or `<` is defined for values of type (possibly const) `T`
|
| 507 |
+
and `<` is a total ordering relationship.
|
| 508 |
+
|
| 509 |
+
*Returns:*
|
| 510 |
+
`lexicographical_compare_three_way(a.begin(), a.end(), b.begin(), b.end(), `*`synth-three-way`*`)`
|
| 511 |
+
|
| 512 |
+
[*Note 1*: The algorithm `lexicographical_compare_three_way` is defined
|
| 513 |
in [[algorithms]]. — *end note*]
|
| 514 |
|
| 515 |
+
*Complexity:* Linear.
|
| 516 |
+
|
| 517 |
+
#### Allocator-aware containers <a id="container.alloc.reqmts">[[container.alloc.reqmts]]</a>
|
| 518 |
+
|
| 519 |
+
All of the containers defined in [[containers]] and in [[basic.string]]
|
| 520 |
+
except `array` meet the additional requirements of an
|
| 521 |
+
*allocator-aware container*, as described below.
|
| 522 |
|
| 523 |
Given an allocator type `A` and given a container type `X` having a
|
| 524 |
`value_type` identical to `T` and an `allocator_type` identical to
|
| 525 |
`allocator_traits<A>::rebind_alloc<T>` and given an lvalue `m` of type
|
| 526 |
+
`A`, a pointer `p` of type `T*`, an expression `v` of type `T` or
|
| 527 |
+
`const T`, and an rvalue `rv` of type `T`, the following terms are
|
| 528 |
+
defined. If `X` is not allocator-aware or is a specialization of
|
| 529 |
+
`basic_string`, the terms below are defined as if `A` were
|
| 530 |
+
`allocator<T>` — no allocator object needs to be created and user
|
| 531 |
+
specializations of `allocator<T>` are not instantiated:
|
| 532 |
|
| 533 |
- `T` is **Cpp17DefaultInsertable* into `X`* means that the following
|
| 534 |
expression is well-formed:
|
| 535 |
``` cpp
|
| 536 |
allocator_traits<A>::construct(m, p)
|
|
|
|
| 550 |
```
|
| 551 |
|
| 552 |
and its evaluation causes the following postcondition to hold: The
|
| 553 |
value of `*p` is equivalent to the value of `rv` before the
|
| 554 |
evaluation.
|
| 555 |
+
\[*Note 1*: `rv` remains a valid object. Its state is
|
| 556 |
unspecified — *end note*]
|
| 557 |
- `T` is **Cpp17CopyInsertable* into `X`* means that, in addition to `T`
|
| 558 |
being *Cpp17MoveInsertable* into `X`, the following expression is
|
| 559 |
well-formed:
|
| 560 |
``` cpp
|
|
|
|
| 573 |
is well-formed:
|
| 574 |
``` cpp
|
| 575 |
allocator_traits<A>::destroy(m, p)
|
| 576 |
```
|
| 577 |
|
| 578 |
+
[*Note 2*: A container calls
|
| 579 |
`allocator_traits<A>::construct(m, p, args)` to construct an element at
|
| 580 |
`p` using `args`, with `m == get_allocator()`. The default `construct`
|
| 581 |
in `allocator` will call `::new((void*)p) T(args)`, but specialized
|
| 582 |
+
allocators can choose a different definition. — *end note*]
|
| 583 |
+
|
| 584 |
+
In this subclause,
|
| 585 |
+
|
| 586 |
+
- `X` denotes an allocator-aware container class with a `value_type` of
|
| 587 |
+
`T` using an allocator of type `A`,
|
| 588 |
+
- `u` denotes a variable,
|
| 589 |
+
- `a` and `b` denote non-const lvalues of type `X`,
|
| 590 |
+
- `c` denotes an lvalue of type `const X`,
|
| 591 |
+
- `t` denotes an lvalue or a const rvalue of type `X`,
|
| 592 |
+
- `rv` denotes a non-const rvalue of type `X`, and
|
| 593 |
+
- `m` is a value of type `A`.
|
| 594 |
+
|
| 595 |
+
A type `X` meets the allocator-aware container requirements if `X` meets
|
| 596 |
+
the container requirements and the following types, statements, and
|
| 597 |
+
expressions are well-formed and have the specified semantics.
|
| 598 |
+
|
| 599 |
+
``` cpp
|
| 600 |
+
typename X::allocator_type
|
| 601 |
+
```
|
| 602 |
+
|
| 603 |
+
*Result:* `A`
|
| 604 |
+
|
| 605 |
+
*Mandates:* `allocator_type::value_type` is the same as `X::value_type`.
|
| 606 |
+
|
| 607 |
+
``` cpp
|
| 608 |
+
c.get_allocator()
|
| 609 |
+
```
|
| 610 |
+
|
| 611 |
+
*Result:* `A`
|
| 612 |
+
|
| 613 |
+
*Complexity:* Constant.
|
| 614 |
+
|
| 615 |
+
``` cpp
|
| 616 |
+
X u;
|
| 617 |
+
X u = X();
|
| 618 |
+
```
|
| 619 |
+
|
| 620 |
+
*Preconditions:* `A` meets the *Cpp17DefaultConstructible* requirements.
|
| 621 |
+
|
| 622 |
+
*Ensures:* `u.empty()` returns `true`, `u.get_allocator() == A()`.
|
| 623 |
+
|
| 624 |
+
*Complexity:* Constant.
|
| 625 |
+
|
| 626 |
+
``` cpp
|
| 627 |
+
X u(m);
|
| 628 |
+
```
|
| 629 |
+
|
| 630 |
+
*Ensures:* `u.empty()` returns `true`, `u.get_allocator() == m`.
|
| 631 |
+
|
| 632 |
+
*Complexity:* Constant.
|
| 633 |
+
|
| 634 |
+
``` cpp
|
| 635 |
+
X u(t, m);
|
| 636 |
+
```
|
| 637 |
+
|
| 638 |
+
*Preconditions:* `T` is *Cpp17CopyInsertable* into `X`.
|
| 639 |
+
|
| 640 |
+
*Ensures:* `u == t`, `u.get_allocator() == m`
|
| 641 |
+
|
| 642 |
+
*Complexity:* Linear.
|
| 643 |
+
|
| 644 |
+
``` cpp
|
| 645 |
+
X u(rv);
|
| 646 |
+
```
|
| 647 |
+
|
| 648 |
+
*Ensures:* `u` has the same elements as `rv` had before this
|
| 649 |
+
construction; the value of `u.get_allocator()` is the same as the value
|
| 650 |
+
of `rv.get_allocator()` before this construction.
|
| 651 |
+
|
| 652 |
+
*Complexity:* Constant.
|
| 653 |
+
|
| 654 |
+
``` cpp
|
| 655 |
+
X u(rv, m);
|
| 656 |
+
```
|
| 657 |
+
|
| 658 |
+
*Preconditions:* `T` is *Cpp17MoveInsertable* into `X`.
|
| 659 |
+
|
| 660 |
+
*Ensures:* `u` has the same elements, or copies of the elements, that
|
| 661 |
+
`rv` had before this construction, `u.get_allocator() == m`.
|
| 662 |
+
|
| 663 |
+
*Complexity:* Constant if `m == rv.get_allocator()`, otherwise linear.
|
| 664 |
+
|
| 665 |
+
``` cpp
|
| 666 |
+
a = t
|
| 667 |
+
```
|
| 668 |
+
|
| 669 |
+
*Result:* `X&`.
|
| 670 |
+
|
| 671 |
+
*Preconditions:* `T` is *Cpp17CopyInsertable* into `X` and
|
| 672 |
+
*Cpp17CopyAssignable*.
|
| 673 |
+
|
| 674 |
+
*Ensures:* `a == t` is `true`.
|
| 675 |
+
|
| 676 |
+
*Complexity:* Linear.
|
| 677 |
+
|
| 678 |
+
``` cpp
|
| 679 |
+
a = rv
|
| 680 |
+
```
|
| 681 |
+
|
| 682 |
+
*Result:* `X&`.
|
| 683 |
+
|
| 684 |
+
*Preconditions:* If
|
| 685 |
+
`allocator_traits<allocator_type>::propagate_on_container_move_assignment::value`
|
| 686 |
+
is `false`, `T` is *Cpp17MoveInsertable* into `X` and
|
| 687 |
+
*Cpp17MoveAssignable*.
|
| 688 |
+
|
| 689 |
+
*Effects:* All existing elements of `a` are either move assigned to or
|
| 690 |
+
destroyed.
|
| 691 |
+
|
| 692 |
+
*Ensures:* If `a` and `rv` do not refer to the same object, `a` is equal
|
| 693 |
+
to the value that `rv` had before this assignment.
|
| 694 |
+
|
| 695 |
+
*Complexity:* Linear.
|
| 696 |
+
|
| 697 |
+
``` cpp
|
| 698 |
+
a.swap(b)
|
| 699 |
+
```
|
| 700 |
+
|
| 701 |
+
*Result:* `void`
|
| 702 |
+
|
| 703 |
+
*Effects:* Exchanges the contents of `a` and `b`.
|
| 704 |
+
|
| 705 |
+
*Complexity:* Constant.
|
| 706 |
|
| 707 |
### Container data races <a id="container.requirements.dataraces">[[container.requirements.dataraces]]</a>
|
| 708 |
|
| 709 |
For purposes of avoiding data races [[res.on.data.races]],
|
| 710 |
implementations shall consider the following functions to be `const`:
|
|
|
|
| 718 |
concurrently.
|
| 719 |
|
| 720 |
[*Note 1*: For a `vector<int> x` with a size greater than one,
|
| 721 |
`x[1] = 5` and `*x.begin() = 10` can be executed concurrently without a
|
| 722 |
data race, but `x[0] = 5` and `*x.begin() = 10` executed concurrently
|
| 723 |
+
can result in a data race. As an exception to the general rule, for a
|
| 724 |
+
`vector<bool> y`, `y[0] = true` can race with
|
| 725 |
`y[1] = true`. — *end note*]
|
| 726 |
|
| 727 |
### Sequence containers <a id="sequence.reqmts">[[sequence.reqmts]]</a>
|
| 728 |
|
| 729 |
A sequence container organizes a finite set of objects, all of the same
|
| 730 |
type, into a strictly linear arrangement. The library provides four
|
| 731 |
basic kinds of sequence containers: `vector`, `forward_list`, `list`,
|
| 732 |
and `deque`. In addition, `array` is provided as a sequence container
|
| 733 |
which provides limited sequence operations because it has a fixed number
|
| 734 |
of elements. The library also provides container adaptors that make it
|
| 735 |
+
easy to construct abstract data types, such as `stack`s, `queue`s,
|
| 736 |
+
`flat_map`s, `flat_multimap`s, `flat_set`s, or `flat_multiset`s, out of
|
| 737 |
+
the basic sequence container kinds (or out of other program-defined
|
| 738 |
+
sequence containers).
|
| 739 |
|
| 740 |
[*Note 1*: The sequence containers offer the programmer different
|
| 741 |
+
complexity trade-offs. `vector` is appropriate in most circumstances.
|
| 742 |
+
`array` has a fixed size known during translation. `list` or
|
| 743 |
+
`forward_list` support frequent insertions and deletions from the middle
|
| 744 |
+
of the sequence. `deque` supports efficient insertions and deletions
|
| 745 |
+
taking place at the beginning or at the end of the sequence. When
|
| 746 |
+
choosing a container, remember `vector` is best; leave a comment to
|
|
|
|
|
|
|
| 747 |
explain if you choose from the rest! — *end note*]
|
| 748 |
|
| 749 |
+
In this subclause,
|
| 750 |
+
|
| 751 |
+
- `X` denotes a sequence container class,
|
| 752 |
+
- `a` denotes a value of type `X` containing elements of type `T`,
|
| 753 |
+
- `u` denotes the name of a variable being declared,
|
| 754 |
+
- `A` denotes `X::allocator_type` if the *qualified-id*
|
| 755 |
`X::allocator_type` is valid and denotes a type [[temp.deduct]] and
|
| 756 |
+
`allocator<T>` if it doesn’t,
|
| 757 |
+
- `i` and `j` denote iterators that meet the *Cpp17InputIterator*
|
| 758 |
+
requirements and refer to elements implicitly convertible to
|
| 759 |
+
`value_type`,
|
| 760 |
+
- `[i, j)` denotes a valid range,
|
| 761 |
+
- `rg` denotes a value of a type `R` that models
|
| 762 |
+
`container-compatible-range<T>`,
|
| 763 |
+
- `il` designates an object of type `initializer_list<value_type>`,
|
| 764 |
+
- `n` denotes a value of type `X::size_type`,
|
| 765 |
+
- `p` denotes a valid constant iterator to `a`,
|
| 766 |
+
- `q` denotes a valid dereferenceable constant iterator to `a`,
|
| 767 |
+
- `[q1, q2)` denotes a valid range of constant iterators in `a`,
|
| 768 |
+
- `t` denotes an lvalue or a const rvalue of `X::value_type`, and
|
| 769 |
+
- `rv` denotes a non-const rvalue of `X::value_type`.
|
| 770 |
+
- `Args` denotes a template parameter pack;
|
| 771 |
+
- `args` denotes a function parameter pack with the pattern `Args&&`.
|
| 772 |
|
| 773 |
The complexities of the expressions are sequence dependent.
|
| 774 |
|
| 775 |
+
A type `X` meets the *sequence container* requirements if `X` meets the
|
| 776 |
+
container requirements and the following statements and expressions are
|
| 777 |
+
well-formed and have the specified semantics.
|
| 778 |
+
|
| 779 |
+
``` cpp
|
| 780 |
+
X u(n, t);
|
| 781 |
+
```
|
| 782 |
+
|
| 783 |
+
*Preconditions:* `T` is *Cpp17CopyInsertable* into `X`.
|
| 784 |
+
|
| 785 |
+
*Effects:* Constructs a sequence container with `n` copies of `t`.
|
| 786 |
+
|
| 787 |
+
*Ensures:* `distance(u.begin(), u.end()) == n` is `true`.
|
| 788 |
+
|
| 789 |
+
``` cpp
|
| 790 |
+
X u(i, j);
|
| 791 |
+
```
|
| 792 |
+
|
| 793 |
+
*Preconditions:* `T` is *Cpp17EmplaceConstructible* into `X` from `*i`.
|
| 794 |
+
For `vector`, if the iterator does not meet the *Cpp17ForwardIterator*
|
| 795 |
+
requirements [[forward.iterators]], `T` is also *Cpp17MoveInsertable*
|
| 796 |
+
into `X`.
|
| 797 |
+
|
| 798 |
+
*Effects:* Constructs a sequence container equal to the range `[i, j)`.
|
| 799 |
+
Each iterator in the range \[`i`, `j`) is dereferenced exactly once.
|
| 800 |
+
|
| 801 |
+
*Ensures:* `distance(u.begin(), u.end()) == distance(i, j)` is `true`.
|
| 802 |
+
|
| 803 |
+
``` cpp
|
| 804 |
+
X(from_range, rg)
|
| 805 |
+
```
|
| 806 |
+
|
| 807 |
+
*Preconditions:* `T` is *Cpp17EmplaceConstructible* into `X` from
|
| 808 |
+
`*ranges::begin(rg)`. For `vector`, if `R` models neither
|
| 809 |
+
`ranges::sized_range` nor `ranges::forward_range`, `T` is also
|
| 810 |
+
*Cpp17MoveInsertable* into `X`.
|
| 811 |
+
|
| 812 |
+
*Effects:* Constructs a sequence container equal to the range `rg`. Each
|
| 813 |
+
iterator in the range `rg` is dereferenced exactly once.
|
| 814 |
+
|
| 815 |
+
*Ensures:* `distance(begin(), end()) == ranges::distance(rg)` is `true`.
|
| 816 |
+
|
| 817 |
+
``` cpp
|
| 818 |
+
X(il)
|
| 819 |
+
```
|
| 820 |
+
|
| 821 |
+
*Effects:* Equivalent to `X(il.begin(), il.end())`.
|
| 822 |
+
|
| 823 |
+
``` cpp
|
| 824 |
+
a = il
|
| 825 |
+
```
|
| 826 |
+
|
| 827 |
+
*Result:* `X&`.
|
| 828 |
+
|
| 829 |
+
*Preconditions:* `T` is *Cpp17CopyInsertable* into `X` and
|
| 830 |
+
*Cpp17CopyAssignable*.
|
| 831 |
+
|
| 832 |
+
*Effects:* Assigns the range \[`il.begin()`, `il.end()`) into `a`. All
|
| 833 |
+
existing elements of `a` are either assigned to or destroyed.
|
| 834 |
+
|
| 835 |
+
*Returns:* `*this`.
|
| 836 |
+
|
| 837 |
+
``` cpp
|
| 838 |
+
a.emplace(p, args)
|
| 839 |
+
```
|
| 840 |
+
|
| 841 |
+
*Result:* `iterator`.
|
| 842 |
+
|
| 843 |
+
*Preconditions:* `T` is *Cpp17EmplaceConstructible* into `X` from
|
| 844 |
+
`args`. For `vector` and `deque`, `T` is also *Cpp17MoveInsertable* into
|
| 845 |
+
`X` and *Cpp17MoveAssignable*.
|
| 846 |
+
|
| 847 |
+
*Effects:* Inserts an object of type `T` constructed with
|
| 848 |
+
`std::forward<Args>(args)...` before `p`.
|
| 849 |
+
|
| 850 |
+
[*Note 1*: `args` can directly or indirectly refer to a value in
|
| 851 |
`a`. — *end note*]
|
| 852 |
|
| 853 |
+
*Returns:* An iterator that points to the new element constructed from
|
| 854 |
+
`args` into `a`.
|
| 855 |
|
| 856 |
+
``` cpp
|
| 857 |
+
a.insert(p, t)
|
| 858 |
+
```
|
| 859 |
|
| 860 |
+
*Result:* `iterator`.
|
|
|
|
| 861 |
|
| 862 |
+
*Preconditions:* `T` is *Cpp17CopyInsertable* into `X`. For `vector` and
|
| 863 |
+
`deque`, `T` is also *Cpp17CopyAssignable*.
|
| 864 |
|
| 865 |
+
*Effects:* Inserts a copy of `t` before `p`.
|
|
|
|
| 866 |
|
| 867 |
+
*Returns:* An iterator that points to the copy of `t` inserted into `a`.
|
|
|
|
| 868 |
|
| 869 |
+
``` cpp
|
| 870 |
+
a.insert(p, rv)
|
| 871 |
+
```
|
| 872 |
|
| 873 |
+
*Result:* `iterator`.
|
| 874 |
+
|
| 875 |
+
*Preconditions:* `T` is *Cpp17MoveInsertable* into `X`. For `vector` and
|
| 876 |
+
`deque`, `T` is also *Cpp17MoveAssignable*.
|
| 877 |
+
|
| 878 |
+
*Effects:* Inserts a copy of `rv` before `p`.
|
| 879 |
+
|
| 880 |
+
*Returns:* An iterator that points to the copy of `rv` inserted into
|
| 881 |
+
`a`.
|
| 882 |
+
|
| 883 |
+
``` cpp
|
| 884 |
+
a.insert(p, n, t)
|
| 885 |
+
```
|
| 886 |
+
|
| 887 |
+
*Result:* `iterator`.
|
| 888 |
+
|
| 889 |
+
*Preconditions:* `T` is *Cpp17CopyInsertable* into `X` and
|
| 890 |
+
*Cpp17CopyAssignable*.
|
| 891 |
+
|
| 892 |
+
*Effects:* Inserts `n` copies of `t` before `p`.
|
| 893 |
+
|
| 894 |
+
*Returns:* An iterator that points to the copy of the first element
|
| 895 |
+
inserted into `a`, or `p` if `n == 0`.
|
| 896 |
+
|
| 897 |
+
``` cpp
|
| 898 |
+
a.insert(p, i, j)
|
| 899 |
+
```
|
| 900 |
+
|
| 901 |
+
*Result:* `iterator`.
|
| 902 |
+
|
| 903 |
+
*Preconditions:* `T` is *Cpp17EmplaceConstructible* into `X` from `*i`.
|
| 904 |
+
For `vector` and `deque`, `T` is also *Cpp17MoveInsertable* into `X`,
|
| 905 |
+
and `T` meets the *Cpp17MoveConstructible*, *Cpp17MoveAssignable*, and
|
| 906 |
+
*Cpp17Swappable*[[swappable.requirements]] requirements. Neither `i` nor
|
| 907 |
+
`j` are iterators into `a`.
|
| 908 |
+
|
| 909 |
+
*Effects:* Inserts copies of elements in `[i, j)` before `p`. Each
|
| 910 |
+
iterator in the range \[`i`, `j`) shall be dereferenced exactly once.
|
| 911 |
+
|
| 912 |
+
*Returns:* An iterator that points to the copy of the first element
|
| 913 |
+
inserted into `a`, or `p` if `i == j`.
|
| 914 |
+
|
| 915 |
+
``` cpp
|
| 916 |
+
a.insert_range(p, rg)
|
| 917 |
+
```
|
| 918 |
+
|
| 919 |
+
*Result:* `iterator`.
|
| 920 |
+
|
| 921 |
+
*Preconditions:* `T` is *Cpp17EmplaceConstructible* into `X` from
|
| 922 |
+
`*ranges::begin(rg)`. For `vector` and `deque`, `T` is also
|
| 923 |
+
*Cpp17MoveInsertable* into `X`, and `T` meets the
|
| 924 |
+
*Cpp17MoveConstructible*, *Cpp17MoveAssignable*, and
|
| 925 |
+
*Cpp17Swappable*[[swappable.requirements]] requirements. `rg` and `a` do
|
| 926 |
+
not overlap.
|
| 927 |
+
|
| 928 |
+
*Effects:* Inserts copies of elements in `rg` before `p`. Each iterator
|
| 929 |
+
in the range `rg` is dereferenced exactly once.
|
| 930 |
+
|
| 931 |
+
*Returns:* An iterator that points to the copy of the first element
|
| 932 |
+
inserted into `a`, or `p` if `rg` is empty.
|
| 933 |
+
|
| 934 |
+
``` cpp
|
| 935 |
+
a.insert(p, il)
|
| 936 |
+
```
|
| 937 |
+
|
| 938 |
+
*Effects:* Equivalent to `a.insert(p, il.begin(), il.end())`.
|
| 939 |
+
|
| 940 |
+
``` cpp
|
| 941 |
+
a.erase(q)
|
| 942 |
+
```
|
| 943 |
+
|
| 944 |
+
*Result:* `iterator`.
|
| 945 |
+
|
| 946 |
+
*Preconditions:* For `vector` and `deque`, `T` is *Cpp17MoveAssignable*.
|
| 947 |
+
|
| 948 |
+
*Effects:* Erases the element pointed to by `q`.
|
| 949 |
+
|
| 950 |
+
*Returns:* An iterator that points to the element immediately following
|
| 951 |
+
`q` prior to the element being erased. If no such element exists,
|
| 952 |
+
`a.end()` is returned.
|
| 953 |
+
|
| 954 |
+
``` cpp
|
| 955 |
+
a.erase(q1, q2)
|
| 956 |
+
```
|
| 957 |
+
|
| 958 |
+
*Result:* `iterator`.
|
| 959 |
+
|
| 960 |
+
*Preconditions:* For `vector` and `deque`, `T` is *Cpp17MoveAssignable*.
|
| 961 |
+
|
| 962 |
+
*Effects:* Erases the elements in the range `[q1, q2)`.
|
| 963 |
+
|
| 964 |
+
*Returns:* An iterator that points to the element pointed to by `q2`
|
| 965 |
+
prior to any elements being erased. If no such element exists, `a.end()`
|
| 966 |
+
is returned.
|
| 967 |
+
|
| 968 |
+
``` cpp
|
| 969 |
+
a.clear()
|
| 970 |
+
```
|
| 971 |
+
|
| 972 |
+
*Result:* `void`
|
| 973 |
+
|
| 974 |
+
*Effects:* Destroys all elements in `a`. Invalidates all references,
|
| 975 |
+
pointers, and iterators referring to the elements of `a` and may
|
| 976 |
+
invalidate the past-the-end iterator.
|
| 977 |
+
|
| 978 |
+
*Ensures:* `a.empty()` is `true`.
|
| 979 |
+
|
| 980 |
+
*Complexity:* Linear.
|
| 981 |
+
|
| 982 |
+
``` cpp
|
| 983 |
+
a.assign(i, j)
|
| 984 |
+
```
|
| 985 |
+
|
| 986 |
+
*Result:* `void`
|
| 987 |
+
|
| 988 |
+
*Preconditions:* `T` is *Cpp17EmplaceConstructible* into `X` from `*i`
|
| 989 |
+
and assignable from `*i`. For `vector`, if the iterator does not meet
|
| 990 |
+
the forward iterator requirements [[forward.iterators]], `T` is also
|
| 991 |
+
*Cpp17MoveInsertable* into `X`. Neither `i` nor `j` are iterators into
|
| 992 |
+
`a`.
|
| 993 |
+
|
| 994 |
+
*Effects:* Replaces elements in `a` with a copy of `[i, j)`. Invalidates
|
| 995 |
+
all references, pointers and iterators referring to the elements of `a`.
|
| 996 |
+
For `vector` and `deque`, also invalidates the past-the-end iterator.
|
| 997 |
+
Each iterator in the range \[`i`, `j`) is dereferenced exactly once.
|
| 998 |
+
|
| 999 |
+
``` cpp
|
| 1000 |
+
a.assign_range(rg)
|
| 1001 |
+
```
|
| 1002 |
+
|
| 1003 |
+
*Result:* `void`
|
| 1004 |
+
|
| 1005 |
+
*Mandates:* `assignable_from<T&, ranges::range_reference_t<R>>` is
|
| 1006 |
+
modeled.
|
| 1007 |
+
|
| 1008 |
+
*Preconditions:* `T` is *Cpp17EmplaceConstructible* into `X` from
|
| 1009 |
+
`*ranges::begin(rg)`. For `vector`, if `R` models neither
|
| 1010 |
+
`ranges::sized_range` nor `ranges::forward_range`, `T` is also
|
| 1011 |
+
*Cpp17MoveInsertable* into `X`. `rg` and `a` do not overlap.
|
| 1012 |
+
|
| 1013 |
+
*Effects:* Replaces elements in `a` with a copy of each element in `rg`.
|
| 1014 |
+
Invalidates all references, pointers, and iterators referring to the
|
| 1015 |
+
elements of `a`. For `vector` and `deque`, also invalidates the
|
| 1016 |
+
past-the-end iterator. Each iterator in the range `rg` is dereferenced
|
| 1017 |
+
exactly once.
|
| 1018 |
+
|
| 1019 |
+
``` cpp
|
| 1020 |
+
a.assign(il)
|
| 1021 |
+
```
|
| 1022 |
+
|
| 1023 |
+
*Effects:* Equivalent to `a.assign(il.begin(), il.end())`.
|
| 1024 |
+
|
| 1025 |
+
``` cpp
|
| 1026 |
+
a.assign(n, t)
|
| 1027 |
+
```
|
| 1028 |
+
|
| 1029 |
+
*Result:* `void`
|
| 1030 |
+
|
| 1031 |
+
*Preconditions:* `T` is *Cpp17CopyInsertable* into `X` and
|
| 1032 |
+
*Cpp17CopyAssignable*. `t` is not a reference into `a`.
|
| 1033 |
+
|
| 1034 |
+
*Effects:* Replaces elements in `a` with `n` copies of `t`. Invalidates
|
| 1035 |
+
all references, pointers and iterators referring to the elements of `a`.
|
| 1036 |
+
For `vector` and `deque`, also invalidates the past-the-end iterator.
|
| 1037 |
|
| 1038 |
For every sequence container defined in this Clause and in [[strings]]:
|
| 1039 |
|
| 1040 |
- If the constructor
|
| 1041 |
``` cpp
|
|
|
|
| 1069 |
and a type that does not qualify as an input iterator is deduced for
|
| 1070 |
that parameter, or if it has an `Allocator` template parameter and a
|
| 1071 |
type that does not qualify as an allocator is deduced for that
|
| 1072 |
parameter.
|
| 1073 |
|
| 1074 |
+
The following operations are provided for some types of sequence
|
| 1075 |
+
containers but not others. Operations other than `prepend_range` and
|
| 1076 |
+
`append_range` are implemented so as to take amortized constant time.
|
|
|
|
| 1077 |
|
| 1078 |
+
``` cpp
|
| 1079 |
+
a.front()
|
| 1080 |
+
```
|
| 1081 |
+
|
| 1082 |
+
*Result:* `reference; const_reference` for constant `a`.
|
| 1083 |
+
|
| 1084 |
+
*Returns:* `*a.begin()`
|
| 1085 |
+
|
| 1086 |
+
*Remarks:* Required for `basic_string`, `array`, `deque`,
|
| 1087 |
+
`forward_list`, `list`, and `vector`.
|
| 1088 |
+
|
| 1089 |
+
``` cpp
|
| 1090 |
+
a.back()
|
| 1091 |
+
```
|
| 1092 |
+
|
| 1093 |
+
*Result:* `reference; const_reference` for constant `a`.
|
| 1094 |
+
|
| 1095 |
+
*Effects:* Equivalent to:
|
| 1096 |
+
|
| 1097 |
+
``` cpp
|
| 1098 |
+
auto tmp = a.end();
|
| 1099 |
+
--tmp;
|
| 1100 |
+
return *tmp;
|
| 1101 |
+
```
|
| 1102 |
+
|
| 1103 |
+
*Remarks:* Required for `basic_string`, `array`, `deque`, `list`, and
|
| 1104 |
+
`vector`.
|
| 1105 |
+
|
| 1106 |
+
``` cpp
|
| 1107 |
+
a.emplace_front(args)
|
| 1108 |
+
```
|
| 1109 |
+
|
| 1110 |
+
*Result:* `reference`
|
| 1111 |
+
|
| 1112 |
+
*Preconditions:* `T` is *Cpp17EmplaceConstructible* into `X` from
|
| 1113 |
+
`args`.
|
| 1114 |
+
|
| 1115 |
+
*Effects:* Prepends an object of type `T` constructed with
|
| 1116 |
+
`std::forward<Args>(args)...`.
|
| 1117 |
+
|
| 1118 |
+
*Returns:* `a.front()`.
|
| 1119 |
+
|
| 1120 |
+
*Remarks:* Required for `deque`, `forward_list`, and `list`.
|
| 1121 |
+
|
| 1122 |
+
``` cpp
|
| 1123 |
+
a.emplace_back(args)
|
| 1124 |
+
```
|
| 1125 |
+
|
| 1126 |
+
*Result:* `reference`
|
| 1127 |
+
|
| 1128 |
+
*Preconditions:* `T` is *Cpp17EmplaceConstructible* into `X` from
|
| 1129 |
+
`args`. For `vector`, `T` is also *Cpp17MoveInsertable* into `X`.
|
| 1130 |
+
|
| 1131 |
+
*Effects:* Appends an object of type `T` constructed with
|
| 1132 |
+
`std::forward<Args>(args)...`.
|
| 1133 |
+
|
| 1134 |
+
*Returns:* `a.back()`.
|
| 1135 |
+
|
| 1136 |
+
*Remarks:* Required for `deque`, `list`, and `vector`.
|
| 1137 |
+
|
| 1138 |
+
``` cpp
|
| 1139 |
+
a.push_front(t)
|
| 1140 |
+
```
|
| 1141 |
+
|
| 1142 |
+
*Result:* `void`
|
| 1143 |
+
|
| 1144 |
+
*Preconditions:* `T` is *Cpp17CopyInsertable* into `X`.
|
| 1145 |
+
|
| 1146 |
+
*Effects:* Prepends a copy of `t`.
|
| 1147 |
+
|
| 1148 |
+
*Remarks:* Required for `deque`, `forward_list`, and `list`.
|
| 1149 |
+
|
| 1150 |
+
``` cpp
|
| 1151 |
+
a.push_front(rv)
|
| 1152 |
+
```
|
| 1153 |
+
|
| 1154 |
+
*Result:* `void`
|
| 1155 |
+
|
| 1156 |
+
*Preconditions:* `T` is *Cpp17MoveInsertable* into `X`.
|
| 1157 |
+
|
| 1158 |
+
*Effects:* Prepends a copy of `rv`.
|
| 1159 |
+
|
| 1160 |
+
*Remarks:* Required for `deque`, `forward_list`, and `list`.
|
| 1161 |
+
|
| 1162 |
+
``` cpp
|
| 1163 |
+
a.prepend_range(rg)
|
| 1164 |
+
```
|
| 1165 |
+
|
| 1166 |
+
*Result:* `void`
|
| 1167 |
+
|
| 1168 |
+
*Preconditions:* `T` is *Cpp17EmplaceConstructible* into `X` from
|
| 1169 |
+
`*ranges::begin(rg)`. For `deque`, `T` is also *Cpp17MoveInsertable*
|
| 1170 |
+
into `X`, and `T` meets the *Cpp17MoveConstructible*,
|
| 1171 |
+
*Cpp17MoveAssignable*, and *Cpp17Swappable*[[swappable.requirements]]
|
| 1172 |
+
requirements.
|
| 1173 |
+
|
| 1174 |
+
*Effects:* Inserts copies of elements in `rg` before `begin()`. Each
|
| 1175 |
+
iterator in the range `rg` is dereferenced exactly once.
|
| 1176 |
+
|
| 1177 |
+
[*Note 2*: The order of elements in `rg` is not
|
| 1178 |
+
reversed. — *end note*]
|
| 1179 |
+
|
| 1180 |
+
*Remarks:* Required for `deque`, `forward_list`, and `list`.
|
| 1181 |
+
|
| 1182 |
+
``` cpp
|
| 1183 |
+
a.push_back(t)
|
| 1184 |
+
```
|
| 1185 |
+
|
| 1186 |
+
*Result:* `void`
|
| 1187 |
+
|
| 1188 |
+
*Preconditions:* `T` is *Cpp17CopyInsertable* into `X`.
|
| 1189 |
+
|
| 1190 |
+
*Effects:* Appends a copy of `t`.
|
| 1191 |
+
|
| 1192 |
+
*Remarks:* Required for `basic_string`, `deque`, `list`, and `vector`.
|
| 1193 |
+
|
| 1194 |
+
``` cpp
|
| 1195 |
+
a.push_back(rv)
|
| 1196 |
+
```
|
| 1197 |
+
|
| 1198 |
+
*Result:* `void`
|
| 1199 |
+
|
| 1200 |
+
*Preconditions:* `T` is *Cpp17MoveInsertable* into `X`.
|
| 1201 |
+
|
| 1202 |
+
*Effects:* Appends a copy of `rv`.
|
| 1203 |
+
|
| 1204 |
+
*Remarks:* Required for `basic_string`, `deque`, `list`, and `vector`.
|
| 1205 |
+
|
| 1206 |
+
``` cpp
|
| 1207 |
+
a.append_range(rg)
|
| 1208 |
+
```
|
| 1209 |
+
|
| 1210 |
+
*Result:* `void`
|
| 1211 |
+
|
| 1212 |
+
*Preconditions:* `T` is *Cpp17EmplaceConstructible* into `X` from
|
| 1213 |
+
`*ranges::begin(rg)`. For `vector`, `T` is also *Cpp17MoveInsertable*
|
| 1214 |
+
into `X`.
|
| 1215 |
+
|
| 1216 |
+
*Effects:* Inserts copies of elements in `rg` before `end()`. Each
|
| 1217 |
+
iterator in the range `rg` is dereferenced exactly once.
|
| 1218 |
+
|
| 1219 |
+
*Remarks:* Required for `deque`, `list`, and `vector`.
|
| 1220 |
+
|
| 1221 |
+
``` cpp
|
| 1222 |
+
a.pop_front()
|
| 1223 |
+
```
|
| 1224 |
+
|
| 1225 |
+
*Result:* `void`
|
| 1226 |
+
|
| 1227 |
+
*Preconditions:* `a.empty()` is `false`.
|
| 1228 |
+
|
| 1229 |
+
*Effects:* Destroys the first element.
|
| 1230 |
+
|
| 1231 |
+
*Remarks:* Required for `deque`, `forward_list`, and `list`.
|
| 1232 |
+
|
| 1233 |
+
``` cpp
|
| 1234 |
+
a.pop_back()
|
| 1235 |
+
```
|
| 1236 |
+
|
| 1237 |
+
*Result:* `void`
|
| 1238 |
+
|
| 1239 |
+
*Preconditions:* `a.empty()` is `false`.
|
| 1240 |
+
|
| 1241 |
+
*Effects:* Destroys the last element.
|
| 1242 |
+
|
| 1243 |
+
*Remarks:* Required for `basic_string`, `deque`, `list`, and `vector`.
|
| 1244 |
+
|
| 1245 |
+
``` cpp
|
| 1246 |
+
a[n]
|
| 1247 |
+
```
|
| 1248 |
+
|
| 1249 |
+
*Result:* `reference; const_reference` for constant `a`
|
| 1250 |
+
|
| 1251 |
+
*Returns:* `*(a.begin() + n)`
|
| 1252 |
+
|
| 1253 |
+
*Remarks:* Required for `basic_string`, `array`, `deque`, and `vector`.
|
| 1254 |
+
|
| 1255 |
+
``` cpp
|
| 1256 |
+
a.at(n)
|
| 1257 |
+
```
|
| 1258 |
+
|
| 1259 |
+
*Result:* `reference; const_reference` for constant `a`
|
| 1260 |
+
|
| 1261 |
+
*Returns:* `*(a.begin() + n)`
|
| 1262 |
+
|
| 1263 |
+
*Throws:* `out_of_range` if `n >= a.size()`.
|
| 1264 |
+
|
| 1265 |
+
*Remarks:* Required for `basic_string`, `array`, `deque`, and `vector`.
|
| 1266 |
|
| 1267 |
### Node handles <a id="container.node">[[container.node]]</a>
|
| 1268 |
|
| 1269 |
#### Overview <a id="container.node.overview">[[container.node.overview]]</a>
|
| 1270 |
|
|
|
|
| 1303 |
|
| 1304 |
``` cpp
|
| 1305 |
template<unspecified>
|
| 1306 |
class node-handle {
|
| 1307 |
public:
|
| 1308 |
+
// These type declarations are described in [associative.reqmts] and [unord.req].
|
| 1309 |
using value_type = see below; // not present for map containers
|
| 1310 |
using key_type = see below; // not present for set containers
|
| 1311 |
using mapped_type = see below; // not present for set containers
|
| 1312 |
using allocator_type = see below;
|
| 1313 |
|
| 1314 |
private:
|
| 1315 |
+
using container_node_type = unspecified; // exposition only
|
| 1316 |
+
using ator_traits = allocator_traits<allocator_type>; // exposition only
|
| 1317 |
|
| 1318 |
+
typename ator_traits::template
|
| 1319 |
+
rebind_traits<container_node_type>::pointer ptr_; // exposition only
|
| 1320 |
+
optional<allocator_type> alloc_; // exposition only
|
| 1321 |
|
| 1322 |
public:
|
| 1323 |
// [container.node.cons], constructors, copy, and assignment
|
| 1324 |
constexpr node-handle() noexcept : ptr_(), alloc_() {}
|
| 1325 |
node-handle(node-handle&&) noexcept;
|
|
|
|
| 1492 |
special members specified above. It has no base classes or members other
|
| 1493 |
than those specified.
|
| 1494 |
|
| 1495 |
### Associative containers <a id="associative.reqmts">[[associative.reqmts]]</a>
|
| 1496 |
|
| 1497 |
+
#### General <a id="associative.reqmts.general">[[associative.reqmts.general]]</a>
|
| 1498 |
+
|
| 1499 |
Associative containers provide fast retrieval of data based on keys. The
|
| 1500 |
library provides four basic kinds of associative containers: `set`,
|
| 1501 |
+
`multiset`, `map` and `multimap`. The library also provides container
|
| 1502 |
+
adaptors that make it easy to construct abstract data types, such as
|
| 1503 |
+
`flat_map`s, `flat_multimap`s, `flat_set`s, or `flat_multiset`s, out of
|
| 1504 |
+
the basic sequence container kinds (or out of other program-defined
|
| 1505 |
+
sequence containers).
|
| 1506 |
|
| 1507 |
Each associative container is parameterized on `Key` and an ordering
|
| 1508 |
relation `Compare` that induces a strict weak ordering [[alg.sorting]]
|
| 1509 |
on elements of `Key`. In addition, `map` and `multimap` associate an
|
| 1510 |
arbitrary *mapped type* `T` with the `Key`. The object of type `Compare`
|
|
|
|
| 1542 |
[*Note 2*: `iterator` and `const_iterator` have identical semantics in
|
| 1543 |
this case, and `iterator` is convertible to `const_iterator`. Users can
|
| 1544 |
avoid violating the one-definition rule by always using `const_iterator`
|
| 1545 |
in their function parameter lists. — *end note*]
|
| 1546 |
|
| 1547 |
+
In this subclause,
|
| 1548 |
+
|
| 1549 |
+
- `X` denotes an associative container class,
|
| 1550 |
+
- `a` denotes a value of type `X`,
|
| 1551 |
+
- `a2` denotes a value of a type with nodes compatible with type `X` (
|
| 1552 |
+
[[container.node.compat]]),
|
| 1553 |
+
- `b` denotes a value or type `X` or `const X`,
|
| 1554 |
+
- `u` denotes the name of a variable being declared,
|
| 1555 |
+
- `a_uniq` denotes a value of type `X` when `X` supports unique keys,
|
| 1556 |
+
- `a_eq` denotes a value of type `X` when `X` supports multiple keys,
|
| 1557 |
+
- `a_tran` denotes a value of type `X` or `const X` when the
|
| 1558 |
+
*qualified-id* `X::key_compare::is_transparent` is valid and denotes a
|
| 1559 |
+
type [[temp.deduct]],
|
| 1560 |
+
- `i` and `j` meet the *Cpp17InputIterator* requirements and refer to
|
| 1561 |
+
elements implicitly convertible to `value_type`,
|
| 1562 |
+
- \[`i`, `j`) denotes a valid range,
|
| 1563 |
+
- `rg` denotes a value of a type `R` that models
|
| 1564 |
+
`container-compatible-range<value_type>`,
|
| 1565 |
+
- `p` denotes a valid constant iterator to `a`,
|
| 1566 |
+
- `q` denotes a valid dereferenceable constant iterator to `a`,
|
| 1567 |
+
- `r` denotes a valid dereferenceable iterator to `a`,
|
| 1568 |
+
- `[q1, q2)` denotes a valid range of constant iterators in `a`,
|
| 1569 |
+
- `il` designates an object of type `initializer_list<value_type>`,
|
| 1570 |
+
- `t` denotes a value of type `X::value_type`,
|
| 1571 |
+
- `k` denotes a value of type `X::key_type`, and
|
| 1572 |
+
- `c` denotes a value of type `X::key_compare` or
|
| 1573 |
+
`const X::key_compare`;
|
| 1574 |
+
- `kl` is a value such that `a` is partitioned [[alg.sorting]] with
|
| 1575 |
+
respect to `c(x, kl)`, with `x` the key value of `e` and `e` in `a`;
|
| 1576 |
+
- `ku` is a value such that `a` is partitioned with respect to
|
| 1577 |
+
`!c(ku, x)`, with `x` the key value of `e` and `e` in `a`;
|
| 1578 |
+
- `ke` is a value such that `a` is partitioned with respect to
|
| 1579 |
+
`c(x, ke)` and `!c(ke, x)`, with `c(x, ke)` implying `!c(ke, x)` and
|
| 1580 |
+
with `x` the key value of `e` and `e` in `a`;
|
| 1581 |
+
- `kx` is a value such that
|
| 1582 |
+
- `a` is partitioned with respect to `c(x, kx)` and `!c(kx, x)`, with
|
| 1583 |
+
`c(x, kx)` implying `!c(kx, x)` and with `x` the key value of `e`
|
| 1584 |
+
and `e` in `a`, and
|
| 1585 |
+
- `kx` is not convertible to either `iterator` or `const_iterator`;
|
| 1586 |
+
and
|
| 1587 |
+
- `A` denotes the storage allocator used by `X`, if any, or
|
| 1588 |
+
`allocator<X::value_type>` otherwise,
|
| 1589 |
+
- `m` denotes an allocator of a type convertible to `A`, and `nh`
|
| 1590 |
+
denotes a non-const rvalue of type `X::node_type`.
|
| 1591 |
+
|
| 1592 |
+
A type `X` meets the *associative container* requirements if `X` meets
|
| 1593 |
+
all the requirements of an allocator-aware container
|
| 1594 |
+
[[container.requirements.general]] and the following types, statements,
|
| 1595 |
+
and expressions are well-formed and have the specified semantics, except
|
| 1596 |
+
that for `map` and `multimap`, the requirements placed on `value_type`
|
| 1597 |
+
in [[container.alloc.reqmts]] apply instead to `key_type` and
|
| 1598 |
+
`mapped_type`.
|
| 1599 |
|
| 1600 |
[*Note 3*: For example, in some cases `key_type` and `mapped_type` are
|
| 1601 |
required to be *Cpp17CopyAssignable* even though the associated
|
| 1602 |
`value_type`, `pair<const key_type, mapped_type>`, is not
|
| 1603 |
*Cpp17CopyAssignable*. — *end note*]
|
| 1604 |
|
| 1605 |
+
``` cpp
|
| 1606 |
+
typename X::key_type
|
| 1607 |
+
```
|
| 1608 |
+
|
| 1609 |
+
*Result:* `Key`.
|
| 1610 |
+
|
| 1611 |
+
``` cpp
|
| 1612 |
+
typename X::mapped_type
|
| 1613 |
+
```
|
| 1614 |
+
|
| 1615 |
+
*Result:* `T`.
|
| 1616 |
+
|
| 1617 |
+
*Remarks:* For `map` and `multimap` only.
|
| 1618 |
+
|
| 1619 |
+
``` cpp
|
| 1620 |
+
typename X::value_type
|
| 1621 |
+
```
|
| 1622 |
+
|
| 1623 |
+
*Result:* `Key` for `set` and `multiset` only; `pair<const Key, T>` for
|
| 1624 |
+
`map` and `multimap` only.
|
| 1625 |
+
|
| 1626 |
+
*Preconditions:* `X::value_type` is *Cpp17Erasable* from `X`.
|
| 1627 |
+
|
| 1628 |
+
``` cpp
|
| 1629 |
+
typename X::key_compare
|
| 1630 |
+
```
|
| 1631 |
+
|
| 1632 |
+
*Result:* `Compare`.
|
| 1633 |
+
|
| 1634 |
+
*Preconditions:* `key_compare` is *Cpp17CopyConstructible*.
|
| 1635 |
+
|
| 1636 |
+
``` cpp
|
| 1637 |
+
typename X::value_compare
|
| 1638 |
+
```
|
| 1639 |
+
|
| 1640 |
+
*Result:* A binary predicate type. It is the same as `key_compare` for
|
| 1641 |
+
`set` and `multiset`; is an ordering relation on pairs induced by the
|
| 1642 |
+
first component (i.e., `Key`) for `map` and `multimap`.
|
| 1643 |
+
|
| 1644 |
+
``` cpp
|
| 1645 |
+
typename X::node_type
|
| 1646 |
+
```
|
| 1647 |
+
|
| 1648 |
+
*Result:* A specialization of the *node-handle* class
|
| 1649 |
+
template [[container.node]], such that the public nested types are the
|
| 1650 |
+
same types as the corresponding types in `X`.
|
| 1651 |
+
|
| 1652 |
+
``` cpp
|
| 1653 |
+
X(c)
|
| 1654 |
+
```
|
| 1655 |
+
|
| 1656 |
+
*Effects:* Constructs an empty container. Uses a copy of `c` as a
|
| 1657 |
+
comparison object.
|
| 1658 |
+
|
| 1659 |
+
*Complexity:* Constant.
|
| 1660 |
+
|
| 1661 |
+
``` cpp
|
| 1662 |
+
X u = X();
|
| 1663 |
+
X u;
|
| 1664 |
+
```
|
| 1665 |
+
|
| 1666 |
+
*Preconditions:* `key_compare` meets the *Cpp17DefaultConstructible*
|
| 1667 |
+
requirements.
|
| 1668 |
+
|
| 1669 |
+
*Effects:* Constructs an empty container. Uses `Compare()` as a
|
| 1670 |
+
comparison object.
|
| 1671 |
+
|
| 1672 |
+
*Complexity:* Constant.
|
| 1673 |
+
|
| 1674 |
+
``` cpp
|
| 1675 |
+
X(i, j, c)
|
| 1676 |
+
```
|
| 1677 |
+
|
| 1678 |
+
*Preconditions:* `value_type` is *Cpp17EmplaceConstructible* into `X`
|
| 1679 |
+
from `*i`.
|
| 1680 |
+
|
| 1681 |
+
*Effects:* Constructs an empty container and inserts elements from the
|
| 1682 |
+
range \[`i`, `j`) into it; uses `c` as a comparison object.
|
| 1683 |
+
|
| 1684 |
+
*Complexity:* N log N in general, where N has the value
|
| 1685 |
+
`distance(i, j)`; linear if \[`i`, `j`) is sorted with respect to
|
| 1686 |
+
`value_comp()`.
|
| 1687 |
+
|
| 1688 |
+
``` cpp
|
| 1689 |
+
X(i, j)
|
| 1690 |
+
```
|
| 1691 |
+
|
| 1692 |
+
*Preconditions:* `key_compare` meets the *Cpp17DefaultConstructible*
|
| 1693 |
+
requirements. `value_type` is *Cpp17EmplaceConstructible* into `X` from
|
| 1694 |
+
`*i`.
|
| 1695 |
+
|
| 1696 |
+
*Effects:* Constructs an empty container and inserts elements from the
|
| 1697 |
+
range \[`i`, `j`) into it; uses `Compare()` as a comparison object.
|
| 1698 |
+
|
| 1699 |
+
*Complexity:* N log N in general, where N has the value
|
| 1700 |
+
`distance(i, j)`; linear if \[`i`, `j`) is sorted with respect to
|
| 1701 |
+
`value_comp()`.
|
| 1702 |
+
|
| 1703 |
+
``` cpp
|
| 1704 |
+
X(from_range, rg, c)
|
| 1705 |
+
```
|
| 1706 |
+
|
| 1707 |
+
*Preconditions:* `value_type` is *Cpp17EmplaceConstructible* into `X`
|
| 1708 |
+
from `*ranges::begin(rg)`.
|
| 1709 |
+
|
| 1710 |
+
*Effects:* Constructs an empty container and inserts each element from
|
| 1711 |
+
`rg` into it. Uses `c` as the comparison object.
|
| 1712 |
+
|
| 1713 |
+
*Complexity:* N log N in general, where N has the value
|
| 1714 |
+
`ranges::distance(rg)`; linear if `rg` is sorted with respect to
|
| 1715 |
+
`value_comp()`.
|
| 1716 |
+
|
| 1717 |
+
``` cpp
|
| 1718 |
+
X(from_range, rg)
|
| 1719 |
+
```
|
| 1720 |
+
|
| 1721 |
+
*Preconditions:* `key_compare` meets the *Cpp17DefaultConstructible*
|
| 1722 |
+
requirements. `value_type` is *Cpp17EmplaceConstructible* into `X` from
|
| 1723 |
+
`*ranges::begin(rg)`.
|
| 1724 |
+
|
| 1725 |
+
*Effects:* Constructs an empty container and inserts each element from
|
| 1726 |
+
`rg` into it. Uses `Compare()` as the comparison object.
|
| 1727 |
+
|
| 1728 |
+
*Complexity:* Same as `X(from_range, rg, c)`.
|
| 1729 |
+
|
| 1730 |
+
``` cpp
|
| 1731 |
+
X(il, c)
|
| 1732 |
+
```
|
| 1733 |
+
|
| 1734 |
+
*Effects:* Equivalent to `X(il.begin(), il.end(), c)`.
|
| 1735 |
+
|
| 1736 |
+
``` cpp
|
| 1737 |
+
X(il)
|
| 1738 |
+
```
|
| 1739 |
+
|
| 1740 |
+
*Effects:* Equivalent to `X(il.begin(), il.end())`.
|
| 1741 |
+
|
| 1742 |
+
``` cpp
|
| 1743 |
+
a = il
|
| 1744 |
+
```
|
| 1745 |
+
|
| 1746 |
+
*Result:* `X&`
|
| 1747 |
+
|
| 1748 |
+
*Preconditions:* `value_type` is *Cpp17CopyInsertable* into `X` and
|
| 1749 |
+
*Cpp17CopyAssignable*.
|
| 1750 |
+
|
| 1751 |
+
*Effects:* Assigns the range \[`il.begin()`, `il.end()`) into `a`. All
|
| 1752 |
+
existing elements of `a` are either assigned to or destroyed.
|
| 1753 |
+
|
| 1754 |
+
*Complexity:* N log N in general, where N has the value
|
| 1755 |
+
`il.size() + a.size()`; linear if \[`il.begin()`, `il.end()`) is sorted
|
| 1756 |
+
with respect to `value_comp()`.
|
| 1757 |
+
|
| 1758 |
+
``` cpp
|
| 1759 |
+
b.key_comp()
|
| 1760 |
+
```
|
| 1761 |
+
|
| 1762 |
+
*Result:* `X::key_compare`
|
| 1763 |
+
|
| 1764 |
+
*Returns:* The comparison object out of which `b` was constructed.
|
| 1765 |
+
|
| 1766 |
+
*Complexity:* Constant.
|
| 1767 |
+
|
| 1768 |
+
``` cpp
|
| 1769 |
+
b.value_comp()
|
| 1770 |
+
```
|
| 1771 |
+
|
| 1772 |
+
*Result:* `X::value_compare`
|
| 1773 |
+
|
| 1774 |
+
*Returns:* An object of `value_compare` constructed out of the
|
| 1775 |
+
comparison object.
|
| 1776 |
+
|
| 1777 |
+
*Complexity:* Constant.
|
| 1778 |
+
|
| 1779 |
+
``` cpp
|
| 1780 |
+
a_uniq.emplace(args)
|
| 1781 |
+
```
|
| 1782 |
+
|
| 1783 |
+
*Result:* `pair<iterator, bool>`
|
| 1784 |
+
|
| 1785 |
+
*Preconditions:* `value_type` is *Cpp17EmplaceConstructible* into `X`
|
| 1786 |
+
from `args`.
|
| 1787 |
+
|
| 1788 |
+
*Effects:* Inserts a `value_type` object `t` constructed with
|
| 1789 |
+
`std::forward<Args>(args)...` if and only if there is no element in the
|
| 1790 |
+
container with key equivalent to the key of `t`.
|
| 1791 |
+
|
| 1792 |
+
*Returns:* The `bool` component of the returned pair is `true` if and
|
| 1793 |
+
only if the insertion takes place, and the iterator component of the
|
| 1794 |
+
pair points to the element with key equivalent to the key of `t`.
|
| 1795 |
+
|
| 1796 |
+
*Complexity:* Logarithmic.
|
| 1797 |
+
|
| 1798 |
+
``` cpp
|
| 1799 |
+
a_eq.emplace(args)
|
| 1800 |
+
```
|
| 1801 |
+
|
| 1802 |
+
*Result:* `iterator`
|
| 1803 |
+
|
| 1804 |
+
*Preconditions:* `value_type` is *Cpp17EmplaceConstructible* into `X`
|
| 1805 |
+
from `args`.
|
| 1806 |
+
|
| 1807 |
+
*Effects:* Inserts a `value_type` object `t` constructed with
|
| 1808 |
+
`std::forward<Args>(args)...`. If a range containing elements equivalent
|
| 1809 |
+
to `t` exists in `a_eq`, `t` is inserted at the end of that range.
|
| 1810 |
+
|
| 1811 |
+
*Returns:* An iterator pointing to the newly inserted element.
|
| 1812 |
+
|
| 1813 |
+
*Complexity:* Logarithmic.
|
| 1814 |
+
|
| 1815 |
+
``` cpp
|
| 1816 |
+
a.emplace_hint(p, args)
|
| 1817 |
+
```
|
| 1818 |
+
|
| 1819 |
+
*Result:* `iterator`
|
| 1820 |
+
|
| 1821 |
+
*Effects:* Equivalent to `a.emplace(std::forward<Args>(args)...)`,
|
| 1822 |
+
except that the element is inserted as close as possible to the position
|
| 1823 |
+
just prior to `p`.
|
| 1824 |
+
|
| 1825 |
+
*Returns:* An iterator pointing to the element with the key equivalent
|
| 1826 |
+
to the newly inserted element.
|
| 1827 |
+
|
| 1828 |
+
*Complexity:* Logarithmic in general, but amortized constant if the
|
| 1829 |
+
element is inserted right before `p`.
|
| 1830 |
+
|
| 1831 |
+
``` cpp
|
| 1832 |
+
a_uniq.insert(t)
|
| 1833 |
+
```
|
| 1834 |
+
|
| 1835 |
+
*Result:* `pair<iterator, bool>`
|
| 1836 |
+
|
| 1837 |
+
*Preconditions:* If `t` is a non-const rvalue, `value_type` is
|
| 1838 |
+
*Cpp17MoveInsertable* into `X`; otherwise, `value_type` is
|
| 1839 |
+
*Cpp17CopyInsertable* into `X`.
|
| 1840 |
+
|
| 1841 |
+
*Effects:* Inserts `t` if and only if there is no element in the
|
| 1842 |
+
container with key equivalent to the key of `t`.
|
| 1843 |
+
|
| 1844 |
+
*Returns:* The `bool` component of the returned pair is `true` if and
|
| 1845 |
+
only if the insertion takes place, and the `iterator` component of the
|
| 1846 |
+
pair points to the element with key equivalent to the key of `t`.
|
| 1847 |
+
|
| 1848 |
+
*Complexity:* Logarithmic.
|
| 1849 |
+
|
| 1850 |
+
``` cpp
|
| 1851 |
+
a_eq.insert(t)
|
| 1852 |
+
```
|
| 1853 |
+
|
| 1854 |
+
*Result:* `iterator`
|
| 1855 |
+
|
| 1856 |
+
*Preconditions:* If `t` is a non-const rvalue, `value_type` is
|
| 1857 |
+
*Cpp17MoveInsertable* into `X`; otherwise, `value_type` is
|
| 1858 |
+
*Cpp17CopyInsertable* into `X`.
|
| 1859 |
+
|
| 1860 |
+
*Effects:* Inserts `t` and returns the iterator pointing to the newly
|
| 1861 |
+
inserted element. If a range containing elements equivalent to `t`
|
| 1862 |
+
exists in `a_eq`, `t` is inserted at the end of that range.
|
| 1863 |
+
|
| 1864 |
+
*Complexity:* Logarithmic.
|
| 1865 |
+
|
| 1866 |
+
``` cpp
|
| 1867 |
+
a.insert(p, t)
|
| 1868 |
+
```
|
| 1869 |
+
|
| 1870 |
+
*Result:* `iterator`
|
| 1871 |
+
|
| 1872 |
+
*Preconditions:* If `t` is a non-const rvalue, `value_type` is
|
| 1873 |
+
*Cpp17MoveInsertable* into `X`; otherwise, `value_type` is
|
| 1874 |
+
*Cpp17CopyInsertable* into `X`.
|
| 1875 |
+
|
| 1876 |
+
*Effects:* Inserts `t` if and only if there is no element with key
|
| 1877 |
+
equivalent to the key of `t` in containers with unique keys; always
|
| 1878 |
+
inserts `t` in containers with equivalent keys. `t` is inserted as close
|
| 1879 |
+
as possible to the position just prior to `p`.
|
| 1880 |
+
|
| 1881 |
+
*Returns:* An iterator pointing to the element with key equivalent to
|
| 1882 |
+
the key of `t`.
|
| 1883 |
+
|
| 1884 |
+
*Complexity:* Logarithmic in general, but amortized constant if `t` is
|
| 1885 |
+
inserted right before `p`.
|
| 1886 |
+
|
| 1887 |
+
``` cpp
|
| 1888 |
+
a.insert(i, j)
|
| 1889 |
+
```
|
| 1890 |
+
|
| 1891 |
+
*Result:* `void`
|
| 1892 |
+
|
| 1893 |
+
*Preconditions:* `value_type` is *Cpp17EmplaceConstructible* into `X`
|
| 1894 |
+
from `*i`. Neither `i` nor `j` are iterators into `a`.
|
| 1895 |
+
|
| 1896 |
+
*Effects:* Inserts each element from the range \[`i`, `j`) if and only
|
| 1897 |
+
if there is no element with key equivalent to the key of that element in
|
| 1898 |
+
containers with unique keys; always inserts that element in containers
|
| 1899 |
+
with equivalent keys.
|
| 1900 |
+
|
| 1901 |
+
*Complexity:* N log (`a.size()` + N), where N has the value
|
| 1902 |
+
`distance(i, j)`.
|
| 1903 |
+
|
| 1904 |
+
``` cpp
|
| 1905 |
+
a.insert_range(rg)
|
| 1906 |
+
```
|
| 1907 |
+
|
| 1908 |
+
*Result:* `void`
|
| 1909 |
+
|
| 1910 |
+
*Preconditions:* `value_type` is *Cpp17EmplaceConstructible* into `X`
|
| 1911 |
+
from `*ranges::begin(rg)`. `rg` and `a` do not overlap.
|
| 1912 |
+
|
| 1913 |
+
*Effects:* Inserts each element from `rg` if and only if there is no
|
| 1914 |
+
element with key equivalent to the key of that element in containers
|
| 1915 |
+
with unique keys; always inserts that element in containers with
|
| 1916 |
+
equivalent keys.
|
| 1917 |
+
|
| 1918 |
+
*Complexity:* N log (`a.size()` + N), where N has the value
|
| 1919 |
+
`ranges::distance(rg)`.
|
| 1920 |
+
|
| 1921 |
+
``` cpp
|
| 1922 |
+
a.insert(il)
|
| 1923 |
+
```
|
| 1924 |
+
|
| 1925 |
+
*Effects:* Equivalent to `a.insert(il.begin(), il.end())`.
|
| 1926 |
+
|
| 1927 |
+
``` cpp
|
| 1928 |
+
a_uniq.insert(nh)
|
| 1929 |
+
```
|
| 1930 |
+
|
| 1931 |
+
*Result:* `insert_return_type`
|
| 1932 |
+
|
| 1933 |
+
*Preconditions:* `nh` is empty or
|
| 1934 |
+
`a_uniq.get_allocator() == nh.get_allocator()` is `true`.
|
| 1935 |
+
|
| 1936 |
+
*Effects:* If `nh` is empty, has no effect. Otherwise, inserts the
|
| 1937 |
+
element owned by `nh` if and only if there is no element in the
|
| 1938 |
+
container with a key equivalent to `nh.key()`.
|
| 1939 |
+
|
| 1940 |
+
*Returns:* If `nh` is empty, `inserted` is `false`, `position` is
|
| 1941 |
+
`end()`, and `node` is empty. Otherwise if the insertion took place,
|
| 1942 |
+
`inserted` is `true`, `position` points to the inserted element, and
|
| 1943 |
+
`node` is empty; if the insertion failed, `inserted` is `false`, `node`
|
| 1944 |
+
has the previous value of `nh`, and `position` points to an element with
|
| 1945 |
+
a key equivalent to `nh.key()`.
|
| 1946 |
+
|
| 1947 |
+
*Complexity:* Logarithmic.
|
| 1948 |
+
|
| 1949 |
+
``` cpp
|
| 1950 |
+
a_eq.insert(nh)
|
| 1951 |
+
```
|
| 1952 |
+
|
| 1953 |
+
*Result:* `iterator`
|
| 1954 |
+
|
| 1955 |
+
*Preconditions:* `nh` is empty or
|
| 1956 |
+
`a_eq.get_allocator() == nh.get_allocator()` is `true`.
|
| 1957 |
+
|
| 1958 |
+
*Effects:* If `nh` is empty, has no effect and returns `a_eq.end()`.
|
| 1959 |
+
Otherwise, inserts the element owned by `nh` and returns an iterator
|
| 1960 |
+
pointing to the newly inserted element. If a range containing elements
|
| 1961 |
+
with keys equivalent to `nh.key()` exists in `a_eq`, the element is
|
| 1962 |
+
inserted at the end of that range.
|
| 1963 |
+
|
| 1964 |
+
*Ensures:* `nh` is empty.
|
| 1965 |
+
|
| 1966 |
+
*Complexity:* Logarithmic.
|
| 1967 |
+
|
| 1968 |
+
``` cpp
|
| 1969 |
+
a.insert(p, nh)
|
| 1970 |
+
```
|
| 1971 |
+
|
| 1972 |
+
*Result:* `iterator`
|
| 1973 |
+
|
| 1974 |
+
*Preconditions:* `nh` is empty or
|
| 1975 |
+
`a.get_allocator() == nh.get_allocator()` is `true`.
|
| 1976 |
+
|
| 1977 |
+
*Effects:* If `nh` is empty, has no effect and returns `a.end()`.
|
| 1978 |
+
Otherwise, inserts the element owned by `nh` if and only if there is no
|
| 1979 |
+
element with key equivalent to `nh.key()` in containers with unique
|
| 1980 |
+
keys; always inserts the element owned by `nh` in containers with
|
| 1981 |
+
equivalent keys. The element is inserted as close as possible to the
|
| 1982 |
+
position just prior to `p`.
|
| 1983 |
+
|
| 1984 |
+
*Ensures:* `nh` is empty if insertion succeeds, unchanged if insertion
|
| 1985 |
+
fails.
|
| 1986 |
+
|
| 1987 |
+
*Returns:* An iterator pointing to the element with key equivalent to
|
| 1988 |
+
`nh.key()`.
|
| 1989 |
+
|
| 1990 |
+
*Complexity:* Logarithmic in general, but amortized constant if the
|
| 1991 |
+
element is inserted right before `p`.
|
| 1992 |
+
|
| 1993 |
+
``` cpp
|
| 1994 |
+
a.extract(k)
|
| 1995 |
+
```
|
| 1996 |
+
|
| 1997 |
+
*Result:* `node_type`
|
| 1998 |
+
|
| 1999 |
+
*Effects:* Removes the first element in the container with key
|
| 2000 |
+
equivalent to `k`.
|
| 2001 |
+
|
| 2002 |
+
*Returns:* A `node_type` owning the element if found, otherwise an empty
|
| 2003 |
+
`node_type`.
|
| 2004 |
+
|
| 2005 |
+
*Complexity:* log (`a.size()`)
|
| 2006 |
+
|
| 2007 |
+
``` cpp
|
| 2008 |
+
a_tran.extract(kx)
|
| 2009 |
+
```
|
| 2010 |
+
|
| 2011 |
+
*Result:* `node_type`
|
| 2012 |
+
|
| 2013 |
+
*Effects:* Removes the first element in the container with key `r` such
|
| 2014 |
+
that `!c(r, kx) && !c(kx, r)` is `true`.
|
| 2015 |
+
|
| 2016 |
+
*Returns:* A `node_type` owning the element if found, otherwise an empty
|
| 2017 |
+
`node_type`.
|
| 2018 |
+
|
| 2019 |
+
*Complexity:* log(`a_tran.size()`)
|
| 2020 |
+
|
| 2021 |
+
``` cpp
|
| 2022 |
+
a.extract(q)
|
| 2023 |
+
```
|
| 2024 |
+
|
| 2025 |
+
*Result:* `node_type`
|
| 2026 |
+
|
| 2027 |
+
*Effects:* Removes the element pointed to by `q`.
|
| 2028 |
+
|
| 2029 |
+
*Returns:* A `node_type` owning that element.
|
| 2030 |
+
|
| 2031 |
+
*Complexity:* Amortized constant.
|
| 2032 |
+
|
| 2033 |
+
``` cpp
|
| 2034 |
+
a.merge(a2)
|
| 2035 |
+
```
|
| 2036 |
+
|
| 2037 |
+
*Result:* `void`
|
| 2038 |
+
|
| 2039 |
+
*Preconditions:* `a.get_allocator() == a2.get_allocator()`.
|
| 2040 |
+
|
| 2041 |
+
*Effects:* Attempts to extract each element in `a2` and insert it into
|
| 2042 |
+
`a` using the comparison object of `a`. In containers with unique keys,
|
| 2043 |
+
if there is an element in `a` with key equivalent to the key of an
|
| 2044 |
+
element from `a2`, then that element is not extracted from `a2`.
|
| 2045 |
+
|
| 2046 |
+
*Ensures:* Pointers and references to the transferred elements of `a2`
|
| 2047 |
+
refer to those same elements but as members of `a`. Iterators referring
|
| 2048 |
+
to the transferred elements will continue to refer to their elements,
|
| 2049 |
+
but they now behave as iterators into `a`, not into `a2`.
|
| 2050 |
+
|
| 2051 |
+
*Throws:* Nothing unless the comparison object throws.
|
| 2052 |
+
|
| 2053 |
+
*Complexity:* N log(`a.size()+` N), where N has the value `a2.size()`.
|
| 2054 |
+
|
| 2055 |
+
``` cpp
|
| 2056 |
+
a.erase(k)
|
| 2057 |
+
```
|
| 2058 |
+
|
| 2059 |
+
*Result:* `size_type`
|
| 2060 |
+
|
| 2061 |
+
*Effects:* Erases all elements in the container with key equivalent to
|
| 2062 |
+
`k`.
|
| 2063 |
+
|
| 2064 |
+
*Returns:* The number of erased elements.
|
| 2065 |
+
|
| 2066 |
+
*Complexity:* log (`a.size()`) + `a.count(k)`
|
| 2067 |
+
|
| 2068 |
+
``` cpp
|
| 2069 |
+
a_tran.erase(kx)
|
| 2070 |
+
```
|
| 2071 |
+
|
| 2072 |
+
*Result:* `size_type`
|
| 2073 |
+
|
| 2074 |
+
*Effects:* Erases all elements in the container with key `r` such that
|
| 2075 |
+
`!c(r, kx) && !c(kx, r)` is `true`.
|
| 2076 |
+
|
| 2077 |
+
*Returns:* The number of erased elements.
|
| 2078 |
+
|
| 2079 |
+
*Complexity:* log(`a_tran.size())` + `a_tran.count(kx)`
|
| 2080 |
+
|
| 2081 |
+
``` cpp
|
| 2082 |
+
a.erase(q)
|
| 2083 |
+
```
|
| 2084 |
+
|
| 2085 |
+
*Result:* `iterator`
|
| 2086 |
+
|
| 2087 |
+
*Effects:* Erases the element pointed to by `q`.
|
| 2088 |
+
|
| 2089 |
+
*Returns:* An iterator pointing to the element immediately following `q`
|
| 2090 |
+
prior to the element being erased. If no such element exists, returns
|
| 2091 |
+
`a.end()`.
|
| 2092 |
+
|
| 2093 |
+
*Complexity:* Amortized constant.
|
| 2094 |
+
|
| 2095 |
+
``` cpp
|
| 2096 |
+
a.erase(r)
|
| 2097 |
+
```
|
| 2098 |
+
|
| 2099 |
+
*Result:* `iterator`
|
| 2100 |
+
|
| 2101 |
+
*Effects:* Erases the element pointed to by `r`.
|
| 2102 |
+
|
| 2103 |
+
*Returns:* An iterator pointing to the element immediately following `r`
|
| 2104 |
+
prior to the element being erased. If no such element exists, returns
|
| 2105 |
+
`a.end()`.
|
| 2106 |
+
|
| 2107 |
+
*Complexity:* Amortized constant.
|
| 2108 |
+
|
| 2109 |
+
``` cpp
|
| 2110 |
+
a.erase(q1, q2)
|
| 2111 |
+
```
|
| 2112 |
+
|
| 2113 |
+
*Result:* `iterator`
|
| 2114 |
+
|
| 2115 |
+
*Effects:* Erases all the elements in the range \[`q1`, `q2`).
|
| 2116 |
+
|
| 2117 |
+
*Returns:* An iterator pointing to the element pointed to by `q2` prior
|
| 2118 |
+
to any elements being erased. If no such element exists, `a.end()` is
|
| 2119 |
+
returned.
|
| 2120 |
+
|
| 2121 |
+
*Complexity:* log(`a.size()`) + N, where N has the value
|
| 2122 |
+
`distance(q1, q2)`.
|
| 2123 |
+
|
| 2124 |
+
``` cpp
|
| 2125 |
+
a.clear()
|
| 2126 |
+
```
|
| 2127 |
+
|
| 2128 |
+
*Effects:* Equivalent to `a.erase(a.begin(), a.end())`.
|
| 2129 |
+
|
| 2130 |
+
*Ensures:* `a.empty()` is `true`.
|
| 2131 |
+
|
| 2132 |
+
*Complexity:* Linear in `a.size()`.
|
| 2133 |
+
|
| 2134 |
+
``` cpp
|
| 2135 |
+
b.find(k)
|
| 2136 |
+
```
|
| 2137 |
+
|
| 2138 |
+
*Result:* `iterator`; `const_iterator` for constant `b`.
|
| 2139 |
+
|
| 2140 |
+
*Returns:* An iterator pointing to an element with the key equivalent to
|
| 2141 |
+
`k`, or `b.end()` if such an element is not found.
|
| 2142 |
+
|
| 2143 |
+
*Complexity:* Logarithmic.
|
| 2144 |
+
|
| 2145 |
+
``` cpp
|
| 2146 |
+
a_tran.find(ke)
|
| 2147 |
+
```
|
| 2148 |
+
|
| 2149 |
+
*Result:* `iterator`; `const_iterator` for constant `a_tran`.
|
| 2150 |
+
|
| 2151 |
+
*Returns:* An iterator pointing to an element with key `r` such that
|
| 2152 |
+
`!c(r, ke) && !c(ke, r)` is `true`, or `a_tran.end()` if such an element
|
| 2153 |
+
is not found.
|
| 2154 |
+
|
| 2155 |
+
*Complexity:* Logarithmic.
|
| 2156 |
+
|
| 2157 |
+
``` cpp
|
| 2158 |
+
b.count(k)
|
| 2159 |
+
```
|
| 2160 |
+
|
| 2161 |
+
*Result:* `size_type`
|
| 2162 |
+
|
| 2163 |
+
*Returns:* The number of elements with key equivalent to `k`.
|
| 2164 |
+
|
| 2165 |
+
*Complexity:* log (`b.size()`) + `b.count(k)`
|
| 2166 |
+
|
| 2167 |
+
``` cpp
|
| 2168 |
+
a_tran.count(ke)
|
| 2169 |
+
```
|
| 2170 |
+
|
| 2171 |
+
*Result:* `size_type`
|
| 2172 |
+
|
| 2173 |
+
*Returns:* The number of elements with key `r` such that
|
| 2174 |
+
`!c(r, ke) && !c(ke, r)`.
|
| 2175 |
+
|
| 2176 |
+
*Complexity:* log (`a_tran.size()`) + `a_tran.count(ke)`
|
| 2177 |
+
|
| 2178 |
+
``` cpp
|
| 2179 |
+
b.contains(k)
|
| 2180 |
+
```
|
| 2181 |
+
|
| 2182 |
+
*Result:* `bool`
|
| 2183 |
+
|
| 2184 |
+
*Effects:* Equivalent to: `return b.find(k) != b.end();`
|
| 2185 |
+
|
| 2186 |
+
``` cpp
|
| 2187 |
+
a_tran.contains(ke)
|
| 2188 |
+
```
|
| 2189 |
+
|
| 2190 |
+
*Result:* `bool`
|
| 2191 |
+
|
| 2192 |
+
*Effects:* Equivalent to: `return a_tran.find(ke) != a_tran.end();`
|
| 2193 |
+
|
| 2194 |
+
``` cpp
|
| 2195 |
+
b.lower_bound(k)
|
| 2196 |
+
```
|
| 2197 |
+
|
| 2198 |
+
*Result:* `iterator`; `const_iterator` for constant `b`.
|
| 2199 |
+
|
| 2200 |
+
*Returns:* An iterator pointing to the first element with key not less
|
| 2201 |
+
than `k`, or `b.end()` if such an element is not found.
|
| 2202 |
+
|
| 2203 |
+
*Complexity:* Logarithmic.
|
| 2204 |
+
|
| 2205 |
+
``` cpp
|
| 2206 |
+
a_tran.lower_bound(kl)
|
| 2207 |
+
```
|
| 2208 |
+
|
| 2209 |
+
*Result:* `iterator`; `const_iterator` for constant `a_tran`.
|
| 2210 |
+
|
| 2211 |
+
*Returns:* An iterator pointing to the first element with key `r` such
|
| 2212 |
+
that `!c(r, kl)`, or `a_tran.end()` if such an element is not found.
|
| 2213 |
+
|
| 2214 |
+
*Complexity:* Logarithmic.
|
| 2215 |
+
|
| 2216 |
+
``` cpp
|
| 2217 |
+
b.upper_bound(k)
|
| 2218 |
+
```
|
| 2219 |
+
|
| 2220 |
+
*Result:* `iterator`; `const_iterator` for constant `b`.
|
| 2221 |
+
|
| 2222 |
+
*Returns:* An iterator pointing to the first element with key greater
|
| 2223 |
+
than `k`, or `b.end()` if such an element is not found.
|
| 2224 |
+
|
| 2225 |
+
*Complexity:* Logarithmic,
|
| 2226 |
+
|
| 2227 |
+
``` cpp
|
| 2228 |
+
a_tran.upper_bound(ku)
|
| 2229 |
+
```
|
| 2230 |
+
|
| 2231 |
+
*Result:* `iterator`; `const_iterator` for constant `a_tran`.
|
| 2232 |
+
|
| 2233 |
+
*Returns:* An iterator pointing to the first element with key `r` such
|
| 2234 |
+
that `c(ku, r)`, or `a_tran.end()` if such an element is not found.
|
| 2235 |
+
|
| 2236 |
+
*Complexity:* Logarithmic.
|
| 2237 |
+
|
| 2238 |
+
``` cpp
|
| 2239 |
+
b.equal_range(k)
|
| 2240 |
+
```
|
| 2241 |
+
|
| 2242 |
+
*Result:* `pair<iterator, iterator>`;
|
| 2243 |
+
`pair<const_iterator, const_iterator>` for constant `b`.
|
| 2244 |
+
|
| 2245 |
+
*Effects:* Equivalent to:
|
| 2246 |
+
`return make_pair(b.lower_bound(k), b.upper_bound(k));`
|
| 2247 |
+
|
| 2248 |
+
*Complexity:* Logarithmic.
|
| 2249 |
+
|
| 2250 |
+
``` cpp
|
| 2251 |
+
a_tran.equal_range(ke)
|
| 2252 |
+
```
|
| 2253 |
+
|
| 2254 |
+
*Result:* `pair<iterator, iterator>`;
|
| 2255 |
+
`pair<const_iterator, const_iterator>` for constant `a_tran`.
|
| 2256 |
+
|
| 2257 |
+
*Effects:* Equivalent to:
|
| 2258 |
+
`return make_pair(a_tran.lower_bound(ke), a_tran.upper_bound(ke));`
|
| 2259 |
+
|
| 2260 |
+
*Complexity:* Logarithmic.
|
| 2261 |
+
|
| 2262 |
+
The `insert`, `insert_range`, and `emplace` members shall not affect the
|
| 2263 |
+
validity of iterators and references to the container, and the `erase`
|
| 2264 |
+
members shall invalidate only iterators and references to the erased
|
| 2265 |
+
elements.
|
| 2266 |
|
| 2267 |
The `extract` members invalidate only iterators to the removed element;
|
| 2268 |
pointers and references to the removed element remain valid. However,
|
| 2269 |
accessing the element through such pointers and references while the
|
| 2270 |
element is owned by a `node_type` is undefined behavior. References and
|
|
|
|
| 2296 |
assignment operator, the target container shall then use the comparison
|
| 2297 |
object from the container being copied, as if that comparison object had
|
| 2298 |
been passed to the target container in its constructor.
|
| 2299 |
|
| 2300 |
The member function templates `find`, `count`, `contains`,
|
| 2301 |
+
`lower_bound`, `upper_bound`, `equal_range`, `erase`, and `extract`
|
| 2302 |
+
shall not participate in overload resolution unless the *qualified-id*
|
| 2303 |
+
`Compare::is_transparent` is valid and denotes a type [[temp.deduct]].
|
| 2304 |
+
Additionally, the member function templates `extract` and `erase` shall
|
| 2305 |
+
not participate in overload resolution if
|
| 2306 |
+
`is_convertible_v<K&&, iterator> || is_convertible_v<K&&, const_iterator>`
|
| 2307 |
+
is `true`, where `K` is the type substituted as the first template
|
| 2308 |
+
argument.
|
| 2309 |
|
| 2310 |
A deduction guide for an associative container shall not participate in
|
| 2311 |
overload resolution if any of the following are true:
|
| 2312 |
|
| 2313 |
- It has an `InputIterator` template parameter and a type that does not
|
|
|
|
| 2331 |
unless that exception is thrown by the swap of the container’s `Compare`
|
| 2332 |
object (if any).
|
| 2333 |
|
| 2334 |
### Unordered associative containers <a id="unord.req">[[unord.req]]</a>
|
| 2335 |
|
| 2336 |
+
#### General <a id="unord.req.general">[[unord.req.general]]</a>
|
| 2337 |
+
|
| 2338 |
Unordered associative containers provide an ability for fast retrieval
|
| 2339 |
of data based on keys. The worst-case complexity for most operations is
|
| 2340 |
linear, but the average case is much faster. The library provides four
|
| 2341 |
unordered associative containers: `unordered_set`, `unordered_map`,
|
| 2342 |
`unordered_multiset`, and `unordered_multimap`.
|
|
|
|
| 2408 |
changes ordering between elements, and changes which buckets elements
|
| 2409 |
appear in, but does not invalidate pointers or references to elements.
|
| 2410 |
For `unordered_multiset` and `unordered_multimap`, rehashing preserves
|
| 2411 |
the relative ordering of equivalent elements.
|
| 2412 |
|
| 2413 |
+
In this subclause,
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 2414 |
|
| 2415 |
- `X` denotes an unordered associative container class,
|
| 2416 |
- `a` denotes a value of type `X`,
|
| 2417 |
- `a2` denotes a value of a type with nodes compatible with type `X` (
|
| 2418 |
[[container.node.compat]]),
|
| 2419 |
+
- `b` denotes a value of type `X` or `const X`,
|
| 2420 |
- `a_uniq` denotes a value of type `X` when `X` supports unique keys,
|
| 2421 |
- `a_eq` denotes a value of type `X` when `X` supports equivalent keys,
|
| 2422 |
+
- `a_tran` denotes a value of type `X` or `const X` when the
|
| 2423 |
*qualified-id*s `X::key_equal::is_transparent` and
|
| 2424 |
`X::hasher::is_transparent` are both valid and denote types
|
| 2425 |
[[temp.deduct]],
|
| 2426 |
- `i` and `j` denote input iterators that refer to `value_type`,
|
| 2427 |
- `[i, j)` denotes a valid range,
|
| 2428 |
+
- `rg` denotes a value of a type `R` that models
|
| 2429 |
+
`container-compatible-range<value_type>`,
|
| 2430 |
- `p` and `q2` denote valid constant iterators to `a`,
|
| 2431 |
- `q` and `q1` denote valid dereferenceable constant iterators to `a`,
|
| 2432 |
- `r` denotes a valid dereferenceable iterator to `a`,
|
| 2433 |
- `[q1, q2)` denotes a valid range in `a`,
|
| 2434 |
- `il` denotes a value of type `initializer_list<value_type>`,
|
| 2435 |
- `t` denotes a value of type `X::value_type`,
|
| 2436 |
- `k` denotes a value of type `key_type`,
|
| 2437 |
+
- `hf` denotes a value of type `hasher` or `const hasher`,
|
| 2438 |
+
- `eq` denotes a value of type `key_equal` or `const key_equal`,
|
| 2439 |
- `ke` is a value such that
|
| 2440 |
+
- `eq(r1, ke) == eq(ke, r1)`,
|
| 2441 |
- `hf(r1) == hf(ke)` if `eq(r1, ke)` is `true`, and
|
| 2442 |
+
- if any two of `eq(r1, ke)`, `eq(r2, ke)`, and `eq(r1, r2)` are
|
| 2443 |
+
`true`, then all three are `true`,
|
| 2444 |
+
|
| 2445 |
+
where `r1` and `r2` are keys of elements in `a_tran`,
|
| 2446 |
+
- `kx` is a value such that
|
| 2447 |
+
- `eq(r1, kx) == eq(kx, r1)`,
|
| 2448 |
+
- `hf(r1) == hf(kx)` if `eq(r1, kx)` is `true`,
|
| 2449 |
+
- if any two of `eq(r1, kx)`, `eq(r2, kx)`, and `eq(r1, r2)` are
|
| 2450 |
+
`true`, then all three are `true`, and
|
| 2451 |
+
- `kx` is not convertible to either `iterator` or `const_iterator`,
|
| 2452 |
|
| 2453 |
where `r1` and `r2` are keys of elements in `a_tran`,
|
| 2454 |
- `n` denotes a value of type `size_type`,
|
| 2455 |
- `z` denotes a value of type `float`, and
|
| 2456 |
+
- `nh` denotes an rvalue of type `X::node_type`.
|
| 2457 |
+
|
| 2458 |
+
A type `X` meets the *unordered associative container* requirements if
|
| 2459 |
+
`X` meets all the requirements of an allocator-aware container
|
| 2460 |
+
[[container.requirements.general]] and the following types, statements,
|
| 2461 |
+
and expressions are well-formed and have the specified semantics, except
|
| 2462 |
+
that for `unordered_map` and `unordered_multimap`, the requirements
|
| 2463 |
+
placed on `value_type` in [[container.alloc.reqmts]] apply instead to
|
| 2464 |
+
`key_type` and `mapped_type`.
|
| 2465 |
+
|
| 2466 |
+
[*Note 3*: For example, `key_type` and `mapped_type` are sometimes
|
| 2467 |
+
required to be *Cpp17CopyAssignable* even though the associated
|
| 2468 |
+
`value_type`, `pair<const key_type, mapped_type>`, is not
|
| 2469 |
+
*Cpp17CopyAssignable*. — *end note*]
|
| 2470 |
+
|
| 2471 |
+
``` cpp
|
| 2472 |
+
typename X::key_type
|
| 2473 |
+
```
|
| 2474 |
+
|
| 2475 |
+
*Result:* `Key`.
|
| 2476 |
+
|
| 2477 |
+
``` cpp
|
| 2478 |
+
typename X::mapped_type
|
| 2479 |
+
```
|
| 2480 |
+
|
| 2481 |
+
*Result:* `T`.
|
| 2482 |
+
|
| 2483 |
+
*Remarks:* For `unordered_map` and `unordered_multimap` only.
|
| 2484 |
+
|
| 2485 |
+
``` cpp
|
| 2486 |
+
typename X::value_type
|
| 2487 |
+
```
|
| 2488 |
+
|
| 2489 |
+
*Result:* `Key` for `unordered_set` and `unordered_multiset` only;
|
| 2490 |
+
`pair<const Key, T>` for `unordered_map` and `unordered_multimap` only.
|
| 2491 |
+
|
| 2492 |
+
*Preconditions:* `value_type` is *Cpp17Erasable* from `X`.
|
| 2493 |
+
|
| 2494 |
+
``` cpp
|
| 2495 |
+
typename X::hasher
|
| 2496 |
+
```
|
| 2497 |
+
|
| 2498 |
+
*Result:* `Hash`.
|
| 2499 |
+
|
| 2500 |
+
*Preconditions:* `Hash` is a unary function object type such that the
|
| 2501 |
+
expression `hf(k)` has type `size_t`.
|
| 2502 |
+
|
| 2503 |
+
``` cpp
|
| 2504 |
+
typename X::key_equal
|
| 2505 |
+
```
|
| 2506 |
+
|
| 2507 |
+
*Result:* `Pred`.
|
| 2508 |
+
|
| 2509 |
+
*Preconditions:* `Pred` meets the *Cpp17CopyConstructible* requirements.
|
| 2510 |
+
`Pred` is a binary predicate that takes two arguments of type `Key`.
|
| 2511 |
+
`Pred` is an equivalence relation.
|
| 2512 |
+
|
| 2513 |
+
``` cpp
|
| 2514 |
+
typename X::local_iterator
|
| 2515 |
+
```
|
| 2516 |
+
|
| 2517 |
+
*Result:* An iterator type whose category, value type, difference type,
|
| 2518 |
+
and pointer and reference types are the same as `X::iterator`’s.
|
| 2519 |
+
|
| 2520 |
+
[*Note 1*: A `local_iterator` object can be used to iterate through a
|
| 2521 |
+
single bucket, but cannot be used to iterate across
|
| 2522 |
+
buckets. — *end note*]
|
| 2523 |
+
|
| 2524 |
+
``` cpp
|
| 2525 |
+
typename X::const_local_iterator
|
| 2526 |
+
```
|
| 2527 |
+
|
| 2528 |
+
*Result:* An iterator type whose category, value type, difference type,
|
| 2529 |
+
and pointer and reference types are the same as `X::const_iterator`’s.
|
| 2530 |
+
|
| 2531 |
+
[*Note 2*: A `const_local_iterator` object can be used to iterate
|
| 2532 |
+
through a single bucket, but cannot be used to iterate across
|
| 2533 |
+
buckets. — *end note*]
|
| 2534 |
+
|
| 2535 |
+
``` cpp
|
| 2536 |
+
typename X::node_type
|
| 2537 |
+
```
|
| 2538 |
+
|
| 2539 |
+
*Result:* A specialization of a *node-handle* class
|
| 2540 |
+
template [[container.node]], such that the public nested types are the
|
| 2541 |
+
same types as the corresponding types in `X`.
|
| 2542 |
+
|
| 2543 |
+
``` cpp
|
| 2544 |
+
X(n, hf, eq)
|
| 2545 |
+
```
|
| 2546 |
+
|
| 2547 |
+
*Effects:* Constructs an empty container with at least `n` buckets,
|
| 2548 |
+
using `hf` as the hash function and `eq` as the key equality predicate.
|
| 2549 |
+
|
| 2550 |
+
*Complexity:* 𝑂(`n`)
|
| 2551 |
+
|
| 2552 |
+
``` cpp
|
| 2553 |
+
X(n, hf)
|
| 2554 |
+
```
|
| 2555 |
+
|
| 2556 |
+
*Preconditions:* `key_equal` meets the *Cpp17DefaultConstructible*
|
| 2557 |
+
requirements.
|
| 2558 |
+
|
| 2559 |
+
*Effects:* Constructs an empty container with at least `n` buckets,
|
| 2560 |
+
using `hf` as the hash function and `key_equal()` as the key equality
|
| 2561 |
+
predicate.
|
| 2562 |
+
|
| 2563 |
+
*Complexity:* 𝑂(`n`)
|
| 2564 |
+
|
| 2565 |
+
``` cpp
|
| 2566 |
+
X(n)
|
| 2567 |
+
```
|
| 2568 |
+
|
| 2569 |
+
*Preconditions:* `hasher` and `key_equal` meet the
|
| 2570 |
+
*Cpp17DefaultConstructible* requirements.
|
| 2571 |
+
|
| 2572 |
+
*Effects:* Constructs an empty container with at least `n` buckets,
|
| 2573 |
+
using `hasher()` as the hash function and `key_equal()` as the key
|
| 2574 |
+
equality predicate.
|
| 2575 |
+
|
| 2576 |
+
*Complexity:* 𝑂(`n`)
|
| 2577 |
+
|
| 2578 |
+
``` cpp
|
| 2579 |
+
X a = X();
|
| 2580 |
+
X a;
|
| 2581 |
+
```
|
| 2582 |
+
|
| 2583 |
+
*Preconditions:* `hasher` and `key_equal` meet the
|
| 2584 |
+
*Cpp17DefaultConstructible* requirements.
|
| 2585 |
+
|
| 2586 |
+
*Effects:* Constructs an empty container with an unspecified number of
|
| 2587 |
+
buckets, using `hasher()` as the hash function and `key_equal()` as the
|
| 2588 |
+
key equality predicate.
|
| 2589 |
+
|
| 2590 |
+
*Complexity:* Constant.
|
| 2591 |
+
|
| 2592 |
+
``` cpp
|
| 2593 |
+
X(i, j, n, hf, eq)
|
| 2594 |
+
```
|
| 2595 |
+
|
| 2596 |
+
*Preconditions:* `value_type` is *Cpp17EmplaceConstructible* into `X`
|
| 2597 |
+
from `*i`.
|
| 2598 |
+
|
| 2599 |
+
*Effects:* Constructs an empty container with at least `n` buckets,
|
| 2600 |
+
using `hf` as the hash function and `eq` as the key equality predicate,
|
| 2601 |
+
and inserts elements from \[`i`, `j`) into it.
|
| 2602 |
+
|
| 2603 |
+
*Complexity:* Average case 𝑂(N) (N is `distance(i, j)`), worst case
|
| 2604 |
+
𝑂(N^2).
|
| 2605 |
+
|
| 2606 |
+
``` cpp
|
| 2607 |
+
X(i, j, n, hf)
|
| 2608 |
+
```
|
| 2609 |
+
|
| 2610 |
+
*Preconditions:* `key_equal` meets the *Cpp17DefaultConstructible*
|
| 2611 |
+
requirements. `value_type` is *Cpp17EmplaceConstructible* into `X` from
|
| 2612 |
+
`*i`.
|
| 2613 |
+
|
| 2614 |
+
*Effects:* Constructs an empty container with at least `n` buckets,
|
| 2615 |
+
using `hf` as the hash function and `key_equal()` as the key equality
|
| 2616 |
+
predicate, and inserts elements from \[`i`, `j`) into it.
|
| 2617 |
+
|
| 2618 |
+
*Complexity:* Average case 𝑂(N) (N is `distance(i, j)`), worst case
|
| 2619 |
+
𝑂(N^2).
|
| 2620 |
+
|
| 2621 |
+
``` cpp
|
| 2622 |
+
X(i, j, n)
|
| 2623 |
+
```
|
| 2624 |
+
|
| 2625 |
+
*Preconditions:* `hasher` and `key_equal` meet the
|
| 2626 |
+
*Cpp17DefaultConstructible* requirements. `value_type` is
|
| 2627 |
+
*Cpp17EmplaceConstructible* into `X` from `*i`.
|
| 2628 |
+
|
| 2629 |
+
*Effects:* Constructs an empty container with at least `n` buckets,
|
| 2630 |
+
using `hasher()` as the hash function and `key_equal()` as the key
|
| 2631 |
+
equality predicate, and inserts elements from \[`i`, `j`) into it.
|
| 2632 |
+
|
| 2633 |
+
*Complexity:* Average case 𝑂(N) (N is `distance(i, j)`), worst case
|
| 2634 |
+
𝑂(N^2).
|
| 2635 |
+
|
| 2636 |
+
``` cpp
|
| 2637 |
+
X(i, j)
|
| 2638 |
+
```
|
| 2639 |
+
|
| 2640 |
+
*Preconditions:* `hasher` and `key_equal` meet the
|
| 2641 |
+
*Cpp17DefaultConstructible* requirements. `value_type` is
|
| 2642 |
+
*Cpp17EmplaceConstructible* into `X` from `*i`.
|
| 2643 |
+
|
| 2644 |
+
*Effects:* Constructs an empty container with an unspecified number of
|
| 2645 |
+
buckets, using `hasher()` as the hash function and `key_equal()` as the
|
| 2646 |
+
key equality predicate, and inserts elements from \[`i`, `j`) into it.
|
| 2647 |
+
|
| 2648 |
+
*Complexity:* Average case 𝑂(N) (N is `distance(i, j)`), worst case
|
| 2649 |
+
𝑂(N^2).
|
| 2650 |
+
|
| 2651 |
+
``` cpp
|
| 2652 |
+
X(from_range, rg, n, hf, eq)
|
| 2653 |
+
```
|
| 2654 |
+
|
| 2655 |
+
*Preconditions:* `value_type` is *Cpp17EmplaceConstructible* into `X`
|
| 2656 |
+
from `*ranges::begin(rg)`.
|
| 2657 |
+
|
| 2658 |
+
*Effects:* Constructs an empty container with at least `n` buckets,
|
| 2659 |
+
using `hf` as the hash function and `eq` as the key equality predicate,
|
| 2660 |
+
and inserts elements from `rg` into it.
|
| 2661 |
+
|
| 2662 |
+
*Complexity:* Average case 𝑂(N) (N is `ranges::distance(rg)`), worst
|
| 2663 |
+
case 𝑂(N^2).
|
| 2664 |
+
|
| 2665 |
+
``` cpp
|
| 2666 |
+
X(from_range, rg, n, hf)
|
| 2667 |
+
```
|
| 2668 |
+
|
| 2669 |
+
*Preconditions:* `key_equal` meets the *Cpp17DefaultConstructible*
|
| 2670 |
+
requirements. `value_type` is *Cpp17EmplaceConstructible* into `X` from
|
| 2671 |
+
`*ranges::begin(rg)`.
|
| 2672 |
+
|
| 2673 |
+
*Effects:* Constructs an empty container with at least `n` buckets,
|
| 2674 |
+
using `hf` as the hash function and `key_equal()` as the key equality
|
| 2675 |
+
predicate, and inserts elements from `rg` into it.
|
| 2676 |
+
|
| 2677 |
+
*Complexity:* Average case 𝑂(N) (N is `ranges::distance(rg)`), worst
|
| 2678 |
+
case 𝑂(N^2).
|
| 2679 |
+
|
| 2680 |
+
``` cpp
|
| 2681 |
+
X(from_range, rg, n)
|
| 2682 |
+
```
|
| 2683 |
+
|
| 2684 |
+
*Preconditions:* `hasher` and `key_equal` meet the
|
| 2685 |
+
*Cpp17DefaultConstructible* requirements. `value_type` is
|
| 2686 |
+
*Cpp17EmplaceConstructible* into `X` from `*ranges::begin(rg)`.
|
| 2687 |
+
|
| 2688 |
+
*Effects:* Constructs an empty container with at least `n` buckets,
|
| 2689 |
+
using `hasher()` as the hash function and `key_equal()` as the key
|
| 2690 |
+
equality predicate, and inserts elements from `rg` into it.
|
| 2691 |
+
|
| 2692 |
+
*Complexity:* Average case 𝑂(N) (N is `ranges::distance(rg)`), worst
|
| 2693 |
+
case 𝑂(N^2).
|
| 2694 |
+
|
| 2695 |
+
``` cpp
|
| 2696 |
+
X(from_range, rg)
|
| 2697 |
+
```
|
| 2698 |
+
|
| 2699 |
+
*Preconditions:* `hasher` and `key_equal` meet the
|
| 2700 |
+
*Cpp17DefaultConstructible* requirements. `value_type` is
|
| 2701 |
+
*Cpp17EmplaceConstructible* into `X` from `*ranges::begin(rg)`.
|
| 2702 |
+
|
| 2703 |
+
*Effects:* Constructs an empty container with an unspecified number of
|
| 2704 |
+
buckets, using `hasher()` as the hash function and `key_equal()` as the
|
| 2705 |
+
key equality predicate, and inserts elements from `rg` into it.
|
| 2706 |
+
|
| 2707 |
+
*Complexity:* Average case 𝑂(N) (N is `ranges::distance(rg)`), worst
|
| 2708 |
+
case 𝑂(N^2).
|
| 2709 |
+
|
| 2710 |
+
``` cpp
|
| 2711 |
+
X(il)
|
| 2712 |
+
```
|
| 2713 |
+
|
| 2714 |
+
*Effects:* Equivalent to `X(il.begin(), il.end())`.
|
| 2715 |
+
|
| 2716 |
+
``` cpp
|
| 2717 |
+
X(il, n)
|
| 2718 |
+
```
|
| 2719 |
+
|
| 2720 |
+
*Effects:* Equivalent to `X(il.begin(), il.end(), n)`.
|
| 2721 |
+
|
| 2722 |
+
``` cpp
|
| 2723 |
+
X(il, n, hf)
|
| 2724 |
+
```
|
| 2725 |
+
|
| 2726 |
+
*Effects:* Equivalent to `X(il.begin(), il.end(), n, hf)`.
|
| 2727 |
+
|
| 2728 |
+
``` cpp
|
| 2729 |
+
X(il, n, hf, eq)
|
| 2730 |
+
```
|
| 2731 |
+
|
| 2732 |
+
*Effects:* Equivalent to `X(il.begin(), il.end(), n, hf, eq)`.
|
| 2733 |
+
|
| 2734 |
+
``` cpp
|
| 2735 |
+
X(b)
|
| 2736 |
+
```
|
| 2737 |
+
|
| 2738 |
+
*Effects:* In addition to the container
|
| 2739 |
+
requirements [[container.requirements.general]], copies the hash
|
| 2740 |
+
function, predicate, and maximum load factor.
|
| 2741 |
+
|
| 2742 |
+
*Complexity:* Average case linear in `b.size()`, worst case quadratic.
|
| 2743 |
+
|
| 2744 |
+
``` cpp
|
| 2745 |
+
a = b
|
| 2746 |
+
```
|
| 2747 |
+
|
| 2748 |
+
*Result:* `X&`
|
| 2749 |
+
|
| 2750 |
+
*Effects:* In addition to the container requirements, copies the hash
|
| 2751 |
+
function, predicate, and maximum load factor.
|
| 2752 |
+
|
| 2753 |
+
*Complexity:* Average case linear in `b.size()`, worst case quadratic.
|
| 2754 |
+
|
| 2755 |
+
``` cpp
|
| 2756 |
+
a = il
|
| 2757 |
+
```
|
| 2758 |
+
|
| 2759 |
+
*Result:* `X&`
|
| 2760 |
+
|
| 2761 |
+
*Preconditions:* `value_type` is *Cpp17CopyInsertable* into `X` and
|
| 2762 |
+
*Cpp17CopyAssignable*.
|
| 2763 |
+
|
| 2764 |
+
*Effects:* Assigns the range \[`il.begin()`, `il.end()`) into `a`. All
|
| 2765 |
+
existing elements of `a` are either assigned to or destroyed.
|
| 2766 |
+
|
| 2767 |
+
*Complexity:* Average case linear in `il.size()`, worst case quadratic.
|
| 2768 |
+
|
| 2769 |
+
``` cpp
|
| 2770 |
+
b.hash_function()
|
| 2771 |
+
```
|
| 2772 |
+
|
| 2773 |
+
*Result:* `hasher`
|
| 2774 |
+
|
| 2775 |
+
*Returns:* `b`’s hash function.
|
| 2776 |
+
|
| 2777 |
+
*Complexity:* Constant.
|
| 2778 |
+
|
| 2779 |
+
``` cpp
|
| 2780 |
+
b.key_eq()
|
| 2781 |
+
```
|
| 2782 |
+
|
| 2783 |
+
*Result:* `key_equal`
|
| 2784 |
+
|
| 2785 |
+
*Returns:* `b`’s key equality predicate.
|
| 2786 |
+
|
| 2787 |
+
*Complexity:* Constant.
|
| 2788 |
+
|
| 2789 |
+
``` cpp
|
| 2790 |
+
a_uniq.emplace(args)
|
| 2791 |
+
```
|
| 2792 |
+
|
| 2793 |
+
*Result:* `pair<iterator,` `bool>`
|
| 2794 |
+
|
| 2795 |
+
*Preconditions:* `value_type` is *Cpp17EmplaceConstructible* into `X`
|
| 2796 |
+
from `args`.
|
| 2797 |
+
|
| 2798 |
+
*Effects:* Inserts a `value_type` object `t` constructed with
|
| 2799 |
+
`std::forward<Args>(args)...` if and only if there is no element in the
|
| 2800 |
+
container with key equivalent to the key of `t`.
|
| 2801 |
+
|
| 2802 |
+
*Returns:* The `bool` component of the returned pair is `true` if and
|
| 2803 |
+
only if the insertion takes place, and the iterator component of the
|
| 2804 |
+
pair points to the element with key equivalent to the key of `t`.
|
| 2805 |
+
|
| 2806 |
+
*Complexity:* Average case 𝑂(1), worst case 𝑂(`a_uniq.size()`).
|
| 2807 |
+
|
| 2808 |
+
``` cpp
|
| 2809 |
+
a_eq.emplace(args)
|
| 2810 |
+
```
|
| 2811 |
+
|
| 2812 |
+
*Result:* `iterator`
|
| 2813 |
+
|
| 2814 |
+
*Preconditions:* `value_type` is *Cpp17EmplaceConstructible* into `X`
|
| 2815 |
+
from `args`.
|
| 2816 |
+
|
| 2817 |
+
*Effects:* Inserts a `value_type` object `t` constructed with
|
| 2818 |
+
`std::forward<Args>(args)...`.
|
| 2819 |
+
|
| 2820 |
+
*Returns:* An iterator pointing to the newly inserted element.
|
| 2821 |
+
|
| 2822 |
+
*Complexity:* Average case 𝑂(1), worst case 𝑂(`a_eq.size()`).
|
| 2823 |
+
|
| 2824 |
+
``` cpp
|
| 2825 |
+
a.emplace_hint(p, args)
|
| 2826 |
+
```
|
| 2827 |
+
|
| 2828 |
+
*Result:* `iterator`
|
| 2829 |
+
|
| 2830 |
+
*Preconditions:* `value_type` is *Cpp17EmplaceConstructible* into `X`
|
| 2831 |
+
from `args`.
|
| 2832 |
+
|
| 2833 |
+
*Effects:* Equivalent to `a.emplace(std::forward<Args>(args)...)`.
|
| 2834 |
+
|
| 2835 |
+
*Returns:* An iterator pointing to the element with the key equivalent
|
| 2836 |
+
to the newly inserted element. The `const_iterator` `p` is a hint
|
| 2837 |
+
pointing to where the search should start. Implementations are permitted
|
| 2838 |
+
to ignore the hint.
|
| 2839 |
+
|
| 2840 |
+
*Complexity:* Average case 𝑂(1), worst case 𝑂(`a.size()`).
|
| 2841 |
+
|
| 2842 |
+
``` cpp
|
| 2843 |
+
a_uniq.insert(t)
|
| 2844 |
+
```
|
| 2845 |
+
|
| 2846 |
+
*Result:* `pair<iterator, bool>`
|
| 2847 |
+
|
| 2848 |
+
*Preconditions:* If `t` is a non-const rvalue, `value_type` is
|
| 2849 |
+
*Cpp17MoveInsertable* into `X`; otherwise, `value_type` is
|
| 2850 |
+
*Cpp17CopyInsertable* into `X`.
|
| 2851 |
+
|
| 2852 |
+
*Effects:* Inserts `t` if and only if there is no element in the
|
| 2853 |
+
container with key equivalent to the key of `t`.
|
| 2854 |
+
|
| 2855 |
+
*Returns:* The `bool` component of the returned pair indicates whether
|
| 2856 |
+
the insertion takes place, and the `iterator` component points to the
|
| 2857 |
+
element with key equivalent to the key of `t`.
|
| 2858 |
+
|
| 2859 |
+
*Complexity:* Average case 𝑂(1), worst case 𝑂(`a_uniq.size()`).
|
| 2860 |
+
|
| 2861 |
+
``` cpp
|
| 2862 |
+
a_eq.insert(t)
|
| 2863 |
+
```
|
| 2864 |
+
|
| 2865 |
+
*Result:* `iterator`
|
| 2866 |
+
|
| 2867 |
+
*Preconditions:* If `t` is a non-const rvalue, `value_type` is
|
| 2868 |
+
*Cpp17MoveInsertable* into `X`; otherwise, `value_type` is
|
| 2869 |
+
*Cpp17CopyInsertable* into `X`.
|
| 2870 |
+
|
| 2871 |
+
*Effects:* Inserts `t`.
|
| 2872 |
+
|
| 2873 |
+
*Returns:* An iterator pointing to the newly inserted element.
|
| 2874 |
+
|
| 2875 |
+
*Complexity:* Average case 𝑂(1), worst case 𝑂(`a_eq.size()`).
|
| 2876 |
+
|
| 2877 |
+
``` cpp
|
| 2878 |
+
a.insert(p, t)
|
| 2879 |
+
```
|
| 2880 |
+
|
| 2881 |
+
*Result:* `iterator`
|
| 2882 |
+
|
| 2883 |
+
*Preconditions:* If `t` is a non-const rvalue, `value_type` is
|
| 2884 |
+
*Cpp17MoveInsertable* into `X`; otherwise, `value_type` is
|
| 2885 |
+
*Cpp17CopyInsertable* into `X`.
|
| 2886 |
+
|
| 2887 |
+
*Effects:* Equivalent to `a.insert(t)`. The iterator `p` is a hint
|
| 2888 |
+
pointing to where the search should start. Implementations are permitted
|
| 2889 |
+
to ignore the hint.
|
| 2890 |
+
|
| 2891 |
+
*Returns:* An iterator pointing to the element with the key equivalent
|
| 2892 |
+
to that of `t`.
|
| 2893 |
+
|
| 2894 |
+
*Complexity:* Average case 𝑂(1), worst case 𝑂(`a.size()`).
|
| 2895 |
+
|
| 2896 |
+
``` cpp
|
| 2897 |
+
a.insert(i, j)
|
| 2898 |
+
```
|
| 2899 |
+
|
| 2900 |
+
*Result:* `void`
|
| 2901 |
+
|
| 2902 |
+
*Preconditions:* `value_type` is *Cpp17EmplaceConstructible* into `X`
|
| 2903 |
+
from `*i`. Neither `i` nor `j` are iterators into `a`.
|
| 2904 |
+
|
| 2905 |
+
*Effects:* Equivalent to `a.insert(t)` for each element in `[i,j)`.
|
| 2906 |
+
|
| 2907 |
+
*Complexity:* Average case 𝑂(N), where N is `distance(i, j)`, worst case
|
| 2908 |
+
𝑂(N(`a.size()` + 1)).
|
| 2909 |
+
|
| 2910 |
+
``` cpp
|
| 2911 |
+
a.insert_range(rg)
|
| 2912 |
+
```
|
| 2913 |
+
|
| 2914 |
+
*Result:* `void`
|
| 2915 |
+
|
| 2916 |
+
*Preconditions:* `value_type` is *Cpp17EmplaceConstructible* into `X`
|
| 2917 |
+
from `*ranges::begin(rg)`. `rg` and `a` do not overlap.
|
| 2918 |
+
|
| 2919 |
+
*Effects:* Equivalent to `a.insert(t)` for each element `t` in `rg`.
|
| 2920 |
+
|
| 2921 |
+
*Complexity:* Average case 𝑂(N), where N is `ranges::distance(rg)`,
|
| 2922 |
+
worst case 𝑂(N(`a.size()` + 1)).
|
| 2923 |
+
|
| 2924 |
+
``` cpp
|
| 2925 |
+
a.insert(il)
|
| 2926 |
+
```
|
| 2927 |
+
|
| 2928 |
+
*Effects:* Equivalent to `a.insert(il.begin(), il.end())`.
|
| 2929 |
+
|
| 2930 |
+
``` cpp
|
| 2931 |
+
a_uniq.insert(nh)
|
| 2932 |
+
```
|
| 2933 |
+
|
| 2934 |
+
*Result:* `insert_return_type`
|
| 2935 |
+
|
| 2936 |
+
*Preconditions:* `nh` is empty or
|
| 2937 |
+
`a_uniq.get_allocator() == nh.get_allocator()` is `true`.
|
| 2938 |
+
|
| 2939 |
+
*Effects:* If `nh` is empty, has no effect. Otherwise, inserts the
|
| 2940 |
+
element owned by `nh` if and only if there is no element in the
|
| 2941 |
+
container with a key equivalent to `nh.key()`.
|
| 2942 |
+
|
| 2943 |
+
*Ensures:* If `nh` is empty, `inserted` is `false`, `position` is
|
| 2944 |
+
`end()`, and `node` is empty. Otherwise if the insertion took place,
|
| 2945 |
+
`inserted` is `true`, `position` points to the inserted element, and
|
| 2946 |
+
`node` is empty; if the insertion failed, `inserted` is `false`, `node`
|
| 2947 |
+
has the previous value of `nh`, and `position` points to an element with
|
| 2948 |
+
a key equivalent to `nh.key()`.
|
| 2949 |
+
|
| 2950 |
+
*Complexity:* Average case 𝑂(1), worst case 𝑂(`a_uniq.size()`).
|
| 2951 |
+
|
| 2952 |
+
``` cpp
|
| 2953 |
+
a_eq.insert(nh)
|
| 2954 |
+
```
|
| 2955 |
+
|
| 2956 |
+
*Result:* `iterator`
|
| 2957 |
+
|
| 2958 |
+
*Preconditions:* `nh` is empty or
|
| 2959 |
+
`a_eq.get_allocator() == nh.get_allocator()` is `true`.
|
| 2960 |
+
|
| 2961 |
+
*Effects:* If `nh` is empty, has no effect and returns `a_eq.end()`.
|
| 2962 |
+
Otherwise, inserts the element owned by `nh` and returns an iterator
|
| 2963 |
+
pointing to the newly inserted element.
|
| 2964 |
+
|
| 2965 |
+
*Ensures:* `nh` is empty.
|
| 2966 |
+
|
| 2967 |
+
*Complexity:* Average case 𝑂(1), worst case 𝑂(`a_eq.size()`).
|
| 2968 |
+
|
| 2969 |
+
``` cpp
|
| 2970 |
+
a.insert(q, nh)
|
| 2971 |
+
```
|
| 2972 |
+
|
| 2973 |
+
*Result:* `iterator`
|
| 2974 |
+
|
| 2975 |
+
*Preconditions:* `nh` is empty or
|
| 2976 |
+
`a.get_allocator() == nh.get_allocator()` is `true`.
|
| 2977 |
+
|
| 2978 |
+
*Effects:* If `nh` is empty, has no effect and returns `a.end()`.
|
| 2979 |
+
Otherwise, inserts the element owned by `nh` if and only if there is no
|
| 2980 |
+
element with key equivalent to `nh.key()` in containers with unique
|
| 2981 |
+
keys; always inserts the element owned by `nh` in containers with
|
| 2982 |
+
equivalent keys. The iterator `q` is a hint pointing to where the search
|
| 2983 |
+
should start. Implementations are permitted to ignore the hint.
|
| 2984 |
+
|
| 2985 |
+
*Ensures:* `nh` is empty if insertion succeeds, unchanged if insertion
|
| 2986 |
+
fails.
|
| 2987 |
+
|
| 2988 |
+
*Returns:* An iterator pointing to the element with key equivalent to
|
| 2989 |
+
`nh.key()`.
|
| 2990 |
+
|
| 2991 |
+
*Complexity:* Average case 𝑂(1), worst case 𝑂(`a.size()`).
|
| 2992 |
+
|
| 2993 |
+
``` cpp
|
| 2994 |
+
a.extract(k)
|
| 2995 |
+
```
|
| 2996 |
+
|
| 2997 |
+
*Result:* `node_type`
|
| 2998 |
+
|
| 2999 |
+
*Effects:* Removes an element in the container with key equivalent to
|
| 3000 |
+
`k`.
|
| 3001 |
+
|
| 3002 |
+
*Returns:* A `node_type` owning the element if found, otherwise an empty
|
| 3003 |
+
`node_type`.
|
| 3004 |
+
|
| 3005 |
+
*Complexity:* Average case 𝑂(1), worst case 𝑂(`a.size()`).
|
| 3006 |
+
|
| 3007 |
+
``` cpp
|
| 3008 |
+
a_tran.extract(kx)
|
| 3009 |
+
```
|
| 3010 |
+
|
| 3011 |
+
*Result:* `node_type`
|
| 3012 |
+
|
| 3013 |
+
*Effects:* Removes an element in the container with key equivalent to
|
| 3014 |
+
`kx`.
|
| 3015 |
+
|
| 3016 |
+
*Returns:* A `node_type` owning the element if found, otherwise an empty
|
| 3017 |
+
`node_type`.
|
| 3018 |
+
|
| 3019 |
+
*Complexity:* Average case 𝑂(1), worst case 𝑂(`a_tran.size()`).
|
| 3020 |
+
|
| 3021 |
+
``` cpp
|
| 3022 |
+
a.extract(q)
|
| 3023 |
+
```
|
| 3024 |
+
|
| 3025 |
+
*Result:* `node_type`
|
| 3026 |
+
|
| 3027 |
+
*Effects:* Removes the element pointed to by `q`.
|
| 3028 |
+
|
| 3029 |
+
*Returns:* A `node_type` owning that element.
|
| 3030 |
+
|
| 3031 |
+
*Complexity:* Average case 𝑂(1), worst case 𝑂(`a.size()`).
|
| 3032 |
+
|
| 3033 |
+
``` cpp
|
| 3034 |
+
a.merge(a2)
|
| 3035 |
+
```
|
| 3036 |
+
|
| 3037 |
+
*Result:* `void`
|
| 3038 |
+
|
| 3039 |
+
*Preconditions:* `a.get_allocator() == a2.get_allocator()`.
|
| 3040 |
+
|
| 3041 |
+
*Effects:* Attempts to extract each element in `a2` and insert it into
|
| 3042 |
+
`a` using the hash function and key equality predicate of `a`. In
|
| 3043 |
+
containers with unique keys, if there is an element in `a` with key
|
| 3044 |
+
equivalent to the key of an element from `a2`, then that element is not
|
| 3045 |
+
extracted from `a2`.
|
| 3046 |
+
|
| 3047 |
+
*Ensures:* Pointers and references to the transferred elements of `a2`
|
| 3048 |
+
refer to those same elements but as members of `a`. Iterators referring
|
| 3049 |
+
to the transferred elements and all iterators referring to `a` will be
|
| 3050 |
+
invalidated, but iterators to elements remaining in `a2` will remain
|
| 3051 |
+
valid.
|
| 3052 |
+
|
| 3053 |
+
*Complexity:* Average case 𝑂(N), where N is `a2.size()`, worst case
|
| 3054 |
+
𝑂(N`*a.size() + N`).
|
| 3055 |
+
|
| 3056 |
+
``` cpp
|
| 3057 |
+
a.erase(k)
|
| 3058 |
+
```
|
| 3059 |
+
|
| 3060 |
+
*Result:* `size_type`
|
| 3061 |
+
|
| 3062 |
+
*Effects:* Erases all elements with key equivalent to `k`.
|
| 3063 |
+
|
| 3064 |
+
*Returns:* The number of elements erased.
|
| 3065 |
+
|
| 3066 |
+
*Complexity:* Average case 𝑂(`a.count(k)`), worst case 𝑂(`a.size()`).
|
| 3067 |
+
|
| 3068 |
+
``` cpp
|
| 3069 |
+
a_tran.erase(kx)
|
| 3070 |
+
```
|
| 3071 |
+
|
| 3072 |
+
*Result:* `size_type`
|
| 3073 |
+
|
| 3074 |
+
*Effects:* Erases all elements with key equivalent to `kx`.
|
| 3075 |
+
|
| 3076 |
+
*Returns:* The number of elements erased.
|
| 3077 |
+
|
| 3078 |
+
*Complexity:* Average case 𝑂(`a_tran.count(kx)`), worst case
|
| 3079 |
+
𝑂(`a_tran.size()`).
|
| 3080 |
+
|
| 3081 |
+
``` cpp
|
| 3082 |
+
a.erase(q)
|
| 3083 |
+
```
|
| 3084 |
+
|
| 3085 |
+
*Result:* `iterator`
|
| 3086 |
+
|
| 3087 |
+
*Effects:* Erases the element pointed to by `q`.
|
| 3088 |
+
|
| 3089 |
+
*Returns:* The iterator immediately following `q` prior to the erasure.
|
| 3090 |
+
|
| 3091 |
+
*Complexity:* Average case 𝑂(1), worst case 𝑂(`a.size()`).
|
| 3092 |
+
|
| 3093 |
+
``` cpp
|
| 3094 |
+
a.erase(r)
|
| 3095 |
+
```
|
| 3096 |
+
|
| 3097 |
+
*Result:* `iterator`
|
| 3098 |
+
|
| 3099 |
+
*Effects:* Erases the element pointed to by `r`.
|
| 3100 |
+
|
| 3101 |
+
*Returns:* The iterator immediately following `r` prior to the erasure.
|
| 3102 |
+
|
| 3103 |
+
*Complexity:* Average case 𝑂(1), worst case 𝑂(`a.size()`).
|
| 3104 |
+
|
| 3105 |
+
``` cpp
|
| 3106 |
+
a.erase(q1, q2)
|
| 3107 |
+
```
|
| 3108 |
+
|
| 3109 |
+
*Result:* `iterator`
|
| 3110 |
+
|
| 3111 |
+
*Effects:* Erases all elements in the range `[q1, q2)`.
|
| 3112 |
+
|
| 3113 |
+
*Returns:* The iterator immediately following the erased elements prior
|
| 3114 |
+
to the erasure.
|
| 3115 |
+
|
| 3116 |
+
*Complexity:* Average case linear in `distance(q1, q2)`, worst case
|
| 3117 |
+
𝑂(`a.size()`).
|
| 3118 |
+
|
| 3119 |
+
``` cpp
|
| 3120 |
+
a.clear()
|
| 3121 |
+
```
|
| 3122 |
+
|
| 3123 |
+
*Result:* `void`
|
| 3124 |
+
|
| 3125 |
+
*Effects:* Erases all elements in the container.
|
| 3126 |
+
|
| 3127 |
+
*Ensures:* `a.empty()` is `true`.
|
| 3128 |
+
|
| 3129 |
+
*Complexity:* Linear in `a.size()`.
|
| 3130 |
+
|
| 3131 |
+
``` cpp
|
| 3132 |
+
b.find(k)
|
| 3133 |
+
```
|
| 3134 |
+
|
| 3135 |
+
*Result:* `iterator`; `const_iterator` for constant `b`.
|
| 3136 |
+
|
| 3137 |
+
*Returns:* An iterator pointing to an element with key equivalent to
|
| 3138 |
+
`k`, or `b.end()` if no such element exists.
|
| 3139 |
+
|
| 3140 |
+
*Complexity:* Average case 𝑂(1), worst case 𝑂(`b.size()`).
|
| 3141 |
+
|
| 3142 |
+
``` cpp
|
| 3143 |
+
a_tran.find(ke)
|
| 3144 |
+
```
|
| 3145 |
+
|
| 3146 |
+
*Result:* `iterator`; `const_iterator` for constant `a_tran`.
|
| 3147 |
+
|
| 3148 |
+
*Returns:* An iterator pointing to an element with key equivalent to
|
| 3149 |
+
`ke`, or `a_tran.end()` if no such element exists.
|
| 3150 |
+
|
| 3151 |
+
*Complexity:* Average case 𝑂(1), worst case 𝑂(`a_tran.size()`).
|
| 3152 |
+
|
| 3153 |
+
``` cpp
|
| 3154 |
+
b.count(k)
|
| 3155 |
+
```
|
| 3156 |
+
|
| 3157 |
+
*Result:* `size_type`
|
| 3158 |
+
|
| 3159 |
+
*Returns:* The number of elements with key equivalent to `k`.
|
| 3160 |
+
|
| 3161 |
+
*Complexity:* Average case 𝑂(`b.count(k)`), worst case 𝑂(`b.size()`).
|
| 3162 |
+
|
| 3163 |
+
``` cpp
|
| 3164 |
+
a_tran.count(ke)
|
| 3165 |
+
```
|
| 3166 |
+
|
| 3167 |
+
*Result:* `size_type`
|
| 3168 |
+
|
| 3169 |
+
*Returns:* The number of elements with key equivalent to `ke`.
|
| 3170 |
+
|
| 3171 |
+
*Complexity:* Average case 𝑂(`a_tran.count(ke)`), worst case
|
| 3172 |
+
𝑂(`a_tran.size()`).
|
| 3173 |
+
|
| 3174 |
+
``` cpp
|
| 3175 |
+
b.contains(k)
|
| 3176 |
+
```
|
| 3177 |
+
|
| 3178 |
+
*Effects:* Equivalent to `b.find(k) != b.end()`.
|
| 3179 |
+
|
| 3180 |
+
``` cpp
|
| 3181 |
+
a_tran.contains(ke)
|
| 3182 |
+
```
|
| 3183 |
+
|
| 3184 |
+
*Effects:* Equivalent to `a_tran.find(ke) != a_tran.end()`.
|
| 3185 |
+
|
| 3186 |
+
``` cpp
|
| 3187 |
+
b.equal_range(k)
|
| 3188 |
+
```
|
| 3189 |
+
|
| 3190 |
+
*Result:* `pair<iterator, iterator>`;
|
| 3191 |
+
`pair<const_iterator, const_iterator>` for constant `b`.
|
| 3192 |
+
|
| 3193 |
+
*Returns:* A range containing all elements with keys equivalent to `k`.
|
| 3194 |
+
Returns `make_pair(b.end(), b.end())` if no such elements exist.
|
| 3195 |
+
|
| 3196 |
+
*Complexity:* Average case 𝑂(`b.count(k)`), worst case 𝑂(`b.size()`).
|
| 3197 |
+
|
| 3198 |
+
``` cpp
|
| 3199 |
+
a_tran.equal_range(ke)
|
| 3200 |
+
```
|
| 3201 |
+
|
| 3202 |
+
*Result:* `pair<iterator, iterator>`;
|
| 3203 |
+
`pair<const_iterator, const_iterator>` for constant `a_tran`.
|
| 3204 |
+
|
| 3205 |
+
*Returns:* A range containing all elements with keys equivalent to `ke`.
|
| 3206 |
+
Returns `make_pair(a_tran.end(), a_tran.end())` if no such elements
|
| 3207 |
+
exist.
|
| 3208 |
+
|
| 3209 |
+
*Complexity:* Average case 𝑂(`a_tran.count(ke)`), worst case
|
| 3210 |
+
𝑂(`a_tran.size()`).
|
| 3211 |
+
|
| 3212 |
+
``` cpp
|
| 3213 |
+
b.bucket_count()
|
| 3214 |
+
```
|
| 3215 |
+
|
| 3216 |
+
*Result:* `size_type`
|
| 3217 |
+
|
| 3218 |
+
*Returns:* The number of buckets that `b` contains.
|
| 3219 |
+
|
| 3220 |
+
*Complexity:* Constant.
|
| 3221 |
+
|
| 3222 |
+
``` cpp
|
| 3223 |
+
b.max_bucket_count()
|
| 3224 |
+
```
|
| 3225 |
+
|
| 3226 |
+
*Result:* `size_type`
|
| 3227 |
+
|
| 3228 |
+
*Returns:* An upper bound on the number of buckets that `b` can ever
|
| 3229 |
+
contain.
|
| 3230 |
+
|
| 3231 |
+
*Complexity:* Constant.
|
| 3232 |
+
|
| 3233 |
+
``` cpp
|
| 3234 |
+
b.bucket(k)
|
| 3235 |
+
```
|
| 3236 |
+
|
| 3237 |
+
*Result:* `size_type`
|
| 3238 |
+
|
| 3239 |
+
*Preconditions:* `b.bucket_count() > 0`.
|
| 3240 |
+
|
| 3241 |
+
*Returns:* The index of the bucket in which elements with keys
|
| 3242 |
+
equivalent to `k` would be found, if any such element existed. The
|
| 3243 |
+
return value is in the range `[0, b.bucket_count())`.
|
| 3244 |
+
|
| 3245 |
+
*Complexity:* Constant.
|
| 3246 |
+
|
| 3247 |
+
``` cpp
|
| 3248 |
+
b.bucket_size(n)
|
| 3249 |
+
```
|
| 3250 |
+
|
| 3251 |
+
*Result:* `size_type`
|
| 3252 |
+
|
| 3253 |
+
*Preconditions:* `n` shall be in the range `[0, b.bucket_count())`.
|
| 3254 |
+
|
| 3255 |
+
*Returns:* The number of elements in the `n`ᵗʰ bucket.
|
| 3256 |
+
|
| 3257 |
+
*Complexity:* 𝑂(`b.bucket_size(n)`)
|
| 3258 |
+
|
| 3259 |
+
``` cpp
|
| 3260 |
+
b.begin(n)
|
| 3261 |
+
```
|
| 3262 |
+
|
| 3263 |
+
*Result:* `local_iterator`; `const_local_iterator` for constant `b`.
|
| 3264 |
+
|
| 3265 |
+
*Preconditions:* `n` is in the range `[0, b.bucket_count())`.
|
| 3266 |
+
|
| 3267 |
+
*Returns:* An iterator referring to the first element in the bucket. If
|
| 3268 |
+
the bucket is empty, then `b.begin(n) == b.end(n)`.
|
| 3269 |
+
|
| 3270 |
+
*Complexity:* Constant.
|
| 3271 |
+
|
| 3272 |
+
``` cpp
|
| 3273 |
+
b.end(n)
|
| 3274 |
+
```
|
| 3275 |
+
|
| 3276 |
+
*Result:* `local_iterator`; `const_local_iterator` for constant `b`.
|
| 3277 |
+
|
| 3278 |
+
*Preconditions:* `n` is in the range `[0, b.bucket_count())`.
|
| 3279 |
+
|
| 3280 |
+
*Returns:* An iterator which is the past-the-end value for the bucket.
|
| 3281 |
+
|
| 3282 |
+
*Complexity:* Constant.
|
| 3283 |
+
|
| 3284 |
+
``` cpp
|
| 3285 |
+
b.cbegin(n)
|
| 3286 |
+
```
|
| 3287 |
+
|
| 3288 |
+
*Result:* `const_local_iterator`
|
| 3289 |
+
|
| 3290 |
+
*Preconditions:* `n` shall be in the range `[0, b.bucket_count())`.
|
| 3291 |
+
|
| 3292 |
+
*Returns:* An iterator referring to the first element in the bucket. If
|
| 3293 |
+
the bucket is empty, then `b.cbegin(n) == b.cend(n)`.
|
| 3294 |
+
|
| 3295 |
+
*Complexity:* Constant.
|
| 3296 |
+
|
| 3297 |
+
``` cpp
|
| 3298 |
+
b.cend(n)
|
| 3299 |
+
```
|
| 3300 |
+
|
| 3301 |
+
*Result:* `const_local_iterator`
|
| 3302 |
+
|
| 3303 |
+
*Preconditions:* `n` is in the range `[0, b.bucket_count())`.
|
| 3304 |
+
|
| 3305 |
+
*Returns:* An iterator which is the past-the-end value for the bucket.
|
| 3306 |
+
|
| 3307 |
+
*Complexity:* Constant.
|
| 3308 |
+
|
| 3309 |
+
``` cpp
|
| 3310 |
+
b.load_factor()
|
| 3311 |
+
```
|
| 3312 |
+
|
| 3313 |
+
*Result:* `float`
|
| 3314 |
+
|
| 3315 |
+
*Returns:* The average number of elements per bucket.
|
| 3316 |
+
|
| 3317 |
+
*Complexity:* Constant.
|
| 3318 |
+
|
| 3319 |
+
``` cpp
|
| 3320 |
+
b.max_load_factor()
|
| 3321 |
+
```
|
| 3322 |
+
|
| 3323 |
+
*Result:* `float`
|
| 3324 |
+
|
| 3325 |
+
*Returns:* A positive number that the container attempts to keep the
|
| 3326 |
+
load factor less than or equal to. The container automatically increases
|
| 3327 |
+
the number of buckets as necessary to keep the load factor below this
|
| 3328 |
+
number.
|
| 3329 |
+
|
| 3330 |
+
*Complexity:* Constant.
|
| 3331 |
+
|
| 3332 |
+
``` cpp
|
| 3333 |
+
a.max_load_factor(z)
|
| 3334 |
+
```
|
| 3335 |
+
|
| 3336 |
+
*Result:* `void`
|
| 3337 |
+
|
| 3338 |
+
*Preconditions:* `z` is positive. May change the container’s maximum
|
| 3339 |
+
load factor, using `z` as a hint.
|
| 3340 |
+
|
| 3341 |
+
*Complexity:* Constant.
|
| 3342 |
+
|
| 3343 |
+
``` cpp
|
| 3344 |
+
a.rehash(n)
|
| 3345 |
+
```
|
| 3346 |
+
|
| 3347 |
+
*Result:* `void`
|
| 3348 |
+
|
| 3349 |
+
*Ensures:* `a.bucket_count() >= a.size() / a.max_load_factor()` and
|
| 3350 |
+
`a.bucket_count() >= n`.
|
| 3351 |
+
|
| 3352 |
+
*Complexity:* Average case linear in `a.size()`, worst case quadratic.
|
| 3353 |
+
|
| 3354 |
+
``` cpp
|
| 3355 |
+
a.reserve(n)
|
| 3356 |
+
```
|
| 3357 |
+
|
| 3358 |
+
*Effects:* Equivalent to `a.rehash(ceil(n / a.max_load_factor()))`.
|
| 3359 |
|
| 3360 |
Two unordered containers `a` and `b` compare equal if
|
| 3361 |
`a.size() == b.size()` and, for every equivalent-key group \[`Ea1`,
|
| 3362 |
`Ea2`) obtained from `a.equal_range(Ea1)`, there exists an
|
| 3363 |
equivalent-key group \[`Eb1`, `Eb2`) obtained from `b.equal_range(Ea1)`,
|
|
|
|
| 3377 |
`unordered_multiset` and `unordered_multimap` becomes proportional to N
|
| 3378 |
(but worst-case complexity remains 𝑂(N^2), e.g., for a pathologically
|
| 3379 |
bad hash function). The behavior of a program that uses `operator==` or
|
| 3380 |
`operator!=` on unordered containers is undefined unless the `Pred`
|
| 3381 |
function object has the same behavior for both containers and the
|
| 3382 |
+
equality comparison function for `Key` is a refinement[^1]
|
| 3383 |
+
|
| 3384 |
+
of the partition into equivalent-key groups produced by `Pred`.
|
| 3385 |
|
| 3386 |
The iterator types `iterator` and `const_iterator` of an unordered
|
| 3387 |
associative container are of at least the forward iterator category. For
|
| 3388 |
unordered associative containers where the key type and value type are
|
| 3389 |
the same, both `iterator` and `const_iterator` are constant iterators.
|
| 3390 |
|
| 3391 |
+
The `insert`, `insert_range`, and `emplace` members shall not affect the
|
| 3392 |
+
validity of references to container elements, but may invalidate all
|
| 3393 |
+
iterators to the container. The `erase` members shall invalidate only
|
| 3394 |
+
iterators and references to the erased elements, and preserve the
|
| 3395 |
+
relative order of the elements that are not erased.
|
| 3396 |
|
| 3397 |
+
The `insert`, `insert_range`, and `emplace` members shall not affect the
|
| 3398 |
+
validity of iterators if `(N+n) <= z * B`, where `N` is the number of
|
| 3399 |
+
elements in the container prior to the insert operation, `n` is the
|
| 3400 |
+
number of elements inserted, `B` is the container’s bucket count, and
|
| 3401 |
+
`z` is the container’s maximum load factor.
|
| 3402 |
|
| 3403 |
The `extract` members invalidate only iterators to the removed element,
|
| 3404 |
and preserve the relative order of the elements that are not erased;
|
| 3405 |
pointers and references to the removed element remain valid. However,
|
| 3406 |
accessing the element through such pointers and references while the
|
| 3407 |
element is owned by a `node_type` is undefined behavior. References and
|
| 3408 |
pointers to an element obtained while it is owned by a `node_type` are
|
| 3409 |
invalidated if the element is successfully inserted.
|
| 3410 |
|
| 3411 |
+
The member function templates `find`, `count`, `equal_range`,
|
| 3412 |
+
`contains`, `extract`, and `erase` shall not participate in overload
|
| 3413 |
+
resolution unless the *qualified-id*s `Pred::is_transparent` and
|
| 3414 |
+
`Hash::is_transparent` are both valid and denote types [[temp.deduct]].
|
| 3415 |
+
Additionally, the member function templates `extract` and `erase` shall
|
| 3416 |
+
not participate in overload resolution if
|
| 3417 |
+
`is_convertible_v<K&&, iterator> || is_convertible_v<K&&, const_iterator>`
|
| 3418 |
+
is `true`, where `K` is the type substituted as the first template
|
| 3419 |
+
argument.
|
| 3420 |
|
| 3421 |
A deduction guide for an unordered associative container shall not
|
| 3422 |
participate in overload resolution if any of the following are true:
|
| 3423 |
|
| 3424 |
- It has an `InputIterator` template parameter and a type that does not
|