This commit is contained in:
2025-10-25 03:02:53 +03:00
commit 043225d523
3416 changed files with 681196 additions and 0 deletions

111
cppdraft/flat/map/access.md Normal file
View File

@@ -0,0 +1,111 @@
[flat.map.access]
# 23 Containers library [[containers]](./#containers)
## 23.6 Container adaptors [[container.adaptors]](container.adaptors#flat.map.access)
### 23.6.8 Class template flat_map [[flat.map]](flat.map#access)
#### 23.6.8.6 Access [flat.map.access]
[🔗](#lib:operator%5b%5d,flat_map)
`constexpr mapped_type& operator[](const key_type& x);
`
[1](#1)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/containers.tex#L17597)
*Effects*: Equivalent to: return try_emplace(x).first->second;
[🔗](#lib:operator%5b%5d,flat_map_)
`constexpr mapped_type& operator[](key_type&& x);
`
[2](#2)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/containers.tex#L17608)
*Effects*: Equivalent to: return try_emplace(std::move(x)).first->second;
[🔗](#lib:operator%5b%5d,flat_map__)
`template<class K> constexpr mapped_type& operator[](K&& x);
`
[3](#3)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/containers.tex#L17619)
*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[.](#3.sentence-1)
[4](#4)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/containers.tex#L17624)
*Effects*: Equivalent to: return try_emplace(std::forward<K>(x)).first->second;
[🔗](#lib:at,flat_map)
`constexpr mapped_type& at(const key_type& x);
constexpr const mapped_type& at(const key_type& x) const;
`
[5](#5)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/containers.tex#L17636)
*Returns*: A reference to the mapped_type corresponding
to x in *this[.](#5.sentence-1)
[6](#6)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/containers.tex#L17641)
*Throws*: An exception object of type out_of_range if
no such element is present[.](#6.sentence-1)
[7](#7)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/containers.tex#L17646)
*Complexity*: Logarithmic[.](#7.sentence-1)
[🔗](#lib:at,flat_map_)
`template<class K> constexpr mapped_type& at(const K& x);
template<class K> constexpr const mapped_type& at(const K& x) const;
`
[8](#8)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/containers.tex#L17658)
*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[.](#8.sentence-1)
[9](#9)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/containers.tex#L17663)
*Preconditions*: The expression find(x) is well-formed and has well-defined behavior[.](#9.sentence-1)
[10](#10)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/containers.tex#L17667)
*Returns*: A reference to the mapped_type corresponding tox in *this[.](#10.sentence-1)
[11](#11)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/containers.tex#L17672)
*Throws*: An exception object of type out_of_range if no such element is present[.](#11.sentence-1)
[12](#12)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/containers.tex#L17677)
*Complexity*: Logarithmic[.](#12.sentence-1)

View File

@@ -0,0 +1,31 @@
[flat.map.capacity]
# 23 Containers library [[containers]](./#containers)
## 23.6 Container adaptors [[container.adaptors]](container.adaptors#flat.map.capacity)
### 23.6.8 Class template flat_map [[flat.map]](flat.map#capacity)
#### 23.6.8.5 Capacity [flat.map.capacity]
[🔗](#lib:size,flat_map)
`constexpr size_type size() const noexcept;
`
[1](#1)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/containers.tex#L17573)
*Returns*: *c*.keys.size()[.](#1.sentence-1)
[🔗](#lib:max_size,flat_map)
`constexpr size_type max_size() const noexcept;
`
[2](#2)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/containers.tex#L17584)
*Returns*: min<size_type>(*c*.keys.max_size(), *c*.values.max_size())[.](#2.sentence-1)

49
cppdraft/flat/map/cons.md Normal file
View File

@@ -0,0 +1,49 @@
[flat.map.cons]
# 23 Containers library [[containers]](./#containers)
## 23.6 Container adaptors [[container.adaptors]](container.adaptors#flat.map.cons)
### 23.6.8 Class template flat_map [[flat.map]](flat.map#cons)
#### 23.6.8.3 Constructors [flat.map.cons]
[🔗](#lib:flat_map,constructor)
`constexpr flat_map(key_container_type key_cont, mapped_container_type mapped_cont,
const key_compare& comp = key_compare());
`
[1](#1)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/containers.tex#L17425)
*Effects*: Initializes*c*.keys with std::move(key_cont),*c*.values with std::move(mapped_cont), and*compare* with comp;
sorts the range [begin(), end()) with respect to value_comp(); and
finally erases the duplicate elements as if by:auto zv = views::zip(*c*.keys, *c*.values);auto it = ranges::unique(zv, *key-equiv*(*compare*)).begin();auto dist = distance(zv.begin(), it);*c*.keys.erase(*c*.keys.begin() + dist, *c*.keys.end());*c*.values.erase(*c*.values.begin() + dist, *c*.values.end());
[2](#2)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/containers.tex#L17441)
*Complexity*: Linear in N if the container arguments are already sorted
with respect to value_comp() and otherwise NlogN,
where N is the value of key_cont.size() before this call[.](#2.sentence-1)
[🔗](#lib:flat_map,constructor_)
`constexpr flat_map(sorted_unique_t, key_container_type key_cont, mapped_container_type mapped_cont,
const key_compare& comp = key_compare());
`
[3](#3)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/containers.tex#L17455)
*Effects*: Initializes*c*.keys with std::move(key_cont),*c*.values with std::move(mapped_cont), and*compare* with comp[.](#3.sentence-1)
[4](#4)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/containers.tex#L17462)
*Complexity*: Constant[.](#4.sentence-1)

View File

@@ -0,0 +1,108 @@
[flat.map.cons.alloc]
# 23 Containers library [[containers]](./#containers)
## 23.6 Container adaptors [[container.adaptors]](container.adaptors#flat.map.cons.alloc)
### 23.6.8 Class template flat_map [[flat.map]](flat.map#cons.alloc)
#### 23.6.8.4 Constructors with allocators [flat.map.cons.alloc]
[1](#1)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/containers.tex#L17469)
The constructors in this subclause shall not participate in overload resolution
unless uses_allocator_v<key_container_type, Alloc> is true and uses_allocator_v<mapped_container_type, Alloc> is true[.](#1.sentence-1)
[🔗](#lib:flat_map,constructor)
`template<class Alloc>
constexpr flat_map(const key_container_type& key_cont, const mapped_container_type& mapped_cont,
const Alloc& a);
template<class Alloc>
constexpr flat_map(const key_container_type& key_cont, const mapped_container_type& mapped_cont,
const key_compare& comp, const Alloc& a);
`
[2](#2)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/containers.tex#L17485)
*Effects*: Equivalent to flat_map(key_cont, mapped_cont) andflat_map(key_cont, mapped_cont, comp), respectively,
except that *c*.keys and *c*.values are constructed with
uses-allocator construction ([[allocator.uses.construction]](allocator.uses.construction "20.2.8.2Uses-allocator construction"))[.](#2.sentence-1)
[3](#3)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/containers.tex#L17492)
*Complexity*: Same as flat_map(key_cont, mapped_cont) andflat_map(key_cont, mapped_cont, comp), respectively[.](#3.sentence-1)
[🔗](#lib:flat_map,constructor_)
`template<class Alloc>
constexpr flat_map(sorted_unique_t, const key_container_type& key_cont,
const mapped_container_type& mapped_cont, const Alloc& a);
template<class Alloc>
constexpr flat_map(sorted_unique_t, const key_container_type& key_cont,
const mapped_container_type& mapped_cont, const key_compare& comp,
const Alloc& a);
`
[4](#4)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/containers.tex#L17510)
*Effects*: Equivalent to flat_map(sorted_unique, key_cont, mapped_cont) andflat_map(sorted_unique, key_cont, mapped_cont, comp), respectively,
except that *c*.keys and *c*.values are constructed
with uses-allocator construction ([[allocator.uses.construction]](allocator.uses.construction "20.2.8.2Uses-allocator construction"))[.](#4.sentence-1)
[5](#5)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/containers.tex#L17517)
*Complexity*: Linear[.](#5.sentence-1)
[🔗](#lib:flat_map,constructor__)
`template<class Alloc>
constexpr explicit flat_map(const Alloc& a);
template<class Alloc>
constexpr flat_map(const key_compare& comp, const Alloc& a);
template<class Alloc>
constexpr flat_map(const flat_map&, const Alloc& a);
template<class Alloc>
constexpr flat_map(flat_map&&, const Alloc& a);
template<class InputIterator, class Alloc>
constexpr flat_map(InputIterator first, InputIterator last, const Alloc& a);
template<class InputIterator, class Alloc>
constexpr flat_map(InputIterator first, InputIterator last, const key_compare& comp,
const Alloc& a);
template<class InputIterator, class Alloc>
constexpr flat_map(sorted_unique_t, InputIterator first, InputIterator last, const Alloc& a);
template<class InputIterator, class Alloc>
constexpr flat_map(sorted_unique_t, InputIterator first, InputIterator last,
const key_compare& comp, const Alloc& a);
template<[container-compatible-range](container.intro.reqmts#concept:container-compatible-range "23.2.2.1Introduction[container.intro.reqmts]")<value_type> R, class Alloc>
constexpr flat_map(from_range_t, R&& rg, const Alloc& a);
template<[container-compatible-range](container.intro.reqmts#concept:container-compatible-range "23.2.2.1Introduction[container.intro.reqmts]")<value_type> R, class Alloc>
constexpr flat_map(from_range_t, R&& rg, const key_compare& comp, const Alloc& a);
template<class Alloc>
constexpr flat_map(initializer_list<value_type> il, const Alloc& a);
template<class Alloc>
constexpr flat_map(initializer_list<value_type> il, const key_compare& comp, const Alloc& a);
template<class Alloc>
constexpr flat_map(sorted_unique_t, initializer_list<value_type> il, const Alloc& a);
template<class Alloc>
constexpr flat_map(sorted_unique_t, initializer_list<value_type> il,
const key_compare& comp, const Alloc& a);
`
[6](#6)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/containers.tex#L17558)
*Effects*: Equivalent to the corresponding non-allocator constructors
except that *c*.keys and *c*.values are constructed
with uses-allocator construction ([[allocator.uses.construction]](allocator.uses.construction "20.2.8.2Uses-allocator construction"))[.](#6.sentence-1)

32
cppdraft/flat/map/defn.md Normal file

File diff suppressed because one or more lines are too long

View File

@@ -0,0 +1,58 @@
[flat.map.erasure]
# 23 Containers library [[containers]](./#containers)
## 23.6 Container adaptors [[container.adaptors]](container.adaptors#flat.map.erasure)
### 23.6.8 Class template flat_map [[flat.map]](flat.map#erasure)
#### 23.6.8.8 Erasure [flat.map.erasure]
[🔗](#lib:erase_if,flat_map)
`template<class Key, class T, class Compare, class KeyContainer, class MappedContainer,
class Predicate>
constexpr typename flat_map<Key, T, Compare, KeyContainer, MappedContainer>::size_type
erase_if(flat_map<Key, T, Compare, KeyContainer, MappedContainer>& c, Predicate pred);
`
[1](#1)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/containers.tex#L18116)
*Preconditions*: Key and T meet the *Cpp17MoveAssignable* requirements[.](#1.sentence-1)
[2](#2)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/containers.tex#L18120)
*Effects*: Let E be bool(pred(pair<const Key&, const T&>(e)))[.](#2.sentence-1)
Erases all elements e in c for which E holds[.](#2.sentence-2)
[3](#3)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/containers.tex#L18125)
*Returns*: The number of elements erased[.](#3.sentence-1)
[4](#4)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/containers.tex#L18129)
*Complexity*: Exactly c.size() applications of the predicate[.](#4.sentence-1)
[5](#5)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/containers.tex#L18133)
*Remarks*: Stable ([[algorithm.stable]](algorithm.stable "16.4.6.8Requirements for stable algorithms"))[.](#5.sentence-1)
If an invocation of erase_if exits via an exception,c is in a valid but unspecified state ([[defns.valid]](defns.valid "3.67valid but unspecified state"))[.](#5.sentence-2)
[*Note [1](#note-1)*:
c still meets its invariants,
but can be empty[.](#5.sentence-3)
— *end note*]

View File

@@ -0,0 +1,407 @@
[flat.map.modifiers]
# 23 Containers library [[containers]](./#containers)
## 23.6 Container adaptors [[container.adaptors]](container.adaptors#flat.map.modifiers)
### 23.6.8 Class template flat_map [[flat.map]](flat.map#modifiers)
#### 23.6.8.7 Modifiers [flat.map.modifiers]
[🔗](#lib:emplace,flat_map)
`template<class... Args> constexpr pair<iterator, bool> emplace(Args&&... args);
`
[1](#1)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/containers.tex#L17690)
*Constraints*: is_constructible_v<pair<key_type, mapped_type>, Args...> is true[.](#1.sentence-1)
[2](#2)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/containers.tex#L17694)
*Effects*: Initializes an object t of type pair<key_type, mapped_type> with std::forward<Args>(args)...;
if the map already contains an element
whose key is equivalent to t.first,*this is unchanged[.](#2.sentence-1)
Otherwise, equivalent to:auto key_it = ranges::upper_bound(*c*.keys, t.first, *compare*);auto value_it = *c*.values.begin() + distance(*c*.keys.begin(), key_it);*c*.keys.insert(key_it, std::move(t.first));*c*.values.insert(value_it, std::move(t.second));
[3](#3)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/containers.tex#L17709)
*Returns*: The bool component of the returned pair is true if and only if the insertion took place, and
the iterator component of the pair points to
the element with key equivalent to t.first[.](#3.sentence-1)
[🔗](#lib:insert,flat_map)
`template<class P> constexpr pair<iterator, bool> insert(P&& x);
template<class P> constexpr iterator insert(const_iterator position, P&& x);
`
[4](#4)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/containers.tex#L17724)
*Constraints*: is_constructible_v<pair<key_type, mapped_type>, P> is true[.](#4.sentence-1)
[5](#5)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/containers.tex#L17728)
*Effects*: The first form is equivalent to return emplace(std::forward<P>(x));[.](#5.sentence-1)
The second form is equivalent toreturn emplace_hint(position, std::forward<P>(x));[.](#5.sentence-2)
[🔗](#lib:insert,flat_map_)
`template<class InputIterator>
constexpr void insert(InputIterator first, InputIterator last);
`
[6](#6)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/containers.tex#L17742)
*Effects*: Adds elements to *c* as if by:for (; first != last; ++first) { value_type value = *first; *c*.keys.insert(*c*.keys.end(), std::move(value.first)); *c*.values.insert(*c*.values.end(), std::move(value.second));}
Then, sorts the range of newly inserted elements
with respect to value_comp();
merges the resulting sorted range and
the sorted range of pre-existing elements into a single sorted range; and
finally erases the duplicate elements as if by:auto zv = views::zip(*c*.keys, *c*.values);auto it = ranges::unique(zv, *key-equiv*(*compare*)).begin();auto dist = distance(zv.begin(), it);*c*.keys.erase(*c*.keys.begin() + dist, *c*.keys.end());*c*.values.erase(*c*.values.begin() + dist, *c*.values.end());
[7](#7)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/containers.tex#L17765)
*Complexity*: N + MlogM,
where N is size() before the operation andM is distance(first, last)[.](#7.sentence-1)
[8](#8)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/containers.tex#L17771)
*Remarks*: Since this operation performs an in-place merge, it may allocate memory[.](#8.sentence-1)
[🔗](#lib:insert,flat_map__)
`template<class InputIterator>
constexpr void insert(sorted_unique_t, InputIterator first, InputIterator last);
`
[9](#9)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/containers.tex#L17783)
*Effects*: Adds elements to *c* as if by:for (; first != last; ++first) { value_type value = *first; *c*.keys.insert(*c*.keys.end(), std::move(value.first)); *c*.values.insert(*c*.values.end(), std::move(value.second));}
Then, merges the sorted range of newly added elements and
the sorted range of pre-existing elements into a single sorted range; and
finally erases the duplicate elements as if by:auto zv = views::zip(*c*.keys, *c*.values);auto it = ranges::unique(zv, *key-equiv*(*compare*)).begin();auto dist = distance(zv.begin(), it);*c*.keys.erase(*c*.keys.begin() + dist, *c*.keys.end());*c*.values.erase(*c*.values.begin() + dist, *c*.values.end());
[10](#10)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/containers.tex#L17804)
*Complexity*: Linear in N, where N is size() after the operation[.](#10.sentence-1)
[11](#11)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/containers.tex#L17808)
*Remarks*: Since this operation performs an in-place merge, it may allocate memory[.](#11.sentence-1)
[🔗](#lib:insert_range,flat_map)
`template<[container-compatible-range](container.intro.reqmts#concept:container-compatible-range "23.2.2.1Introduction[container.intro.reqmts]")<value_type> R>
constexpr void insert_range(R&& rg);
`
[12](#12)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/containers.tex#L17820)
*Effects*: Adds elements to *c* as if by:for (const auto& e : rg) {*c*.keys.insert(*c*.keys.end(), e.first); *c*.values.insert(*c*.values.end(), e.second);}
Then, sorts the range of newly inserted elements
with respect to value_comp();
merges the resulting sorted range and
the sorted range of pre-existing elements into a single sorted range; and
finally erases the duplicate elements as if by:auto zv = views::zip(*c*.keys, *c*.values);auto it = ranges::unique(zv, *key-equiv*(*compare*)).begin();auto dist = distance(zv.begin(), it);*c*.keys.erase(*c*.keys.begin() + dist, *c*.keys.end());*c*.values.erase(*c*.values.begin() + dist, *c*.values.end());
[13](#13)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/containers.tex#L17842)
*Complexity*: N + MlogM,
where N is size() before the operation andM is ranges::distance(rg)[.](#13.sentence-1)
[14](#14)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/containers.tex#L17848)
*Remarks*: Since this operation performs an in-place merge, it may allocate memory[.](#14.sentence-1)
[🔗](#lib:try_emplace,flat_map)
`template<class... Args>
constexpr pair<iterator, bool> try_emplace(const key_type& k, Args&&... args);
template<class... Args>
constexpr pair<iterator, bool> try_emplace(key_type&& k, Args&&... args);
template<class... Args>
constexpr iterator try_emplace(const_iterator hint, const key_type& k, Args&&... args);
template<class... Args>
constexpr iterator try_emplace(const_iterator hint, key_type&& k, Args&&... args);
`
[15](#15)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/containers.tex#L17866)
*Constraints*: is_constructible_v<mapped_type, Args...> is true[.](#15.sentence-1)
[16](#16)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/containers.tex#L17870)
*Effects*: If the map already contains an element whose key is equivalent to k,*this and args... are unchanged[.](#16.sentence-1)
Otherwise equivalent to:auto key_it = ranges::upper_bound(*c*.keys, k, *compare*);auto value_it = *c*.values.begin() + distance(*c*.keys.begin(), key_it);*c*.keys.insert(key_it, std::forward<decltype(k)>(k));*c*.values.emplace(value_it, std::forward<Args>(args)...);
[17](#17)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/containers.tex#L17882)
*Returns*: In the first two overloads,
the bool component of the returned pair is true if and only if the insertion took place[.](#17.sentence-1)
The returned iterator points to the map element
whose key is equivalent to k[.](#17.sentence-2)
[18](#18)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/containers.tex#L17890)
*Complexity*: The same as emplace for the first two overloads, and
the same as emplace_hint for the last two overloads[.](#18.sentence-1)
[🔗](#lib:try_emplace,flat_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);
`
[19](#19)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/containers.tex#L17905)
*Constraints*:
- [(19.1)](#19.1)
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[.](#19.1.sentence-1)
- [(19.2)](#19.2)
is_constructible_v<key_type, K> is true[.](#19.2.sentence-1)
- [(19.3)](#19.3)
is_constructible_v<mapped_type, Args...> is true[.](#19.3.sentence-1)
- [(19.4)](#19.4)
For the first overload,is_convertible_v<K&&, const_iterator> andis_convertible_v<K&&, iterator> are both false[.](#19.4.sentence-1)
[20](#20)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/containers.tex#L17921)
*Preconditions*: The conversion from k into key_type constructs
an object u,
for which find(k) == find(u) is true[.](#20.sentence-1)
[21](#21)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/containers.tex#L17927)
*Effects*: If the map already contains an element whose key is equivalent to k,*this and args... are unchanged[.](#21.sentence-1)
Otherwise equivalent to:auto key_it = upper_bound(*c*.keys.begin(), *c*.keys.end(), k, *compare*);auto value_it = *c*.values.begin() + distance(*c*.keys.begin(), key_it);*c*.keys.emplace(key_it, std::forward<K>(k));*c*.values.emplace(value_it, std::forward<Args>(args)...);
[22](#22)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/containers.tex#L17939)
*Returns*: In the first overload,
the bool component of the returned pair is true if and only if the insertion took place[.](#22.sentence-1)
The returned iterator points to the map element
whose key is equivalent to k[.](#22.sentence-2)
[23](#23)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/containers.tex#L17947)
*Complexity*: The same as emplace and emplace_hint, respectively[.](#23.sentence-1)
[🔗](#lib:insert_or_assign,flat_map)
`template<class M>
constexpr pair<iterator, bool> insert_or_assign(const key_type& k, M&& obj);
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, const key_type& k, M&& obj);
template<class M>
constexpr iterator insert_or_assign(const_iterator hint, key_type&& k, M&& obj);
`
[24](#24)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/containers.tex#L17965)
*Constraints*: is_assignable_v<mapped_type&, M> is true andis_constructible_v<mapped_type, M> is true[.](#24.sentence-1)
[25](#25)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/containers.tex#L17970)
*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, equivalent totry_emplace(std::forward<decltype(k)>(k), std::forward<M>(obj)) for the first two overloads ortry_emplace(hint, std::forward<decltype(k)>(k), std::forward<M>(obj)) for the last two overloads[.](#25.sentence-2)
[26](#26)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/containers.tex#L17985)
*Returns*: In the first two overloads, 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#L17991)
*Complexity*: The same as emplace for the first two overloads and
the same as emplace_hint for the last two overloads[.](#27.sentence-1)
[🔗](#lib:insert_or_assign,flat_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#L18006)
*Constraints*:
- [(28.1)](#28.1)
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[.](#28.1.sentence-1)
- [(28.2)](#28.2)
is_constructible_v<key_type, K> is true[.](#28.2.sentence-1)
- [(28.3)](#28.3)
is_assignable_v<mapped_type&, M> is true[.](#28.3.sentence-1)
- [(28.4)](#28.4)
is_constructible_v<mapped_type, M> is true[.](#28.4.sentence-1)
[29](#29)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/containers.tex#L18020)
*Preconditions*: The conversion from k into key_type constructs
an object u, for which find(k) == find(u) is true[.](#29.sentence-1)
[30](#30)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/containers.tex#L18025)
*Effects*: If the map already contains an element e whose key is equivalent to k,
assigns std::forward<M>(obj) to e.second[.](#30.sentence-1)
Otherwise, equivalent totry_emplace(std::forward<K>(k), std::forward<M>(obj)) for the first overload ortry_emplace(hint, std::forward<K>(k), std::forward<M>(obj)) for the second overload[.](#30.sentence-2)
[31](#31)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/containers.tex#L18040)
*Returns*: In the first overload,
the bool component of the returned pair is true if and only if the insertion took place[.](#31.sentence-1)
The returned iterator points to the map element
whose key is equivalent to k[.](#31.sentence-2)
[32](#32)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/containers.tex#L18048)
*Complexity*: The same as emplace and emplace_hint, respectively[.](#32.sentence-1)
[🔗](#lib:swap,flat_map)
`constexpr void swap(flat_map& y) noexcept;
`
[33](#33)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/containers.tex#L18059)
*Effects*: Equivalent to:ranges::swap(*compare*, y.*compare*);
ranges::swap(*c*.keys, y.*c*.keys);
ranges::swap(*c*.values, y.*c*.values);
[🔗](#lib:extract,flat_map)
`constexpr containers extract() &&;
`
[34](#34)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/containers.tex#L18075)
*Postconditions*: *this is emptied, even if the function exits via an exception[.](#34.sentence-1)
[35](#35)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/containers.tex#L18079)
*Returns*: std::move(*c*)[.](#35.sentence-1)
[🔗](#lib:replace,flat_map)
`constexpr void replace(key_container_type&& key_cont, mapped_container_type&& mapped_cont);
`
[36](#36)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/containers.tex#L18090)
*Preconditions*: key_cont.size() == mapped_cont.size() is true,
the elements of key_cont are sorted with respect to *compare*, andkey_cont contains no equal elements[.](#36.sentence-1)
[37](#37)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/containers.tex#L18096)
*Effects*: Equivalent to:*c*.keys = std::move(key_cont);*c*.values = std::move(mapped_cont);

View File

@@ -0,0 +1,162 @@
[flat.map.overview]
# 23 Containers library [[containers]](./#containers)
## 23.6 Container adaptors [[container.adaptors]](container.adaptors#flat.map.overview)
### 23.6.8 Class template flat_map [[flat.map]](flat.map#overview)
#### 23.6.8.1 Overview [flat.map.overview]
[1](#1)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/containers.tex#L16954)
A flat_map is a container adaptor
that provides an associative container interface
that supports unique keys
(i.e., contains at most one of each key value) and
provides for fast retrieval of values of another type T based on the keys[.](#1.sentence-1)
flat_map supports iterators
that meet the *Cpp17InputIterator* requirements and
model the[random_access_iterator](iterator.concept.random.access#concept:random_access_iterator "24.3.4.13Concept random_­access_­iterator[iterator.concept.random.access]") concept ([[iterator.concept.random.access]](iterator.concept.random.access "24.3.4.13Concept random_­access_­iterator"))[.](#1.sentence-2)
[2](#2)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/containers.tex#L16967)
A flat_map meets all of the requirements
of a container ([[container.reqmts]](container.reqmts "23.2.2.2Container requirements")) and
of a reversible container ([[container.rev.reqmts]](container.rev.reqmts "23.2.2.3Reversible container requirements")),
plus the optional container requirements ([[container.opt.reqmts]](container.opt.reqmts "23.2.2.4Optional container requirements"))[.](#2.sentence-1)
flat_map meets the requirements of
an associative container ([[associative.reqmts]](associative.reqmts "23.2.7Associative containers")),
except that:
- [(2.1)](#2.1)
it does not meet the requirements related to node handles ([[container.node]](container.node "23.2.5Node handles")),
- [(2.2)](#2.2)
it does not meet the requirements related to iterator invalidation, and
- [(2.3)](#2.3)
the time complexity of the operations that insert or erase a single
element from the map is linear, including the ones that take an insertion
position iterator[.](#2.sentence-2)
[*Note [1](#note-1)*:
A flat_map does not meet the additional requirements of
an allocator-aware container ([[container.alloc.reqmts]](container.alloc.reqmts "23.2.2.5Allocator-aware containers"))[.](#2.sentence-3)
— *end note*]
[3](#3)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/containers.tex#L16990)
A flat_map also provides most operations
described in [[associative.reqmts]](associative.reqmts "23.2.7Associative containers") for unique keys[.](#3.sentence-1)
This means that a flat_map supports
the a_uniq operations in [[associative.reqmts]](associative.reqmts "23.2.7Associative containers") but not the a_eq operations[.](#3.sentence-2)
For a flat_map<Key, T> the key_type is Key and
the value_type is pair<Key, T>[.](#3.sentence-3)
[4](#4)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/containers.tex#L17000)
Descriptions are provided here only for operations on flat_map that
are not described in one of those sets of requirements or for operations where
there is additional semantic information[.](#4.sentence-1)
[5](#5)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/containers.tex#L17005)
A flat_map maintains the following invariants:
- [(5.1)](#5.1)
it contains the same number of keys and values;
- [(5.2)](#5.2)
the keys are sorted with respect to the comparison object; and
- [(5.3)](#5.3)
the value at offset off within the value container is
the value associated with the key at offset off within the key container[.](#5.sentence-1)
[6](#6)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/containers.tex#L17018)
If any member function in [[flat.map.defn]](flat.map.defn "23.6.8.2Definition") exits via an exception
the invariants are restored[.](#6.sentence-1)
[*Note [2](#note-2)*:
This can result in the flat_map being emptied[.](#6.sentence-2)
— *end note*]
[7](#7)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/containers.tex#L17025)
Any type C that meets the sequence container requirements ([[sequence.reqmts]](sequence.reqmts "23.2.4Sequence containers"))
can be used to instantiate flat_map,
as long asC::iterator meets the *Cpp17RandomAccessIterator* requirements and
invocations of
member functions C::size and C::max_size do not exit via an exception[.](#7.sentence-1)
In particular, vector ([[vector]](vector "23.3.13Class template vector")) and deque ([[deque]](deque "23.3.5Class template deque"))
can be used[.](#7.sentence-2)
[*Note [3](#note-3)*:
vector<bool> is not a sequence container[.](#7.sentence-3)
— *end note*]
[8](#8)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/containers.tex#L17039)
The program is ill-formed ifKey is not the same type as KeyContainer::value_type orT is not the same type as MappedContainer::value_type[.](#8.sentence-1)
[9](#9)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/containers.tex#L17044)
The effect of calling a constructor
that takes
both key_container_type and mapped_container_type arguments with
containers of different sizes is undefined[.](#9.sentence-1)
[10](#10)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/containers.tex#L17050)
The effect of calling a constructor or member function
that takes a sorted_unique_t argument with
a container, containers, or range
that is not sorted with respect to key_comp(), or
that contains equal elements,
is undefined[.](#10.sentence-1)
[11](#11)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/containers.tex#L17058)
The types iterator and const_iterator meet
the constexpr iterator requirements ([[iterator.requirements.general]](iterator.requirements.general "24.3.1General"))[.](#11.sentence-1)

15
cppdraft/flat/map/syn.md Normal file
View File

@@ -0,0 +1,15 @@
[flat.map.syn]
# 23 Containers library [[containers]](./#containers)
## 23.6 Container adaptors [[container.adaptors]](container.adaptors#flat.map.syn)
### 23.6.7 Header <flat_map> synopsis [flat.map.syn]
[🔗](#header:%3cflat_map%3e)
#include <compare> // see [[compare.syn]](compare.syn "17.12.1Header <compare> synopsis")#include <initializer_list> // see [[initializer.list.syn]](initializer.list.syn "17.11.2Header <initializer_­list> synopsis")namespace std {// [[flat.map]](flat.map "23.6.8Class template flat_­map"), class template flat_maptemplate<class Key, class T, class Compare = less<Key>, class KeyContainer = vector<Key>, class MappedContainer = vector<T>>class flat_map; struct sorted_unique_t { explicit sorted_unique_t() = default; }; inline constexpr sorted_unique_t sorted_unique{}; template<class Key, class T, class Compare, class KeyContainer, class MappedContainer, class Allocator>struct uses_allocator<flat_map<Key, T, Compare, KeyContainer, MappedContainer>,
Allocator>; // [[flat.map.erasure]](flat.map.erasure "23.6.8.8Erasure"), erasure for flat_maptemplate<class Key, class T, class Compare, class KeyContainer, class MappedContainer, class Predicate>constexpr typename flat_map<Key, T, Compare, KeyContainer, MappedContainer>::size_type
erase_if(flat_map<Key, T, Compare, KeyContainer, MappedContainer>& c, Predicate pred); // [[flat.multimap]](flat.multimap "23.6.9Class template flat_­multimap"), class template flat_multimaptemplate<class Key, class T, class Compare = less<Key>, class KeyContainer = vector<Key>, class MappedContainer = vector<T>>class flat_multimap; struct sorted_equivalent_t { explicit sorted_equivalent_t() = default; }; inline constexpr sorted_equivalent_t sorted_equivalent{}; template<class Key, class T, class Compare, class KeyContainer, class MappedContainer, class Allocator>struct uses_allocator<flat_multimap<Key, T, Compare, KeyContainer, MappedContainer>,
Allocator>; // [[flat.multimap.erasure]](flat.multimap.erasure "23.6.9.5Erasure"), erasure for flat_multimaptemplate<class Key, class T, class Compare, class KeyContainer, class MappedContainer, class Predicate>constexpr typename flat_multimap<Key, T, Compare, KeyContainer, MappedContainer>::size_type
erase_if(flat_multimap<Key, T, Compare, KeyContainer, MappedContainer>& c, Predicate pred);}