Detect if variable defined

arturg var.spool.mail700 at gmail.com
Fri Sep 29 18:44:07 UTC 2017


On Friday, 29 September 2017 at 18:03:52 UTC, Joseph wrote:
> static if ()
> {
>  enum x;
> }
>
> static if (isDefined!x)
> {
> }
>
> What's the correct way to check if a variable has been defined? 
> (note x may or may not be defined above. I need to know if it 
> is)

import std.traits;
static if(hasMember!(T, "x"))
{
}

or if at module level

static if(__traits(hasMember, mixin(__MODULE__), "x"))
{
}


More information about the Digitalmars-d-learn mailing list