From Jason Turner

[flat.map.defn]

Diff to HTML by rtfpessoa

Files changed (1) hide show
  1. tmp/tmpni1tecz9/{from.md → to.md} +339 -0
tmp/tmpni1tecz9/{from.md → to.md} RENAMED
@@ -0,0 +1,339 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #### Definition <a id="flat.map.defn">[[flat.map.defn]]</a>
2
+
3
+ ``` cpp
4
+ namespace std {
5
+ template<class Key, class T, class Compare = less<Key>,
6
+ class KeyContainer = vector<Key>, class MappedContainer = vector<T>>
7
+ class flat_map {
8
+ public:
9
+ // types
10
+ using key_type = Key;
11
+ using mapped_type = T;
12
+ using value_type = pair<key_type, mapped_type>;
13
+ using key_compare = Compare;
14
+ using reference = pair<const key_type&, mapped_type&>;
15
+ using const_reference = pair<const key_type&, const mapped_type&>;
16
+ using size_type = size_t;
17
+ using difference_type = ptrdiff_t;
18
+ using iterator = implementation-defined // type of flat_map::iterator; // see [container.requirements]
19
+ using const_iterator = implementation-defined // type of flat_map::const_iterator; // see [container.requirements]
20
+ using reverse_iterator = std::reverse_iterator<iterator>;
21
+ using const_reverse_iterator = std::reverse_iterator<const_iterator>;
22
+ using key_container_type = KeyContainer;
23
+ using mapped_container_type = MappedContainer;
24
+
25
+ class value_compare {
26
+ private:
27
+ key_compare comp; // exposition only
28
+ value_compare(key_compare c) : comp(c) { } // exposition only
29
+
30
+ public:
31
+ bool operator()(const_reference x, const_reference y) const {
32
+ return comp(x.first, y.first);
33
+ }
34
+ };
35
+
36
+ struct containers {
37
+ key_container_type keys;
38
+ mapped_container_type values;
39
+ };
40
+
41
+ // [flat.map.cons], construct/copy/destroy
42
+ flat_map() : flat_map(key_compare()) { }
43
+
44
+ flat_map(key_container_type key_cont, mapped_container_type mapped_cont,
45
+ const key_compare& comp = key_compare());
46
+ template<class Allocator>
47
+ flat_map(const key_container_type& key_cont, const mapped_container_type& mapped_cont,
48
+ const Allocator& a);
49
+ template<class Allocator>
50
+ flat_map(const key_container_type& key_cont, const mapped_container_type& mapped_cont,
51
+ const key_compare& comp, const Allocator& a);
52
+
53
+ flat_map(sorted_unique_t, key_container_type key_cont, mapped_container_type mapped_cont,
54
+ const key_compare& comp = key_compare());
55
+ template<class Allocator>
56
+ flat_map(sorted_unique_t, const key_container_type& key_cont,
57
+ const mapped_container_type& mapped_cont, const Allocator& a);
58
+ template<class Allocator>
59
+ flat_map(sorted_unique_t, const key_container_type& key_cont,
60
+ const mapped_container_type& mapped_cont,
61
+ const key_compare& comp, const Allocator& a);
62
+
63
+ explicit flat_map(const key_compare& comp)
64
+ : c(), compare(comp) { }
65
+ template<class Allocator>
66
+ flat_map(const key_compare& comp, const Allocator& a);
67
+ template<class Allocator>
68
+ explicit flat_map(const Allocator& a);
69
+
70
+ template<class InputIterator>
71
+ flat_map(InputIterator first, InputIterator last, const key_compare& comp = key_compare())
72
+ : c(), compare(comp) { insert(first, last); }
73
+ template<class InputIterator, class Allocator>
74
+ flat_map(InputIterator first, InputIterator last,
75
+ const key_compare& comp, const Allocator& a);
76
+ template<class InputIterator, class Allocator>
77
+ flat_map(InputIterator first, InputIterator last, const Allocator& a);
78
+
79
+ template<container-compatible-range<value_type> R>
80
+ flat_map(from_range_t fr, R&& rg)
81
+ : flat_map(fr, std::forward<R>(rg), key_compare()) { }
82
+ template<container-compatible-range<value_type> R, class Allocator>
83
+ flat_map(from_range_t, R&& rg, const Allocator& a);
84
+ template<container-compatible-range<value_type> R>
85
+ flat_map(from_range_t, R&& rg, const key_compare& comp)
86
+ : flat_map(comp) { insert_range(std::forward<R>(rg)); }
87
+ template<container-compatible-range<value_type> R, class Allocator>
88
+ flat_map(from_range_t, R&& rg, const key_compare& comp, const Allocator& a);
89
+
90
+ template<class InputIterator>
91
+ flat_map(sorted_unique_t s, InputIterator first, InputIterator last,
92
+ const key_compare& comp = key_compare())
93
+ : c(), compare(comp) { insert(s, first, last); }
94
+ template<class InputIterator, class Allocator>
95
+ flat_map(sorted_unique_t, InputIterator first, InputIterator last,
96
+ const key_compare& comp, const Allocator& a);
97
+ template<class InputIterator, class Allocator>
98
+ flat_map(sorted_unique_t, InputIterator first, InputIterator last, const Allocator& a);
99
+
100
+ flat_map(initializer_list<value_type> il, const key_compare& comp = key_compare())
101
+ : flat_map(il.begin(), il.end(), comp) { }
102
+ template<class Allocator>
103
+ flat_map(initializer_list<value_type> il, const key_compare& comp, const Allocator& a);
104
+ template<class Allocator>
105
+ flat_map(initializer_list<value_type> il, const Allocator& a);
106
+
107
+ flat_map(sorted_unique_t s, initializer_list<value_type> il,
108
+ const key_compare& comp = key_compare())
109
+ : flat_map(s, il.begin(), il.end(), comp) { }
110
+ template<class Allocator>
111
+ flat_map(sorted_unique_t, initializer_list<value_type> il,
112
+ const key_compare& comp, const Allocator& a);
113
+ template<class Allocator>
114
+ flat_map(sorted_unique_t, initializer_list<value_type> il, const Allocator& a);
115
+
116
+ flat_map& operator=(initializer_list<value_type> il);
117
+
118
+ // iterators
119
+ iterator begin() noexcept;
120
+ const_iterator begin() const noexcept;
121
+ iterator end() noexcept;
122
+ const_iterator end() const noexcept;
123
+
124
+ reverse_iterator rbegin() noexcept;
125
+ const_reverse_iterator rbegin() const noexcept;
126
+ reverse_iterator rend() noexcept;
127
+ const_reverse_iterator rend() const noexcept;
128
+
129
+ const_iterator cbegin() const noexcept;
130
+ const_iterator cend() const noexcept;
131
+ const_reverse_iterator crbegin() const noexcept;
132
+ const_reverse_iterator crend() const noexcept;
133
+
134
+ // [flat.map.capacity], capacity
135
+ [[nodiscard]] bool empty() const noexcept;
136
+ size_type size() const noexcept;
137
+ size_type max_size() const noexcept;
138
+
139
+ // [flat.map.access], element access
140
+ mapped_type& operator[](const key_type& x);
141
+ mapped_type& operator[](key_type&& x);
142
+ template<class K> mapped_type& operator[](K&& x);
143
+ mapped_type& at(const key_type& x);
144
+ const mapped_type& at(const key_type& x) const;
145
+ template<class K> mapped_type& at(const K& x);
146
+ template<class K> const mapped_type& at(const K& x) const;
147
+
148
+ // [flat.map.modifiers], modifiers
149
+ template<class... Args> pair<iterator, bool> emplace(Args&&... args);
150
+ template<class... Args>
151
+ iterator emplace_hint(const_iterator position, Args&&... args);
152
+
153
+ pair<iterator, bool> insert(const value_type& x)
154
+ { return emplace(x); }
155
+ pair<iterator, bool> insert(value_type&& x)
156
+ { return emplace(std::move(x)); }
157
+ iterator insert(const_iterator position, const value_type& x)
158
+ { return emplace_hint(position, x); }
159
+ iterator insert(const_iterator position, value_type&& x)
160
+ { return emplace_hint(position, std::move(x)); }
161
+
162
+ template<class P> pair<iterator, bool> insert(P&& x);
163
+ template<class P>
164
+ iterator insert(const_iterator position, P&&);
165
+ template<class InputIterator>
166
+ void insert(InputIterator first, InputIterator last);
167
+ template<class InputIterator>
168
+ void insert(sorted_unique_t, InputIterator first, InputIterator last);
169
+ template<container-compatible-range<value_type> R>
170
+ void insert_range(R&& rg);
171
+
172
+ void insert(initializer_list<value_type> il)
173
+ { insert(il.begin(), il.end()); }
174
+ void insert(sorted_unique_t s, initializer_list<value_type> il)
175
+ { insert(s, il.begin(), il.end()); }
176
+
177
+ containers extract() &&;
178
+ void replace(key_container_type&& key_cont, mapped_container_type&& mapped_cont);
179
+
180
+ template<class... Args>
181
+ pair<iterator, bool> try_emplace(const key_type& k, Args&&... args);
182
+ template<class... Args>
183
+ pair<iterator, bool> try_emplace(key_type&& k, Args&&... args);
184
+ template<class K, class... Args>
185
+ pair<iterator, bool> try_emplace(K&& k, Args&&... args);
186
+ template<class... Args>
187
+ iterator try_emplace(const_iterator hint, const key_type& k, Args&&... args);
188
+ template<class... Args>
189
+ iterator try_emplace(const_iterator hint, key_type&& k, Args&&... args);
190
+ template<class K, class... Args>
191
+ iterator try_emplace(const_iterator hint, K&& k, Args&&... args);
192
+ template<class M>
193
+ pair<iterator, bool> insert_or_assign(const key_type& k, M&& obj);
194
+ template<class M>
195
+ pair<iterator, bool> insert_or_assign(key_type&& k, M&& obj);
196
+ template<class K, class M>
197
+ pair<iterator, bool> insert_or_assign(K&& k, M&& obj);
198
+ template<class M>
199
+ iterator insert_or_assign(const_iterator hint, const key_type& k, M&& obj);
200
+ template<class M>
201
+ iterator insert_or_assign(const_iterator hint, key_type&& k, M&& obj);
202
+ template<class K, class M>
203
+ iterator insert_or_assign(const_iterator hint, K&& k, M&& obj);
204
+
205
+ iterator erase(iterator position);
206
+ iterator erase(const_iterator position);
207
+ size_type erase(const key_type& x);
208
+ template<class K> size_type erase(K&& x);
209
+ iterator erase(const_iterator first, const_iterator last);
210
+
211
+ void swap(flat_map& y) noexcept;
212
+ void clear() noexcept;
213
+
214
+ // observers
215
+ key_compare key_comp() const;
216
+ value_compare value_comp() const;
217
+
218
+ const key_container_type& keys() const noexcept { return c.keys; }
219
+ const mapped_container_type& values() const noexcept { return c.values; }
220
+
221
+ // map operations
222
+ iterator find(const key_type& x);
223
+ const_iterator find(const key_type& x) const;
224
+ template<class K> iterator find(const K& x);
225
+ template<class K> const_iterator find(const K& x) const;
226
+
227
+ size_type count(const key_type& x) const;
228
+ template<class K> size_type count(const K& x) const;
229
+
230
+ bool contains(const key_type& x) const;
231
+ template<class K> bool contains(const K& x) const;
232
+
233
+ iterator lower_bound(const key_type& x);
234
+ const_iterator lower_bound(const key_type& x) const;
235
+ template<class K> iterator lower_bound(const K& x);
236
+ template<class K> const_iterator lower_bound(const K& x) const;
237
+
238
+ iterator upper_bound(const key_type& x);
239
+ const_iterator upper_bound(const key_type& x) const;
240
+ template<class K> iterator upper_bound(const K& x);
241
+ template<class K> const_iterator upper_bound(const K& x) const;
242
+
243
+ pair<iterator, iterator> equal_range(const key_type& x);
244
+ pair<const_iterator, const_iterator> equal_range(const key_type& x) const;
245
+ template<class K> pair<iterator, iterator> equal_range(const K& x);
246
+ template<class K> pair<const_iterator, const_iterator> equal_range(const K& x) const;
247
+
248
+ friend bool operator==(const flat_map& x, const flat_map& y);
249
+
250
+ friend synth-three-way-result<value_type>
251
+ operator<=>(const flat_map& x, const flat_map& y);
252
+
253
+ friend void swap(flat_map& x, flat_map& y) noexcept
254
+ { x.swap(y); }
255
+
256
+ private:
257
+ containers c; // exposition only
258
+ key_compare compare; // exposition only
259
+
260
+ struct key_equiv { // exposition only
261
+ key_equiv(key_compare c) : comp(c) { }
262
+ bool operator()(const_reference x, const_reference y) const {
263
+ return !comp(x.first, y.first) && !comp(y.first, x.first);
264
+ }
265
+ key_compare comp;
266
+ };
267
+ };
268
+
269
+ template<class KeyContainer, class MappedContainer,
270
+ class Compare = less<typename KeyContainer::value_type>>
271
+ flat_map(KeyContainer, MappedContainer, Compare = Compare())
272
+ -> flat_map<typename KeyContainer::value_type, typename MappedContainer::value_type,
273
+ Compare, KeyContainer, MappedContainer>;
274
+
275
+ template<class KeyContainer, class MappedContainer, class Allocator>
276
+ flat_map(KeyContainer, MappedContainer, Allocator)
277
+ -> flat_map<typename KeyContainer::value_type, typename MappedContainer::value_type,
278
+ less<typename KeyContainer::value_type>, KeyContainer, MappedContainer>;
279
+ template<class KeyContainer, class MappedContainer, class Compare, class Allocator>
280
+ flat_map(KeyContainer, MappedContainer, Compare, Allocator)
281
+ -> flat_map<typename KeyContainer::value_type, typename MappedContainer::value_type,
282
+ Compare, KeyContainer, MappedContainer>;
283
+
284
+ template<class KeyContainer, class MappedContainer,
285
+ class Compare = less<typename KeyContainer::value_type>>
286
+ flat_map(sorted_unique_t, KeyContainer, MappedContainer, Compare = Compare())
287
+ -> flat_map<typename KeyContainer::value_type, typename MappedContainer::value_type,
288
+ Compare, KeyContainer, MappedContainer>;
289
+
290
+ template<class KeyContainer, class MappedContainer, class Allocator>
291
+ flat_map(sorted_unique_t, KeyContainer, MappedContainer, Allocator)
292
+ -> flat_map<typename KeyContainer::value_type, typename MappedContainer::value_type,
293
+ less<typename KeyContainer::value_type>, KeyContainer, MappedContainer>;
294
+ template<class KeyContainer, class MappedContainer, class Compare, class Allocator>
295
+ flat_map(sorted_unique_t, KeyContainer, MappedContainer, Compare, Allocator)
296
+ -> flat_map<typename KeyContainer::value_type, typename MappedContainer::value_type,
297
+ Compare, KeyContainer, MappedContainer>;
298
+
299
+ template<class InputIterator, class Compare = less<iter-key-type<InputIterator>>>
300
+ flat_map(InputIterator, InputIterator, Compare = Compare())
301
+ -> flat_map<iter-key-type<InputIterator>, iter-mapped-type<InputIterator>, Compare>;
302
+
303
+ template<class InputIterator, class Compare = less<iter-key-type<InputIterator>>>
304
+ flat_map(sorted_unique_t, InputIterator, InputIterator, Compare = Compare())
305
+ -> flat_map<iter-key-type<InputIterator>, iter-mapped-type<InputIterator>, Compare>;
306
+
307
+ template<ranges::input_range R, class Compare = less<range-key-type<R>>,
308
+ class Allocator = allocator<byte>>
309
+ flat_map(from_range_t, R&&, Compare = Compare(), Allocator = Allocator())
310
+ -> flat_map<range-key-type<R>, range-mapped-type<R>, Compare,
311
+ vector<range-key-type<R>, alloc-rebind<Allocator, range-key-type<R>>>,
312
+ vector<range-mapped-type<R>, alloc-rebind<Allocator, range-mapped-type<R>>>>;
313
+
314
+ template<ranges::input_range R, class Allocator>
315
+ flat_map(from_range_t, R&&, Allocator)
316
+ -> flat_map<range-key-type<R>, range-mapped-type<R>, less<range-key-type<R>>,
317
+ vector<range-key-type<R>, alloc-rebind<Allocator, range-key-type<R>>>,
318
+ vector<range-mapped-type<R>, alloc-rebind<Allocator, range-mapped-type<R>>>>;
319
+
320
+ template<class Key, class T, class Compare = less<Key>>
321
+ flat_map(initializer_list<pair<Key, T>>, Compare = Compare())
322
+ -> flat_map<Key, T, Compare>;
323
+
324
+ template<class Key, class T, class Compare = less<Key>>
325
+ flat_map(sorted_unique_t, initializer_list<pair<Key, T>>, Compare = Compare())
326
+ -> flat_map<Key, T, Compare>;
327
+
328
+ template<class Key, class T, class Compare, class KeyContainer, class MappedContainer,
329
+ class Allocator>
330
+ struct uses_allocator<flat_map<Key, T, Compare, KeyContainer, MappedContainer>, Allocator>
331
+ : bool_constant<uses_allocator_v<KeyContainer, Allocator> &&
332
+ uses_allocator_v<MappedContainer, Allocator>> { };
333
+ }
334
+ ```
335
+
336
+ The member type `containers` has the data members and special members
337
+ specified above. It has no base classes or members other than those
338
+ specified.
339
+