December 21, 2012 [Issue 5543] to!int to see a char as a single-char string | ||||
---|---|---|---|---|
| ||||
Posted in reply to bearophile_hugs@eml.cc | http://d.puremagic.com/issues/show_bug.cgi?id=5543 --- Comment #20 from monarchdodra@gmail.com 2012-12-21 10:55:24 PST --- (In reply to comment #18) > (In reply to comment #16) > > > Whereas if it threw to begin with you're forced to catch exceptions. > > There is no perfect solution. Exceptions are safer than error codes because if you forget to test for a negative result, your program stops. On the other hand exceptions are less efficient, less handy to use in nothrow functions, and often require some try-catch wrapping. > > In this enhancement request I was originally asking for an overload of to!(), this means a solution that throws exceptions when the input is wrong. > > Efficiency is not a significant problem for me here because where I need to convert char digits to numerical digits with max efficientcy I use a '0' subtraction (or a vectorized version of it). So with this overload of to!() I was looking for safety. I think a good solution is to accept having different semantics: std.ascii.numericValue: int numericValue(dchar c) safe nothrow pure; returns -1 on failure std.uni.numericValue: double numericValue(dchar c) safe pure; Throws on failure If you are doing anything with unicode, the exception's overhead will be mostly moot compared to the cost (I think). When operating with ASCII, then it's a different ballgame (IMO). That's my opinion anyways. -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: ------- |
Copyright © 1999-2021 by the D Language Foundation