tmp/tmpyd056q7t/{from.md → to.md}
RENAMED
|
@@ -1,37 +1,37 @@
|
|
| 1 |
### Class template `unordered_map` <a id="unord.map">[[unord.map]]</a>
|
| 2 |
|
| 3 |
-
####
|
| 4 |
|
| 5 |
An `unordered_map` is an unordered associative container that supports
|
| 6 |
unique keys (an `unordered_map` contains at most one of each key value)
|
| 7 |
and that associates values of another type `mapped_type` with the keys.
|
| 8 |
The `unordered_map` class supports forward iterators.
|
| 9 |
|
| 10 |
-
An `unordered_map`
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
|
| 16 |
`Key`, the mapped type is `T`, and the value type is
|
| 17 |
`pair<const Key, T>`.
|
| 18 |
|
| 19 |
-
|
| 20 |
-
described in one of the requirement tables, or for which
|
| 21 |
-
additional semantic information.
|
| 22 |
|
| 23 |
``` cpp
|
| 24 |
namespace std {
|
| 25 |
template<class Key,
|
| 26 |
class T,
|
| 27 |
class Hash = hash<Key>,
|
| 28 |
class Pred = equal_to<Key>,
|
| 29 |
class Allocator = allocator<pair<const Key, T>>>
|
| 30 |
class unordered_map {
|
| 31 |
public:
|
| 32 |
-
// types
|
| 33 |
using key_type = Key;
|
| 34 |
using mapped_type = T;
|
| 35 |
using value_type = pair<const Key, T>;
|
| 36 |
using hasher = Hash;
|
| 37 |
using key_equal = Pred;
|
|
@@ -46,11 +46,11 @@ namespace std {
|
|
| 46 |
using iterator = implementation-defined // type of unordered_map::iterator; // see [container.requirements]
|
| 47 |
using const_iterator = implementation-defined // type of unordered_map::const_iterator; // see [container.requirements]
|
| 48 |
using local_iterator = implementation-defined // type of unordered_map::local_iterator; // see [container.requirements]
|
| 49 |
using const_local_iterator = implementation-defined // type of unordered_map::const_local_iterator; // see [container.requirements]
|
| 50 |
using node_type = unspecified;
|
| 51 |
-
using insert_return_type =
|
| 52 |
|
| 53 |
// [unord.map.cnstr], construct/copy/destroy
|
| 54 |
unordered_map();
|
| 55 |
explicit unordered_map(size_type n,
|
| 56 |
const hasher& hf = hasher(),
|
|
@@ -95,20 +95,20 @@ namespace std {
|
|
| 95 |
is_nothrow_move_assignable_v<Hash> &&
|
| 96 |
is_nothrow_move_assignable_v<Pred>);
|
| 97 |
unordered_map& operator=(initializer_list<value_type>);
|
| 98 |
allocator_type get_allocator() const noexcept;
|
| 99 |
|
| 100 |
-
// iterators
|
| 101 |
iterator begin() noexcept;
|
| 102 |
const_iterator begin() const noexcept;
|
| 103 |
iterator end() noexcept;
|
| 104 |
const_iterator end() const noexcept;
|
| 105 |
const_iterator cbegin() const noexcept;
|
| 106 |
const_iterator cend() const noexcept;
|
| 107 |
|
| 108 |
-
// capacity
|
| 109 |
-
bool
|
| 110 |
size_type size() const noexcept;
|
| 111 |
size_type max_size() const noexcept;
|
| 112 |
|
| 113 |
// [unord.map.modifiers], modifiers
|
| 114 |
template<class... Args> pair<iterator, bool> emplace(Args&&... args);
|
|
@@ -161,28 +161,42 @@ namespace std {
|
|
| 161 |
template<class H2, class P2>
|
| 162 |
void merge(unordered_multimap<Key, T, H2, P2, Allocator>& source);
|
| 163 |
template<class H2, class P2>
|
| 164 |
void merge(unordered_multimap<Key, T, H2, P2, Allocator>&& source);
|
| 165 |
|
| 166 |
-
// observers
|
| 167 |
hasher hash_function() const;
|
| 168 |
key_equal key_eq() const;
|
| 169 |
|
| 170 |
-
// map operations
|
| 171 |
iterator find(const key_type& k);
|
| 172 |
const_iterator find(const key_type& k) const;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 173 |
size_type count(const key_type& k) const;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 174 |
pair<iterator, iterator> equal_range(const key_type& k);
|
| 175 |
pair<const_iterator, const_iterator> equal_range(const key_type& k) const;
|
|
|
|
|
|
|
|
|
|
|
|
|
| 176 |
|
| 177 |
// [unord.map.elem], element access
|
| 178 |
mapped_type& operator[](const key_type& k);
|
| 179 |
mapped_type& operator[](key_type&& k);
|
| 180 |
mapped_type& at(const key_type& k);
|
| 181 |
const mapped_type& at(const key_type& k) const;
|
| 182 |
|
| 183 |
-
// bucket interface
|
| 184 |
size_type bucket_count() const noexcept;
|
| 185 |
size_type max_bucket_count() const noexcept;
|
| 186 |
size_type bucket_size(size_type n) const;
|
| 187 |
size_type bucket(const key_type& k) const;
|
| 188 |
local_iterator begin(size_type n);
|
|
@@ -190,73 +204,66 @@ namespace std {
|
|
| 190 |
local_iterator end(size_type n);
|
| 191 |
const_local_iterator end(size_type n) const;
|
| 192 |
const_local_iterator cbegin(size_type n) const;
|
| 193 |
const_local_iterator cend(size_type n) const;
|
| 194 |
|
| 195 |
-
// hash policy
|
| 196 |
float load_factor() const noexcept;
|
| 197 |
float max_load_factor() const noexcept;
|
| 198 |
void max_load_factor(float z);
|
| 199 |
void rehash(size_type n);
|
| 200 |
void reserve(size_type n);
|
| 201 |
};
|
| 202 |
|
| 203 |
template<class InputIterator,
|
| 204 |
-
class Hash = hash<
|
| 205 |
-
class Pred = equal_to<
|
| 206 |
-
class Allocator = allocator<
|
| 207 |
unordered_map(InputIterator, InputIterator, typename see below::size_type = see below,
|
| 208 |
Hash = Hash(), Pred = Pred(), Allocator = Allocator())
|
| 209 |
-
-> unordered_map<
|
| 210 |
Allocator>;
|
| 211 |
|
| 212 |
template<class Key, class T, class Hash = hash<Key>,
|
| 213 |
class Pred = equal_to<Key>, class Allocator = allocator<pair<const Key, T>>>
|
| 214 |
-
unordered_map(initializer_list<pair<
|
| 215 |
typename see below::size_type = see below, Hash = Hash(),
|
| 216 |
Pred = Pred(), Allocator = Allocator())
|
| 217 |
-> unordered_map<Key, T, Hash, Pred, Allocator>;
|
| 218 |
|
| 219 |
template<class InputIterator, class Allocator>
|
| 220 |
unordered_map(InputIterator, InputIterator, typename see below::size_type, Allocator)
|
| 221 |
-
-> unordered_map<
|
| 222 |
-
hash<
|
| 223 |
-
Allocator>;
|
| 224 |
|
| 225 |
template<class InputIterator, class Allocator>
|
| 226 |
unordered_map(InputIterator, InputIterator, Allocator)
|
| 227 |
-
-> unordered_map<
|
| 228 |
-
hash<
|
| 229 |
-
Allocator>;
|
| 230 |
|
| 231 |
template<class InputIterator, class Hash, class Allocator>
|
| 232 |
unordered_map(InputIterator, InputIterator, typename see below::size_type, Hash, Allocator)
|
| 233 |
-
-> unordered_map<
|
| 234 |
-
equal_to<
|
| 235 |
|
| 236 |
-
template<class Key, class T,
|
| 237 |
-
unordered_map(initializer_list<pair<
|
| 238 |
Allocator)
|
| 239 |
-> unordered_map<Key, T, hash<Key>, equal_to<Key>, Allocator>;
|
| 240 |
|
| 241 |
-
template<class Key, class T,
|
| 242 |
-
unordered_map(initializer_list<pair<
|
| 243 |
-> unordered_map<Key, T, hash<Key>, equal_to<Key>, Allocator>;
|
| 244 |
|
| 245 |
template<class Key, class T, class Hash, class Allocator>
|
| 246 |
-
unordered_map(initializer_list<pair<
|
| 247 |
Allocator)
|
| 248 |
-> unordered_map<Key, T, Hash, equal_to<Key>, Allocator>;
|
| 249 |
|
| 250 |
-
|
| 251 |
-
bool operator==(const unordered_map<Key, T, Hash, Pred, Alloc>& a,
|
| 252 |
-
const unordered_map<Key, T, Hash, Pred, Alloc>& b);
|
| 253 |
-
template <class Key, class T, class Hash, class Pred, class Alloc>
|
| 254 |
-
bool operator!=(const unordered_map<Key, T, Hash, Pred, Alloc>& a,
|
| 255 |
-
const unordered_map<Key, T, Hash, Pred, Alloc>& b);
|
| 256 |
-
|
| 257 |
-
// [unord.map.swap], swap
|
| 258 |
template<class Key, class T, class Hash, class Pred, class Alloc>
|
| 259 |
void swap(unordered_map<Key, T, Hash, Pred, Alloc>& x,
|
| 260 |
unordered_map<Key, T, Hash, Pred, Alloc>& y)
|
| 261 |
noexcept(noexcept(x.swap(y)));
|
| 262 |
}
|
|
@@ -264,11 +271,11 @@ namespace std {
|
|
| 264 |
|
| 265 |
A `size_type` parameter type in an `unordered_map` deduction guide
|
| 266 |
refers to the `size_type` member type of the type deduced by the
|
| 267 |
deduction guide.
|
| 268 |
|
| 269 |
-
####
|
| 270 |
|
| 271 |
``` cpp
|
| 272 |
unordered_map() : unordered_map(size_type(see below)) { }
|
| 273 |
explicit unordered_map(size_type n,
|
| 274 |
const hasher& hf = hasher(),
|
|
@@ -304,11 +311,11 @@ buckets. If `n` is not provided, the number of buckets is
|
|
| 304 |
`l`) for the first form, or from the range \[`il.begin()`, `il.end()`)
|
| 305 |
for the second form. `max_load_factor()` returns `1.0`.
|
| 306 |
|
| 307 |
*Complexity:* Average case linear, worst case quadratic.
|
| 308 |
|
| 309 |
-
####
|
| 310 |
|
| 311 |
``` cpp
|
| 312 |
mapped_type& operator[](const key_type& k);
|
| 313 |
```
|
| 314 |
|
|
@@ -329,41 +336,39 @@ const mapped_type& at(const key_type& k) const;
|
|
| 329 |
whose key is equivalent to `k`.
|
| 330 |
|
| 331 |
*Throws:* An exception object of type `out_of_range` if no such element
|
| 332 |
is present.
|
| 333 |
|
| 334 |
-
####
|
| 335 |
|
| 336 |
``` cpp
|
| 337 |
template<class P>
|
| 338 |
pair<iterator, bool> insert(P&& obj);
|
| 339 |
```
|
| 340 |
|
|
|
|
|
|
|
| 341 |
*Effects:* Equivalent to: `return emplace(std::forward<P>(obj));`
|
| 342 |
|
| 343 |
-
*Remarks:* This signature shall not participate in overload resolution
|
| 344 |
-
unless `is_constructible_v<value_type, P&&>` is `true`.
|
| 345 |
-
|
| 346 |
``` cpp
|
| 347 |
template<class P>
|
| 348 |
iterator insert(const_iterator hint, P&& obj);
|
| 349 |
```
|
| 350 |
|
|
|
|
|
|
|
| 351 |
*Effects:* Equivalent to:
|
| 352 |
`return emplace_hint(hint, std::forward<P>(obj));`
|
| 353 |
|
| 354 |
-
*Remarks:* This signature shall not participate in overload resolution
|
| 355 |
-
unless `is_constructible_v<value_type, P&&>` is `true`.
|
| 356 |
-
|
| 357 |
``` cpp
|
| 358 |
template<class... Args>
|
| 359 |
pair<iterator, bool> try_emplace(const key_type& k, Args&&... args);
|
| 360 |
template<class... Args>
|
| 361 |
iterator try_emplace(const_iterator hint, const key_type& k, Args&&... args);
|
| 362 |
```
|
| 363 |
|
| 364 |
-
*
|
| 365 |
`unordered_map` from `piecewise_construct`, `forward_as_tuple(k)`,
|
| 366 |
`forward_as_tuple(std::forward<Args>(args)...)`.
|
| 367 |
|
| 368 |
*Effects:* If the map already contains an element whose key is
|
| 369 |
equivalent to `k`, there is no effect. Otherwise inserts an object of
|
|
@@ -381,11 +386,11 @@ template <class... Args>
|
|
| 381 |
pair<iterator, bool> try_emplace(key_type&& k, Args&&... args);
|
| 382 |
template<class... Args>
|
| 383 |
iterator try_emplace(const_iterator hint, key_type&& k, Args&&... args);
|
| 384 |
```
|
| 385 |
|
| 386 |
-
*
|
| 387 |
`unordered_map` from `piecewise_construct`,
|
| 388 |
`forward_as_tuple(std::move(k))`,
|
| 389 |
`forward_as_tuple(std::forward<Args>(args)...)`.
|
| 390 |
|
| 391 |
*Effects:* If the map already contains an element whose key is
|
|
@@ -405,13 +410,14 @@ template <class M>
|
|
| 405 |
pair<iterator, bool> insert_or_assign(const key_type& k, M&& obj);
|
| 406 |
template<class M>
|
| 407 |
iterator insert_or_assign(const_iterator hint, const key_type& k, M&& obj);
|
| 408 |
```
|
| 409 |
|
| 410 |
-
*
|
| 411 |
-
|
| 412 |
-
|
|
|
|
| 413 |
|
| 414 |
*Effects:* If the map already contains an element `e` whose key is
|
| 415 |
equivalent to `k`, assigns `std::forward<M>(obj)` to `e.second`.
|
| 416 |
Otherwise inserts an object of type `value_type` constructed with `k`,
|
| 417 |
`std::forward<M>(obj)`.
|
|
@@ -427,13 +433,14 @@ template <class M>
|
|
| 427 |
pair<iterator, bool> insert_or_assign(key_type&& k, M&& obj);
|
| 428 |
template<class M>
|
| 429 |
iterator insert_or_assign(const_iterator hint, key_type&& k, M&& obj);
|
| 430 |
```
|
| 431 |
|
| 432 |
-
*
|
| 433 |
-
|
| 434 |
-
|
|
|
|
| 435 |
|
| 436 |
*Effects:* If the map already contains an element `e` whose key is
|
| 437 |
equivalent to `k`, assigns `std::forward<M>(obj)` to `e.second`.
|
| 438 |
Otherwise inserts an object of type `value_type` constructed with
|
| 439 |
`std::move(k)`, `std::forward<M>(obj)`.
|
|
@@ -442,16 +449,27 @@ Otherwise inserts an object of type `value_type` constructed with
|
|
| 442 |
pair is `true` if and only if the insertion took place. The returned
|
| 443 |
iterator points to the map element whose key is equivalent to `k`.
|
| 444 |
|
| 445 |
*Complexity:* The same as `emplace` and `emplace_hint`, respectively.
|
| 446 |
|
| 447 |
-
####
|
| 448 |
|
| 449 |
``` cpp
|
| 450 |
-
template
|
| 451 |
-
|
| 452 |
-
|
| 453 |
-
noexcept(noexcept(x.swap(y)));
|
| 454 |
```
|
| 455 |
|
| 456 |
-
*Effects:*
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 457 |
|
|
|
|
| 1 |
### Class template `unordered_map` <a id="unord.map">[[unord.map]]</a>
|
| 2 |
|
| 3 |
+
#### Overview <a id="unord.map.overview">[[unord.map.overview]]</a>
|
| 4 |
|
| 5 |
An `unordered_map` is an unordered associative container that supports
|
| 6 |
unique keys (an `unordered_map` contains at most one of each key value)
|
| 7 |
and that associates values of another type `mapped_type` with the keys.
|
| 8 |
The `unordered_map` class supports forward iterators.
|
| 9 |
|
| 10 |
+
An `unordered_map` meets all of the requirements of a container, of an
|
| 11 |
+
unordered associative container, and of an allocator-aware container (
|
| 12 |
+
[[container.alloc.req]]). It provides the operations described in the
|
| 13 |
+
preceding requirements table for unique keys; that is, an
|
| 14 |
+
`unordered_map` supports the `a_uniq` operations in that table, not the
|
| 15 |
+
`a_eq` operations. For an `unordered_map<Key, T>` the `key type` is
|
| 16 |
`Key`, the mapped type is `T`, and the value type is
|
| 17 |
`pair<const Key, T>`.
|
| 18 |
|
| 19 |
+
Subclause [[unord.map]] only describes operations on `unordered_map`
|
| 20 |
+
that are not described in one of the requirement tables, or for which
|
| 21 |
+
there is additional semantic information.
|
| 22 |
|
| 23 |
``` cpp
|
| 24 |
namespace std {
|
| 25 |
template<class Key,
|
| 26 |
class T,
|
| 27 |
class Hash = hash<Key>,
|
| 28 |
class Pred = equal_to<Key>,
|
| 29 |
class Allocator = allocator<pair<const Key, T>>>
|
| 30 |
class unordered_map {
|
| 31 |
public:
|
| 32 |
+
// types
|
| 33 |
using key_type = Key;
|
| 34 |
using mapped_type = T;
|
| 35 |
using value_type = pair<const Key, T>;
|
| 36 |
using hasher = Hash;
|
| 37 |
using key_equal = Pred;
|
|
|
|
| 46 |
using iterator = implementation-defined // type of unordered_map::iterator; // see [container.requirements]
|
| 47 |
using const_iterator = implementation-defined // type of unordered_map::const_iterator; // see [container.requirements]
|
| 48 |
using local_iterator = implementation-defined // type of unordered_map::local_iterator; // see [container.requirements]
|
| 49 |
using const_local_iterator = implementation-defined // type of unordered_map::const_local_iterator; // see [container.requirements]
|
| 50 |
using node_type = unspecified;
|
| 51 |
+
using insert_return_type = insert-return-type<iterator, node_type>;
|
| 52 |
|
| 53 |
// [unord.map.cnstr], construct/copy/destroy
|
| 54 |
unordered_map();
|
| 55 |
explicit unordered_map(size_type n,
|
| 56 |
const hasher& hf = hasher(),
|
|
|
|
| 95 |
is_nothrow_move_assignable_v<Hash> &&
|
| 96 |
is_nothrow_move_assignable_v<Pred>);
|
| 97 |
unordered_map& operator=(initializer_list<value_type>);
|
| 98 |
allocator_type get_allocator() const noexcept;
|
| 99 |
|
| 100 |
+
// iterators
|
| 101 |
iterator begin() noexcept;
|
| 102 |
const_iterator begin() const noexcept;
|
| 103 |
iterator end() noexcept;
|
| 104 |
const_iterator end() const noexcept;
|
| 105 |
const_iterator cbegin() const noexcept;
|
| 106 |
const_iterator cend() const noexcept;
|
| 107 |
|
| 108 |
+
// capacity
|
| 109 |
+
[[nodiscard]] bool empty() const noexcept;
|
| 110 |
size_type size() const noexcept;
|
| 111 |
size_type max_size() const noexcept;
|
| 112 |
|
| 113 |
// [unord.map.modifiers], modifiers
|
| 114 |
template<class... Args> pair<iterator, bool> emplace(Args&&... args);
|
|
|
|
| 161 |
template<class H2, class P2>
|
| 162 |
void merge(unordered_multimap<Key, T, H2, P2, Allocator>& source);
|
| 163 |
template<class H2, class P2>
|
| 164 |
void merge(unordered_multimap<Key, T, H2, P2, Allocator>&& source);
|
| 165 |
|
| 166 |
+
// observers
|
| 167 |
hasher hash_function() const;
|
| 168 |
key_equal key_eq() const;
|
| 169 |
|
| 170 |
+
// map operations
|
| 171 |
iterator find(const key_type& k);
|
| 172 |
const_iterator find(const key_type& k) const;
|
| 173 |
+
template<class K>
|
| 174 |
+
iterator find(const K& k);
|
| 175 |
+
template<class K>
|
| 176 |
+
const_iterator find(const K& k) const;
|
| 177 |
+
template<class K>
|
| 178 |
size_type count(const key_type& k) const;
|
| 179 |
+
template<class K>
|
| 180 |
+
size_type count(const K& k) const;
|
| 181 |
+
bool contains(const key_type& k) const;
|
| 182 |
+
template<class K>
|
| 183 |
+
bool contains(const K& k) const;
|
| 184 |
pair<iterator, iterator> equal_range(const key_type& k);
|
| 185 |
pair<const_iterator, const_iterator> equal_range(const key_type& k) const;
|
| 186 |
+
template<class K>
|
| 187 |
+
pair<iterator, iterator> equal_range(const K& k);
|
| 188 |
+
template<class K>
|
| 189 |
+
pair<const_iterator, const_iterator> equal_range(const K& k) const;
|
| 190 |
|
| 191 |
// [unord.map.elem], element access
|
| 192 |
mapped_type& operator[](const key_type& k);
|
| 193 |
mapped_type& operator[](key_type&& k);
|
| 194 |
mapped_type& at(const key_type& k);
|
| 195 |
const mapped_type& at(const key_type& k) const;
|
| 196 |
|
| 197 |
+
// bucket interface
|
| 198 |
size_type bucket_count() const noexcept;
|
| 199 |
size_type max_bucket_count() const noexcept;
|
| 200 |
size_type bucket_size(size_type n) const;
|
| 201 |
size_type bucket(const key_type& k) const;
|
| 202 |
local_iterator begin(size_type n);
|
|
|
|
| 204 |
local_iterator end(size_type n);
|
| 205 |
const_local_iterator end(size_type n) const;
|
| 206 |
const_local_iterator cbegin(size_type n) const;
|
| 207 |
const_local_iterator cend(size_type n) const;
|
| 208 |
|
| 209 |
+
// hash policy
|
| 210 |
float load_factor() const noexcept;
|
| 211 |
float max_load_factor() const noexcept;
|
| 212 |
void max_load_factor(float z);
|
| 213 |
void rehash(size_type n);
|
| 214 |
void reserve(size_type n);
|
| 215 |
};
|
| 216 |
|
| 217 |
template<class InputIterator,
|
| 218 |
+
class Hash = hash<iter-key-type<InputIterator>>,
|
| 219 |
+
class Pred = equal_to<iter-key-type<InputIterator>>,
|
| 220 |
+
class Allocator = allocator<iter-to-alloc-type<InputIterator>>>
|
| 221 |
unordered_map(InputIterator, InputIterator, typename see below::size_type = see below,
|
| 222 |
Hash = Hash(), Pred = Pred(), Allocator = Allocator())
|
| 223 |
+
-> unordered_map<iter-key-type<InputIterator>, iter-mapped-type<InputIterator>, Hash, Pred,
|
| 224 |
Allocator>;
|
| 225 |
|
| 226 |
template<class Key, class T, class Hash = hash<Key>,
|
| 227 |
class Pred = equal_to<Key>, class Allocator = allocator<pair<const Key, T>>>
|
| 228 |
+
unordered_map(initializer_list<pair<Key, T>>,
|
| 229 |
typename see below::size_type = see below, Hash = Hash(),
|
| 230 |
Pred = Pred(), Allocator = Allocator())
|
| 231 |
-> unordered_map<Key, T, Hash, Pred, Allocator>;
|
| 232 |
|
| 233 |
template<class InputIterator, class Allocator>
|
| 234 |
unordered_map(InputIterator, InputIterator, typename see below::size_type, Allocator)
|
| 235 |
+
-> unordered_map<iter-key-type<InputIterator>, iter-mapped-type<InputIterator>,
|
| 236 |
+
hash<iter-key-type<InputIterator>>,
|
| 237 |
+
equal_to<iter-key-type<InputIterator>>, Allocator>;
|
| 238 |
|
| 239 |
template<class InputIterator, class Allocator>
|
| 240 |
unordered_map(InputIterator, InputIterator, Allocator)
|
| 241 |
+
-> unordered_map<iter-key-type<InputIterator>, iter-mapped-type<InputIterator>,
|
| 242 |
+
hash<iter-key-type<InputIterator>>,
|
| 243 |
+
equal_to<iter-key-type<InputIterator>>, Allocator>;
|
| 244 |
|
| 245 |
template<class InputIterator, class Hash, class Allocator>
|
| 246 |
unordered_map(InputIterator, InputIterator, typename see below::size_type, Hash, Allocator)
|
| 247 |
+
-> unordered_map<iter-key-type<InputIterator>, iter-mapped-type<InputIterator>, Hash,
|
| 248 |
+
equal_to<iter-key-type<InputIterator>>, Allocator>;
|
| 249 |
|
| 250 |
+
template<class Key, class T, class Allocator>
|
| 251 |
+
unordered_map(initializer_list<pair<Key, T>>, typename see below::size_type,
|
| 252 |
Allocator)
|
| 253 |
-> unordered_map<Key, T, hash<Key>, equal_to<Key>, Allocator>;
|
| 254 |
|
| 255 |
+
template<class Key, class T, class Allocator>
|
| 256 |
+
unordered_map(initializer_list<pair<Key, T>>, Allocator)
|
| 257 |
-> unordered_map<Key, T, hash<Key>, equal_to<Key>, Allocator>;
|
| 258 |
|
| 259 |
template<class Key, class T, class Hash, class Allocator>
|
| 260 |
+
unordered_map(initializer_list<pair<Key, T>>, typename see below::size_type, Hash,
|
| 261 |
Allocator)
|
| 262 |
-> unordered_map<Key, T, Hash, equal_to<Key>, Allocator>;
|
| 263 |
|
| 264 |
+
// swap
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 265 |
template<class Key, class T, class Hash, class Pred, class Alloc>
|
| 266 |
void swap(unordered_map<Key, T, Hash, Pred, Alloc>& x,
|
| 267 |
unordered_map<Key, T, Hash, Pred, Alloc>& y)
|
| 268 |
noexcept(noexcept(x.swap(y)));
|
| 269 |
}
|
|
|
|
| 271 |
|
| 272 |
A `size_type` parameter type in an `unordered_map` deduction guide
|
| 273 |
refers to the `size_type` member type of the type deduced by the
|
| 274 |
deduction guide.
|
| 275 |
|
| 276 |
+
#### Constructors <a id="unord.map.cnstr">[[unord.map.cnstr]]</a>
|
| 277 |
|
| 278 |
``` cpp
|
| 279 |
unordered_map() : unordered_map(size_type(see below)) { }
|
| 280 |
explicit unordered_map(size_type n,
|
| 281 |
const hasher& hf = hasher(),
|
|
|
|
| 311 |
`l`) for the first form, or from the range \[`il.begin()`, `il.end()`)
|
| 312 |
for the second form. `max_load_factor()` returns `1.0`.
|
| 313 |
|
| 314 |
*Complexity:* Average case linear, worst case quadratic.
|
| 315 |
|
| 316 |
+
#### Element access <a id="unord.map.elem">[[unord.map.elem]]</a>
|
| 317 |
|
| 318 |
``` cpp
|
| 319 |
mapped_type& operator[](const key_type& k);
|
| 320 |
```
|
| 321 |
|
|
|
|
| 336 |
whose key is equivalent to `k`.
|
| 337 |
|
| 338 |
*Throws:* An exception object of type `out_of_range` if no such element
|
| 339 |
is present.
|
| 340 |
|
| 341 |
+
#### Modifiers <a id="unord.map.modifiers">[[unord.map.modifiers]]</a>
|
| 342 |
|
| 343 |
``` cpp
|
| 344 |
template<class P>
|
| 345 |
pair<iterator, bool> insert(P&& obj);
|
| 346 |
```
|
| 347 |
|
| 348 |
+
*Constraints:* `is_constructible_v<value_type, P&&>` is `true`.
|
| 349 |
+
|
| 350 |
*Effects:* Equivalent to: `return emplace(std::forward<P>(obj));`
|
| 351 |
|
|
|
|
|
|
|
|
|
|
| 352 |
``` cpp
|
| 353 |
template<class P>
|
| 354 |
iterator insert(const_iterator hint, P&& obj);
|
| 355 |
```
|
| 356 |
|
| 357 |
+
*Constraints:* `is_constructible_v<value_type, P&&>` is `true`.
|
| 358 |
+
|
| 359 |
*Effects:* Equivalent to:
|
| 360 |
`return emplace_hint(hint, std::forward<P>(obj));`
|
| 361 |
|
|
|
|
|
|
|
|
|
|
| 362 |
``` cpp
|
| 363 |
template<class... Args>
|
| 364 |
pair<iterator, bool> try_emplace(const key_type& k, Args&&... args);
|
| 365 |
template<class... Args>
|
| 366 |
iterator try_emplace(const_iterator hint, const key_type& k, Args&&... args);
|
| 367 |
```
|
| 368 |
|
| 369 |
+
*Preconditions:* `value_type` is *Cpp17EmplaceConstructible* into
|
| 370 |
`unordered_map` from `piecewise_construct`, `forward_as_tuple(k)`,
|
| 371 |
`forward_as_tuple(std::forward<Args>(args)...)`.
|
| 372 |
|
| 373 |
*Effects:* If the map already contains an element whose key is
|
| 374 |
equivalent to `k`, there is no effect. Otherwise inserts an object of
|
|
|
|
| 386 |
pair<iterator, bool> try_emplace(key_type&& k, Args&&... args);
|
| 387 |
template<class... Args>
|
| 388 |
iterator try_emplace(const_iterator hint, key_type&& k, Args&&... args);
|
| 389 |
```
|
| 390 |
|
| 391 |
+
*Preconditions:* `value_type` is *Cpp17EmplaceConstructible* into
|
| 392 |
`unordered_map` from `piecewise_construct`,
|
| 393 |
`forward_as_tuple(std::move(k))`,
|
| 394 |
`forward_as_tuple(std::forward<Args>(args)...)`.
|
| 395 |
|
| 396 |
*Effects:* If the map already contains an element whose key is
|
|
|
|
| 410 |
pair<iterator, bool> insert_or_assign(const key_type& k, M&& obj);
|
| 411 |
template<class M>
|
| 412 |
iterator insert_or_assign(const_iterator hint, const key_type& k, M&& obj);
|
| 413 |
```
|
| 414 |
|
| 415 |
+
*Mandates:* `is_assignable_v<mapped_type&, M&&>` is `true`.
|
| 416 |
+
|
| 417 |
+
*Preconditions:* `value_type` is *Cpp17EmplaceConstructible* into
|
| 418 |
+
`unordered_map` from `k`, `std::forward<M>(obj)`.
|
| 419 |
|
| 420 |
*Effects:* If the map already contains an element `e` whose key is
|
| 421 |
equivalent to `k`, assigns `std::forward<M>(obj)` to `e.second`.
|
| 422 |
Otherwise inserts an object of type `value_type` constructed with `k`,
|
| 423 |
`std::forward<M>(obj)`.
|
|
|
|
| 433 |
pair<iterator, bool> insert_or_assign(key_type&& k, M&& obj);
|
| 434 |
template<class M>
|
| 435 |
iterator insert_or_assign(const_iterator hint, key_type&& k, M&& obj);
|
| 436 |
```
|
| 437 |
|
| 438 |
+
*Mandates:* `is_assignable_v<mapped_type&, M&&>` is `true`.
|
| 439 |
+
|
| 440 |
+
*Preconditions:* `value_type` is *Cpp17EmplaceConstructible* into
|
| 441 |
+
`unordered_map` from `std::move(k)`, `std::forward<M>(obj)`.
|
| 442 |
|
| 443 |
*Effects:* If the map already contains an element `e` whose key is
|
| 444 |
equivalent to `k`, assigns `std::forward<M>(obj)` to `e.second`.
|
| 445 |
Otherwise inserts an object of type `value_type` constructed with
|
| 446 |
`std::move(k)`, `std::forward<M>(obj)`.
|
|
|
|
| 449 |
pair is `true` if and only if the insertion took place. The returned
|
| 450 |
iterator points to the map element whose key is equivalent to `k`.
|
| 451 |
|
| 452 |
*Complexity:* The same as `emplace` and `emplace_hint`, respectively.
|
| 453 |
|
| 454 |
+
#### Erasure <a id="unord.map.erasure">[[unord.map.erasure]]</a>
|
| 455 |
|
| 456 |
``` cpp
|
| 457 |
+
template<class K, class T, class H, class P, class A, class Predicate>
|
| 458 |
+
typename unordered_map<K, T, H, P, A>::size_type
|
| 459 |
+
erase_if(unordered_map<K, T, H, P, A>& c, Predicate pred);
|
|
|
|
| 460 |
```
|
| 461 |
|
| 462 |
+
*Effects:* Equivalent to:
|
| 463 |
+
|
| 464 |
+
``` cpp
|
| 465 |
+
auto original_size = c.size();
|
| 466 |
+
for (auto i = c.begin(), last = c.end(); i != last; ) {
|
| 467 |
+
if (pred(*i)) {
|
| 468 |
+
i = c.erase(i);
|
| 469 |
+
} else {
|
| 470 |
+
++i;
|
| 471 |
+
}
|
| 472 |
+
}
|
| 473 |
+
return original_size - c.size();
|
| 474 |
+
```
|
| 475 |
|