Title
`hive::reserve()` needs Throws: element adjusted to match block min/max considerations
Status
new
Section
[hive.capacity]
Submitter
Matt Bentley

Created on 2025-09-17.00:00:00 last changed 3 weeks ago

Messages

Date: 2025-09-21.06:25:49

Proposed resolution:

This wording is relative to N5014.

  1. Modify [hive.capacity] as indicated:

    void reserve(size_type n);
    

    -3- Effects: If n <= capacity() is `true`, there are no effects. Otherwise increases `capacity()` by allocating reserved blocks.

    -4- Postconditions: capacity() >= n is `true`.

    -5- Throws: `length_error` if `n``capacity()` cannot be made >= n without being > max_size(), as well as any exceptions thrown by the allocator.

    […]

Date: 2025-09-17.00:00:00

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`.

In addition, in the above scenario if we increase `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.

History
Date User Action Args
2025-09-21 06:25:49adminsetmessages: + msg15074
2025-09-17 00:00:00admincreate