śr., 8 paź 2025 o 11:36 Richard Hodges via Boost <boost@lists.boost.org> napisał(a):
On Wed, 8 Oct 2025 at 10:09, Matt Borland <matt@mattborland.com> wrote:
On Wednesday, October 8th, 2025 at 9:53 AM, Richard Hodges via Boost < boost@lists.boost.org> wrote:
- What is your evaluation of the design?
There seems to be no way to construct a boost.decimal from a string representing a decimal number.
Is that correct, or have I missed it?
Without a constructor or conversion mechanism from string, when using decimal to store numbers received off the wire one would either have to round trip through (lossy) strtod or write a conversion function, which is tiresome.
The best way to do this (and how current users are) is via the <charconv> functions[1]. There are also literals if you prefer to go that route [2].
This is a terrible user experience, and the opposite of "make simple things simple". Why not just have a constructor that constructs the decimal from a string?
I noted the literals, but these are irrelevant as the pain will come when accepting text inputs and building decimals from them.
As things stand I think boost.multiprecision remains a better solution because of this one feature.
I appreciate that John's intent is to implement the standard verbatim, but this has frankly never been a good idea.
While having the ability to convert from string to a decimal is a valid expectation, I do not think it is justified to require that this must be done via a constructor. If not anything else, the author may want to keep the headers smaller and not couple the representation with string parsing. You may consider from_chars too clumsy, but how do you propose to signal parsing failures given that this library is designed to service environments without exceptions? Regards, &rzej;