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
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #### General <a id="unord.req.general">[[unord.req.general]]</a>
2
+
3
+ Unordered associative containers provide an ability for fast retrieval
4
+ of data based on keys. The worst-case complexity for most operations is
5
+ linear, but the average case is much faster. The library provides four
6
+ unordered associative containers: `unordered_set`, `unordered_map`,
7
+ `unordered_multiset`, and `unordered_multimap`.
8
+
9
+ Unordered associative containers conform to the requirements for
10
+ Containers [[container.requirements]], except that the expressions
11
+ `a == b` and `a != b` have different semantics than for the other
12
+ container types.
13
+
14
+ Each unordered associative container is parameterized by `Key`, by a
15
+ function object type `Hash` that meets the *Cpp17Hash* requirements
16
+ [[hash.requirements]] and acts as a hash function for argument values of
17
+ type `Key`, and by a binary predicate `Pred` that induces an equivalence
18
+ relation on values of type `Key`. Additionally, `unordered_map` and
19
+ `unordered_multimap` associate an arbitrary *mapped type* `T` with the
20
+ `Key`.
21
+
22
+ The container’s object of type `Hash` — denoted by `hash` — is called
23
+ the *hash function* of the container. The container’s object of type
24
+ `Pred` — denoted by `pred` — is called the *key equality predicate* of
25
+ the container.
26
+
27
+ Two values `k1` and `k2` are considered equivalent if the container’s
28
+ key equality predicate `pred(k1, k2)` is valid and returns `true` when
29
+ passed those values. If `k1` and `k2` are equivalent, the container’s
30
+ hash function shall return the same value for both.
31
+
32
+ [*Note 1*: Thus, when an unordered associative container is
33
+ instantiated with a non-default `Pred` parameter it usually needs a
34
+ non-default `Hash` parameter as well. — *end note*]
35
+
36
+ For any two keys `k1` and `k2` in the same container, calling
37
+ `pred(k1, k2)` shall always return the same value. For any key `k` in a
38
+ container, calling `hash(k)` shall always return the same value.
39
+
40
+ An unordered associative container supports *unique keys* if it may
41
+ contain at most one element for each key. Otherwise, it supports
42
+ *equivalent keys*. `unordered_set` and `unordered_map` support unique
43
+ keys. `unordered_multiset` and `unordered_multimap` support equivalent
44
+ keys. In containers that support equivalent keys, elements with
45
+ equivalent keys are adjacent to each other in the iteration order of the
46
+ container. Thus, although the absolute order of elements in an unordered
47
+ container is not specified, its elements are grouped into
48
+ *equivalent-key groups* such that all elements of each group have
49
+ equivalent keys. Mutating operations on unordered containers shall
50
+ preserve the relative order of elements within each equivalent-key group
51
+ unless otherwise specified.
52
+
53
+ For `unordered_set` and `unordered_multiset` the value type is the same
54
+ as the key type. For `unordered_map` and `unordered_multimap` it is
55
+ `pair<const Key,
56
+ T>`.
57
+
58
+ For unordered containers where the value type is the same as the key
59
+ type, both `iterator` and `const_iterator` are constant iterators. It is
60
+ unspecified whether or not `iterator` and `const_iterator` are the same
61
+ type.
62
+
63
+ [*Note 2*: `iterator` and `const_iterator` have identical semantics in
64
+ this case, and `iterator` is convertible to `const_iterator`. Users can
65
+ avoid violating the one-definition rule by always using `const_iterator`
66
+ in their function parameter lists. — *end note*]
67
+
68
+ The elements of an unordered associative container are organized into
69
+ *buckets*. Keys with the same hash code appear in the same bucket. The
70
+ number of buckets is automatically increased as elements are added to an
71
+ unordered associative container, so that the average number of elements
72
+ per bucket is kept below a bound. Rehashing invalidates iterators,
73
+ changes ordering between elements, and changes which buckets elements
74
+ appear in, but does not invalidate pointers or references to elements.
75
+ For `unordered_multiset` and `unordered_multimap`, rehashing preserves
76
+ the relative ordering of equivalent elements.
77
+
78
+ In this subclause,
79
+
80
+ - `X` denotes an unordered associative container class,
81
+ - `a` denotes a value of type `X`,
82
+ - `a2` denotes a value of a type with nodes compatible with type `X` (
83
+ [[container.node.compat]]),
84
+ - `b` denotes a value of type `X` or `const X`,
85
+ - `a_uniq` denotes a value of type `X` when `X` supports unique keys,
86
+ - `a_eq` denotes a value of type `X` when `X` supports equivalent keys,
87
+ - `a_tran` denotes a value of type `X` or `const X` when the
88
+ *qualified-id*s `X::key_equal::is_transparent` and
89
+ `X::hasher::is_transparent` are both valid and denote types
90
+ [[temp.deduct]],
91
+ - `i` and `j` denote input iterators that refer to `value_type`,
92
+ - `[i, j)` denotes a valid range,
93
+ - `rg` denotes a value of a type `R` that models
94
+ `container-compatible-range<value_type>`,
95
+ - `p` and `q2` denote valid constant iterators to `a`,
96
+ - `q` and `q1` denote valid dereferenceable constant iterators to `a`,
97
+ - `r` denotes a valid dereferenceable iterator to `a`,
98
+ - `[q1, q2)` denotes a valid range in `a`,
99
+ - `il` denotes a value of type `initializer_list<value_type>`,
100
+ - `t` denotes a value of type `X::value_type`,
101
+ - `k` denotes a value of type `key_type`,
102
+ - `hf` denotes a value of type `hasher` or `const hasher`,
103
+ - `eq` denotes a value of type `key_equal` or `const key_equal`,
104
+ - `ke` is a value such that
105
+ - `eq(r1, ke) == eq(ke, r1)`,
106
+ - `hf(r1) == hf(ke)` if `eq(r1, ke)` is `true`, and
107
+ - if any two of `eq(r1, ke)`, `eq(r2, ke)`, and `eq(r1, r2)` are
108
+ `true`, then all three are `true`,
109
+
110
+ where `r1` and `r2` are keys of elements in `a_tran`,
111
+ - `kx` is a value such that
112
+ - `eq(r1, kx) == eq(kx, r1)`,
113
+ - `hf(r1) == hf(kx)` if `eq(r1, kx)` is `true`,
114
+ - if any two of `eq(r1, kx)`, `eq(r2, kx)`, and `eq(r1, r2)` are
115
+ `true`, then all three are `true`, and
116
+ - `kx` is not convertible to either `iterator` or `const_iterator`,
117
+
118
+ where `r1` and `r2` are keys of elements in `a_tran`,
119
+ - `n` denotes a value of type `size_type`,
120
+ - `z` denotes a value of type `float`, and
121
+ - `nh` denotes an rvalue of type `X::node_type`.
122
+
123
+ A type `X` meets the *unordered associative container* requirements if
124
+ `X` meets all the requirements of an allocator-aware container
125
+ [[container.requirements.general]] and the following types, statements,
126
+ and expressions are well-formed and have the specified semantics, except
127
+ that for `unordered_map` and `unordered_multimap`, the requirements
128
+ placed on `value_type` in [[container.alloc.reqmts]] apply instead to
129
+ `key_type` and `mapped_type`.
130
+
131
+ [*Note 3*: For example, `key_type` and `mapped_type` are sometimes
132
+ required to be *Cpp17CopyAssignable* even though the associated
133
+ `value_type`, `pair<const key_type, mapped_type>`, is not
134
+ *Cpp17CopyAssignable*. — *end note*]
135
+
136
+ ``` cpp
137
+ typename X::key_type
138
+ ```
139
+
140
+ *Result:* `Key`.
141
+
142
+ ``` cpp
143
+ typename X::mapped_type
144
+ ```
145
+
146
+ *Result:* `T`.
147
+
148
+ *Remarks:* For `unordered_map` and `unordered_multimap` only.
149
+
150
+ ``` cpp
151
+ typename X::value_type
152
+ ```
153
+
154
+ *Result:* `Key` for `unordered_set` and `unordered_multiset` only;
155
+ `pair<const Key, T>` for `unordered_map` and `unordered_multimap` only.
156
+
157
+ *Preconditions:* `value_type` is *Cpp17Erasable* from `X`.
158
+
159
+ ``` cpp
160
+ typename X::hasher
161
+ ```
162
+
163
+ *Result:* `Hash`.
164
+
165
+ *Preconditions:* `Hash` is a unary function object type such that the
166
+ expression `hf(k)` has type `size_t`.
167
+
168
+ ``` cpp
169
+ typename X::key_equal
170
+ ```
171
+
172
+ *Result:* `Pred`.
173
+
174
+ *Preconditions:* `Pred` meets the *Cpp17CopyConstructible* requirements.
175
+ `Pred` is a binary predicate that takes two arguments of type `Key`.
176
+ `Pred` is an equivalence relation.
177
+
178
+ ``` cpp
179
+ typename X::local_iterator
180
+ ```
181
+
182
+ *Result:* An iterator type whose category, value type, difference type,
183
+ and pointer and reference types are the same as `X::iterator`’s.
184
+
185
+ [*Note 1*: A `local_iterator` object can be used to iterate through a
186
+ single bucket, but cannot be used to iterate across
187
+ buckets. — *end note*]
188
+
189
+ ``` cpp
190
+ typename X::const_local_iterator
191
+ ```
192
+
193
+ *Result:* An iterator type whose category, value type, difference type,
194
+ and pointer and reference types are the same as `X::const_iterator`’s.
195
+
196
+ [*Note 2*: A `const_local_iterator` object can be used to iterate
197
+ through a single bucket, but cannot be used to iterate across
198
+ buckets. — *end note*]
199
+
200
+ ``` cpp
201
+ typename X::node_type
202
+ ```
203
+
204
+ *Result:* A specialization of a *node-handle* class
205
+ template [[container.node]], such that the public nested types are the
206
+ same types as the corresponding types in `X`.
207
+
208
+ ``` cpp
209
+ X(n, hf, eq)
210
+ ```
211
+
212
+ *Effects:* Constructs an empty container with at least `n` buckets,
213
+ using `hf` as the hash function and `eq` as the key equality predicate.
214
+
215
+ *Complexity:* 𝑂(`n`)
216
+
217
+ ``` cpp
218
+ X(n, hf)
219
+ ```
220
+
221
+ *Preconditions:* `key_equal` meets the *Cpp17DefaultConstructible*
222
+ requirements.
223
+
224
+ *Effects:* Constructs an empty container with at least `n` buckets,
225
+ using `hf` as the hash function and `key_equal()` as the key equality
226
+ predicate.
227
+
228
+ *Complexity:* 𝑂(`n`)
229
+
230
+ ``` cpp
231
+ X(n)
232
+ ```
233
+
234
+ *Preconditions:* `hasher` and `key_equal` meet the
235
+ *Cpp17DefaultConstructible* requirements.
236
+
237
+ *Effects:* Constructs an empty container with at least `n` buckets,
238
+ using `hasher()` as the hash function and `key_equal()` as the key
239
+ equality predicate.
240
+
241
+ *Complexity:* 𝑂(`n`)
242
+
243
+ ``` cpp
244
+ X a = X();
245
+ X a;
246
+ ```
247
+
248
+ *Preconditions:* `hasher` and `key_equal` meet the
249
+ *Cpp17DefaultConstructible* requirements.
250
+
251
+ *Effects:* Constructs an empty container with an unspecified number of
252
+ buckets, using `hasher()` as the hash function and `key_equal()` as the
253
+ key equality predicate.
254
+
255
+ *Complexity:* Constant.
256
+
257
+ ``` cpp
258
+ X(i, j, n, hf, eq)
259
+ ```
260
+
261
+ *Preconditions:* `value_type` is *Cpp17EmplaceConstructible* into `X`
262
+ from `*i`.
263
+
264
+ *Effects:* Constructs an empty container with at least `n` buckets,
265
+ using `hf` as the hash function and `eq` as the key equality predicate,
266
+ and inserts elements from \[`i`, `j`) into it.
267
+
268
+ *Complexity:* Average case 𝑂(N) (N is `distance(i, j)`), worst case
269
+ 𝑂(N^2).
270
+
271
+ ``` cpp
272
+ X(i, j, n, hf)
273
+ ```
274
+
275
+ *Preconditions:* `key_equal` meets the *Cpp17DefaultConstructible*
276
+ requirements. `value_type` is *Cpp17EmplaceConstructible* into `X` from
277
+ `*i`.
278
+
279
+ *Effects:* Constructs an empty container with at least `n` buckets,
280
+ using `hf` as the hash function and `key_equal()` as the key equality
281
+ predicate, and inserts elements from \[`i`, `j`) into it.
282
+
283
+ *Complexity:* Average case 𝑂(N) (N is `distance(i, j)`), worst case
284
+ 𝑂(N^2).
285
+
286
+ ``` cpp
287
+ X(i, j, n)
288
+ ```
289
+
290
+ *Preconditions:* `hasher` and `key_equal` meet the
291
+ *Cpp17DefaultConstructible* requirements. `value_type` is
292
+ *Cpp17EmplaceConstructible* into `X` from `*i`.
293
+
294
+ *Effects:* Constructs an empty container with at least `n` buckets,
295
+ using `hasher()` as the hash function and `key_equal()` as the key
296
+ equality predicate, and inserts elements from \[`i`, `j`) into it.
297
+
298
+ *Complexity:* Average case 𝑂(N) (N is `distance(i, j)`), worst case
299
+ 𝑂(N^2).
300
+
301
+ ``` cpp
302
+ X(i, j)
303
+ ```
304
+
305
+ *Preconditions:* `hasher` and `key_equal` meet the
306
+ *Cpp17DefaultConstructible* requirements. `value_type` is
307
+ *Cpp17EmplaceConstructible* into `X` from `*i`.
308
+
309
+ *Effects:* Constructs an empty container with an unspecified number of
310
+ buckets, using `hasher()` as the hash function and `key_equal()` as the
311
+ key equality predicate, and inserts elements from \[`i`, `j`) into it.
312
+
313
+ *Complexity:* Average case 𝑂(N) (N is `distance(i, j)`), worst case
314
+ 𝑂(N^2).
315
+
316
+ ``` cpp
317
+ X(from_range, rg, n, hf, eq)
318
+ ```
319
+
320
+ *Preconditions:* `value_type` is *Cpp17EmplaceConstructible* into `X`
321
+ from `*ranges::begin(rg)`.
322
+
323
+ *Effects:* Constructs an empty container with at least `n` buckets,
324
+ using `hf` as the hash function and `eq` as the key equality predicate,
325
+ and inserts elements from `rg` into it.
326
+
327
+ *Complexity:* Average case 𝑂(N) (N is `ranges::distance(rg)`), worst
328
+ case 𝑂(N^2).
329
+
330
+ ``` cpp
331
+ X(from_range, rg, n, hf)
332
+ ```
333
+
334
+ *Preconditions:* `key_equal` meets the *Cpp17DefaultConstructible*
335
+ requirements. `value_type` is *Cpp17EmplaceConstructible* into `X` from
336
+ `*ranges::begin(rg)`.
337
+
338
+ *Effects:* Constructs an empty container with at least `n` buckets,
339
+ using `hf` as the hash function and `key_equal()` as the key equality
340
+ predicate, and inserts elements from `rg` into it.
341
+
342
+ *Complexity:* Average case 𝑂(N) (N is `ranges::distance(rg)`), worst
343
+ case 𝑂(N^2).
344
+
345
+ ``` cpp
346
+ X(from_range, rg, n)
347
+ ```
348
+
349
+ *Preconditions:* `hasher` and `key_equal` meet the
350
+ *Cpp17DefaultConstructible* requirements. `value_type` is
351
+ *Cpp17EmplaceConstructible* into `X` from `*ranges::begin(rg)`.
352
+
353
+ *Effects:* Constructs an empty container with at least `n` buckets,
354
+ using `hasher()` as the hash function and `key_equal()` as the key
355
+ equality predicate, and inserts elements from `rg` into it.
356
+
357
+ *Complexity:* Average case 𝑂(N) (N is `ranges::distance(rg)`), worst
358
+ case 𝑂(N^2).
359
+
360
+ ``` cpp
361
+ X(from_range, rg)
362
+ ```
363
+
364
+ *Preconditions:* `hasher` and `key_equal` meet the
365
+ *Cpp17DefaultConstructible* requirements. `value_type` is
366
+ *Cpp17EmplaceConstructible* into `X` from `*ranges::begin(rg)`.
367
+
368
+ *Effects:* Constructs an empty container with an unspecified number of
369
+ buckets, using `hasher()` as the hash function and `key_equal()` as the
370
+ key equality predicate, and inserts elements from `rg` into it.
371
+
372
+ *Complexity:* Average case 𝑂(N) (N is `ranges::distance(rg)`), worst
373
+ case 𝑂(N^2).
374
+
375
+ ``` cpp
376
+ X(il)
377
+ ```
378
+
379
+ *Effects:* Equivalent to `X(il.begin(), il.end())`.
380
+
381
+ ``` cpp
382
+ X(il, n)
383
+ ```
384
+
385
+ *Effects:* Equivalent to `X(il.begin(), il.end(), n)`.
386
+
387
+ ``` cpp
388
+ X(il, n, hf)
389
+ ```
390
+
391
+ *Effects:* Equivalent to `X(il.begin(), il.end(), n, hf)`.
392
+
393
+ ``` cpp
394
+ X(il, n, hf, eq)
395
+ ```
396
+
397
+ *Effects:* Equivalent to `X(il.begin(), il.end(), n, hf, eq)`.
398
+
399
+ ``` cpp
400
+ X(b)
401
+ ```
402
+
403
+ *Effects:* In addition to the container
404
+ requirements [[container.requirements.general]], copies the hash
405
+ function, predicate, and maximum load factor.
406
+
407
+ *Complexity:* Average case linear in `b.size()`, worst case quadratic.
408
+
409
+ ``` cpp
410
+ a = b
411
+ ```
412
+
413
+ *Result:* `X&`
414
+
415
+ *Effects:* In addition to the container requirements, copies the hash
416
+ function, predicate, and maximum load factor.
417
+
418
+ *Complexity:* Average case linear in `b.size()`, worst case quadratic.
419
+
420
+ ``` cpp
421
+ a = il
422
+ ```
423
+
424
+ *Result:* `X&`
425
+
426
+ *Preconditions:* `value_type` is *Cpp17CopyInsertable* into `X` and
427
+ *Cpp17CopyAssignable*.
428
+
429
+ *Effects:* Assigns the range \[`il.begin()`, `il.end()`) into `a`. All
430
+ existing elements of `a` are either assigned to or destroyed.
431
+
432
+ *Complexity:* Average case linear in `il.size()`, worst case quadratic.
433
+
434
+ ``` cpp
435
+ b.hash_function()
436
+ ```
437
+
438
+ *Result:* `hasher`
439
+
440
+ *Returns:* `b`’s hash function.
441
+
442
+ *Complexity:* Constant.
443
+
444
+ ``` cpp
445
+ b.key_eq()
446
+ ```
447
+
448
+ *Result:* `key_equal`
449
+
450
+ *Returns:* `b`’s key equality predicate.
451
+
452
+ *Complexity:* Constant.
453
+
454
+ ``` cpp
455
+ a_uniq.emplace(args)
456
+ ```
457
+
458
+ *Result:* `pair<iterator,` `bool>`
459
+
460
+ *Preconditions:* `value_type` is *Cpp17EmplaceConstructible* into `X`
461
+ from `args`.
462
+
463
+ *Effects:* Inserts a `value_type` object `t` constructed with
464
+ `std::forward<Args>(args)...` if and only if there is no element in the
465
+ container with key equivalent to the key of `t`.
466
+
467
+ *Returns:* The `bool` component of the returned pair is `true` if and
468
+ only if the insertion takes place, and the iterator component of the
469
+ pair points to the element with key equivalent to the key of `t`.
470
+
471
+ *Complexity:* Average case 𝑂(1), worst case 𝑂(`a_uniq.size()`).
472
+
473
+ ``` cpp
474
+ a_eq.emplace(args)
475
+ ```
476
+
477
+ *Result:* `iterator`
478
+
479
+ *Preconditions:* `value_type` is *Cpp17EmplaceConstructible* into `X`
480
+ from `args`.
481
+
482
+ *Effects:* Inserts a `value_type` object `t` constructed with
483
+ `std::forward<Args>(args)...`.
484
+
485
+ *Returns:* An iterator pointing to the newly inserted element.
486
+
487
+ *Complexity:* Average case 𝑂(1), worst case 𝑂(`a_eq.size()`).
488
+
489
+ ``` cpp
490
+ a.emplace_hint(p, args)
491
+ ```
492
+
493
+ *Result:* `iterator`
494
+
495
+ *Preconditions:* `value_type` is *Cpp17EmplaceConstructible* into `X`
496
+ from `args`.
497
+
498
+ *Effects:* Equivalent to `a.emplace(std::forward<Args>(args)...)`.
499
+
500
+ *Returns:* An iterator pointing to the element with the key equivalent
501
+ to the newly inserted element. The `const_iterator` `p` is a hint
502
+ pointing to where the search should start. Implementations are permitted
503
+ to ignore the hint.
504
+
505
+ *Complexity:* Average case 𝑂(1), worst case 𝑂(`a.size()`).
506
+
507
+ ``` cpp
508
+ a_uniq.insert(t)
509
+ ```
510
+
511
+ *Result:* `pair<iterator, bool>`
512
+
513
+ *Preconditions:* If `t` is a non-const rvalue, `value_type` is
514
+ *Cpp17MoveInsertable* into `X`; otherwise, `value_type` is
515
+ *Cpp17CopyInsertable* into `X`.
516
+
517
+ *Effects:* Inserts `t` if and only if there is no element in the
518
+ container with key equivalent to the key of `t`.
519
+
520
+ *Returns:* The `bool` component of the returned pair indicates whether
521
+ the insertion takes place, and the `iterator` component points to the
522
+ element with key equivalent to the key of `t`.
523
+
524
+ *Complexity:* Average case 𝑂(1), worst case 𝑂(`a_uniq.size()`).
525
+
526
+ ``` cpp
527
+ a_eq.insert(t)
528
+ ```
529
+
530
+ *Result:* `iterator`
531
+
532
+ *Preconditions:* If `t` is a non-const rvalue, `value_type` is
533
+ *Cpp17MoveInsertable* into `X`; otherwise, `value_type` is
534
+ *Cpp17CopyInsertable* into `X`.
535
+
536
+ *Effects:* Inserts `t`.
537
+
538
+ *Returns:* An iterator pointing to the newly inserted element.
539
+
540
+ *Complexity:* Average case 𝑂(1), worst case 𝑂(`a_eq.size()`).
541
+
542
+ ``` cpp
543
+ a.insert(p, t)
544
+ ```
545
+
546
+ *Result:* `iterator`
547
+
548
+ *Preconditions:* If `t` is a non-const rvalue, `value_type` is
549
+ *Cpp17MoveInsertable* into `X`; otherwise, `value_type` is
550
+ *Cpp17CopyInsertable* into `X`.
551
+
552
+ *Effects:* Equivalent to `a.insert(t)`. The iterator `p` is a hint
553
+ pointing to where the search should start. Implementations are permitted
554
+ to ignore the hint.
555
+
556
+ *Returns:* An iterator pointing to the element with the key equivalent
557
+ to that of `t`.
558
+
559
+ *Complexity:* Average case 𝑂(1), worst case 𝑂(`a.size()`).
560
+
561
+ ``` cpp
562
+ a.insert(i, j)
563
+ ```
564
+
565
+ *Result:* `void`
566
+
567
+ *Preconditions:* `value_type` is *Cpp17EmplaceConstructible* into `X`
568
+ from `*i`. Neither `i` nor `j` are iterators into `a`.
569
+
570
+ *Effects:* Equivalent to `a.insert(t)` for each element in `[i,j)`.
571
+
572
+ *Complexity:* Average case 𝑂(N), where N is `distance(i, j)`, worst case
573
+ 𝑂(N(`a.size()` + 1)).
574
+
575
+ ``` cpp
576
+ a.insert_range(rg)
577
+ ```
578
+
579
+ *Result:* `void`
580
+
581
+ *Preconditions:* `value_type` is *Cpp17EmplaceConstructible* into `X`
582
+ from `*ranges::begin(rg)`. `rg` and `a` do not overlap.
583
+
584
+ *Effects:* Equivalent to `a.insert(t)` for each element `t` in `rg`.
585
+
586
+ *Complexity:* Average case 𝑂(N), where N is `ranges::distance(rg)`,
587
+ worst case 𝑂(N(`a.size()` + 1)).
588
+
589
+ ``` cpp
590
+ a.insert(il)
591
+ ```
592
+
593
+ *Effects:* Equivalent to `a.insert(il.begin(), il.end())`.
594
+
595
+ ``` cpp
596
+ a_uniq.insert(nh)
597
+ ```
598
+
599
+ *Result:* `insert_return_type`
600
+
601
+ *Preconditions:* `nh` is empty or
602
+ `a_uniq.get_allocator() == nh.get_allocator()` is `true`.
603
+
604
+ *Effects:* If `nh` is empty, has no effect. Otherwise, inserts the
605
+ element owned by `nh` if and only if there is no element in the
606
+ container with a key equivalent to `nh.key()`.
607
+
608
+ *Ensures:* If `nh` is empty, `inserted` is `false`, `position` is
609
+ `end()`, and `node` is empty. Otherwise if the insertion took place,
610
+ `inserted` is `true`, `position` points to the inserted element, and
611
+ `node` is empty; if the insertion failed, `inserted` is `false`, `node`
612
+ has the previous value of `nh`, and `position` points to an element with
613
+ a key equivalent to `nh.key()`.
614
+
615
+ *Complexity:* Average case 𝑂(1), worst case 𝑂(`a_uniq.size()`).
616
+
617
+ ``` cpp
618
+ a_eq.insert(nh)
619
+ ```
620
+
621
+ *Result:* `iterator`
622
+
623
+ *Preconditions:* `nh` is empty or
624
+ `a_eq.get_allocator() == nh.get_allocator()` is `true`.
625
+
626
+ *Effects:* If `nh` is empty, has no effect and returns `a_eq.end()`.
627
+ Otherwise, inserts the element owned by `nh` and returns an iterator
628
+ pointing to the newly inserted element.
629
+
630
+ *Ensures:* `nh` is empty.
631
+
632
+ *Complexity:* Average case 𝑂(1), worst case 𝑂(`a_eq.size()`).
633
+
634
+ ``` cpp
635
+ a.insert(q, nh)
636
+ ```
637
+
638
+ *Result:* `iterator`
639
+
640
+ *Preconditions:* `nh` is empty or
641
+ `a.get_allocator() == nh.get_allocator()` is `true`.
642
+
643
+ *Effects:* If `nh` is empty, has no effect and returns `a.end()`.
644
+ Otherwise, inserts the element owned by `nh` if and only if there is no
645
+ element with key equivalent to `nh.key()` in containers with unique
646
+ keys; always inserts the element owned by `nh` in containers with
647
+ equivalent keys. The iterator `q` is a hint pointing to where the search
648
+ should start. Implementations are permitted to ignore the hint.
649
+
650
+ *Ensures:* `nh` is empty if insertion succeeds, unchanged if insertion
651
+ fails.
652
+
653
+ *Returns:* An iterator pointing to the element with key equivalent to
654
+ `nh.key()`.
655
+
656
+ *Complexity:* Average case 𝑂(1), worst case 𝑂(`a.size()`).
657
+
658
+ ``` cpp
659
+ a.extract(k)
660
+ ```
661
+
662
+ *Result:* `node_type`
663
+
664
+ *Effects:* Removes an element in the container with key equivalent to
665
+ `k`.
666
+
667
+ *Returns:* A `node_type` owning the element if found, otherwise an empty
668
+ `node_type`.
669
+
670
+ *Complexity:* Average case 𝑂(1), worst case 𝑂(`a.size()`).
671
+
672
+ ``` cpp
673
+ a_tran.extract(kx)
674
+ ```
675
+
676
+ *Result:* `node_type`
677
+
678
+ *Effects:* Removes an element in the container with key equivalent to
679
+ `kx`.
680
+
681
+ *Returns:* A `node_type` owning the element if found, otherwise an empty
682
+ `node_type`.
683
+
684
+ *Complexity:* Average case 𝑂(1), worst case 𝑂(`a_tran.size()`).
685
+
686
+ ``` cpp
687
+ a.extract(q)
688
+ ```
689
+
690
+ *Result:* `node_type`
691
+
692
+ *Effects:* Removes the element pointed to by `q`.
693
+
694
+ *Returns:* A `node_type` owning that element.
695
+
696
+ *Complexity:* Average case 𝑂(1), worst case 𝑂(`a.size()`).
697
+
698
+ ``` cpp
699
+ a.merge(a2)
700
+ ```
701
+
702
+ *Result:* `void`
703
+
704
+ *Preconditions:* `a.get_allocator() == a2.get_allocator()`.
705
+
706
+ *Effects:* Attempts to extract each element in `a2` and insert it into
707
+ `a` using the hash function and key equality predicate of `a`. In
708
+ containers with unique keys, if there is an element in `a` with key
709
+ equivalent to the key of an element from `a2`, then that element is not
710
+ extracted from `a2`.
711
+
712
+ *Ensures:* Pointers and references to the transferred elements of `a2`
713
+ refer to those same elements but as members of `a`. Iterators referring
714
+ to the transferred elements and all iterators referring to `a` will be
715
+ invalidated, but iterators to elements remaining in `a2` will remain
716
+ valid.
717
+
718
+ *Complexity:* Average case 𝑂(N), where N is `a2.size()`, worst case
719
+ 𝑂(N`*a.size() + N`).
720
+
721
+ ``` cpp
722
+ a.erase(k)
723
+ ```
724
+
725
+ *Result:* `size_type`
726
+
727
+ *Effects:* Erases all elements with key equivalent to `k`.
728
+
729
+ *Returns:* The number of elements erased.
730
+
731
+ *Complexity:* Average case 𝑂(`a.count(k)`), worst case 𝑂(`a.size()`).
732
+
733
+ ``` cpp
734
+ a_tran.erase(kx)
735
+ ```
736
+
737
+ *Result:* `size_type`
738
+
739
+ *Effects:* Erases all elements with key equivalent to `kx`.
740
+
741
+ *Returns:* The number of elements erased.
742
+
743
+ *Complexity:* Average case 𝑂(`a_tran.count(kx)`), worst case
744
+ 𝑂(`a_tran.size()`).
745
+
746
+ ``` cpp
747
+ a.erase(q)
748
+ ```
749
+
750
+ *Result:* `iterator`
751
+
752
+ *Effects:* Erases the element pointed to by `q`.
753
+
754
+ *Returns:* The iterator immediately following `q` prior to the erasure.
755
+
756
+ *Complexity:* Average case 𝑂(1), worst case 𝑂(`a.size()`).
757
+
758
+ ``` cpp
759
+ a.erase(r)
760
+ ```
761
+
762
+ *Result:* `iterator`
763
+
764
+ *Effects:* Erases the element pointed to by `r`.
765
+
766
+ *Returns:* The iterator immediately following `r` prior to the erasure.
767
+
768
+ *Complexity:* Average case 𝑂(1), worst case 𝑂(`a.size()`).
769
+
770
+ ``` cpp
771
+ a.erase(q1, q2)
772
+ ```
773
+
774
+ *Result:* `iterator`
775
+
776
+ *Effects:* Erases all elements in the range `[q1, q2)`.
777
+
778
+ *Returns:* The iterator immediately following the erased elements prior
779
+ to the erasure.
780
+
781
+ *Complexity:* Average case linear in `distance(q1, q2)`, worst case
782
+ 𝑂(`a.size()`).
783
+
784
+ ``` cpp
785
+ a.clear()
786
+ ```
787
+
788
+ *Result:* `void`
789
+
790
+ *Effects:* Erases all elements in the container.
791
+
792
+ *Ensures:* `a.empty()` is `true`.
793
+
794
+ *Complexity:* Linear in `a.size()`.
795
+
796
+ ``` cpp
797
+ b.find(k)
798
+ ```
799
+
800
+ *Result:* `iterator`; `const_iterator` for constant `b`.
801
+
802
+ *Returns:* An iterator pointing to an element with key equivalent to
803
+ `k`, or `b.end()` if no such element exists.
804
+
805
+ *Complexity:* Average case 𝑂(1), worst case 𝑂(`b.size()`).
806
+
807
+ ``` cpp
808
+ a_tran.find(ke)
809
+ ```
810
+
811
+ *Result:* `iterator`; `const_iterator` for constant `a_tran`.
812
+
813
+ *Returns:* An iterator pointing to an element with key equivalent to
814
+ `ke`, or `a_tran.end()` if no such element exists.
815
+
816
+ *Complexity:* Average case 𝑂(1), worst case 𝑂(`a_tran.size()`).
817
+
818
+ ``` cpp
819
+ b.count(k)
820
+ ```
821
+
822
+ *Result:* `size_type`
823
+
824
+ *Returns:* The number of elements with key equivalent to `k`.
825
+
826
+ *Complexity:* Average case 𝑂(`b.count(k)`), worst case 𝑂(`b.size()`).
827
+
828
+ ``` cpp
829
+ a_tran.count(ke)
830
+ ```
831
+
832
+ *Result:* `size_type`
833
+
834
+ *Returns:* The number of elements with key equivalent to `ke`.
835
+
836
+ *Complexity:* Average case 𝑂(`a_tran.count(ke)`), worst case
837
+ 𝑂(`a_tran.size()`).
838
+
839
+ ``` cpp
840
+ b.contains(k)
841
+ ```
842
+
843
+ *Effects:* Equivalent to `b.find(k) != b.end()`.
844
+
845
+ ``` cpp
846
+ a_tran.contains(ke)
847
+ ```
848
+
849
+ *Effects:* Equivalent to `a_tran.find(ke) != a_tran.end()`.
850
+
851
+ ``` cpp
852
+ b.equal_range(k)
853
+ ```
854
+
855
+ *Result:* `pair<iterator, iterator>`;
856
+ `pair<const_iterator, const_iterator>` for constant `b`.
857
+
858
+ *Returns:* A range containing all elements with keys equivalent to `k`.
859
+ Returns `make_pair(b.end(), b.end())` if no such elements exist.
860
+
861
+ *Complexity:* Average case 𝑂(`b.count(k)`), worst case 𝑂(`b.size()`).
862
+
863
+ ``` cpp
864
+ a_tran.equal_range(ke)
865
+ ```
866
+
867
+ *Result:* `pair<iterator, iterator>`;
868
+ `pair<const_iterator, const_iterator>` for constant `a_tran`.
869
+
870
+ *Returns:* A range containing all elements with keys equivalent to `ke`.
871
+ Returns `make_pair(a_tran.end(), a_tran.end())` if no such elements
872
+ exist.
873
+
874
+ *Complexity:* Average case 𝑂(`a_tran.count(ke)`), worst case
875
+ 𝑂(`a_tran.size()`).
876
+
877
+ ``` cpp
878
+ b.bucket_count()
879
+ ```
880
+
881
+ *Result:* `size_type`
882
+
883
+ *Returns:* The number of buckets that `b` contains.
884
+
885
+ *Complexity:* Constant.
886
+
887
+ ``` cpp
888
+ b.max_bucket_count()
889
+ ```
890
+
891
+ *Result:* `size_type`
892
+
893
+ *Returns:* An upper bound on the number of buckets that `b` can ever
894
+ contain.
895
+
896
+ *Complexity:* Constant.
897
+
898
+ ``` cpp
899
+ b.bucket(k)
900
+ ```
901
+
902
+ *Result:* `size_type`
903
+
904
+ *Preconditions:* `b.bucket_count() > 0`.
905
+
906
+ *Returns:* The index of the bucket in which elements with keys
907
+ equivalent to `k` would be found, if any such element existed. The
908
+ return value is in the range `[0, b.bucket_count())`.
909
+
910
+ *Complexity:* Constant.
911
+
912
+ ``` cpp
913
+ b.bucket_size(n)
914
+ ```
915
+
916
+ *Result:* `size_type`
917
+
918
+ *Preconditions:* `n` shall be in the range `[0, b.bucket_count())`.
919
+
920
+ *Returns:* The number of elements in the `n`ᵗʰ bucket.
921
+
922
+ *Complexity:* 𝑂(`b.bucket_size(n)`)
923
+
924
+ ``` cpp
925
+ b.begin(n)
926
+ ```
927
+
928
+ *Result:* `local_iterator`; `const_local_iterator` for constant `b`.
929
+
930
+ *Preconditions:* `n` is in the range `[0, b.bucket_count())`.
931
+
932
+ *Returns:* An iterator referring to the first element in the bucket. If
933
+ the bucket is empty, then `b.begin(n) == b.end(n)`.
934
+
935
+ *Complexity:* Constant.
936
+
937
+ ``` cpp
938
+ b.end(n)
939
+ ```
940
+
941
+ *Result:* `local_iterator`; `const_local_iterator` for constant `b`.
942
+
943
+ *Preconditions:* `n` is in the range `[0, b.bucket_count())`.
944
+
945
+ *Returns:* An iterator which is the past-the-end value for the bucket.
946
+
947
+ *Complexity:* Constant.
948
+
949
+ ``` cpp
950
+ b.cbegin(n)
951
+ ```
952
+
953
+ *Result:* `const_local_iterator`
954
+
955
+ *Preconditions:* `n` shall be in the range `[0, b.bucket_count())`.
956
+
957
+ *Returns:* An iterator referring to the first element in the bucket. If
958
+ the bucket is empty, then `b.cbegin(n) == b.cend(n)`.
959
+
960
+ *Complexity:* Constant.
961
+
962
+ ``` cpp
963
+ b.cend(n)
964
+ ```
965
+
966
+ *Result:* `const_local_iterator`
967
+
968
+ *Preconditions:* `n` is in the range `[0, b.bucket_count())`.
969
+
970
+ *Returns:* An iterator which is the past-the-end value for the bucket.
971
+
972
+ *Complexity:* Constant.
973
+
974
+ ``` cpp
975
+ b.load_factor()
976
+ ```
977
+
978
+ *Result:* `float`
979
+
980
+ *Returns:* The average number of elements per bucket.
981
+
982
+ *Complexity:* Constant.
983
+
984
+ ``` cpp
985
+ b.max_load_factor()
986
+ ```
987
+
988
+ *Result:* `float`
989
+
990
+ *Returns:* A positive number that the container attempts to keep the
991
+ load factor less than or equal to. The container automatically increases
992
+ the number of buckets as necessary to keep the load factor below this
993
+ number.
994
+
995
+ *Complexity:* Constant.
996
+
997
+ ``` cpp
998
+ a.max_load_factor(z)
999
+ ```
1000
+
1001
+ *Result:* `void`
1002
+
1003
+ *Preconditions:* `z` is positive. May change the container’s maximum
1004
+ load factor, using `z` as a hint.
1005
+
1006
+ *Complexity:* Constant.
1007
+
1008
+ ``` cpp
1009
+ a.rehash(n)
1010
+ ```
1011
+
1012
+ *Result:* `void`
1013
+
1014
+ *Ensures:* `a.bucket_count() >= a.size() / a.max_load_factor()` and
1015
+ `a.bucket_count() >= n`.
1016
+
1017
+ *Complexity:* Average case linear in `a.size()`, worst case quadratic.
1018
+
1019
+ ``` cpp
1020
+ a.reserve(n)
1021
+ ```
1022
+
1023
+ *Effects:* Equivalent to `a.rehash(ceil(n / a.max_load_factor()))`.
1024
+
1025
+ Two unordered containers `a` and `b` compare equal if
1026
+ `a.size() == b.size()` and, for every equivalent-key group \[`Ea1`,
1027
+ `Ea2`) obtained from `a.equal_range(Ea1)`, there exists an
1028
+ equivalent-key group \[`Eb1`, `Eb2`) obtained from `b.equal_range(Ea1)`,
1029
+ such that `is_permutation(Ea1, Ea2, Eb1, Eb2)` returns `true`. For
1030
+ `unordered_set` and `unordered_map`, the complexity of `operator==`
1031
+ (i.e., the number of calls to the `==` operator of the `value_type`, to
1032
+ the predicate returned by `key_eq()`, and to the hasher returned by
1033
+ `hash_function()`) is proportional to N in the average case and to N² in
1034
+ the worst case, where N is `a.size()`. For `unordered_multiset` and
1035
+ `unordered_multimap`, the complexity of `operator==` is proportional to
1036
+ $\sum E_i^2$ in the average case and to N² in the worst case, where N is
1037
+ `a.size()`, and Eᵢ is the size of the iᵗʰ equivalent-key group in `a`.
1038
+ However, if the respective elements of each corresponding pair of
1039
+ equivalent-key groups Eaᵢ and Ebᵢ are arranged in the same order (as is
1040
+ commonly the case, e.g., if `a` and `b` are unmodified copies of the
1041
+ same container), then the average-case complexity for
1042
+ `unordered_multiset` and `unordered_multimap` becomes proportional to N
1043
+ (but worst-case complexity remains 𝑂(N^2), e.g., for a pathologically
1044
+ bad hash function). The behavior of a program that uses `operator==` or
1045
+ `operator!=` on unordered containers is undefined unless the `Pred`
1046
+ function object has the same behavior for both containers and the
1047
+ equality comparison function for `Key` is a refinement[^1]
1048
+
1049
+ of the partition into equivalent-key groups produced by `Pred`.
1050
+
1051
+ The iterator types `iterator` and `const_iterator` of an unordered
1052
+ associative container are of at least the forward iterator category. For
1053
+ unordered associative containers where the key type and value type are
1054
+ the same, both `iterator` and `const_iterator` are constant iterators.
1055
+
1056
+ The `insert`, `insert_range`, and `emplace` members shall not affect the
1057
+ validity of references to container elements, but may invalidate all
1058
+ iterators to the container. The `erase` members shall invalidate only
1059
+ iterators and references to the erased elements, and preserve the
1060
+ relative order of the elements that are not erased.
1061
+
1062
+ The `insert`, `insert_range`, and `emplace` members shall not affect the
1063
+ validity of iterators if `(N+n) <= z * B`, where `N` is the number of
1064
+ elements in the container prior to the insert operation, `n` is the
1065
+ number of elements inserted, `B` is the container’s bucket count, and
1066
+ `z` is the container’s maximum load factor.
1067
+
1068
+ The `extract` members invalidate only iterators to the removed element,
1069
+ and preserve the relative order of the elements that are not erased;
1070
+ pointers and references to the removed element remain valid. However,
1071
+ accessing the element through such pointers and references while the
1072
+ element is owned by a `node_type` is undefined behavior. References and
1073
+ pointers to an element obtained while it is owned by a `node_type` are
1074
+ invalidated if the element is successfully inserted.
1075
+
1076
+ The member function templates `find`, `count`, `equal_range`,
1077
+ `contains`, `extract`, and `erase` shall not participate in overload
1078
+ resolution unless the *qualified-id*s `Pred::is_transparent` and
1079
+ `Hash::is_transparent` are both valid and denote types [[temp.deduct]].
1080
+ Additionally, the member function templates `extract` and `erase` shall
1081
+ not participate in overload resolution if
1082
+ `is_convertible_v<K&&, iterator> || is_convertible_v<K&&, const_iterator>`
1083
+ is `true`, where `K` is the type substituted as the first template
1084
+ argument.
1085
+
1086
+ A deduction guide for an unordered associative container shall not
1087
+ participate in overload resolution if any of the following are true:
1088
+
1089
+ - It has an `InputIterator` template parameter and a type that does not
1090
+ qualify as an input iterator is deduced for that parameter.
1091
+ - It has an `Allocator` template parameter and a type that does not
1092
+ qualify as an allocator is deduced for that parameter.
1093
+ - It has a `Hash` template parameter and an integral type or a type that
1094
+ qualifies as an allocator is deduced for that parameter.
1095
+ - It has a `Pred` template parameter and a type that qualifies as an
1096
+ allocator is deduced for that parameter.
1097
+