Matt Borland wrote:
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.
There are at least two reasons to not do that. First, NaN is a possible legitimate return value, so you have no way to reliably determine failure. Second, it makes it very easy to forget to check for errors. This is not the same as 0.0 / 0.0 returning NaN. We do that for the practical reason that we don't want, after several hours of computation, element 17108 out of 1048576 in total causing the loss of all the results because of a floating point exception terminating the process. This constructor / factory function is used to convert _input_ values, at the outer perimeter, and should therefore validate them.