From Jason Turner

[container.requirements]

Diff to HTML by rtfpessoa

Files changed (1) hide show
  1. tmp/tmpj47lu1pn/{from.md → to.md} +235 -202
tmp/tmpj47lu1pn/{from.md → to.md} RENAMED
@@ -16,31 +16,31 @@ linear complexity, even though the complexity of copying each contained
16
  For the components affected by this subclause that declare an
17
  `allocator_type`, objects stored in these components shall be
18
  constructed using the function
19
  `allocator_traits<allocator_type>::rebind_traits<U>::{}construct` and
20
  destroyed using the function
21
- `allocator_traits<allocator_type>::rebind_traits<U>::{}destroy` (
22
- [[allocator.traits.members]]), where `U` is either
23
  `allocator_type::value_type` or an internal type used by the container.
24
  These functions are called only for the container’s element type, not
25
  for internal types used by the container.
26
 
27
  [*Note 1*: This means, for example, that a node-based container might
28
  need to construct nodes containing aligned buffers and call `construct`
29
  to place the element into the buffer. — *end note*]
30
 
31
- In Tables  [[tab:containers.container.requirements]],
32
- [[tab:containers.reversible.requirements]], and
33
- [[tab:containers.optional.operations]] `X` denotes a container class
34
- containing objects of type `T`, `a` and `b` denote values of type `X`,
35
- `u` denotes an identifier, `r` denotes a non-const value of type `X`,
36
- and `rv` denotes a non-const rvalue of type `X`.
37
 
38
  Those entries marked “(Note A)” or “(Note B)” have linear complexity for
39
  `array` and have constant complexity for all other standard containers.
40
 
41
- [*Note 2*: The algorithm `equal()` is defined in Clause 
42
  [[algorithms]]. — *end note*]
43
 
44
  The member function `size()` returns the number of elements in the
45
  container. The number of elements is defined by the rules of
46
  constructors, inserts, and erases.
@@ -58,10 +58,11 @@ i == j
58
  i != j
59
  i < j
60
  i <= j
61
  i >= j
62
  i > j
 
63
  i - j
64
  ```
65
 
66
  where `i` and `j` denote objects of a container’s `iterator` type,
67
  either or both may be replaced by an object of the container’s
@@ -85,11 +86,11 @@ constructors obtain an allocator by move construction from the allocator
85
  belonging to the container being moved. Such move construction of the
86
  allocator shall not exit via an exception. All other constructors for
87
  these container types take a `const allocator_type&` argument.
88
 
89
  [*Note 4*: If an invocation of a constructor uses the default value of
90
- an optional allocator argument, then the `Allocator` type must support
91
  value-initialization. — *end note*]
92
 
93
  A copy of this allocator is used for any memory allocation and element
94
  construction performed, by these constructors and by all member
95
  functions, during the lifetime of each container object or until the
@@ -123,13 +124,13 @@ element in one container before the swap shall refer to the same element
123
  in the other container after the swap. It is unspecified whether an
124
  iterator with value `a.end()` before the swap will have value `b.end()`
125
  after the swap.
126
 
127
  If the iterator type of a container belongs to the bidirectional or
128
- random access iterator categories ([[iterator.requirements]]), the
129
- container is called *reversible* and satisfies the additional
130
- requirements in Table  [[tab:containers.reversible.requirements]].
131
 
132
  Unless otherwise specified (see  [[associative.reqmts.except]],
133
  [[unord.req.except]], [[deque.modifiers]], and [[vector.modifiers]]) all
134
  container types defined in this Clause meet the following additional
135
  requirements:
@@ -153,38 +154,40 @@ Unless otherwise specified (either explicitly or by defining a function
153
  in terms of other functions), invoking a container member function or
154
  passing a container as an argument to a library function shall not
155
  invalidate iterators to, or change the values of, objects within that
156
  container.
157
 
158
- A *contiguous container* is a container that supports random access
159
- iterators ([[random.access.iterators]]) and whose member types
160
- `iterator` and `const_iterator` are contiguous iterators (
161
- [[iterator.requirements.general]]).
162
 
163
- Table  [[tab:containers.optional.operations]] lists operations that are
164
- provided for some types of containers but not others. Those containers
165
- for which the listed operations are provided shall implement the
166
- semantics described in Table  [[tab:containers.optional.operations]]
167
- unless otherwise stated.
 
 
168
 
169
- [*Note 6*: The algorithm `lexicographical_compare()` is defined in
170
- Clause  [[algorithms]]. — *end note*]
171
 
172
  All of the containers defined in this Clause and in  [[basic.string]]
173
  except `array` meet the additional requirements of an allocator-aware
174
- container, as described in Table  [[tab:containers.allocatoraware]].
175
 
176
  Given an allocator type `A` and given a container type `X` having a
177
  `value_type` identical to `T` and an `allocator_type` identical to
178
  `allocator_traits<A>::rebind_alloc<T>` and given an lvalue `m` of type
179
  `A`, a pointer `p` of type `T*`, an expression `v` of type (possibly
180
  `const`) `T`, and an rvalue `rv` of type `T`, the following terms are
181
  defined. If `X` is not allocator-aware, the terms below are defined as
182
  if `A` were `allocator<T>` — no allocator object needs to be created and
183
  user specializations of `allocator<T>` are not instantiated:
184
 
185
- - `T` is *`DefaultInsertable` into `X`* means that the following
186
  expression is well-formed:
187
  ``` cpp
188
  allocator_traits<A>::construct(m, p)
189
  ```
190
  - An element of `X` is *default-inserted* if it is initialized by
@@ -193,71 +196,71 @@ user specializations of `allocator<T>` are not instantiated:
193
  allocator_traits<A>::construct(m, p)
194
  ```
195
 
196
  where `p` is the address of the uninitialized storage for the element
197
  allocated within `X`.
198
- - `T` is *`MoveInsertable` into `X`* means that the following expression
199
- is well-formed:
200
  ``` cpp
201
  allocator_traits<A>::construct(m, p, rv)
202
  ```
203
 
204
  and its evaluation causes the following postcondition to hold: The
205
  value of `*p` is equivalent to the value of `rv` before the
206
  evaluation.
207
  \[*Note 7*: `rv` remains a valid object. Its state is
208
  unspecified — *end note*]
209
- - `T` is *`CopyInsertable` into `X`* means that, in addition to `T`
210
- being `MoveInsertable` into `X`, the following expression is
211
  well-formed:
212
  ``` cpp
213
  allocator_traits<A>::construct(m, p, v)
214
  ```
215
 
216
  and its evaluation causes the following postcondition to hold: The
217
  value of `v` is unchanged and is equivalent to `*p`.
218
- - `T` is *`EmplaceConstructible` into `X` from `args`*, for zero or more
219
- arguments `args`, means that the following expression is well-formed:
 
220
  ``` cpp
221
  allocator_traits<A>::construct(m, p, args)
222
  ```
223
- - `T` is *`Erasable` from `X`* means that the following expression is
224
- well-formed:
225
  ``` cpp
226
  allocator_traits<A>::destroy(m, p)
227
  ```
