Files
cppdraft_translate/cppdraft/map/modifiers.md
2025-10-25 03:02:53 +03:00

323 lines
12 KiB
Markdown
Raw Permalink Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

[map.modifiers]
# 23 Containers library [[containers]](./#containers)
## 23.4 Associative containers [[associative]](associative#map.modifiers)
### 23.4.3 Class template map [[map]](map#modifiers)
#### 23.4.3.4 Modifiers [map.modifiers]
[🔗](#lib:insert,map)
`template<class P>
constexpr pair<iterator, bool> insert(P&& x);
template<class P>
constexpr iterator insert(const_iterator position, P&& x);
`
[1](#1)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/containers.tex#L11909)
*Constraints*: is_constructible_v<value_type, P&&> is true[.](#1.sentence-1)
[2](#2)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/containers.tex#L11913)
*Effects*: The first form is equivalent toreturn emplace(std::forward<P>(x))[.](#2.sentence-1)
The second form is
equivalent to return emplace_hint(position, std::forward<P>(x))[.](#2.sentence-2)
[🔗](#lib:try_emplace,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);
`
[3](#3)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/containers.tex#L11929)
*Preconditions*: value_type is *Cpp17EmplaceConstructible* into map from piecewise_construct, forward_as_tuple(k),forward_as_tuple(std::forward<Args>(args)...)[.](#3.sentence-1)
[4](#4)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/containers.tex#L11935)
*Effects*: If the map already contains an element
whose key is equivalent to k,
there is no effect[.](#4.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)...)[.](#4.sentence-2)
[5](#5)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/containers.tex#L11944)
*Returns*: In the first overload,
the bool component of the returned pair is true if and only if the insertion took place[.](#5.sentence-1)
The returned iterator points to the map element
whose key is equivalent to k[.](#5.sentence-2)
[6](#6)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/containers.tex#L11952)
*Complexity*: The same as emplace and emplace_hint,
respectively[.](#6.sentence-1)
[🔗](#lib:try_emplace,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);
`
[7](#7)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/containers.tex#L11967)
*Preconditions*: value_type is *Cpp17EmplaceConstructible* into map from piecewise_construct, forward_as_tuple(std::move(k)),forward_as_tuple(std::forward<Args>(args)...)[.](#7.sentence-1)
[8](#8)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/containers.tex#L11973)
*Effects*: If the map already contains an element
whose key is equivalent to k,
there is no effect[.](#8.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)...)[.](#8.sentence-2)
[9](#9)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/containers.tex#L11982)
*Returns*: In the first overload,
the bool component of the returned pair is true if and only if the insertion took place[.](#9.sentence-1)
The returned iterator points to the map element
whose key is equivalent to k[.](#9.sentence-2)
[10](#10)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/containers.tex#L11990)
*Complexity*: The same as emplace and emplace_hint,
respectively[.](#10.sentence-1)
[🔗](#lib:try_emplace,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);
`
[11](#11)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/containers.tex#L12005)
*Constraints*: The [*qualified-id*](expr.prim.id.qual#nt:qualified-id "7.5.5.3Qualified names[expr.prim.id.qual]") Compare::is_transparent is valid and denotes a type[.](#11.sentence-1)
For the first overload,is_convertible_v<K&&, const_iterator> andis_convertible_v<K&&, iterator> are both false[.](#11.sentence-2)
[12](#12)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/containers.tex#L12014)
*Preconditions*: value_type is *Cpp17EmplaceConstructible* into map frompiecewise_construct, forward_as_tuple(std::forward<K>(k)),
forward_as_tuple(std::forward<Args>(args)...)[.](#12.sentence-1)
[13](#13)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/containers.tex#L12020)
*Effects*: If the map already contains an element whose key is equivalent to k,
there is no effect[.](#13.sentence-1)
Otherwise, let r be equal_range(k)[.](#13.sentence-2)
Constructs an object u of type value_type withpiecewise_construct, forward_as_tuple(std::forward<K>(k)),
forward_as_tuple(std::forward<Args>(args)...)[.](#13.sentence-3)
If equal_range(u.first) == r is false,
the behavior is undefined[.](#13.sentence-4)
Inserts u into *this[.](#13.sentence-5)
[14](#14)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/containers.tex#L12032)
*Returns*: For the first overload,
the bool component of the returned pair is true if and only if the insertion took place[.](#14.sentence-1)
The returned iterator points to the map element
whose key is equivalent to k[.](#14.sentence-2)
[15](#15)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/containers.tex#L12040)
*Complexity*: The same as emplace and emplace_hint, respectively[.](#15.sentence-1)
[🔗](#lib:insert_or_assign,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);
`
[16](#16)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/containers.tex#L12054)
*Mandates*: is_assignable_v<mapped_type&, M&&> is true[.](#16.sentence-1)
[17](#17)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/containers.tex#L12058)
*Preconditions*: value_type is *Cpp17EmplaceConstructible* into map from k, std::forward<M>(obj)[.](#17.sentence-1)
[18](#18)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/containers.tex#L12063)
*Effects*: If the map already contains an element e whose key is equivalent to k,
assigns std::forward<M>(obj) to e.second[.](#18.sentence-1)
Otherwise inserts an object of type value_type constructed with k, std::forward<M>(obj)[.](#18.sentence-2)
[19](#19)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/containers.tex#L12071)
*Returns*: In the first overload,
the bool component of the returned pair is true if and only if the insertion took place[.](#19.sentence-1)
The returned iterator points to the map element
whose key is equivalent to k[.](#19.sentence-2)
[20](#20)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/containers.tex#L12079)
*Complexity*: The same as emplace and emplace_hint,
respectively[.](#20.sentence-1)
[🔗](#lib:insert_or_assign,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);
`
[21](#21)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/containers.tex#L12094)
*Mandates*: is_assignable_v<mapped_type&, M&&> is true[.](#21.sentence-1)
[22](#22)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/containers.tex#L12098)
*Preconditions*: value_type is *Cpp17EmplaceConstructible* into map from std::move(k), std::forward<M>(obj)[.](#22.sentence-1)
[23](#23)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/containers.tex#L12103)
*Effects*: If the map already contains an element e whose key is equivalent to k,
assigns std::forward<M>(obj) to e.second[.](#23.sentence-1)
Otherwise inserts an object of type value_type constructed with std::move(k), std::forward<M>(obj)[.](#23.sentence-2)
[24](#24)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/containers.tex#L12111)
*Returns*: In the first overload,
the bool component of the returned pair is true if and only if the insertion took place[.](#24.sentence-1)
The returned iterator points to the map element
whose key is equivalent to k[.](#24.sentence-2)
[25](#25)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/containers.tex#L12119)
*Complexity*: The same as emplace and emplace_hint,
respectively[.](#25.sentence-1)
[🔗](#lib:insert_or_assign,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);
`
[26](#26)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/containers.tex#L12134)
*Constraints*: The [*qualified-id*](expr.prim.id.qual#nt:qualified-id "7.5.5.3Qualified names[expr.prim.id.qual]") Compare::is_transparent is valid and denotes a type[.](#26.sentence-1)
[27](#27)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/containers.tex#L12139)
*Mandates*: is_assignable_v<mapped_type&, M&&> is true[.](#27.sentence-1)
[28](#28)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/containers.tex#L12143)
*Preconditions*: value_type is *Cpp17EmplaceConstructible* into map fromstd::forward<K>(k), std::
forward<M>(obj)[.](#28.sentence-1)
[29](#29)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/containers.tex#L12148)
*Effects*: If the map already contains an element e whose key is equivalent to k,
assigns std::forward<M>
(obj) to e.second[.](#29.sentence-1)
Otherwise, let r be equal_range(k)[.](#29.sentence-2)
Constructs an object u of type value_type with std::forward<K>(k), std::forward<M>(obj)[.](#29.sentence-3)
If equal_range(u.first) == r is false,
the behavior is undefined[.](#29.sentence-4)
Inserts u into *this[.](#29.sentence-5)
[30](#30)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/containers.tex#L12160)
*Returns*: For the first overload,
the bool component of the returned pair is true if and only if the insertion took place[.](#30.sentence-1)
The returned iterator points to the map element
whose key is equivalent to k[.](#30.sentence-2)
[31](#31)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/containers.tex#L12168)
*Complexity*: The same as emplace and emplace_hint, respectively[.](#31.sentence-1)