Viktor Sehr wrote:
I'm not a reviewer, but I'd like to add a note on the interface:
I think boost::charconv should add one convenience function as follows:
// Returns std::nullopt on error
template <typename NumberType>
std::optional<NumberType> boost::charconv::to_number(const
std::string_view& sv) noexcept;
This throws away the error code; it should return (if we stick to standard
facilities)
std::expected
However, std::expected is C++23 (std::optional is "only" C++17, same as
std::from_chars.)
Expressed with our facilities it would return boost::system::result<NumberType>.
Interestingly, returning a boost::system::error_code instead of errc could
in principle have the additional benefit of returning the source location
where the error originated (this tends to be pretty useful when debugging
failures.) But for that, the implementation needs to be refactored to return
error_code instead of errc, only dropping it at the from_chars level.
Also interestingly, std::from_chars used to return std::error_code, but was
changed to return std::errc to avoid a dependency on and
therefore <string>.
One issue with this interface is that we're again losing the ability to
distinguish between the four possible ERANGE failures, as now a return
value is no longer available on error. Although I suppose we can define
our own erange_category with four values there, all equivalent to ERANGE
from the generic category.