November 01, 2016 Re: newbie problem with nothrow | ||||
---|---|---|---|---|
| ||||
Posted in reply to Steven Schveighoffer | On Tuesday, November 01, 2016 12:19:11 Steven Schveighoffer via Digitalmars- d-learn wrote:
> On 11/1/16 11:54 AM, Jonathan M Davis via Digitalmars-d-learn wrote:
> > On Tuesday, November 01, 2016 10:57:38 Steven Schveighoffer via
> >> Is there not some assumeNoThrow wrapper somewhere?
> >
> > Someone added assemWontThrow to std.exception semi-recently, but I'd be very surprised if it didn't incur performance overhead such that I'd just as soon use an explicit try-catch and be done with it.
>
> The function I'm imagining shouldn't add any overhead...
assumeWontThrow uses lazy to do what it does (and I'm not sure that there's any other way to do it other than string mixins), and as I understand it, lazy isn't exactly efficient. Given that it always calls the resulting delegate though, the optimizer may be able to remove the extra cost.
- Jonathan M Davis
|
November 01, 2016 Re: newbie problem with nothrow | ||||
---|---|---|---|---|
| ||||
Posted in reply to Jonathan M Davis | On 11/1/16 12:24 PM, Jonathan M Davis via Digitalmars-d-learn wrote:
> On Tuesday, November 01, 2016 12:19:11 Steven Schveighoffer via Digitalmars-
> d-learn wrote:
>> On 11/1/16 11:54 AM, Jonathan M Davis via Digitalmars-d-learn wrote:
>>> On Tuesday, November 01, 2016 10:57:38 Steven Schveighoffer via
>>>> Is there not some assumeNoThrow wrapper somewhere?
>>>
>>> Someone added assemWontThrow to std.exception semi-recently, but I'd be
>>> very surprised if it didn't incur performance overhead such that I'd
>>> just as soon use an explicit try-catch and be done with it.
>>
>> The function I'm imagining shouldn't add any overhead...
>
> assumeWontThrow uses lazy to do what it does (and I'm not sure that there's
> any other way to do it other than string mixins), and as I understand it,
> lazy isn't exactly efficient. Given that it always calls the resulting
> delegate though, the optimizer may be able to remove the extra cost.
I was thinking something like this:
auto assumeNoThrow(alias foo, Args...)(Args args) nothrow
{
try
{
return foo(args);
}
catch(Exception e)
{
throw new Error("foo should not have done that!");
}
}
-Steve
|
Copyright © 1999-2021 by the D Language Foundation