From Jason Turner

[flat.map.modifiers]

Diff to HTML by rtfpessoa

Files changed (1) hide show
  1. tmp/tmpisuy6fzx/{from.md → to.md} +318 -0
tmp/tmpisuy6fzx/{from.md → to.md} RENAMED
@@ -0,0 +1,318 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #### Modifiers <a id="flat.map.modifiers">[[flat.map.modifiers]]</a>
2
+
3
+ ``` cpp
4
+ template<class... Args> pair<iterator, bool> emplace(Args&&... args);
5
+ ```
6
+
7
+ *Constraints:*
8
+ `is_constructible_v<pair<key_type, mapped_type>, Args...>` is `true`.
9
+
10
+ *Effects:* Initializes an object `t` of type
11
+ `pair<key_type, mapped_type>` with `std::forward<Args>(args)...`; if the
12
+ map already contains an element whose key is equivalent to `t.first`,
13
+ `*this` is unchanged. Otherwise, equivalent to:
14
+
15
+ ``` cpp
16
+ auto key_it = ranges::upper_bound(c.keys, t.first, compare);
17
+ auto value_it = c.values.begin() + distance(c.keys.begin(), key_it);
18
+ c.keys.insert(key_it, std::move(t.first));
19
+ c.values.insert(value_it, std::move(t.second));
20
+ ```
21
+
22
+ *Returns:* The `bool` component of the returned pair is `true` if and
23
+ only if the insertion took place, and the iterator component of the pair
24
+ points to the element with key equivalent to `t.first`.
25
+
26
+ ``` cpp
27
+ template<class P> pair<iterator, bool> insert(P&& x);
28
+ template<class P> iterator insert(const_iterator position, P&& x);
29
+ ```
30
+
31
+ *Constraints:* `is_constructible_v<pair<key_type, mapped_type>, P>` is
32
+ `true`.
33
+
34
+ *Effects:* The first form is equivalent to
35
+ `return emplace(std::forward<P>(x));`. The second form is equivalent to
36
+ `return emplace_hint(position, std::forward<P>(x));`.
37
+
38
+ ``` cpp
39
+ template<class InputIterator>
40
+ void insert(InputIterator first, InputIterator last);
41
+ ```
42
+
43
+ *Effects:* Adds elements to `c` as if by:
44
+
45
+ ``` cpp
46
+ for (; first != last; ++first) {
47
+ value_type value = *first;
48
+ c.keys.insert(c.keys.end(), std::move(value.first));
49
+ c.values.insert(c.values.end(), std::move(value.second));
50
+ }
51
+ ```
52
+
53
+ Then, sorts the range of newly inserted elements with respect to
54
+ `value_comp()`; merges the resulting sorted range and the sorted range
55
+ of pre-existing elements into a single sorted range; and finally erases
56
+ the duplicate elements as if by:
57
+
58
+ ``` cpp
59
+ auto zv = ranges::zip_view(c.keys, c.values);
60
+ auto it = ranges::unique(zv, key_equiv(compare)).begin();
61
+ auto dist = distance(zv.begin(), it);
62
+ c.keys.erase(c.keys.begin() + dist, c.keys.end());
63
+ c.values.erase(c.values.begin() + dist, c.values.end());
64
+ ```
65
+
66
+ *Complexity:* N + M log M, where N is `size()` before the operation and
67
+ M is `distance(first, last)`.
68
+
69
+ *Remarks:* Since this operation performs an in-place merge, it may
70
+ allocate memory.
71
+
72
+ ``` cpp
73
+ template<class InputIterator>
74
+ void insert(sorted_unique_t, InputIterator first, InputIterator last);
75
+ ```
76
+
77
+ *Effects:* Adds elements to `c` as if by:
78
+
79
+ ``` cpp
80
+ for (; first != last; ++first) {
81
+ value_type value = *first;
82
+ c.keys.insert(c.keys.end(), std::move(value.first));
83
+ c.values.insert(c.values.end(), std::move(value.second));
84
+ }
85
+ ```
86
+
87
+ Then, merges the sorted range of newly added elements and the sorted
88
+ range of pre-existing elements into a single sorted range; and finally
89
+ erases the duplicate elements as if by:
90
+
91
+ ``` cpp
92
+ auto zv = ranges::zip_view(c.keys, c.values);
93
+ auto it = ranges::unique(zv, key_equiv(compare)).begin();
94
+ auto dist = distance(zv.begin(), it);
95
+ c.keys.erase(c.keys.begin() + dist, c.keys.end());
96
+ c.values.erase(c.values.begin() + dist, c.values.end());
97
+ ```
98
+
99
+ *Complexity:* Linear in N, where N is `size()` after the operation.
100
+
101
+ *Remarks:* Since this operation performs an in-place merge, it may
102
+ allocate memory.
103
+
104
+ ``` cpp
105
+ template<container-compatible-range<value_type> R>
106
+ void insert_range(R&& rg);
107
+ ```
108
+
109
+ *Effects:* Adds elements to `c` as if by:
110
+
111
+ ``` cpp
112
+ for (const auto& e : rg) {
113
+ c.keys.insert(c.keys.end(), e.first);
114
+ c.values.insert(c.values.end(), e.second);
115
+ }
116
+ ```
117
+
118
+ Then, sorts the range of newly inserted elements with respect to
119
+ `value_comp()`; merges the resulting sorted range and the sorted range
120
+ of pre-existing elements into a single sorted range; and finally erases
121
+ the duplicate elements as if by:
122
+
123
+ ``` cpp
124
+ auto zv = ranges::zip_view(c.keys, c.values);
125
+ auto it = ranges::unique(zv, key_equiv(compare)).begin();
126
+ auto dist = distance(zv.begin(), it);
127
+ c.keys.erase(c.keys.begin() + dist, c.keys.end());
128
+ c.values.erase(c.values.begin() + dist, c.values.end());
129
+ ```
130
+
131
+ *Complexity:* N + M log M, where N is `size()` before the operation and
132
+ M is `ranges::distance(rg)`.
133
+
134
+ *Remarks:* Since this operation performs an in-place merge, it may
135
+ allocate memory.
136
+
137
+ ``` cpp
138
+ template<class... Args>
139
+ pair<iterator, bool> try_emplace(const key_type& k, Args&&... args);
140
+ template<class... Args>
141
+ pair<iterator, bool> try_emplace(key_type&& k, Args&&... args);
142
+ template<class... Args>
143
+ iterator try_emplace(const_iterator hint, const key_type& k, Args&&... args);
144
+ template<class... Args>
145
+ iterator try_emplace(const_iterator hint, key_type&& k, Args&&... args);
146
+ ```
147
+
148
+ *Constraints:* `is_constructible_v<mapped_type, Args...>` is `true`.
149
+
150
+ *Effects:* If the map already contains an element whose key is
151
+ equivalent to `k`, `*this` and `args...` are unchanged. Otherwise
152
+ equivalent to:
153
+
154
+ ``` cpp
155
+ auto key_it = ranges::upper_bound(c.keys, k, compare);
156
+ auto value_it = c.values.begin() + distance(c.keys.begin(), key_it);
157
+ c.keys.insert(key_it, std::forward<decltype(k)>(k));
158
+ c.values.emplace(value_it, std::forward<Args>(args)...);
159
+ ```
160
+
161
+ *Returns:* In the first two overloads, the `bool` component of the
162
+ returned pair is `true` if and only if the insertion took place. The
163
+ returned iterator points to the map element whose key is equivalent to
164
+ `k`.
165
+
166
+ *Complexity:* The same as `emplace` for the first two overloads, and the
167
+ same as `emplace_hint` for the last two overloads.
168
+
169
+ ``` cpp
170
+ template<class K, class... Args>
171
+ pair<iterator, bool> try_emplace(K&& k, Args&&... args);
172
+ template<class K, class... Args>
173
+ iterator try_emplace(const_iterator hint, K&& k, Args&&... args);
174
+ ```
175
+
176
+ *Constraints:*
177
+
178
+ - The *qualified-id* `Compare::is_transparent` is valid and denotes a
179
+ type.
180
+ - `is_constructible_v<key_type, K>` is `true`.
181
+ - `is_constructible_v<mapped_type, Args...>` is `true`.
182
+ - For the first overload, `is_convertible_v<K&&, const_iterator>` and
183
+ `is_convertible_v<K&&, iterator>` are both `false`.
184
+
185
+ *Preconditions:* The conversion from `k` into `key_type` constructs an
186
+ object `u`, for which `find(k) == find(u)` is `true`.
187
+
188
+ *Effects:* If the map already contains an element whose key is
189
+ equivalent to `k`, `*this` and `args...` are unchanged. Otherwise
190
+ equivalent to:
191
+
192
+ ``` cpp
193
+ auto key_it = ranges::upper_bound(c.keys, k, compare);
194
+ auto value_it = c.values.begin() + distance(c.keys.begin(), key_it);
195
+ c.keys.emplace(key_it, std::forward<K>(k));
196
+ c.values.emplace(value_it, std::forward<Args>(args)...);
197
+ ```
198
+
199
+ *Returns:* In the first overload, the `bool` component of the returned
200
+ pair is `true` if and only if the insertion took place. The returned
201
+ iterator points to the map element whose key is equivalent to `k`.
202
+
203
+ *Complexity:* The same as `emplace` and `emplace_hint`, respectively.
204
+
205
+ ``` cpp
206
+ template<class M>
207
+ pair<iterator, bool> insert_or_assign(const key_type& k, M&& obj);
208
+ template<class M>
209
+ pair<iterator, bool> insert_or_assign(key_type&& k, M&& obj);
210
+ template<class M>
211
+ iterator insert_or_assign(const_iterator hint, const key_type& k, M&& obj);
212
+ template<class M>
213
+ iterator insert_or_assign(const_iterator hint, key_type&& k, M&& obj);
214
+ ```
215
+
216
+ *Constraints:* `is_assignable_v<mapped_type&, M>` is `true` and
217
+ `is_constructible_v<mapped_type, M>` is `true`.
218
+
219
+ *Effects:* If the map already contains an element `e` whose key is
220
+ equivalent to `k`, assigns `std::forward<M>(obj)` to `e.second`.
221
+ Otherwise, equivalent to
222
+
223
+ ``` cpp
224
+ try_emplace(std::forward<decltype(k)>(k), std::forward<M>(obj))
225
+ ```
226
+
227
+ for the first two overloads or
228
+
229
+ ``` cpp
230
+ try_emplace(hint, std::forward<decltype(k)>(k), std::forward<M>(obj))
231
+ ```
232
+
233
+ for the last two overloads.
234
+
235
+ *Returns:* In the first two overloads, the `bool` component of the
236
+ returned pair is `true` if and only if the insertion took place. The
237
+ returned iterator points to the map element whose key is equivalent to
238
+ `k`.
239
+
240
+ *Complexity:* The same as `emplace` for the first two overloads and the
241
+ same as `emplace_hint` for the last two overloads.
242
+
243
+ ``` cpp
244
+ template<class K, class M>
245
+ pair<iterator, bool> insert_or_assign(K&& k, M&& obj);
246
+ template<class K, class M>
247
+ iterator insert_or_assign(const_iterator hint, K&& k, M&& obj);
248
+ ```
249
+
250
+ *Constraints:*
251
+
252
+ - The *qualified-id* `Compare::is_transparent` is valid and denotes a
253
+ type.
254
+ - `is_constructible_v<key_type, K>` is `true`.
255
+ - `is_assignable_v<mapped_type&, M>` is `true`.
256
+ - `is_constructible_v<mapped_type, M>` is `true`.
257
+
258
+ *Preconditions:* The conversion from `k` into `key_type` constructs an
259
+ object `u`, for which `find(k) == find(u)` is `true`.
260
+
261
+ *Effects:* If the map already contains an element `e` whose key is
262
+ equivalent to `k`, assigns `std::forward<M>(obj)` to `e.second`.
263
+ Otherwise, equivalent to
264
+
265
+ ``` cpp
266
+ try_emplace(std::forward<K>(k), std::forward<M>(obj))
267
+ ```
268
+
269
+ for the first overload or
270
+
271
+ ``` cpp
272
+ try_emplace(hint, std::forward<K>(k), std::forward<M>(obj))
273
+ ```
274
+
275
+ for the second overload.
276
+
277
+ *Returns:* In the first overload, the `bool` component of the returned
278
+ pair is `true` if and only if the insertion took place. The returned
279
+ iterator points to the map element whose key is equivalent to `k`.
280
+
281
+ *Complexity:* The same as `emplace` and `emplace_hint`, respectively.
282
+
283
+ ``` cpp
284
+ void swap(flat_map& y) noexcept;
285
+ ```
286
+
287
+ *Effects:* Equivalent to:
288
+
289
+ ``` cpp
290
+ ranges::swap(compare, y.compare);
291
+ ranges::swap(c.keys, y.c.keys);
292
+ ranges::swap(c.values, y.c.values);
293
+ ```
294
+
295
+ ``` cpp
296
+ containers extract() &&;
297
+ ```
298
+
299
+ *Ensures:* `*this` is emptied, even if the function exits via an
300
+ exception.
301
+
302
+ *Returns:* `std::move(c)`.
303
+
304
+ ``` cpp
305
+ void replace(key_container_type&& key_cont, mapped_container_type&& mapped_cont);
306
+ ```
307
+
308
+ *Preconditions:* `key_cont.size() == mapped_cont.size()` is `true`, the
309
+ elements of `key_cont` are sorted with respect to `compare`, and
310
+ `key_cont` contains no equal elements.
311
+
312
+ *Effects:* Equivalent to:
313
+
314
+ ``` cpp
315
+ c.keys = std::move(key_cont);
316
+ c.values = std::move(mapped_cont);
317
+ ```
318
+