[unord.map.modifiers]

# 23 Containers library [[containers]](./#containers)

## 23.5 Unordered associative containers [[unord]](unord#map.modifiers)

### 23.5.3 Class template unordered_map [[unord.map]](unord.map#modifiers)

#### 23.5.3.4 Modifiers [unord.map.modifiers]

[ð](#lib:unordered_map,insert)

`template<class P>
  constexpr pair<iterator, bool> insert(P&& obj);
`

[1](#1)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/containers.tex#L13891)

*Constraints*: is_constructible_v<value_type, P&&> is true[.](#1.sentence-1)

[2](#2)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/containers.tex#L13895)

*Effects*: Equivalent to: return emplace(std​::​forward<P>(obj));

[ð](#lib:unordered_map,insert_)

`template<class P>
  constexpr iterator insert(const_iterator hint, P&& obj);
`

[3](#3)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/containers.tex#L13907)

*Constraints*: is_constructible_v<value_type, P&&> is true[.](#3.sentence-1)

[4](#4)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/containers.tex#L13911)

*Effects*: Equivalent to:return emplace_hint(hint, std​::​forward<P>(obj));

[ð](#lib:try_emplace,unordered_map)

`template<class... Args>
  constexpr pair<iterator, bool> try_emplace(const key_type& k, Args&&... args);
template<class... Args>
  constexpr iterator try_emplace(const_iterator hint, const key_type& k, Args&&... args);
`

[5](#5)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/containers.tex#L13926)

*Preconditions*: value_type is *Cpp17EmplaceConstructible* into unordered_map from piecewise_construct, forward_as_tuple(k),forward_as_tuple(std​::​forward<Args>(args)...)[.](#5.sentence-1)

[6](#6)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/containers.tex#L13932)

*Effects*: If the map already contains an element
whose key is equivalent to k,
there is no effect[.](#6.sentence-1)

Otherwise inserts an object of type value_type constructed with piecewise_construct, forward_as_tuple(k),forward_as_tuple(std​::​forward<Args>(args)...)[.](#6.sentence-2)

[7](#7)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/containers.tex#L13941)

*Returns*: In the first overload,
the bool component of the returned pair is true if and only if the insertion took place[.](#7.sentence-1)

The returned iterator points to the map element
whose key is equivalent to k[.](#7.sentence-2)

[8](#8)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/containers.tex#L13949)

*Complexity*: The same as emplace and emplace_hint,
respectively[.](#8.sentence-1)

[ð](#lib:try_emplace,unordered_map_)

`template<class... Args>
  constexpr pair<iterator, bool> try_emplace(key_type&& k, Args&&... args);
template<class... Args>
  constexpr iterator try_emplace(const_iterator hint, key_type&& k, Args&&... args);
`

[9](#9)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/containers.tex#L13964)

*Preconditions*: value_type is *Cpp17EmplaceConstructible* into unordered_map from piecewise_construct, forward_as_tuple(std​::​move(k)),forward_as_tuple(std​::​forward<Args>(args)...)[.](#9.sentence-1)

[10](#10)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/containers.tex#L13970)

*Effects*: If the map already contains an element
whose key is equivalent to k,
there is no effect[.](#10.sentence-1)

Otherwise inserts an object of type value_type constructed with piecewise_construct, forward_as_tuple(std​::​move(k)),forward_as_tuple(std​::​forward<Args>(args)...)[.](#10.sentence-2)

[11](#11)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/containers.tex#L13979)

*Returns*: In the first overload,
the bool component of the returned pair is true if and only if the insertion took place[.](#11.sentence-1)

The returned iterator points to the map element
whose key is equivalent to k[.](#11.sentence-2)

[12](#12)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/containers.tex#L13987)

*Complexity*: The same as emplace and emplace_hint,
respectively[.](#12.sentence-1)

[ð](#lib:try_emplace,unordered_map__)

`template<class K, class... Args>
  constexpr pair<iterator, bool> try_emplace(K&& k, Args&&... args);
template<class K, class... Args>
  constexpr iterator try_emplace(const_iterator hint, K&& k, Args&&... args);
`

[13](#13)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/containers.tex#L14002)

*Constraints*: The [*qualified-id*](expr.prim.id.qual#nt:qualified-id "7.5.5.3 Qualified names [expr.prim.id.qual]")*s* Hash​::​is_transparent andPred​::​is_transparent are valid and denote types[.](#13.sentence-1)

For the first overload,is_convertible_v<K&&, const_iterator> andis_convertible_v<K&&, iterator> are both false[.](#13.sentence-2)

[14](#14)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/containers.tex#L14010)

*Preconditions*: value_type is *Cpp17EmplaceConstructible* into unordered_map frompiecewise_construct, forward_as_tuple(std​::​forward<K>(k)),
forward_as_tuple(std​::​forward<Args>  
(args)...)[.](#14.sentence-1)

[15](#15)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/containers.tex#L14017)

*Effects*: If the map already contains an element whose key is equivalent to k,
there is no effect[.](#15.sentence-1)

Otherwise, let h be hash_function()(k)[.](#15.sentence-2)

Constructs an object u of type value_type with piecewise_construct, forward_as_tuple(std​::​forward<K>(k)),
forward_as_tuple(std​::​forward<Args>(args)...)[.](#15.sentence-3)

  
If hash_function()(u.first) != h || contains(u.first) is true,
the behavior is undefined[.](#15.sentence-4)

Inserts u into *this[.](#15.sentence-5)

[16](#16)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/containers.tex#L14029)

*Returns*: For the first overload,
the bool component of the returned pair is true if and only if the insertion took place[.](#16.sentence-1)

The returned iterator points to the map element
whose key is equivalent to k[.](#16.sentence-2)

[17](#17)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/containers.tex#L14037)

*Complexity*: The same as emplace and emplace_hint, respectively[.](#17.sentence-1)

[ð](#lib:insert_or_assign,unordered_map)

`template<class M>
  constexpr pair<iterator, bool> insert_or_assign(const key_type& k, M&& obj);
template<class M>
  constexpr iterator insert_or_assign(const_iterator hint, const key_type& k, M&& obj);
`

[18](#18)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/containers.tex#L14051)

*Mandates*: is_assignable_v<mapped_type&, M&&> is true[.](#18.sentence-1)

[19](#19)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/containers.tex#L14055)

*Preconditions*: value_type is *Cpp17EmplaceConstructible* into unordered_map from k, std​::​forward<M>(obj)[.](#19.sentence-1)

[20](#20)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/containers.tex#L14060)

*Effects*: If the map already contains an element e whose key is equivalent to k,
assigns std​::​forward<M>(obj) to e.second[.](#20.sentence-1)

Otherwise inserts an object of type value_type constructed with k, std​::​forward<M>(obj)[.](#20.sentence-2)

[21](#21)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/containers.tex#L14068)

*Returns*: In the first overload,
the bool component of the returned pair is true if and only if the insertion took place[.](#21.sentence-1)

The returned iterator points to the map element
whose key is equivalent to k[.](#21.sentence-2)

[22](#22)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/containers.tex#L14076)

*Complexity*: The same as emplace and emplace_hint,
respectively[.](#22.sentence-1)

[ð](#lib:insert_or_assign,unordered_map_)

`template<class M>
  constexpr pair<iterator, bool> insert_or_assign(key_type&& k, M&& obj);
template<class M>
  constexpr iterator insert_or_assign(const_iterator hint, key_type&& k, M&& obj);
`

[23](#23)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/containers.tex#L14091)

*Mandates*: is_assignable_v<mapped_type&, M&&> is true[.](#23.sentence-1)

[24](#24)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/containers.tex#L14095)

*Preconditions*: value_type is *Cpp17EmplaceConstructible* into unordered_map from std​::​move(k), std​::​​forward<M>(obj)[.](#24.sentence-1)

[25](#25)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/containers.tex#L14100)

*Effects*: If the map already contains an element e whose key is equivalent to k,
assigns std​::​forward<M>(obj) to e.second[.](#25.sentence-1)

Otherwise inserts an object of type value_type constructed with std​::​​move(k), std​::​forward<M>(obj)[.](#25.sentence-2)

[26](#26)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/containers.tex#L14108)

*Returns*: In the first overload,
the bool component of the returned pair is true if and only if the insertion took place[.](#26.sentence-1)

The returned iterator points to the map element
whose key is equivalent to k[.](#26.sentence-2)

[27](#27)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/containers.tex#L14116)

*Complexity*: The same as emplace and emplace_hint,
respectively[.](#27.sentence-1)

[ð](#lib:insert_or_assign,unordered_map__)

`template<class K, class M>
  constexpr pair<iterator, bool> insert_or_assign(K&& k, M&& obj);
template<class K, class M>
  constexpr iterator insert_or_assign(const_iterator hint, K&& k, M&& obj);
`

[28](#28)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/containers.tex#L14131)

*Constraints*: The [*qualified-id*](expr.prim.id.qual#nt:qualified-id "7.5.5.3 Qualified names [expr.prim.id.qual]")*s* Hash​::​is_transparent andPred​::​is_transparent are valid and denote types[.](#28.sentence-1)

[29](#29)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/containers.tex#L14136)

*Mandates*: is_assignable_v<mapped_type&, M&&> is true[.](#29.sentence-1)

[30](#30)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/containers.tex#L14140)

*Preconditions*: value_type is *Cpp17EmplaceConstructible* into unordered_map from std​::​forward<K>  
(k), std​::​forward<M>(obj)[.](#30.sentence-1)

[31](#31)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/containers.tex#L14146)

*Effects*: If the map already contains an element e whose key is equivalent to k,
assigns std​::​forward<M>  
(obj) to e.second[.](#31.sentence-1)

Otherwise, let h be hash_function()(k)[.](#31.sentence-2)

Constructs an object u of type value_type with std​::​forward<K>(k), std​::​forward<M>(obj)[.](#31.sentence-3)

If hash_function()(u.first) != h || contains(u.first) is true,
the behavior is undefined[.](#31.sentence-4)

Inserts u into *this[.](#31.sentence-5)

[32](#32)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/containers.tex#L14158)

*Returns*: For the first overload,
the bool component of the returned pair is true if and only if the insertion took place[.](#32.sentence-1)

The returned iterator points to the map element
whose key is equivalent to k[.](#32.sentence-2)

[33](#33)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/containers.tex#L14166)

*Complexity*: The same as emplace and emplace_hint, respectively[.](#33.sentence-1)
