blocks with attributes vs inlined lambda

monarch_dodra monarchdodra at gmail.com
Tue Jun 18 01:10:22 PDT 2013


On Tuesday, 18 June 2013 at 07:58:06 UTC, Kenji Hara wrote:
> In D, variable declaration with default construction is always 
> nothrow.
> So, enclosing the declaration of s by nothrow block is 
> unnecessary.

Well, what about construction with args...

> For nothrow destruction, you can add following static assert in 
> foo().
>
>     static assert(__traits(compiles, ()nothrow{ Sentinel s; }), 
> "Sentinel
> dtor is not nothrow");

Right. Good point.

> This is a compiler bug, and I recently fixed it in git master. 
> Explicit
> argument passing does not need anymore.

Cool, thanks.

> Inlining should remove performance penalty. Nobody holds the 
> immediately
> called lambda, so it should be treated as a 'scope delegate'. 
> For that, we
> would need to add a section in language spec to support it.

Alright.

>> ----------------
>> So my conclusion is that the lambda tric is a partial 
>> workaround. We'd
>> need real support for being able to have specific 
>> qualification inside
>> bodies.
>>
>
> I don't think so. We can sufficiently use lambda for the 
> "attribute block".
>
> Kenji Hara

Maybe you are right. I will keep using it for now.


More information about the Digitalmars-d mailing list