This page is a snapshot from the LWG issues list, see the Library Active Issues List for more information and the meaning of New status.
hive::reserve()
needs Throws: element adjusted to match block min/max considerationsSection: 23.3.9.3 [hive.capacity] Status: New Submitter: Matt Bentley Opened: 2025-09-17 Last modified: 2025-09-23
Priority: Not Prioritized
View other active issues in [hive.capacity].
View all other issues in [hive.capacity].
View all issues with New status.
Discussion:
This issue comes from Bloomberg as part of their C++26 comments via Incits. To summarize their case, in a
call to reserve(n)
,
if (n > capacity() && capacity() + current-limits.min > max_size()),
reserve
should throw, e.g when max_size=100
, capacity=80
, current-limits.min
and
current-limits.max
are 40
and n=90
.
max_size()
to 140 and n
to 130,
we can see that although we could add one block with a capacity of current-limits.min
,
adding another would be impossible; we still cannot make capacity >= n
without also
being > max_size
.
This is currently not stated in the Throws: element. I've implemented the requested additional
throws and they are easily achievable.
Proposed resolution:
This wording is relative to N5014.
Modify 23.3.9.3 [hive.capacity] as indicated:
void reserve(size_type n);-3- Effects: If
-4- Postconditions:n <= capacity()
istrue
, there are no effects. Otherwise increasescapacity()
by allocating reserved blocks.capacity() >= n
istrue
. -5- Throws:length_error
ifn
capacity()
cannot be made>= n
without being> max_size()
, as well as any exceptions thrown by the allocator. […]