228
 
229
  [*Note 8*: A container calls
230
  `allocator_traits<A>::construct(m, p, args)` to construct an element at
231
  `p` using `args`, with `m == get_allocator()`. The default `construct`
232
  in `allocator` will call `::new((void*)p) T(args)`, but specialized
233
  allocators may choose a different definition. — *end note*]
234
 
235
- In Table  [[tab:containers.allocatoraware]], `X` denotes an
236
- allocator-aware container class with a `value_type` of `T` using
237
- allocator of type `A`, `u` denotes a variable, `a` and `b` denote
238
- non-const lvalues of type `X`, `t` denotes an lvalue or a const rvalue
239
- of type `X`, `rv` denotes a non-const rvalue of type `X`, and `m` is a
240
- value of type `A`.
241
 
242
  The behavior of certain container member functions and deduction guides
243
  depends on whether types qualify as input iterators or allocators. The
244
  extent to which an implementation determines that a type cannot be an
245
  input iterator is unspecified, except that as a minimum integral types
246
  shall not qualify as input iterators. Likewise, the extent to which an
247
  implementation determines that a type cannot be an allocator is
248
  unspecified, except that as a minimum a type `A` shall not qualify as an
249
- allocator unless it satisfies both of the following conditions:
250
 
251
- - The *qualified-id* `A::value_type` is valid and denotes a type (
252
- [[temp.deduct]]).
253
  - The expression `declval<A&>().allocate(size_t{})` is well-formed when
254
  treated as an unevaluated operand.
255
 
256
  ### Container data races <a id="container.requirements.dataraces">[[container.requirements.dataraces]]</a>
257
 
258
- For purposes of avoiding data races ([[res.on.data.races]]),
259
  implementations shall consider the following functions to be `const`:
260
  `begin`, `end`, `rbegin`, `rend`, `front`, `back`, `data`, `find`,
261
  `lower_bound`, `upper_bound`, `equal_range`, `at` and, except in
262
  associative or unordered associative containers, `operator[]`.
263
 
@@ -283,38 +286,43 @@ which provides limited sequence operations because it has a fixed number
283
  of elements. The library also provides container adaptors that make it
284
  easy to construct abstract data types, such as `stack`s or `queue`s, out
285
  of the basic sequence container kinds (or out of other kinds of sequence
286
  containers that the user might define).
287
 
288
- The sequence containers offer the programmer different complexity
289
- trade-offs and should be used accordingly. `vector` or `array` is the
290
- type of sequence container that should be used by default. `list` or
291
- `forward_list` should be used when there are frequent insertions and
292
- deletions from the middle of the sequence. `deque` is the data structure
293
- of choice when most insertions and deletions take place at the beginning
294
- or at the end of the sequence.
 
 
 
295
 
296
- In Tables  [[tab:containers.sequence.requirements]] and
297
- [[tab:containers.sequence.optional]], `X` denotes a sequence container
298
- class, `a` denotes a value of type `X` containing elements of type `T`,
299
- `u` denotes the name of a variable being declared, `A` denotes
300
- `X::allocator_type` if the *qualified-id* `X::allocator_type` is valid
301
- and denotes a type ([[temp.deduct]]) and `allocator<T>` if it doesn’t,
302
- `i` and `j` denote iterators satisfying input iterator requirements and
303
- refer to elements implicitly convertible to `value_type`, `[i, j)`
304
- denotes a valid range, `il` designates an object of type
305
- `initializer_list<value_type>`, `n` denotes a value of type
306
- `X::size_type`, `p` denotes a valid constant iterator to `a`, `q`
307
- denotes a valid dereferenceable constant iterator to `a`, `[q1, q2)`
308
- denotes a valid range of constant iterators in `a`, `t` denotes an
309
- lvalue or a const rvalue of `X::value_type`, and `rv` denotes a
310
- non-const rvalue of `X::value_type`. `Args` denotes a template parameter
311
- pack; `args` denotes a function parameter pack with the pattern
312
- `Args&&`.
313
 
314
  The complexities of the expressions are sequence dependent.
315
 
 
 
 
316
  The iterator returned from `a.insert(p, t)` points to the copy of `t`
317
  inserted into `a`.
318
 
319
  The iterator returned from `a.insert(p, rv)` points to the copy of `rv`
320
  inserted into `a`.
@@ -337,12 +345,11 @@ element exists, `a.end()` is returned.
337
 
338
  The iterator returned by `a.erase(q1, q2)` points to the element pointed
339
  to by `q2` prior to any elements being erased. If no such element
340
  exists, `a.end()` is returned.
341
 
342
- For every sequence container defined in this Clause and in Clause 
343
- [[strings]]:
344
 
345
  - If the constructor
346
  ``` cpp
347
  template<class InputIterator>
348
  X(InputIterator first, InputIterator last,
@@ -374,32 +381,31 @@ For every sequence container defined in this Clause and in Clause 
374
  and a type that does not qualify as an input iterator is deduced for
375
  that parameter, or if it has an `Allocator` template parameter and a
376
  type that does not qualify as an allocator is deduced for that
377
  parameter.
378
 
379
- Table  [[tab:containers.sequence.optional]] lists operations that are
380
- provided for some types of sequence containers but not others. An
381
- implementation shall provide these operations for all container types
382
- shown in the “container” column, and shall implement them so as to take
383
- amortized constant time.
384
 
385
  The member function `at()` provides bounds-checked access to container
386
  elements. `at()` throws `out_of_range` if `n >= a.size()`.
387
 
388
  ### Node handles <a id="container.node">[[container.node]]</a>
389
 
390
- #### `node_handle` overview <a id="container.node.overview">[[container.node.overview]]</a>
391
 
392
  A *node handle* is an object that accepts ownership of a single element
393
- from an associative container ([[associative.reqmts]]) or an unordered
394
- associative container ([[unord.req]]). It may be used to transfer that
395
  ownership to another container with compatible nodes. Containers with
396
  compatible nodes have the same node handle type. Elements may be
397
  transferred in either direction between container types in the same row
398
- of Table  [[tab:containers.node.compat]].
399
 
400
- **Table: Container types with compatible nodes** <a id="tab:containers.node.compat">[tab:containers.node.compat]</a>
401
 
402
  | | |
403
  | -------------------------------- | ------------------------------------- |
404
  | `map<K, T, C1, A>` | `map<K, T, C2, A>` |
405
  | `map<K, T, C1, A>` | `multimap<K, T, C2, A>` |
@@ -413,122 +419,126 @@ of Table  [[tab:containers.node.compat]].
413
 
414
  If a node handle is not empty, then it contains an allocator that is
415
  equal to the allocator of the container when the element was extracted.
416
  If a node handle is empty, it contains no allocator.
417
 
418
- Class `node_handle` is for exposition only. An implementation is
419
- permitted to provide equivalent functionality without providing a class
420
- with this name.
421
 
422
  If a user-defined specialization of `pair` exists for
423
  `pair<const Key, T>` or `pair<Key, T>`, where `Key` is the container’s
424
  `key_type` and `T` is the container’s `mapped_type`, the behavior of
425
  operations involving node handles is undefined.
426
 
427
  ``` cpp
