using .init reliably

Cauterite via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Fri Aug 26 01:59:55 PDT 2016


How can I get the initial value of an arbitrary type? Since any 
struct can override it, .init is not reliable:

struct Z {
	enum init = 6;
	string val = `asdf`;
};
assert(Z.init == 6);
assert(typeof(Z()).init == 6);

I know I could use
*(cast(Z*) typeid(Z).initializer.ptr)
but that doesn't work in CTFE (because the typeinfo doesn't exist 
yet).

Z() is obviously not reliable either since it can override static 
opCall.


More information about the Digitalmars-d-learn mailing list