From Jason Turner

[hive]

Diff to HTML by rtfpessoa

Files changed (1) hide show
  1. tmp/tmplhby6pw6/{from.md → to.md} +736 -0
tmp/tmplhby6pw6/{from.md → to.md} RENAMED
@@ -0,0 +1,736 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ### Class template `hive` <a id="hive">[[hive]]</a>
2
+
3
+ #### Overview <a id="hive.overview">[[hive.overview]]</a>
4
+
5
+ A `hive` is a type of sequence container that provides constant-time
6
+ insertion and erasure operations. Storage is automatically managed in
7
+ multiple memory blocks, referred to as *element blocks*. Insertion
8
+ position is determined by the container, and insertion may re-use the
9
+ memory locations of erased elements.
10
+
11
+ Element blocks which contain elements are referred to as *active
12
+ blocks*, those which do not are referred to as *reserved blocks*. Active
13
+ blocks which become empty of elements are either deallocated or become
14
+ reserved blocks. Reserved blocks become active blocks when they are used
15
+ to store elements. A user can create additional reserved blocks by
16
+ calling `reserve`.
17
+
18
+ Erasures use unspecified techniques of constant time complexity to
19
+ identify the memory locations of erased elements, which are subsequently
20
+ skipped during iteration, as opposed to relocating subsequent elements
21
+ during erasure.
22
+
23
+ Active block capacities have an *implementation-defined* growth factor
24
+ (which need not be integral), for example a new active block’s capacity
25
+ could be equal to the summed capacities of the pre-existing active
26
+ blocks.
27
+
28
+ Limits can be placed on both the minimum and maximum element capacities
29
+ of element blocks, both by users and implementations.
30
+
31
+ - The minimum limit shall be no larger than the maximum limit.
32
+ - When limits are not specified by a user during construction, the
33
+ implementation’s default limits are used.
34
+ - The default limits of an implementation are not guaranteed to be the
35
+ same as the minimum and maximum possible capacities for an
36
+ implementation’s element blocks. \[*Note 1*: To allow latitude for
37
+ both implementation-specific and user-directed
38
+ optimization. — *end note*] The latter are defined as hard limits.
39
+ The maximum hard limit shall be no larger than
40
+ `std::allocator_traits<Allocator>::max_size()`.
41
+ - If user-specified limits are not within hard limits, or if the
42
+ specified minimum limit is greater than the specified maximum limit,
43
+ the behavior is undefined.
44
+ - An element block is said to be *within the bounds* of a pair of
45
+ minimum/maximum limits when its capacity is greater-or-equal-to the
46
+ minimum limit and less-than-or-equal-to the maximum limit.
47
+
48
+ A `hive` conforms to the requirements for containers
49
+ [[container.reqmts]], with the exception of operators `==` and `!=`. A
50
+ `hive` also meets the requirements of a reversible container
51
+ [[container.rev.reqmts]], of an allocator-aware container
52
+ [[container.alloc.reqmts]], and some of the requirements of a sequence
53
+ container [[sequence.reqmts]]. Descriptions are provided here only for
54
+ operations on `hive` that are not described in that table or for
55
+ operations where there is additional semantic information.
56
+
57
+ The iterators of `hive` meet the *Cpp17BidirectionalIterator*
58
+ requirements but also model `three_way_comparable<strong_ordering>`.
59
+
60
+ ``` cpp
61
+ namespace std {
62
+ template<class T, class Allocator = allocator<T>>
63
+ class hive {
64
+ public:
65
+ // types
66
+ using value_type = T;
67
+ using allocator_type = Allocator;
68
+ using pointer = allocator_traits<Allocator>::pointer;
69
+ using const_pointer = allocator_traits<Allocator>::const_pointer;
70
+ using reference = value_type&;
71
+ using const_reference = const value_type&;
72
+ using size_type = implementation-defined; // see [container.requirements]
73
+ using difference_type = implementation-defined; // see [container.requirements]
74
+ using iterator = implementation-defined; // see [container.requirements]
75
+ using const_iterator = implementation-defined; // see [container.requirements]
76
+ using reverse_iterator = std::reverse_iterator<iterator>; // see [container.requirements]
77
+ using const_reverse_iterator = std::reverse_iterator<const_iterator>; // see [container.requirements]
78
+
79
+ // [hive.cons], construct/copy/destroy
80
+ constexpr hive() noexcept(noexcept(Allocator())) : hive(Allocator()) {}
81
+ constexpr explicit hive(const Allocator&) noexcept;
82
+ constexpr explicit hive(hive_limits block_limits) : hive(block_limits, Allocator()) {}
83
+ constexpr hive(hive_limits block_limits, const Allocator&);
84
+ explicit hive(size_type n, const Allocator& = Allocator());
85
+ hive(size_type n, hive_limits block_limits, const Allocator& = Allocator());
86
+ hive(size_type n, const T& value, const Allocator& = Allocator());
87
+ hive(size_type n, const T& value, hive_limits block_limits, const Allocator& = Allocator());
88
+ template<class InputIterator>
89
+ hive(InputIterator first, InputIterator last, const Allocator& = Allocator());
90
+ template<class InputIterator>
91
+ hive(InputIterator first, InputIterator last, hive_limits block_limits,
92
+ const Allocator& = Allocator());
93
+ template<container-compatible-range<T> R>
94
+ hive(from_range_t, R&& rg, const Allocator& = Allocator());
95
+ template<container-compatible-range<T> R>
96
+ hive(from_range_t, R&& rg, hive_limits block_limits, const Allocator& = Allocator());
97
+ hive(const hive& x);
98
+ hive(hive&&) noexcept;
99
+ hive(const hive& x, const type_identity_t<Allocator>& alloc);
100
+ hive(hive&&, const type_identity_t<Allocator>& alloc);
101
+ hive(initializer_list<T> il, const Allocator& = Allocator());
102
+ hive(initializer_list<T> il, hive_limits block_limits, const Allocator& = Allocator());
103
+ ~hive();
104
+
105
+ hive& operator=(const hive& x);
106
+ hive& operator=(hive&& x) noexcept(see below);
107
+ hive& operator=(initializer_list<T>);
108
+ template<class InputIterator>
109
+ void assign(InputIterator first, InputIterator last);
110
+ template<container-compatible-range<T> R>
111
+ void assign_range(R&& rg);
112
+ void assign(size_type n, const T& t);
113
+ void assign(initializer_list<T>);
114
+ allocator_type get_allocator() const noexcept;
115
+
116
+ // iterators
117
+ iterator begin() noexcept;
118
+ const_iterator begin() const noexcept;
119
+ iterator end() noexcept;
120
+ const_iterator end() const noexcept;
121
+ reverse_iterator rbegin() noexcept;
122
+ const_reverse_iterator rbegin() const noexcept;
123
+ reverse_iterator rend() noexcept;
124
+ const_reverse_iterator rend() const noexcept;
125
+ const_iterator cbegin() const noexcept;
126
+ const_iterator cend() const noexcept;
127
+ const_reverse_iterator crbegin() const noexcept;
128
+ const_reverse_iterator crend() const noexcept;
129
+
130
+ // [hive.capacity], capacity
131
+ bool empty() const noexcept;
132
+ size_type size() const noexcept;
133
+ size_type max_size() const noexcept;
134
+ size_type capacity() const noexcept;
135
+ void reserve(size_type n);
136
+ void shrink_to_fit();
137
+ void trim_capacity() noexcept;
138
+ void trim_capacity(size_type n) noexcept;
139
+ constexpr hive_limits block_capacity_limits() const noexcept;
140
+ static constexpr hive_limits block_capacity_default_limits() noexcept;
141
+ static constexpr hive_limits block_capacity_hard_limits() noexcept;
142
+ void reshape(hive_limits block_limits);
143
+
144
+ // [hive.modifiers], modifiers
145
+ template<class... Args> iterator emplace(Args&&... args);
146
+ template<class... Args> iterator emplace_hint(const_iterator hint, Args&&... args);
147
+ iterator insert(const T& x);
148
+ iterator insert(T&& x);
149
+ iterator insert(const_iterator hint, const T& x);
150
+ iterator insert(const_iterator hint, T&& x);
151
+ void insert(initializer_list<T> il);
152
+ template<container-compatible-range<T> R>
153
+ void insert_range(R&& rg);
154
+ template<class InputIterator>
155
+ void insert(InputIterator first, InputIterator last);
156
+ void insert(size_type n, const T& x);
157
+
158
+ iterator erase(const_iterator position);
159
+ iterator erase(const_iterator first, const_iterator last);
160
+ void swap(hive&) noexcept(see below);
161
+ void clear() noexcept;
162
+
163
+ // [hive.operations], hive operations
164
+ void splice(hive& x);
165
+ void splice(hive&& x);
166
+ template<class BinaryPredicate = equal_to<T>>
167
+ size_type unique(BinaryPredicate binary_pred = BinaryPredicate());
168
+
169
+ template<class Compare = less<T>>
170
+ void sort(Compare comp = Compare());
171
+
172
+ iterator get_iterator(const_pointer p) noexcept;
173
+ const_iterator get_iterator(const_pointer p) const noexcept;
174
+
175
+ private:
176
+ hive_limits current-limits = implementation-defined; // exposition only
177
+ };
178
+
179
+ template<class InputIterator, class Allocator = allocator<iter-value-type<InputIterator>>>
180
+ hive(InputIterator, InputIterator, Allocator = Allocator())
181
+ -> hive<iter-value-type<InputIterator>, Allocator>;
182
+
183
+ template<class InputIterator, class Allocator = allocator<iter-value-type<InputIterator>>>
184
+ hive(InputIterator, InputIterator, hive_limits, Allocator = Allocator())
185
+ -> hive<iter-value-type<InputIterator>, Allocator>;
186
+
187
+ template<ranges::input_range R, class Allocator = allocator<ranges::range_value_t<R>>>
188
+ hive(from_range_t, R&&, Allocator = Allocator())
189
+ -> hive<ranges::range_value_t<R>, Allocator>;
190
+
191
+ template<ranges::input_range R, class Allocator = allocator<ranges::range_value_t<R>>>
192
+ hive(from_range_t, R&&, hive_limits, Allocator = Allocator())
193
+ -> hive<ranges::range_value_t<R>, Allocator>;
194
+ }
195
+ ```
196
+
197
+ #### Constructors, copy, and assignment <a id="hive.cons">[[hive.cons]]</a>
198
+
199
+ ``` cpp
200
+ constexpr explicit hive(const Allocator&) noexcept;
201
+ ```
202
+
203
+ *Effects:* Constructs an empty `hive`, using the specified allocator.
204
+
205
+ *Complexity:* Constant.
206
+
207
+ ``` cpp
208
+ constexpr hive(hive_limits block_limits, const Allocator&);
209
+ ```
210
+
211
+ *Effects:* Constructs an empty `hive`, using the specified allocator.
212
+ Initializes *current-limits* with `block_limits`.
213
+
214
+ *Complexity:* Constant.
215
+
216
+ ``` cpp
217
+ explicit hive(size_type n, const Allocator& = Allocator());
218
+ hive(size_type n, hive_limits block_limits, const Allocator& = Allocator());
219
+ ```
220
+
221
+ *Preconditions:* `T` is *Cpp17DefaultInsertable* into `hive`.
222
+
223
+ *Effects:* Constructs a `hive` with `n` default-inserted elements, using
224
+ the specified allocator. If the second overload is called, also
225
+ initializes *current-limits* with `block_limits`.
226
+
227
+ *Complexity:* Linear in `n`.
228
+
229
+ ``` cpp
230
+ hive(size_type n, const T& value, const Allocator& = Allocator());
231
+ hive(size_type n, const T& value, hive_limits block_limits, const Allocator& = Allocator());
232
+ ```
233
+
234
+ *Preconditions:* `T` is *Cpp17CopyInsertable* into `hive`.
235
+
236
+ *Effects:* Constructs a `hive` with `n` copies of `value`, using the
237
+ specified allocator. If the second overload is called, also initializes
238
+ *current-limits* with `block_limits`.
239
+
240
+ *Complexity:* Linear in `n`.
241
+
242
+ ``` cpp
243
+ template<class InputIterator>
244
+ hive(InputIterator first, InputIterator last, const Allocator& = Allocator());
245
+ template<class InputIterator>
246
+ hive(InputIterator first, InputIterator last, hive_limits block_limits,
247
+ const Allocator& = Allocator());
248
+ ```
249
+
250
+ *Effects:* Constructs a `hive` equal to the range \[`first`, `last`),
251
+ using the specified allocator. If the second overload is called, also
252
+ initializes *current-limits* with `block_limits`.
253
+
254
+ *Complexity:* Linear in `distance(first, last)`.
255
+
256
+ ``` cpp
257
+ template<container-compatible-range<T> R>
258
+ hive(from_range_t, R&& rg, const Allocator& = Allocator());
259
+ template<container-compatible-range<T> R>
260
+ hive(from_range_t, R&& rg, hive_limits block_limits, const Allocator& = Allocator());
261
+ ```
262
+
263
+ *Effects:* Constructs a `hive` object with the elements of the range
264
+ `rg`, using the specified allocator. If the second overload is called,
265
+ also initializes *current-limits* with `block_limits`.
266
+
267
+ *Complexity:* Linear in `ranges::distance(rg)`.
268
+
269
+ ``` cpp
270
+ hive(const hive& x);
271
+ hive(const hive& x, const type_identity_t<Allocator>& alloc);
272
+ ```
273
+
274
+ *Preconditions:* `T` is *Cpp17CopyInsertable* into `hive`.
275
+
276
+ *Effects:* Constructs a `hive` object with the elements of `x`. If the
277
+ second overload is called, uses `alloc`. Initializes *current-limits*
278
+ with `x.`*`current-limits`*.
279
+
280
+ *Complexity:* Linear in `x.size()`.
281
+
282
+ ``` cpp
283
+ hive(hive&& x) noexcept;
284
+ hive(hive&& x, const type_identity_t<Allocator>& alloc);
285
+ ```
286
+
287
+ *Preconditions:* For the second overload, when
288
+ `allocator_traits<alloc>::is_always_equal::value` is `false`, `T` meets
289
+ the *Cpp17MoveInsertable* requirements.
290
+
291
+ *Effects:* When the first overload is called, or the second overload is
292
+ called and `alloc == x.get_allocator()` is `true`, *current-limits* is
293
+ set to `x.`*`current-limits`* and each element block is moved from `x`
294
+ into `*this`. Pointers and references to the elements of `x` now refer
295
+ to those same elements but as members of `*this`. Iterators referring to
296
+ the elements of `x` will continue to refer to their elements, but they
297
+ now behave as iterators into `*this`.
298
+
299
+ If the second overload is called and `alloc == x.get_allocator()` is
300
+ `false`, each element in `x` is moved into `*this`. References, pointers
301
+ and iterators referring to the elements of `x`, as well as the
302
+ past-the-end iterator of `x`, are invalidated.
303
+
304
+ *Ensures:* `x.empty()` is `true`.
305
+
306
+ *Complexity:* If the second overload is called and
307
+ `alloc == x.get_allocator()` is `false`, linear in `x.size()`. Otherwise
308
+ constant.
309
+
310
+ ``` cpp
311
+ hive(initializer_list<T> il, const Allocator& = Allocator());
312
+ hive(initializer_list<T> il, hive_limits block_limits, const Allocator& = Allocator());
313
+ ```
314
+
315
+ *Preconditions:* `T` is *Cpp17CopyInsertable* into `hive`.
316
+
317
+ *Effects:* Constructs a `hive` object with the elements of `il`, using
318
+ the specified allocator. If the second overload is called, also
319
+ initializes *current-limits* with `block_limits`.
320
+
321
+ *Complexity:* Linear in `il.size()`.
322
+
323
+ ``` cpp
324
+ hive& operator=(const hive& x);
325
+ ```
326
+
327
+ *Preconditions:* `T` is *Cpp17CopyInsertable* into `hive` and
328
+ *Cpp17CopyAssignable*.
329
+
330
+ *Effects:* All elements in `*this` are either copy-assigned to, or
331
+ destroyed. All elements in `x` are copied into `*this`.
332
+
333
+ [*Note 1*: *current-limits* is unchanged. — *end note*]
334
+
335
+ *Complexity:* Linear in `size() + x.size()`.
336
+
337
+ ``` cpp
338
+ hive& operator=(hive&& x)
339
+ noexcept(allocator_traits<Allocator>::propagate_on_container_move_assignment::value ||
340
+ allocator_traits<Allocator>::is_always_equal::value);
341
+ ```
342
+
343
+ *Preconditions:* When
344
+
345
+ ``` cpp
346
+ (allocator_traits<Allocator>::propagate_on_container_move_assignment::value ||
347
+ allocator_traits<Allocator>::is_always_equal::value)
348
+ ```
349
+
350
+ is `false`, `T` is *Cpp17MoveInsertable* into `hive` and
351
+ *Cpp17MoveAssignable*.
352
+
353
+ *Effects:* Each element in `*this` is either move-assigned to, or
354
+ destroyed. When
355
+
356
+ ``` cpp
357
+ (allocator_traits<Allocator>::propagate_on_container_move_assignment::value ||
358
+ get_allocator() == x.get_allocator())
359
+ ```
360
+
361
+ is `true`, *current-limits* is set to `x.`*`current-limits`* and each
362
+ element block is moved from `x` into `*this`. Pointers and references to
363
+ the elements of `x` now refer to those same elements but as members of
364
+ `*this`. Iterators referring to the elements of `x` will continue to
365
+ refer to their elements, but they now behave as iterators into `*this`,
366
+ not into `x`.
367
+
368
+ When
369
+
370
+ ``` cpp
371
+ (allocator_traits<Allocator>::propagate_on_container_move_assignment::value ||
372
+ get_allocator() == x.get_allocator())
373
+ ```
374
+
375
+ is `false`, each element in `x` is moved into `*this`. References,
376
+ pointers and iterators referring to the elements of `x`, as well as the
377
+ past-the-end iterator of `x`, are invalidated.
378
+
379
+ *Ensures:* `x.empty()` is `true`.
380
+
381
+ *Complexity:* Linear in `size()`. If
382
+
383
+ ``` cpp
384
+ (allocator_traits<Allocator>::propagate_on_container_move_assignment::value ||
385
+ get_allocator() == x.get_allocator())
386
+ ```
387
+
388
+ is `false`, also linear in `x.size()`.
389
+
390
+ #### Capacity <a id="hive.capacity">[[hive.capacity]]</a>
391
+
392
+ ``` cpp
393
+ size_type capacity() const noexcept;
394
+ ```
395
+
396
+ *Returns:* The total number of elements that `*this` can hold without
397
+ requiring allocation of more element blocks.
398
+
399
+ *Complexity:* Constant.
400
+
401
+ ``` cpp
402
+ void reserve(size_type n);
403
+ ```
404
+
405
+ *Effects:* If `n <= capacity()` is `true`, there are no effects.
406
+ Otherwise increases `capacity()` by allocating reserved blocks.
407
+
408
+ *Ensures:* `capacity() >= n` is `true`.
409
+
410
+ *Throws:* `length_error` if `n > max_size()`, as well as any exceptions
411
+ thrown by the allocator.
412
+
413
+ *Complexity:* Linear in the number of reserved blocks allocated.
414
+
415
+ *Remarks:* The size of the sequence is not changed. All references,
416
+ pointers, and iterators referring to elements in `*this`, as well as the
417
+ past-the-end iterator, remain valid.
418
+
419
+ ``` cpp
420
+ void shrink_to_fit();
421
+ ```
422
+
423
+ *Preconditions:* `T` is *Cpp17MoveInsertable* into `hive`.
424
+
425
+ *Effects:* `shrink_to_fit` is a non-binding request to reduce
426
+ `capacity()` to be closer to `size()`.
427
+
428
+ [*Note 1*: The request is non-binding to allow latitude for
429
+ implementation-specific optimizations. — *end note*]
430
+
431
+ It does not increase `capacity()`, but may reduce `capacity()`. It may
432
+ reallocate elements. If `capacity()` is already equal to `size()`, there
433
+ are no effects. If an exception is thrown during allocation of a new
434
+ element block, `capacity()` may be reduced and reallocation may occur.
435
+ Otherwise if an exception is thrown, the effects are unspecified.
436
+
437
+ *Complexity:* If reallocation happens, linear in the size of the
438
+ sequence.
439
+
440
+ *Remarks:* If reallocation happens, the order of the elements in `*this`
441
+ may change and all references, pointers, and iterators referring to the
442
+ elements in `*this`, as well as the past-the-end iterator, are
443
+ invalidated.
444
+
445
+ ``` cpp
446
+ void trim_capacity() noexcept;
447
+ void trim_capacity(size_type n) noexcept;
448
+ ```
449
+
450
+ *Effects:* For the first overload, all reserved blocks are deallocated,
451
+ and `capacity()` is reduced accordingly. For the second overload,
452
+ `capacity()` is reduced to no less than `n`.
453
+
454
+ *Complexity:* Linear in the number of reserved blocks deallocated.
455
+
456
+ *Remarks:* All references, pointers, and iterators referring to elements
457
+ in `*this`, as well as the past-the-end iterator, remain valid.
458
+
459
+ ``` cpp
460
+ constexpr hive_limits block_capacity_limits() const noexcept;
461
+ ```
462
+
463
+ *Returns:* *current-limits*.
464
+
465
+ *Complexity:* Constant.
466
+
467
+ ``` cpp
468
+ static constexpr hive_limits block_capacity_default_limits() noexcept;
469
+ ```
470
+
471
+ *Returns:* A `hive_limits` struct with the `min` and `max` members set
472
+ to the implementation’s default limits.
473
+
474
+ *Complexity:* Constant.
475
+
476
+ ``` cpp
477
+ static constexpr hive_limits block_capacity_hard_limits() noexcept;
478
+ ```
479
+
480
+ *Returns:* A `hive_limits` struct with the `min` and `max` members set
481
+ to the implementation’s hard limits.
482
+
483
+ *Complexity:* Constant.
484
+
485
+ ``` cpp
486
+ void reshape(hive_limits block_limits);
487
+ ```
488
+
489
+ *Preconditions:* `T` is *Cpp17MoveInsertable* into `hive`.
490
+
491
+ *Effects:* For any active blocks not within the bounds of
492
+ `block_limits`, the elements within those active blocks are reallocated
493
+ to new or existing element blocks which are within the bounds. Any
494
+ element blocks not within the bounds of `block_limits` are deallocated.
495
+ If an exception is thrown during allocation of a new element block,
496
+ `capacity()` may be reduced, reallocation may occur, and
497
+ *current-limits* may be assigned a value other than `block_limits`.
498
+ Otherwise `block_limits` is assigned to *current-limits*. If any other
499
+ exception is thrown the effects are unspecified.
500
+
501
+ *Ensures:* `size()` is unchanged.
502
+
503
+ *Complexity:* Linear in the number of element blocks in `*this`. If
504
+ reallocation happens, also linear in the number of elements reallocated.
505
+
506
+ *Remarks:* This operation may change `capacity()`. If reallocation
507
+ happens, the order of the elements in `*this` may change. Reallocation
508
+ invalidates all references, pointers, and iterators referring to the
509
+ elements in `*this`, as well as the past-the-end iterator.
510
+
511
+ [*Note 2*: If no reallocation happens, they remain
512
+ valid. — *end note*]
513
+
514
+ #### Modifiers <a id="hive.modifiers">[[hive.modifiers]]</a>
515
+
516
+ ``` cpp
517
+ template<class... Args> iterator emplace(Args&&... args);
518
+ template<class... Args> iterator emplace_hint(const_iterator hint, Args&&... args);
519
+ ```
520
+
521
+ *Preconditions:* `T` is *Cpp17EmplaceConstructible* into `hive` from
522
+ `args`.
523
+
524
+ *Effects:* Inserts an object of type `T` constructed with
525
+ `std::forward<Args>(args)...`. The `hint` parameter is ignored. If an
526
+ exception is thrown, there are no effects.
527
+
528
+ [*Note 1*: `args` can directly or indirectly refer to a value in
529
+ `*this`. — *end note*]
530
+
531
+ *Returns:* An iterator that points to the new element.
532
+
533
+ *Complexity:* Constant. Exactly one object of type `T` is constructed.
534
+
535
+ *Remarks:* Invalidates the past-the-end iterator.
536
+
537
+ ``` cpp
538
+ iterator insert(const T& x);
539
+ iterator insert(const_iterator hint, const T& x);
540
+ iterator insert(T&& x);
541
+ iterator insert(const_iterator hint, T&& x);
542
+ ```
543
+
544
+ *Effects:* Equivalent to:
545
+ `return emplace(std::forward<decltype(x)>(x));`
546
+
547
+ [*Note 2*: The `hint` parameter is ignored. — *end note*]
548
+
549
+ ``` cpp
550
+ void insert(initializer_list<T> rg);
551
+ template<container-compatible-range<T> R>
552
+ void insert_range(R&& rg);
553
+ ```
554
+
555
+ *Preconditions:* `T` is *Cpp17EmplaceInsertable* into `hive` from
556
+ `*ranges::begin(rg)`. `rg` and `*this` do not overlap.
557
+
558
+ *Effects:* Inserts copies of elements in `rg`. Each iterator in the
559
+ range `rg` is dereferenced exactly once.
560
+
561
+ *Complexity:* Linear in the number of elements inserted. Exactly one
562
+ object of type `T` is constructed for each element inserted.
563
+
564
+ *Remarks:* If an element is inserted, invalidates the past-the-end
565
+ iterator.
566
+
567
+ ``` cpp
568
+ void insert(size_type n, const T& x);
569
+ ```
570
+
571
+ *Preconditions:* `T` is *Cpp17CopyInsertable* into `hive`.
572
+
573
+ *Effects:* Inserts `n` copies of `x`.
574
+
575
+ *Complexity:* Linear in `n`. Exactly one object of type `T` is
576
+ constructed for each element inserted.
577
+
578
+ *Remarks:* If an element is inserted, invalidates the past-the-end
579
+ iterator.
580
+
581
+ ``` cpp
582
+ template<class InputIterator>
583
+ void insert(InputIterator first, InputIterator last);
584
+ ```
585
+
586
+ *Effects:* Equivalent to `insert_range(ranges::subrange(first, last))`.
587
+
588
+ ``` cpp
589
+ iterator erase(const_iterator position);
590
+ iterator erase(const_iterator first, const_iterator last);
591
+ ```
592
+
593
+ *Complexity:* Linear in the number of elements erased. Additionally, if
594
+ any active blocks become empty of elements as a result of the function
595
+ call, at worst linear in the number of element blocks.
596
+
597
+ *Remarks:* Invalidates references, pointers and iterators referring to
598
+ the erased elements. An erase operation that erases the last element in
599
+ `*this` also invalidates the past-the-end iterator.
600
+
601
+ ``` cpp
602
+ void swap(hive& x)
603
+ noexcept(allocator_traits<Allocator>::propagate_on_container_swap::value ||
604
+ allocator_traits<Allocator>::is_always_equal::value);
605
+ ```
606
+
607
+ *Effects:* Exchanges the contents, `capacity()`, and *current-limits* of
608
+ `*this` with that of `x`.
609
+
610
+ *Complexity:* Constant.
611
+
612
+ #### Operations <a id="hive.operations">[[hive.operations]]</a>
613
+
614
+ In this subclause, arguments for a template parameter named `Predicate`
615
+ or `BinaryPredicate` shall meet the corresponding requirements in
616
+ [[algorithms.requirements]]. The semantics of `i + n` and `i - n`, where
617
+ `i` is an iterator into the `hive` and `n` is an integer, are the same
618
+ as those of `next(i, n)` and `prev(i, n)`, respectively. For `sort`, the
619
+ definitions and requirements in [[alg.sorting]] apply.
620
+
621
+ ``` cpp
622
+ void splice(hive& x);
623
+ void splice(hive&& x);
624
+ ```
625
+
626
+ *Preconditions:* `get_allocator() == x.get_allocator()` is `true`.
627
+
628
+ *Effects:* If `addressof(x) == this` is `true`, the behavior is
629
+ erroneous and there are no effects. Otherwise, inserts the contents of
630
+ `x` into `*this` and `x` becomes empty. Pointers and references to the
631
+ moved elements of `x` now refer to those same elements but as members of
632
+ `*this`. Iterators referring to the moved elements continue to refer to
633
+ their elements, but they now behave as iterators into `*this`, not into
634
+ `x`.
635
+
636
+ *Throws:* `length_error` if any of `x`’s active blocks are not within
637
+ the bounds of *current-limits*.
638
+
639
+ *Complexity:* Linear in the sum of all element blocks in `x` plus all
640
+ element blocks in `*this`.
641
+
642
+ *Remarks:* Reserved blocks in `x` are not transferred into `*this`. If
643
+ `addressof(x) == this` is `false`, invalidates the past-the-end iterator
644
+ for both `x` and `*this`.
645
+
646
+ ``` cpp
647
+ template<class BinaryPredicate = equal_to<T>>
648
+ size_type unique(BinaryPredicate binary_pred = BinaryPredicate());
649
+ ```
650
+
651
+ *Preconditions:* `binary_pred` is an equivalence relation.
652
+
653
+ *Effects:* Erases all but the first element from every consecutive group
654
+ of equivalent elements. That is, for a nonempty `hive`, erases all
655
+ elements referred to by the iterator `i` in the range \[`begin() + 1`,
656
+ `end()`) for which `binary_pred(*i, *(i - 1))` is `true`.
657
+
658
+ *Returns:* The number of elements erased.
659
+
660
+ *Throws:* Nothing unless an exception is thrown by the predicate.
661
+
662
+ *Complexity:* If `empty()` is `false`, exactly `size() - 1` applications
663
+ of the corresponding predicate, otherwise no applications of the
664
+ predicate.
665
+
666
+ *Remarks:* Invalidates references, pointers, and iterators referring to
667
+ the erased elements. If the last element in `*this` is erased, also
668
+ invalidates the past-the-end iterator.
669
+
670
+ ``` cpp
671
+ template<class Compare = less<T>>
672
+ void sort(Compare comp = Compare());
673
+ ```
674
+
675
+ *Preconditions:* `T` is *Cpp17MoveInsertable* into `hive`,
676
+ *Cpp17MoveAssignable*, and *Cpp17Swappable*.
677
+
678
+ *Effects:* Sorts `*this` according to the `comp` function object. If an
679
+ exception is thrown, the order of the elements in `*this` is
680
+ unspecified.
681
+
682
+ *Complexity:* 𝑂(N log N) comparisons, where N is `size()`.
683
+
684
+ *Remarks:* May allocate. References, pointers, and iterators referring
685
+ to elements in `*this`, as well as the past-the-end iterator, may be
686
+ invalidated.
687
+
688
+ [*Note 1*: Not required to be
689
+ stable [[algorithm.stable]]. — *end note*]
690
+
691
+ ``` cpp
692
+ iterator get_iterator(const_pointer p) noexcept;
693
+ const_iterator get_iterator(const_pointer p) const noexcept;
694
+ ```
695
+
696
+ *Preconditions:* `p` points to an element in `*this`.
697
+
698
+ *Returns:* An `iterator` or `const_iterator` pointing to the same
699
+ element as `p`.
700
+
701
+ *Complexity:* Linear in the number of active blocks in `*this`.
702
+
703
+ #### Erasure <a id="hive.erasure">[[hive.erasure]]</a>
704
+
705
+ ``` cpp
706
+ template<class T, class Allocator, class U = T>
707
+ typename hive<T, Allocator>::size_type
708
+ erase(hive<T, Allocator>& c, const U& value);
709
+ ```
710
+
711
+ *Effects:* Equivalent to:
712
+
713
+ ``` cpp
714
+ return erase_if(c, [&](const auto& elem) -> bool { return elem == value; });
715
+ ```
716
+
717
+ ``` cpp
718
+ template<class T, class Allocator, class Predicate>
719
+ typename hive<T, Allocator>::size_type
720
+ erase_if(hive<T, Allocator>& c, Predicate pred);
721
+ ```
722
+
723
+ *Effects:* Equivalent to:
724
+
725
+ ``` cpp
726
+ auto original_size = c.size();
727
+ for (auto i = c.begin(), last = c.end(); i != last; ) {
728
+ if (pred(*i)) {
729
+ i = c.erase(i);
730
+ } else {
731
+ ++i;
732
+ }
733
+ }
734
+ return original_size - c.size();
735
+ ```
736
+