how to test if member of instance exists/defined?

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


On Wednesday, 22 March 2017 at 21:02:41 UTC, StarGrazer wrote:
> 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.
>

It's not that it doesn't work but the code still trying to be 
compiled by the compiler, when I don't want it to.
		




More information about the Digitalmars-d-learn mailing list