Le 2025-10-08 15:58, Matt Borland a écrit :
10-08 14:59, Matt Borland via Boost a écrit :
What about something like the following:
decimal64_t dec = make_decimal64(const std::string&)
or decimal64_t dec = make_decimal64(std::string_view)
This could assume C locale like from_chars to avoid strtod surprises, be more ergonomic than from_chars, and allow leading "+" like strtod.
How do you report failure ? Shouldn't it return an expected-like for that purpose ?
I maintain NAN is the way to go for reporting failure here, and I won't be scolded for returning that from the constructor. NAN is designed to represent undefined or unrepresentable values. I would argue that an unparseable or any bad string is an undefined/unrepresentable value and thus a NAN.
That makes sense but that also lose the information about why the parsing failed. Given that boost::from_chars in charconv had to diverge from the standard to be usable by Boost.Json for precisely that reason (handling different ERANGE errors IIRC), i think that there's definitely some value in not losing that information. Regards, Julien