fake RefCounted for CTFE?

Stanislav Blinov stanislav.blinov at gmail.com
Tue Jun 16 15:20:04 UTC 2020


On Tuesday, 16 June 2020 at 13:36:28 UTC, John Colvin wrote:

> why not just have it continue doing ref-counting but use the GC 
> to do the allocating? Can't use GC.malloc at ctfe but `new 
> ubyte[](N)` works fine. You could even do a lambda cast to 
> trick it in to being nogc.

You can't. RefCounted (in Phobos, and any sane implementation 
otherwise) performs operations that simply aren't supported by 
CTFE. You can't do reinterpret casts in CTFE. You can't `new` a 
type with disabled default constructor. You can't properly 
initialize it if it has overridden opAssign.

This is due to the sad deficiency of the language in that it 
doesn't define a form of placement new. There's a library 
solution, but it won't work in CTFE generically for the above 
reasons.


More information about the Digitalmars-d mailing list