Getting the initial value of a class field in compile time.
realhet
real_het at hotmail.com
Sun Feb 9 00:41:12 UTC 2020
On Sunday, 9 February 2020 at 00:27:21 UTC, Adam D. Ruppe wrote:
> On Saturday, 8 February 2020 at 23:37:56 UTC, realhet wrote:
>> classinfo.m_init can be an option, but maybe there's a nicer
>> way to do this?
>
> eh the initializer i think is the best. you can sometimes
> shortcut it
>
> pragma(msg, (new A).i);
>
> which will call the ctor at ctfe and get the value. but if
> there isn't a default constructor that's harder. (of course at
> runtime you can yank it out of the init member... but ctfe will
> fail that i believe because of the reinterpret cast involved).
>
> i can't think of a better way right now.
Thank you! It works!
Somehow I thought that 'new' is too much in CTFE, now I can
rethink that.
More information about the Digitalmars-d-learn
mailing list