Detect if variable defined

Steven Schveighoffer schveiguy at yahoo.com
Fri Sep 29 18:57:47 UTC 2017


On 9/29/17 2:03 PM, 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)

Check to see that it has a type:

static if(is(typeof(x)))
{
}

-Steve


More information about the Digitalmars-d-learn mailing list