428
  template<unspecified>
429
- class node_handle {
430
  public:
431
- // These type declarations are described in Tables [tab:containers.associative.requirements] and [tab:HashRequirements].
432
  using value_type = see below; // not present for map containers
433
  using key_type = see below; // not present for set containers
434
  using mapped_type = see below; // not present for set containers
435
  using allocator_type = see below;
436
 
437
  private:
438
  using container_node_type = unspecified;
439
  using ator_traits = allocator_traits<allocator_type>;
440
 
441
- typename ator_traits::rebind_traits<container_node_type>::pointer ptr_;
442
  optional<allocator_type> alloc_;
443
 
444
  public:
445
- constexpr node_handle() noexcept : ptr_(), alloc_() {}
446
- ~node_handle();
447
- node_handle(node_handle&&) noexcept;
448
- node_handle& operator=(node_handle&&);
449
 
 
 
 
 
450
  value_type& value() const; // not present for map containers
451
  key_type& key() const; // not present for set containers
452
  mapped_type& mapped() const; // not present for set containers
453
 
454
  allocator_type get_allocator() const;
455
  explicit operator bool() const noexcept;
456
- bool empty() const noexcept;
457
 
458
- void swap(node_handle&)
 
459
  noexcept(ator_traits::propagate_on_container_swap::value ||
460
  ator_traits::is_always_equal::value);
461
 
462
- friend void swap(node_handle& x, node_handle& y) noexcept(noexcept(x.swap(y))) {
463
  x.swap(y);
464
  }
465
  };
466
  ```
467
 
468
- #### `node_handle` constructors, copy, and assignment <a id="container.node.cons">[[container.node.cons]]</a>
469
 
470
  ``` cpp
471
- node_handle(node_handle&& nh) noexcept;
472
  ```
473
 
474
- *Effects:* Constructs a *`node_handle`* object initializing `ptr_` with
475
  `nh.ptr_`. Move constructs `alloc_` with `nh.alloc_`. Assigns `nullptr`
476
  to `nh.ptr_` and assigns `nullopt` to `nh.alloc_`.
477
 
478
  ``` cpp
479
- node_handle& operator=(node_handle&& nh);
480
  ```
481
 
482
- *Requires:* Either `!alloc_`, or
483
- `ator_traits::propagate_on_container_move_assignment` is `true`, or
484
- `alloc_ == nh.alloc_`.
485
 
486
  *Effects:*
487
 
488
  - If `ptr_ != nullptr`, destroys the `value_type` subobject in the
489
  `container_node_type` object pointed to by `ptr_` by calling
490
  `ator_traits::destroy`, then deallocates `ptr_` by calling
491
- `ator_traits::rebind_traits<container_node_type>::deallocate`.
492
  - Assigns `nh.ptr_` to `ptr_`.
493
- - If `!alloc` or `ator_traits::propagate_on_container_move_assignment`
494
- is `true`, move assigns `nh.alloc_` to `alloc_`.
 
495
  - Assigns `nullptr` to `nh.ptr_` and assigns `nullopt` to `nh.alloc_`.
496
 
497
  *Returns:* `*this`.
498
 
499
  *Throws:* Nothing.
500
 
501
- #### `node_handle` destructor <a id="container.node.dtor">[[container.node.dtor]]</a>
502
 
503
  ``` cpp
504
- ~node_handle();
505
  ```
506
 
507
  *Effects:* If `ptr_ != nullptr`, destroys the `value_type` subobject in
508
  the `container_node_type` object pointed to by `ptr_` by calling
509
  `ator_traits::destroy`, then deallocates `ptr_` by calling
510
- `ator_traits::rebind_traits<container_node_type>::deallocate`.
511
 
512
- #### `node_handle` observers <a id="container.node.observers">[[container.node.observers]]</a>
513
 
514
  ``` cpp
515
  value_type& value() const;
516
  ```
517
 
518
- *Requires:* `empty() == false`.
519
 
520
  *Returns:* A reference to the `value_type` subobject in the
521
  `container_node_type` object pointed to by `ptr_`.
522
 
523
  *Throws:* Nothing.
524
 
525
  ``` cpp
526
  key_type& key() const;
527
  ```
528
 
529
- *Requires:* `empty() == false`.
530
 
531
  *Returns:* A non-const reference to the `key_type` member of the
532
  `value_type` subobject in the `container_node_type` object pointed to by
533
  `ptr_`.
534
 
@@ -539,22 +549,22 @@ permitted.
539
 
540
  ``` cpp
541
  mapped_type& mapped() const;
542
  ```
543
 
544
- *Requires:* `empty() == false`.
545
 
546
  *Returns:* A reference to the `mapped_type` member of the `value_type`
547
  subobject in the `container_node_type` object pointed to by `ptr_`.
548
 
549
  *Throws:* Nothing.
550
 
551
  ``` cpp
552
  allocator_type get_allocator() const;
553
  ```
554
 
555
- *Requires:* `empty() == false`.
556
 
557
  *Returns:* `*alloc_`.
558
 
559
  *Throws:* Nothing.
560
 
@@ -563,70 +573,75 @@ explicit operator bool() const noexcept;
563
  ```
564
 
565
  *Returns:* `ptr_ != nullptr`.
566
 
567
  ``` cpp
568
- bool empty() const noexcept;
569
  ```
570
 
571
  *Returns:* `ptr_ == nullptr`.
572
 
573
- #### `node_handle` modifiers <a id="container.node.modifiers">[[container.node.modifiers]]</a>
574
 
575
  ``` cpp
576
- void swap(node_handle& nh)
577
  noexcept(ator_traits::propagate_on_container_swap::value ||
578
  ator_traits::is_always_equal::value);
579
  ```
580
 
581
- *Requires:* `!alloc_`, or `!nh.alloc_`, or
582
- `ator_traits::propagate_on_container_swap` is `true`, or
583
  `alloc_ == nh.alloc_`.
584
 
585
  *Effects:* Calls `swap(ptr_, nh.ptr_)`. If `!alloc_`, or `!nh.alloc_`,
586
- or `ator_traits::propagate_on_container_swap` is `true` calls
587
  `swap(alloc_, nh.alloc_)`.
588
 
589
  ### Insert return type <a id="container.insert.return">[[container.insert.return]]</a>
590
 
591
  The associative containers with unique keys and the unordered containers
592
  with unique keys have a member function `insert` that returns a nested
593
  type `insert_return_type`. That return type is a specialization of the
594
- type specified in this subclause.
595
 
596
  ``` cpp
597
  template<class Iterator, class NodeType>
598
- struct INSERT_RETURN_TYPE
599
  {
600
  Iterator position;
601
  bool inserted;
602
  NodeType node;
603
  };
604
  ```
605
 
606
- The name `INSERT_RETURN_TYPE` is exposition only. `INSERT_RETURN_TYPE`
607
- has the template parameters, data members, and special members specified
608
- above. It has no base classes or members other than those specified.
 
609
 
