how to test if member of instance exists/defined?

StarGrazer via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Wed Mar 22 14:02:41 PDT 2017


On Wednesday, 22 March 2017 at 20:53:17 UTC, crimaniak wrote:
> On Wednesday, 22 March 2017 at 20:35:27 UTC, StarGrazer wrote:
>> I've tried compiles but I guess that only checks if the code 
>> has valid syntax, not if it actually will compile in context.
>
> https://dlang.org/spec/traits.html#hasMember

I tried that but D complains

static if (hasMember!(S, "x"))
	return;
else
	s.x = 3;


D says that x doesn't exist.

		


More information about the Digitalmars-d-learn mailing list