[Issue 6843] Function to check whether std.conv.to will succeed

d-bugmail at puremagic.com d-bugmail at puremagic.com
Sun Oct 23 12:47:50 PDT 2011


http://d.puremagic.com/issues/show_bug.cgi?id=6843



--- Comment #4 from bearophile_hugs at eml.cc 2011-10-23 12:46:46 PDT ---
(In reply to comment #3)
> They're similar but not the same. Bug# 6840 is suggesting the creation of a
> template which wraps whether std.conv.to succeeds by catching the exception.
> This is highly inefficient and ends up creating a new type in the deal, which
> is messier IMHO.
> 
> What I'm suggesting here is that a new function be created which doesn't risk a
> ConvException being thrown at all, completely avoiding the huge inefficiency of
> catching the thrown exception.

You have missed this part of that bug 6840:

> 2) This simple implementation of maybeTo contains a try-catch, but there is no
> need to actually throw and catch an exception in all wrong conversion cases.
> Example: when Tin is string and Tout is int, maybeTo is free to use something
> lighter, like a C function that produces no exceptions, instead of to!(). I
> think this allows the compiler to perform some extra optimizations.

If you create a conversion function that doesn't throw, then it is useful to
create a maybeTo :-)

-- 
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