610
  ### Associative containers <a id="associative.reqmts">[[associative.reqmts]]</a>
611
 
612
  Associative containers provide fast retrieval of data based on keys. The
613
  library provides four basic kinds of associative containers: `set`,
614
  `multiset`, `map` and `multimap`.
615
 
616
  Each associative container is parameterized on `Key` and an ordering
617
- relation `Compare` that induces a strict weak ordering (
618
- [[alg.sorting]]) on elements of `Key`. In addition, `map` and `multimap`
619
- associate an arbitrary *mapped type* `T` with the `Key`. The object of
620
- type `Compare` is called the *comparison object* of a container.
621
 
622
  The phrase “equivalence of keys” means the equivalence relation imposed
623
- by the comparison and *not* the `operator==` on keys. That is, two keys
624
- `k1` and `k2` are considered to be equivalent if for the comparison
625
- object `comp`, `comp(k1, k2) == false && comp(k2, k1) == false`. For any
626
- two keys `k1` and `k2` in the same container, calling `comp(k1, k2)`
627
- shall always return the same value.
 
 
 
 
628
 
629
  An associative container supports *unique keys* if it may contain at
630
  most one element for each key. Otherwise, it supports *equivalent keys*.
631
  The `set` and `map` classes support unique keys; the `multiset` and
632
  `multimap` classes support equivalent keys. For `multiset` and
@@ -642,45 +657,44 @@ of an associative container is of the bidirectional iterator category.
642
  For associative containers where the value type is the same as the key
643
  type, both `iterator` and `const_iterator` are constant iterators. It is
644
  unspecified whether or not `iterator` and `const_iterator` are the same
645
  type.
646
 
647
- [*Note 1*: `iterator` and `const_iterator` have identical semantics in
648
  this case, and `iterator` is convertible to `const_iterator`. Users can
649
  avoid violating the one-definition rule by always using `const_iterator`
650
  in their function parameter lists. — *end note*]
651
 
652
  The associative containers meet all the requirements of Allocator-aware
653
- containers ([[container.requirements.general]]), except that for `map`
654
- and `multimap`, the requirements placed on `value_type` in Table 
655
- [[tab:containers.container.requirements]] apply instead to `key_type`
656
- and `mapped_type`.
657
 
658
- [*Note 2*: For example, in some cases `key_type` and `mapped_type` are
659
- required to be `CopyAssignable` even though the associated `value_type`,
660
- `pair<const key_type, mapped_type>`, is not
661
- `CopyAssignable`. — *end note*]
662
 
663
- In Table  [[tab:containers.associative.requirements]], `X` denotes an
664
- associative container class, `a` denotes a value of type `X`, `a2`
665
- denotes a value of a type with nodes compatible with type `X` (Table 
666
- [[tab:containers.node.compat]]), `b` denotes a possibly `const` value of
667
- type `X`, `u` denotes the name of a variable being declared, `a_uniq`
668
- denotes a value of type `X` when `X` supports unique keys, `a_eq`
669
- denotes a value of type `X` when `X` supports multiple keys, `a_tran`
670
- denotes a possibly `const` value of type `X` when the *qualified-id*
671
- `X::key_compare::is_transparent` is valid and denotes a type (
672
- [[temp.deduct]]), `i` and `j` satisfy input iterator requirements and
673
- refer to elements implicitly convertible to `value_type`, \[`i`, `j`)
674
- denotes a valid range, `p` denotes a valid constant iterator to `a`, `q`
675
- denotes a valid dereferenceable constant iterator to `a`, `r` denotes a
676
- valid dereferenceable iterator to `a`, `[q1, q2)` denotes a valid range
677
- of constant iterators in `a`, `il` designates an object of type
678
  `initializer_list<value_type>`, `t` denotes a value of type
679
  `X::value_type`, `k` denotes a value of type `X::key_type` and `c`
680
  denotes a possibly `const` value of type `X::key_compare`; `kl` is a
681
- value such that `a` is partitioned ([[alg.sorting]]) with respect to
682
  `c(r, kl)`, with `r` the key value of `e` and `e` in `a`; `ku` is a
683
  value such that `a` is partitioned with respect to `!c(ku, r)`; `ke` is
684
  a value such that `a` is partitioned with respect to `c(r, ke)` and
685
  `!c(ke, r)`, with `c(r, ke)` implying `!c(ke, r)`. `A` denotes the
686
  storage allocator used by `X`, if any, or `allocator<X::value_type>`
