|
| 1 | +<?xml version='1.0' encoding='utf-8' standalone='no'?> |
| 2 | +<!DOCTYPE issue SYSTEM "lwg-issue.dtd"> |
| 3 | + |
| 4 | +<issue num="4380" status="New"> |
| 5 | +<title>`hive::reserve()` complexity does not reflect potential deallocation of blocks |
| 6 | +</title> |
| 7 | +<section> |
| 8 | +<sref ref="[hive.capacity]"/> |
| 9 | +</section> |
| 10 | +<submitter>Matt Bentley</submitter> |
| 11 | +<date>23 Sep 2025</date> |
| 12 | +<priority>99</priority> |
| 13 | + |
| 14 | +<discussion> |
| 15 | +<p> |
| 16 | +As noted by Arthur in issue <iref ref="4379"/>, `reserve(n)` could choose to deallocate some |
| 17 | +reserved (empty) blocks if in doing so it could then allocate blocks which brought `capacity()` |
| 18 | +closer to `n`. |
| 19 | +<p/> |
| 20 | +For example if `capacity()` is `460`, `n` is `480`, the <tt><i>current-limits</i>.min</tt> is |
| 21 | +`40` and there is a reserved block of capacity `70`, the latter could be deallocated and a |
| 22 | +new reserved block allocated of capacity `90`, bringing total capacity to `480`. As opposed |
| 23 | +to allocating a new reserved block at the min capacity of `40`, bringing the total capacity |
| 24 | +to `500`. |
| 25 | +<p/> |
| 26 | +The implicit assumption in this issue is that we want `reserve()` to be able to deallocate. |
| 27 | +No-one has objected to this before, but if you want to, please speak up. |
| 28 | +<p/> |
| 29 | +Anyway, the <i>Complexity</i> of `reserve()` does not presently reflect this ability. |
| 30 | +</p> |
| 31 | +</discussion> |
| 32 | + |
| 33 | +<resolution> |
| 34 | +<p> |
| 35 | +This wording is relative to <paper num="N5014"/>. |
| 36 | +</p> |
| 37 | + |
| 38 | +<ol> |
| 39 | + |
| 40 | + |
| 41 | +<li><p>Modify <sref ref="[hive.capacity]"/> as indicated:</p> |
| 42 | + |
| 43 | +<blockquote> |
| 44 | +<pre> |
| 45 | +void reserve(size_type n); |
| 46 | +</pre> |
| 47 | +<blockquote> |
| 48 | +<p> |
| 49 | +-3- <i>Effects</i>: If <tt>n <= capacity()</tt> is `true`, there are no effects. Otherwise increases |
| 50 | +`capacity()` by allocating reserved blocks. |
| 51 | +<p/> |
| 52 | +-4- <i>Postconditions</i>: <tt>capacity() >= n</tt> is `true`. |
| 53 | +<p/> |
| 54 | +-5- <i>Throws</i>: `length_error` if `n` <tt>> max_size()</tt>, as well as any exceptions |
| 55 | +thrown by the allocator. |
| 56 | +<p/> |
| 57 | +-6- <i>Complexity</i>: It does not change the size of the sequence and takes at most linear time in the number of |
| 58 | +reserved blocks allocated <ins>and deallocated</ins>. |
| 59 | +<p/> |
| 60 | +-7- <i>Remarks</i>: All references, pointers, and iterators referring to elements in `*this`, as well as the |
| 61 | +past-the-end iterator, remain valid. |
| 62 | +</p> |
| 63 | +</blockquote> |
| 64 | +</blockquote> |
| 65 | + |
| 66 | +</li> |
| 67 | + |
| 68 | +</ol> |
| 69 | +</resolution> |
| 70 | + |
| 71 | +</issue> |
0 commit comments