While reviewing #32520, I noticed that the function ToIntegral()
could be improved:
-
Instead of manually asserting
std::is_integral_v<T>
, the template can be constrained with the standardstd::integral
for clearer intent. -
Annotation with
[[nodiscard]]
andnoexcept
. Compilers will warn if the return value is discarded and sincestd::from_chars
is guaranteed to throw nothing, declaring the wrappernoexcept
makes the exception guarantee explicit. -
With C++23, the integral overloads of
std::from_chars
areconstexpr
, allowingToIntegral
to become aconstexpr
function.