@@ -717,19 +731,19 @@ value_comp(*i, *j) != false
717
  ```
718
 
719
  When an associative container is constructed by passing a comparison
720
  object the container shall not store a pointer or reference to the
721
  passed object, even if that object is passed by reference. When an
722
- associative container is copied, either through a copy constructor or an
723
  assignment operator, the target container shall then use the comparison
724
  object from the container being copied, as if that comparison object had
725
  been passed to the target container in its constructor.
726
 
727
- The member function templates `find`, `count`, `lower_bound`,
728
- `upper_bound`, and `equal_range` shall not participate in overload
729
- resolution unless the *qualified-id* `Compare::is_transparent` is valid
730
- and denotes a type ([[temp.deduct]]).
731
 
732
  A deduction guide for an associative container shall not participate in
733
  overload resolution if any of the following are true:
734
 
735
  - It has an `InputIterator` template parameter and a type that does not
@@ -760,31 +774,31 @@ of data based on keys. The worst-case complexity for most operations is
760
  linear, but the average case is much faster. The library provides four
761
  unordered associative containers: `unordered_set`, `unordered_map`,
762
  `unordered_multiset`, and `unordered_multimap`.
763
 
764
  Unordered associative containers conform to the requirements for
765
- Containers ([[container.requirements]]), except that the expressions
766
  `a == b` and `a != b` have different semantics than for the other
767
  container types.
768
 
769
  Each unordered associative container is parameterized by `Key`, by a
770
- function object type `Hash` that meets the `Hash` requirements (
771
- [[hash.requirements]]) and acts as a hash function for argument values
772
- of type `Key`, and by a binary predicate `Pred` that induces an
773
- equivalence relation on values of type `Key`. Additionally,
774
- `unordered_map` and `unordered_multimap` associate an arbitrary *mapped
775
- type* `T` with the `Key`.
776
 
777
  The container’s object of type `Hash` — denoted by `hash` — is called
778
  the *hash function* of the container. The container’s object of type
779
  `Pred` — denoted by `pred` — is called the *key equality predicate* of
780
  the container.
781
 
782
- Two values `k1` and `k2` of type `Key` are considered equivalent if the
783
- container’s key equality predicate returns `true` when passed those
784
- values. If `k1` and `k2` are equivalent, the container’s hash function
785
- shall return the same value for both.
786
 
787
  [*Note 1*: Thus, when an unordered associative container is
788
  instantiated with a non-default `Pred` parameter it usually needs a
789
  non-default `Hash` parameter as well. — *end note*]
790
 
@@ -829,64 +843,78 @@ changes ordering between elements, and changes which buckets elements
829
  appear in, but does not invalidate pointers or references to elements.
830
  For `unordered_multiset` and `unordered_multimap`, rehashing preserves
831
  the relative ordering of equivalent elements.
832
 
833
  The unordered associative containers meet all the requirements of
834
- Allocator-aware containers ([[container.requirements.general]]), except
835
  that for `unordered_map` and `unordered_multimap`, the requirements
836
- placed on `value_type` in Table 
837
- [[tab:containers.container.requirements]] apply instead to `key_type`
838
- and `mapped_type`.
839
 
840
  [*Note 3*: For example, `key_type` and `mapped_type` are sometimes
841
- required to be `CopyAssignable` even though the associated `value_type`,
842
- `pair<const key_type, mapped_type>`, is not
843
- `CopyAssignable`. — *end note*]
844
 
845
- In Table  [[tab:HashRequirements]]: `X` denotes an unordered associative
846
- container class, `a` denotes a value of type `X`, `a2` denotes a value
847
- of a type with nodes compatible with type `X` (Table 
848
- [[tab:containers.node.compat]]), `b` denotes a possibly const value of
849
- type `X`, `a_uniq` denotes a value of type `X` when `X` supports unique
850
- keys, `a_eq` denotes a value of type `X` when `X` supports equivalent
851
- keys, `i` and `j` denote input iterators that refer to `value_type`,
852
- `[i, j)` denotes a valid range, `p` and `q2` denote valid constant
853
- iterators to `a`, `q` and `q1` denote valid dereferenceable constant
854
- iterators to `a`, `r` denotes a valid dereferenceable iterator to `a`,
855
- `[q1, q2)` denotes a valid range in `a`, `il` denotes a value of type
856
- `initializer_list<value_type>`, `t` denotes a value of type
857
- `X::value_type`, `k` denotes a value of type `key_type`, `hf` denotes a
858
- possibly const value of type `hasher`, `eq` denotes a possibly const
859
- value of type `key_equal`, `n` denotes a value of type `size_type`, `z`
860
- denotes a value of type `float`, and `nh` denotes a non-const rvalue of
861
- type `X::node_type`.
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
862
 
863
  Two unordered containers `a` and `b` compare equal if
864
  `a.size() == b.size()` and, for every equivalent-key group \[`Ea1`,
865
  `Ea2`) obtained from `a.equal_range(Ea1)`, there exists an
866
  equivalent-key group \[`Eb1`, `Eb2`) obtained from `b.equal_range(Ea1)`,
867
  such that `is_permutation(Ea1, Ea2, Eb1, Eb2)` returns `true`. For
868
  `unordered_set` and `unordered_map`, the complexity of `operator==`
869
  (i.e., the number of calls to the `==` operator of the `value_type`, to
870
  the predicate returned by `key_eq()`, and to the hasher returned by
871
  `hash_function()`) is proportional to N in the average case and to N² in
872
- the worst case, where N is a.size(). For `unordered_multiset` and
873
  `unordered_multimap`, the complexity of `operator==` is proportional to
874
  $\sum E_i^2$ in the average case and to N² in the worst case, where N is
875
  `a.size()`, and Eᵢ is the size of the iᵗʰ equivalent-key group in `a`.
876
  However, if the respective elements of each corresponding pair of
877
  equivalent-key groups Eaᵢ and Ebᵢ are arranged in the same order (as is
878
  commonly the case, e.g., if `a` and `b` are unmodified copies of the
879
  same container), then the average-case complexity for
880
  `unordered_multiset` and `unordered_multimap` becomes proportional to N
881
  (but worst-case complexity remains 𝑂(N^2), e.g., for a pathologically
882
  bad hash function). The behavior of a program that uses `operator==` or
883
- `operator!=` on unordered containers is undefined unless the `Hash` and
884
- `Pred` function objects respectively have the same behavior for both
885
- containers and the equality comparison function for `Key` is a
886
- refinement[^1] of the partition into equivalent-key groups produced by
887
- `Pred`.
888
 
889
  The iterator types `iterator` and `const_iterator` of an unordered
890
  associative container are of at least the forward iterator category. For
891
  unordered associative containers where the key type and value type are
892
  the same, both `iterator` and `const_iterator` are constant iterators.
@@ -909,10 +937,15 @@ pointers and references to the removed element remain valid. However,
909
  accessing the element through such pointers and references while the
910
  element is owned by a `node_type` is undefined behavior. References and
911
  pointers to an element obtained while it is owned by a `node_type` are
912
  invalidated if the element is successfully inserted.
913
 
 
 
 
 
 
914
  A deduction guide for an unordered associative container shall not
915
  participate in overload resolution if any of the following are true:
916
 
917
  - It has an `InputIterator` template parameter and a type that does not
918
  qualify as an input iterator is deduced for that parameter.
 
16
  For the components affected by this subclause that declare an
17
  `allocator_type`, objects stored in these components shall be
18
  constructed using the function
19
  `allocator_traits<allocator_type>::rebind_traits<U>::{}construct` and
20
  destroyed using the function
21
+ `allocator_traits<allocator_type>::rebind_traits<U>::{}destroy`
22
+ [[allocator.traits.members]], where `U` is either
23
  `allocator_type::value_type` or an internal type used by the container.
24
  These functions are called only for the container’s element type, not
25
  for internal types used by the container.
26
 
27
  [*Note 1*: This means, for example, that a node-based container might
28
  need to construct nodes containing aligned buffers and call `construct`
29
  to place the element into the buffer. — *end note*]
30
 
31
+ In Tables  [[tab:container.req]], [[tab:container.rev.req]], and
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
  Those entries marked “(Note A)” or “(Note B)” have linear complexity for
39
  `array` and have constant complexity for all other standard containers.
40
 
41
+ [*Note 2*: The algorithm `equal()` is defined in
42
  [[algorithms]]. — *end note*]
43
 
44
  The member function `size()` returns the number of elements in the
45
  container. The number of elements is defined by the rules of
46
  constructors, inserts, and erases.
 
58
  i != j
59
  i < j
60
  i <= j
61
  i >= j
62
  i > j
63
+ i <=> j
64
  i - j
65
  ```
66
 
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
 
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 4*: If an invocation of a constructor uses the default value of
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
 
124
  in the other container after the swap. It is unspecified whether an
125
  iterator with value `a.end()` before the swap will have value `b.end()`
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:
 
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
157
  container.
158
 
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
+ [[container.opt]] lists operations that are provided for some types of
165
+ containers but not others. Those containers for which the listed
166
+ operations are provided shall implement the semantics described in
167
+ [[container.opt]] unless otherwise stated. If the iterators passed to
168
+ `lexicographical_compare_three_way` meet the constexpr iterator
169
+ requirements [[iterator.requirements.general]] then the operations
170
+ described in [[container.opt]] are implemented by constexpr functions.
171
 
172
+ [*Note 6*: The algorithm `lexicographical_compare_three_way` is defined
173
+ in [[algorithms]]. — *end note*]
174
 
175
  All of the containers defined in this Clause and in  [[basic.string]]
176
  except `array` meet the additional requirements of an allocator-aware
