Getting the initial value of a class field in compile time.

Adam D. Ruppe destructionator at gmail.com
Sun Feb 9 00:27:21 UTC 2020


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.


More information about the Digitalmars-d-learn mailing list