www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 11807] New: Functions to attempt string-to-T conversions (a la C#'s TryParse)

reply d-bugmail puremagic.com writes:
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 puremagic.com
        ReportedBy: peter.alexander.au gmail.com


--- Comment #0 from Peter Alexander <peter.alexander.au 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: -------
Dec 23 2013
next sibling parent d-bugmail puremagic.com writes:
https://d.puremagic.com/issues/show_bug.cgi?id=11807


bearophile_hugs eml.cc changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |bearophile_hugs eml.cc


--- Comment #1 from bearophile_hugs eml.cc 2013-12-23 14:10:38 PST ---
See also Issue 6840

-- 
Configure issuemail: https://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Dec 23 2013
prev sibling parent d-bugmail puremagic.com writes:
https://d.puremagic.com/issues/show_bug.cgi?id=11807


Peter Alexander <peter.alexander.au gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
         Resolution|                            |DUPLICATE


--- Comment #2 from Peter Alexander <peter.alexander.au gmail.com> 2013-12-24
02:35:27 PST ---
Duplicate of Issue 6840.

*** This issue has been marked as a duplicate of issue 6840 ***

-- 
Configure issuemail: https://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Dec 24 2013