177
+ container, as described in [[container.alloc.req]].
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 (possibly
183
  `const`) `T`, and an rvalue `rv` of type `T`, the following terms are
184
  defined. If `X` is not allocator-aware, the terms below are defined as
185
  if `A` were `allocator<T>` — no allocator object needs to be created and
186
  user specializations of `allocator<T>` are not instantiated:
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)
192
  ```
193
  - An element of `X` is *default-inserted* if it is initialized by
 
196
  allocator_traits<A>::construct(m, p)
197
  ```
198
 
199
  where `p` is the address of the uninitialized storage for the element
200
  allocated within `X`.
201
+ - `T` is **Cpp17MoveInsertable* into `X`* means that the following
202
+ expression is well-formed:
203
  ``` cpp
204
  allocator_traits<A>::construct(m, p, rv)
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 7*: `rv` remains a valid object. Its state is
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
216
  allocator_traits<A>::construct(m, p, v)
217
  ```
218
 
219
  and its evaluation causes the following postcondition to hold: The
220
  value of `v` is unchanged and is equivalent to `*p`.
221
+ - `T` is **Cpp17EmplaceConstructible* into `X` from `args`*, for zero or
222
+ more arguments `args`, means that the following expression is
223
+ well-formed:
224
  ``` cpp
225
  allocator_traits<A>::construct(m, p, args)
226
  ```
227
+ - `T` is **Cpp17Erasable* from `X`* means that the following expression
228
+ is well-formed:
229
  ``` cpp
230
  allocator_traits<A>::destroy(m, p)
231
  ```
232
 
233
  [*Note 8*: A container calls
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 may choose a different definition. — *end note*]
238
 
239
+ In [[container.alloc.req]], `X` denotes an allocator-aware container
240
+ class with a `value_type` of `T` using allocator of type `A`, `u`
241
+ denotes a variable, `a` and `b` denote non-const lvalues of type `X`,
242
+ `t` denotes an lvalue or a const rvalue of type `X`, `rv` denotes a
243
+ non-const rvalue of type `X`, and `m` is a value of type `A`.
 
244
 
245
  The behavior of certain container member functions and deduction guides
246
  depends on whether types qualify as input iterators or allocators. The
247
  extent to which an implementation determines that a type cannot be an
248
  input iterator is unspecified, except that as a minimum integral types
249
  shall not qualify as input iterators. Likewise, the extent to which an
250
  implementation determines that a type cannot be an allocator is
251
  unspecified, except that as a minimum a type `A` shall not qualify as an
252
+ allocator unless it meets both of the following conditions:
253
 
254
+ - The *qualified-id* `A::value_type` is valid and denotes a type
255
+ [[temp.deduct]].
256
  - The expression `declval<A&>().allocate(size_t{})` is well-formed when
257
  treated as an unevaluated operand.
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`:
263
  `begin`, `end`, `rbegin`, `rend`, `front`, `back`, `data`, `find`,
264
  `lower_bound`, `upper_bound`, `equal_range`, `at` and, except in
265
  associative or unordered associative containers, `operator[]`.
266
 
 
286
  of elements. The library also provides container adaptors that make it
287
  easy to construct abstract data types, such as `stack`s or `queue`s, out
288
  of the basic sequence container kinds (or out of other kinds of sequence
289
  containers that the user might define).
290
 
291
+ [*Note 1*: The sequence containers offer the programmer different
292
+ complexity trade-offs and should be used accordingly. `vector` is the
293
+ type of sequence container that should be used by default. `array`
294
+ should be used when the container has a fixed size known during
295
+ translation. `list` or `forward_list` should be used when there are
296
+ frequent insertions and deletions from the middle of the sequence.
297
+ `deque` is the data structure of choice when most insertions and
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 Tables  [[tab:container.seq.req]] and [[tab:container.seq.opt]], `X`
303
+ denotes a sequence container class, `a` denotes a value of type `X`
304
+ containing elements of type `T`, `u` denotes the name of a variable
305
+ being declared, `A` denotes `X::allocator_type` if the *qualified-id*
306
+ `X::allocator_type` is valid and denotes a type [[temp.deduct]] and
307
+ `allocator<T>` if it doesn’t, `i` and `j` denote iterators that meet the
308
+ *Cpp17InputIterator* requirements and refer to elements implicitly
309
+ convertible to `value_type`, `[i, j)` denotes a valid range, `il`
310
+ designates an object of type `initializer_list<value_type>`, `n` denotes
311
+ a value of type `X::size_type`, `p` denotes a valid constant iterator to
312
+ `a`, `q` denotes a valid dereferenceable constant iterator to `a`,
313
+ `[q1, q2)` denotes a valid range of constant iterators in `a`, `t`
314
+ denotes an lvalue or a const rvalue of `X::value_type`, and `rv` denotes
315
+ a non-const rvalue of `X::value_type`. `Args` denotes a template
316
+ parameter pack; `args` denotes a function parameter pack with the
317
+ pattern `Args&&`.
 
318
 
319
  The complexities of the expressions are sequence dependent.
320
 
321
+ [*Note 2*: `args` may directly or indirectly refer to a value in
322
+ `a`. — *end note*]
323
+
324
  The iterator returned from `a.insert(p, t)` points to the copy of `t`
325
  inserted into `a`.
326
 
327
  The iterator returned from `a.insert(p, rv)` points to the copy of `rv`
328
  inserted into `a`.
 
345
 
346
  The iterator returned by `a.erase(q1, q2)` points to the element pointed
347
  to by `q2` prior to any elements being erased. If no such element
348
  exists, `a.end()` is returned.
349
 
350
+ For every sequence container defined in this Clause and in [[strings]]:
 
351
 
352
  - If the constructor
353
  ``` cpp
354
  template<class InputIterator>
