[Issue 11807] New: Functions to attempt string-to-T conversions (a la C#'s TryParse)
d-bugmail at puremagic.com
d-bugmail at puremagic.com
Mon Dec 23 11:40:25 PST 2013
https://d.puremagic.com/issues/show_bug.cgi?id=11807
Summary: Functions to attempt string-to-T conversions (a la
C#'s TryParse)
Product: D
Version: D2
Platform: All
OS/Version: All
Status: NEW
Severity: normal
Priority: P2
Component: Phobos
AssignedTo: nobody at puremagic.com
ReportedBy: peter.alexander.au at gmail.com
--- Comment #0 from Peter Alexander <peter.alexander.au at gmail.com> 2013-12-23 11:40:23 PST ---
std.conv provides 'to' and 'parse', but both will throw exceptions if they fail
to convert. The only way to test if a conversion is possible is to call these
functions and catch the exception. This isn't a great situation because
throwing exceptions is not good for performance.
This enhancement requests something akin to C#'s TryParse, which returns a
boolean false if the conversion failed and returns the converted value as an
out parameter. Like this:
bool tryParse(T)(string s, out T value)
An alternative API would be to return a Nullable!T
See Also:
http://msdn.microsoft.com/en-us/library/f02979c7(v=vs.110).aspx
--
Configure issuemail: https://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
More information about the Digitalmars-d-bugs
mailing list