Date: Wed, 15 Apr 2026 21:31:41 -0400
I had an idea for a simple library level addition which would avoid some
boiler plate that I find myself needing to write often, and suspect that
others do too. The instructions say to float the idea first, so this is in
in a nutshell:
I am interested in proposing a **signed integral overload** for reserve()
in all standard containers that currently accept only an unsigned
size_type. The goal is to improve ergonomics and safety when reserving
capacity based on signed computations such as std::ptrdiff_t results from
std::distance.
Today, users who want to avoid conversion warnings (which I personally
consider a best practice) must manually convert from signed to unsigned,
often after performing explicit negative checks which are easy to forget to
do. I would propose it as a template restricted to std::signed_integral so
the extra cost of the negative value check is only paid for signed types
and to avoid ambiguity with the existing size_type based implementation.
Essentially it amounts to adding this:
template <std::signed_integral S>
void reserve(S n); // throws std::length_error if n is negative, otherwise
behaves as if reserve(static_cast<size_type>(n)) were called.
Perhaps something similar with resize(), but for now I'm happy to start
small and focused.
So two questions:
1. Would there be any interest in such a proposal?
2. I understand that if there were interest, then meeting attendance is
needed to move forward, is this in person, or can it be via video
attendance?
Thanks for your time,
Evan Teran
boiler plate that I find myself needing to write often, and suspect that
others do too. The instructions say to float the idea first, so this is in
in a nutshell:
I am interested in proposing a **signed integral overload** for reserve()
in all standard containers that currently accept only an unsigned
size_type. The goal is to improve ergonomics and safety when reserving
capacity based on signed computations such as std::ptrdiff_t results from
std::distance.
Today, users who want to avoid conversion warnings (which I personally
consider a best practice) must manually convert from signed to unsigned,
often after performing explicit negative checks which are easy to forget to
do. I would propose it as a template restricted to std::signed_integral so
the extra cost of the negative value check is only paid for signed types
and to avoid ambiguity with the existing size_type based implementation.
Essentially it amounts to adding this:
template <std::signed_integral S>
void reserve(S n); // throws std::length_error if n is negative, otherwise
behaves as if reserve(static_cast<size_type>(n)) were called.
Perhaps something similar with resize(), but for now I'm happy to start
small and focused.
So two questions:
1. Would there be any interest in such a proposal?
2. I understand that if there were interest, then meeting attendance is
needed to move forward, is this in person, or can it be via video
attendance?
Thanks for your time,
Evan Teran
Received on 2026-04-16 01:31:56