355
  X(InputIterator first, InputIterator last,
 
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
+ [[container.seq.opt]] lists operations that are provided for some types
387
+ of sequence containers but not others. An implementation shall provide
388
+ these operations for all container types shown in the “container”
389
+ column, and shall implement them so as to take amortized constant time.
 
390
 
391
  The member function `at()` provides bounds-checked access to container
392
  elements. `at()` throws `out_of_range` if `n >= a.size()`.
393
 
394
  ### Node handles <a id="container.node">[[container.node]]</a>
395
 
396
+ #### Overview <a id="container.node.overview">[[container.node.overview]]</a>
397
 
398
  A *node handle* is an object that accepts ownership of a single element
399
+ from an associative container [[associative.reqmts]] or an unordered
400
+ associative container [[unord.req]]. It may be used to transfer that
401
  ownership to another container with compatible nodes. Containers with
402
  compatible nodes have the same node handle type. Elements may be
403
  transferred in either direction between container types in the same row
404
+ of [[container.node.compat]].
405
 
406
+ **Table: Container types with compatible nodes** <a id="container.node.compat">[container.node.compat]</a>
407
 
408
  | | |
409
  | -------------------------------- | ------------------------------------- |
410
  | `map<K, T, C1, A>` | `map<K, T, C2, A>` |
411
  | `map<K, T, C1, A>` | `multimap<K, T, C2, A>` |
 
419
 
420
  If a node handle is not empty, then it contains an allocator that is
421
  equal to the allocator of the container when the element was extracted.
422
  If a node handle is empty, it contains no allocator.
423
 
424
+ Class *`node-handle`* is for exposition only.
 
 
425
 
426
  If a user-defined specialization of `pair` exists for
427
  `pair<const Key, T>` or `pair<Key, T>`, where `Key` is the container’s
428
  `key_type` and `T` is the container’s `mapped_type`, the behavior of
429
  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 Tables [tab:container.assoc.req] and [tab:container.hash.req].
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 rebind_traits<container_node_type>::pointer ptr_;
446
  optional<allocator_type> alloc_;
447
 
448
  public:
449
+ // [container.node.cons], constructors, copy, and assignment
450
+ constexpr node-handle() noexcept : ptr_(), alloc_() {}
451
+ node-handle(node-handle&&) noexcept;
452
+ node-handle& operator=(node-handle&&);
453
 
454
+ // [container.node.dtor], destructor
455
+ ~node-handle();
456
+
457
+ // [container.node.observers], observers
458
  value_type& value() const; // not present for map containers
459
  key_type& key() const; // not present for set containers
460
  mapped_type& mapped() const; // not present for set containers
461
 
462
  allocator_type get_allocator() const;
463
  explicit operator bool() const noexcept;
464
+ [[nodiscard]] bool empty() const noexcept;
465
 
466
+ // [container.node.modifiers], modifiers
467
+ void swap(node-handle&)
468
  noexcept(ator_traits::propagate_on_container_swap::value ||
469
  ator_traits::is_always_equal::value);
470
 
471
+ friend void swap(node-handle& x, node-handle& y) noexcept(noexcept(x.swap(y))) {
472
  x.swap(y);
473
  }
474
  };
475
  ```
476
 
477
+ #### Constructors, copy, and assignment <a id="container.node.cons">[[container.node.cons]]</a>
478
 
479
  ``` cpp
480
+ node-handle(node-handle&& nh) noexcept;
481
  ```
482
 
483
+ *Effects:* Constructs a *node-handle* object initializing `ptr_` with
484
  `nh.ptr_`. Move constructs `alloc_` with `nh.alloc_`. Assigns `nullptr`
485
  to `nh.ptr_` and assigns `nullopt` to `nh.alloc_`.
486
 
487
  ``` cpp
488
+ node-handle& operator=(node-handle&& nh);
489
  ```
490
 
491
+ *Preconditions:* Either `!alloc_`, or
492
+ `ator_traits::propagate_on_container_move_assignment::value` is `true`,
493
+ or `alloc_ == nh.alloc_`.
494
 
495
  *Effects:*
496
 
497
  - If `ptr_ != nullptr`, destroys the `value_type` subobject in the
498
  `container_node_type` object pointed to by `ptr_` by calling
499
  `ator_traits::destroy`, then deallocates `ptr_` by calling
500
+ `ator_traits::template rebind_traits<container_node_type>::deallocate`.
501
  - Assigns `nh.ptr_` to `ptr_`.
502
+ - If `!alloc` or
503
+ `ator_traits::propagate_on_container_move_assignment::value` is
504
+ `true`, move assigns `nh.alloc_` to `alloc_`.
505
  - Assigns `nullptr` to `nh.ptr_` and assigns `nullopt` to `nh.alloc_`.
506
 
507
  *Returns:* `*this`.
508
 
509
  *Throws:* Nothing.
510
 
511
+ #### Destructor <a id="container.node.dtor">[[container.node.dtor]]</a>
512
 
513
  ``` cpp
514
+ ~node-handle();
515
  ```
516
 
517
  *Effects:* If `ptr_ != nullptr`, destroys the `value_type` subobject in
518
  the `container_node_type` object pointed to by `ptr_` by calling
519
  `ator_traits::destroy`, then deallocates `ptr_` by calling
520
+ `ator_traits::template rebind_traits<container_node_type>::deallocate`.
521
 
522
+ #### Observers <a id="container.node.observers">[[container.node.observers]]</a>
523
 
524
  ``` cpp
525
  value_type& value() const;
526
  ```
527
 
528
+ *Preconditions:* `empty() == false`.
529
 
530
  *Returns:* A reference to the `value_type` subobject in the
531
  `container_node_type` object pointed to by `ptr_`.
532
 
533
  *Throws:* Nothing.
534
 
535
  ``` cpp
536
  key_type& key() const;
537
  ```
538
 
539
+ *Preconditions:* `empty() == false`.
540
 
541
  *Returns:* A non-const reference to the `key_type` member of the
542
  `value_type` subobject in the `container_node_type` object pointed to by
543
  `ptr_`.
544
 
 
549
 
550
  ``` cpp
551
  mapped_type& mapped() const;
552
  ```
553
 
554
+ *Preconditions:* `empty() == false`.
555
 
556
  *Returns:* A reference to the `mapped_type` member of the `value_type`
557
  subobject in the `container_node_type` object pointed to by `ptr_`.
558
 
559
  *Throws:* Nothing.
560
 
561
  ``` cpp
562
  allocator_type get_allocator() const;
563
  ```
564
 
565
+ *Preconditions:* `empty() == false`.
566
 
567
  *Returns:* `*alloc_`.
568
 
569
  *Throws:* Nothing.
570
 
 
573
  ```
574
 
575
  *Returns:* `ptr_ != nullptr`.
576
 
577
  ``` cpp
578
+ [[nodiscard]] bool empty() const noexcept;
579
  ```
580
 
581
  *Returns:* `ptr_ == nullptr`.
582
 
583
+ #### Modifiers <a id="container.node.modifiers">[[container.node.modifiers]]</a>
584
 
585
  ``` cpp
586
+ void swap(node-handle& nh)
587
  noexcept(ator_traits::propagate_on_container_swap::value ||
588
  ator_traits::is_always_equal::value);
589
  ```
590
 
591
+ *Preconditions:* `!alloc_`, or `!nh.alloc_`, or
592
+ `ator_traits::propagate_on_container_swap::value` is `true`, or
593
  `alloc_ == nh.alloc_`.
594
 
595
  *Effects:* Calls `swap(ptr_, nh.ptr_)`. If `!alloc_`, or `!nh.alloc_`,
596
+ or `ator_traits::propagate_on_container_swap::value` is `true` calls
597
  `swap(alloc_, nh.alloc_)`.
598
 
599
  ### Insert return type <a id="container.insert.return">[[container.insert.return]]</a>
600
 
601
  The associative containers with unique keys and the unordered containers
602
  with unique keys have a member function `insert` that returns a nested
603
  type `insert_return_type`. That return type is a specialization of the
604
+ template specified in this subclause.
605
 
606
  ``` cpp
607
  template<class Iterator, class NodeType>
608
+ struct insert-return-type
609
  {
610
  Iterator position;
611
  bool inserted;
612
  NodeType node;
613
  };
614
  ```
615
 
