Fixing std.string
bearophile
bearophileHUGS at lycos.com
Fri Aug 20 07:36:32 PDT 2010
bearophile Wrote:
> The difference is that a well designed isNumeric doesn't need to use exceptions,<
A possible design is to use only one template function, like:
private auto _realConvert(bool useExepions)(string txt) {
...
if (some_error_condition) {
static if (useExcepions)
throw new ConversionError(...);
else
return false;
}
...
static if (useExcepions)
return result;
else
return true;
}
And then create isNumeric() and to!real() calling _realConvert!(false) and _realConvert!(true).
(But maybe the simple implementation with collectException(to!real(input)) is enough because it's uncommon to use isNumeric where speed matters a lot).
Bye,
bearophile
More information about the Digitalmars-d
mailing list