1/2/2013 7:24 PM, bearophile пишет:
monarch_dodra:

The rationale for this:
std.ascii: I think returning -1 as a magic number should help keep the
code faster and with less clutter than with exceptions.

For the ASCII version I have two use cases:
- Where I want to go fast&unsafe I just use "c - '0'".
- When I want more safety I'd like to use something as to!(), that
raises exceptions in case of errors.

A function that works on ASCII and returns -1 doesn't give me much more
than "c - '0'". So maybe exceptions are good in the ASCII case too.


Then we can maybe just drop this function? What's wrong with
if(std.ascii.isNumeric(a))
   a -= '0';
else
   enforce(false);

I mean that the time to look it up in std library is much bigger then to roll your own with any of the 2 semantics.

Unlike the unicode version, of course. Then IMO having the std.ascii one is mostly just for symmetry and thus I think that both should just use some sentinel value.

There is also std.typecons.nullable, it's a possibility for
std.uni.numericValue. Generally Phobos should eat more of its dog food :-)


double.nan sounds more like it.

Bye,
bearophile


--
Dmitry Olshansky

Reply via email to