616
+ The name *`insert-return-type`* is exposition only.
617
+ *`insert-return-type`* has the template parameters, data members, and
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`
631
+ is called the *comparison object* of a container.
632
 
633
  The phrase “equivalence of keys” means the equivalence relation imposed
634
+ by the comparison object. That is, two keys `k1` and `k2` are considered
635
+ to be equivalent if for the comparison object `comp`,
636
+ `comp(k1, k2) == false && comp(k2, k1) == false`.
637
+
638
+ [*Note 1*: This is not necessarily the same as the result of
639
+ `k1 == k2`. — *end note*]
640
+
641
+ For any two keys `k1` and `k2` in the same container, calling
642
+ `comp(k1, k2)` shall always return the same value.
643
 
644
  An associative container supports *unique keys* if it may contain at
645
  most one element for each key. Otherwise, it supports *equivalent keys*.
646
  The `set` and `map` classes support unique keys; the `multiset` and
647
  `multimap` classes support equivalent keys. For `multiset` and
 
657
  For associative containers where the value type is the same as the key
658
  type, both `iterator` and `const_iterator` are constant iterators. It is
659
  unspecified whether or not `iterator` and `const_iterator` are the same
660
  type.
661
 
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
  The associative containers meet all the requirements of Allocator-aware
668
+ containers [[container.requirements.general]], except that for `map` and
669
+ `multimap`, the requirements placed on `value_type` in
670
+ [[container.alloc.req]] apply instead to `key_type` and `mapped_type`.
 
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
+ In [[container.assoc.req]], `X` denotes an associative container class,
678
+ `a` denotes a value of type `X`, `a2` denotes a value of a type with
679
+ nodes compatible with type `X` ([[container.node.compat]]), `b` denotes
680
+ a possibly `const` value of type `X`, `u` denotes the name of a variable
681
+ being declared, `a_uniq` denotes a value of type `X` when `X` supports
682
+ unique keys, `a_eq` denotes a value of type `X` when `X` supports
683
+ multiple keys, `a_tran` denotes a possibly `const` value of type `X`
684
+ when the *qualified-id* `X::key_compare::is_transparent` is valid and
685
+ denotes a type [[temp.deduct]], `i` and `j` meet the
686
+ *Cpp17InputIterator* requirements and refer to elements implicitly
687
+ convertible to `value_type`, \[`i`, `j`) denotes a valid range, `p`
688
+ denotes a valid constant iterator to `a`, `q` denotes a valid
689
+ dereferenceable constant iterator to `a`, `r` denotes a valid
690
+ dereferenceable iterator to `a`, `[q1, q2)` denotes a valid range of
691
+ constant iterators in `a`, `il` designates an object of type
692
  `initializer_list<value_type>`, `t` denotes a value of type
693
  `X::value_type`, `k` denotes a value of type `X::key_type` and `c`
694
  denotes a possibly `const` value of type `X::key_compare`; `kl` is a
695
+ value such that `a` is partitioned [[alg.sorting]] with respect to
696
  `c(r, kl)`, with `r` the key value of `e` and `e` in `a`; `ku` is a
697
  value such that `a` is partitioned with respect to `!c(ku, r)`; `ke` is
698
  a value such that `a` is partitioned with respect to `c(r, ke)` and
699
  `!c(ke, r)`, with `c(r, ke)` implying `!c(ke, r)`. `A` denotes the
700
  storage allocator used by `X`, if any, or `allocator<X::value_type>`
 
731
  ```
732
 
733
  When an associative container is constructed by passing a comparison
734
  object the container shall not store a pointer or reference to the
735
  passed object, even if that object is passed by reference. When an
736
+ 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`, and `equal_range` shall not participate in
743
+ overload resolution unless the *qualified-id* `Compare::is_transparent`
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
 
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`.
777
 
778
  Unordered associative containers conform to the requirements for
779
+ Containers [[container.requirements]], except that the expressions
780
  `a == b` and `a != b` have different semantics than for the other
781
  container types.
782
 
783
  Each unordered associative container is parameterized by `Key`, by a
784
+ function object type `Hash` that meets the *Cpp17Hash* requirements
785
+ [[hash.requirements]] and acts as a hash function for argument values of
786
+ type `Key`, and by a binary predicate `Pred` that induces an equivalence
787
+ relation on values of type `Key`. Additionally, `unordered_map` and
788
+ `unordered_multimap` associate an arbitrary *mapped type* `T` with the
789
+ `Key`.
790
 
791
  The container’s object of type `Hash` — denoted by `hash` — is called
792
  the *hash function* of the container. The container’s object of type
793
  `Pred` — denoted by `pred` — is called the *key equality predicate* of
794
  the container.
795
 
796
+ Two values `k1` and `k2` are considered equivalent if the container’s
797
+ key equality predicate `pred(k1, k2)` is valid and returns `true` when
798
+ passed those values. If `k1` and `k2` are equivalent, the container’s
799
+ hash function shall return the same value for both.
800
 
801
  [*Note 1*: Thus, when an unordered associative container is
802
  instantiated with a non-default `Pred` parameter it usually needs a
803
  non-default `Hash` parameter as well. — *end note*]
804
 
 
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
  The unordered associative containers meet all the requirements of
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 possibly const value of type `X`,
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 possibly const value of type `X` when the
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 possibly const value of type `hasher`,
881
+ - `eq` denotes a possibly const value of type `key_equal`,
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
+ - `(eq(r1, ke) && eq(r1, r2)) == eq(r2, ke)`
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 a non-const rvalue of type `X::node_type`.
891
 
892
  Two unordered containers `a` and `b` compare equal if
893
  `a.size() == b.size()` and, for every equivalent-key group \[`Ea1`,
894
  `Ea2`) obtained from `a.equal_range(Ea1)`, there exists an
895
  equivalent-key group \[`Eb1`, `Eb2`) obtained from `b.equal_range(Ea1)`,
896
  such that `is_permutation(Ea1, Ea2, Eb1, Eb2)` returns `true`. For
897
  `unordered_set` and `unordered_map`, the complexity of `operator==`
898
  (i.e., the number of calls to the `==` operator of the `value_type`, to
899
  the predicate returned by `key_eq()`, and to the hasher returned by
900
  `hash_function()`) is proportional to N in the average case and to N² in
901
+ the worst case, where N is `a.size()`. For `unordered_multiset` and
902
  `unordered_multimap`, the complexity of `operator==` is proportional to
903
  $\sum E_i^2$ in the average case and to N² in the worst case, where N is
904
  `a.size()`, and Eᵢ is the size of the iᵗʰ equivalent-key group in `a`.
905
  However, if the respective elements of each corresponding pair of
906
  equivalent-key groups Eaᵢ and Ebᵢ are arranged in the same order (as is
907
  commonly the case, e.g., if `a` and `b` are unmodified copies of the
908
  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] of the
915
+ partition into equivalent-key groups produced by `Pred`.
 
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.
 
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`, and
943
+ `contains` shall not participate in overload resolution unless the
944
+ *qualified-id*s `Pred::is_transparent` and `Hash::is_transparent` are
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
951
  qualify as an input iterator is deduced for that parameter.