[Issue 5543] to!int to see a char as a single-char string
d-bugmail at puremagic.com
d-bugmail at puremagic.com
Fri Dec 21 10:10:42 PST 2012
http://d.puremagic.com/issues/show_bug.cgi?id=5543
--- Comment #16 from Andrej Mitrovic <andrej.mitrovich at gmail.com> 2012-12-21 10:10:37 PST ---
(In reply to comment #15)
> Having functions in std.ascii (and elsewhere) seems acceptable. But I think the
> name of such functions shouldn't be too much long.
>
>
> to!int raises exceptions. Returning -1 in case of errors seems able to cause
> some problems. One common use case for the char->int conversion:
>
> auto s = "123x456";
> auto digits = s.map!numericValue().array();
>
> Now I have to scan digits again looking for any -1.
*But* you can wrap it inside a function which throws on -1 (pseudocode):
auto s = "123x456";
auto thr = (a) => a == -1 ? throw ConvException() : a;
auto digits = s.map!numericValue().array();
Whereas if it threw to begin with you're forced to catch exceptions.
--
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
More information about the Digitalmars-d-bugs
mailing list