|
| 1 | +<?xml version='1.0' encoding='utf-8' standalone='no'?> |
| 2 | +<!DOCTYPE issue SYSTEM "lwg-issue.dtd"> |
| 3 | + |
| 4 | +<issue num="4379" status="New"> |
| 5 | +<title>`hive::reserve()` needs <i>Throws:</i> element adjusted to match block min/max considerations</title> |
| 6 | +<section> |
| 7 | +<sref ref="[hive.capacity]"/> |
| 8 | +</section> |
| 9 | +<submitter>Matt Bentley</submitter> |
| 10 | +<date>17 Sep 2025</date> |
| 11 | +<priority>99</priority> |
| 12 | + |
| 13 | +<discussion> |
| 14 | +<p> |
| 15 | +This issue comes from Bloomberg as part of their C++26 comments via Incits. To summarize their case, in a |
| 16 | +call to `reserve(n)`, |
| 17 | +</p> |
| 18 | +<blockquote> |
| 19 | +<pre> |
| 20 | +if (n > capacity() && capacity() + <i>current-limits</i>.min > max_size()), |
| 21 | +</pre> |
| 22 | +</blockquote> |
| 23 | +<p> |
| 24 | +`reserve` should throw, e.g when `max_size=100`, `capacity=80`, <tt><i>current-limits</i>.min</tt> and |
| 25 | +<tt><i>current-limits</i>.max</tt> are `40` and `n=90`. |
| 26 | +<p/> |
| 27 | +In addition, in the above scenario if we increase `max_size()` to 140 and `n` to 130, |
| 28 | +we can see that although we could add one block with a capacity of <tt><i>current-limits</i>.min</tt>, |
| 29 | +adding another would be impossible; we still cannot make <tt>capacity >= n</tt> without also |
| 30 | +being <tt>>= max_size</tt>. |
| 31 | +<p/> |
| 32 | +This is currently not stated in the <i>Throws:</i> element. I've implemented the requested additional |
| 33 | +throws and they are easily achievable. |
| 34 | +</p> |
| 35 | +</discussion> |
| 36 | + |
| 37 | +<resolution> |
| 38 | +<p> |
| 39 | +This wording is relative to <paper num="N5014"/>. |
| 40 | +</p> |
| 41 | + |
| 42 | +<ol> |
| 43 | + |
| 44 | + |
| 45 | +<li><p>Modify <sref ref="[hive.capacity]"/> as indicated:</p> |
| 46 | + |
| 47 | +<blockquote> |
| 48 | +<pre> |
| 49 | +void reserve(size_type n); |
| 50 | +</pre> |
| 51 | +<blockquote> |
| 52 | +<p> |
| 53 | +-3- <i>Effects</i>: If <tt>n <= capacity()</tt> is `true`, there are no effects. Otherwise increases |
| 54 | +`capacity()` by allocating reserved blocks. |
| 55 | +<p/> |
| 56 | +-4- <i>Postconditions</i>: <tt>capacity() >= n</tt> is `true`. |
| 57 | +<p/> |
| 58 | +-5- <i>Throws</i>: `length_error` if <del>`n`</del><ins>`capacity()` cannot be made <tt>>= n</tt> without |
| 59 | +being</ins> <tt>> max_size()</tt>, as well as any exceptions thrown by the allocator. |
| 60 | +<p/> |
| 61 | +[…] |
| 62 | +</p> |
| 63 | +</blockquote> |
| 64 | +</blockquote> |
| 65 | + |
| 66 | +</li> |
| 67 | + |
| 68 | +</ol> |
| 69 | +</resolution> |
| 70 | + |
| 71 | +</issue> |
0 commit comments