Anonymous nogc class

Biotronic via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Fri Sep 8 09:10:55 PDT 2017


On Friday, 8 September 2017 at 12:32:35 UTC, Jiyan wrote:
> On Friday, 8 September 2017 at 06:37:54 UTC, Biotronic wrote:
>> On Thursday, 7 September 2017 at 23:40:11 UTC, Jiyan wrote:
>>> [...]
>>
>> Sadly, even std.typecons.scoped isn't currently @nogc:
>> https://issues.dlang.org/show_bug.cgi?id=13972
>> https://issues.dlang.org/show_bug.cgi?id=17592
>>
>> [...]
>
> First thanks :)
>
> i understand the part with scopedAnon, but can you explain what 
> the ~this is referring to?
> Is it the Modul destructor?

It's scoped!T's destructor. If you decide to use that workaround, 
you should probably copy scoped!T from std.typecons and have your 
own version. It's not safe in all cases, and the next standard 
library update might break it.

> And in general is it just that scoped is just not marked @nogc 
> or is it that it would really need to use the gc?

In your case, scoped!T is can be safely called from @nogc code, 
and thus could be marked @nogc. However, when a class C has a 
destructor that allocates, scoped!C could not be @nogc. So in 
order to be safe in all cases, it can't be @nogc in the general 
case.

--
   Biotronic


More information about the Digitalmars-d-learn mailing list