try/catch idiom in std.datetime
Regan Heath
regan at netmail.co.nz
Tue Nov 19 09:00:13 PST 2013
On Tue, 19 Nov 2013 03:29:48 -0000, Michel Fortin
<michel.fortin at michelf.ca> wrote:
> On 2013-11-18 23:42:13 +0000, "Jonathan M Davis" <jmdavisProg at gmx.com>
> said:
>
>> I understand this. The problem is that in some cases, in order to do the
>> check, you have to do all of the work that the function you're trying to
>> protect bad input from has to do anyway - even without it asserting
>> anything.
>> So, having a separate function do the checking would just be extra
>> overhead.
>
> Very true.
>
> I'll just point out now that you could actually have only one function
> that does one or the other or both depending on template parameters. One
> template parameter is the output sink, which could be a dummy type that
> does nothing or an actual type that saves the data somewhere. Another
> parameter is the error handler, which can be a dummy type that does
> nothing, or it could assert or throw when an error is found. Let the
> optimizer remove the do-nothing code paths that will result.
>
> Now, I really have no idea but that could be overkill in this situation.
Why use templates at all? Lets just keep it simple..
You just write /the/ one internal conversion/check function (for each
case) such that it returns a boolean success status, then.. in release
mode you call it and throw on false/failure, and in debug mode you call it
in and assert on false/failure.
R
--
Using Opera's revolutionary email client: http://www.opera.com/mail/
More information about the Digitalmars-d
mailing list