Does string.isNumeric mean that parse!int will not throw?
w0rp
devw0rp at gmail.com
Thu Feb 20 12:43:51 PST 2014
On Thursday, 20 February 2014 at 19:58:10 UTC, Stanislav Blinov
wrote:
> On Thursday, 20 February 2014 at 19:46:35 UTC, w0rp wrote:
>
>> if (s.length > 0 && s.all!isDigit) {
>> // Never throws now.
>> auto x = parse!int(s);
>> }
>
> And what about +/- and U/L suffixes? Or, say, different base
> (i.e. hexadecimal)?
>
> It would be way more beneficial if Phobos' parse (or some
> additional function) returned some kind of Optional. Maybe a D
> implementation of Andrei's Expected<T>?
True, this doesn't cover those. Returning a
Maybe/Option/Nullable/Whatever type from another function may be
better.
More information about the Digitalmars-d-learn
mailing list