Testing if a function is defined in a module
Carlos Smith
carlos-smith at sympatico.ca
Wed Feb 21 06:56:40 PST 2007
"Kirk McDonald" <kirklin.mcdonald at gmail.com> wrote
: There are a few ways of phrasing this, but here's one:
:
: static if (is(typeof(&YYUSERINIT))) {
: // Do stuff with the function
: }
Just tried with dmd 1.007, in a program
defining int a=0;
static if( is(typeof(main) == function ) )
...
static if( is(typeof(yymain) == function ) )
...
static if( is(typeof(a) == int ) )
...
static if( is(typeof(a) == float ) )
...
All 4 tests gives what they suggest.
Ie: main is a function, yymain is not.
a is an int and not a float.
Great !
Looks like D wont miss the C preprocessor...
More information about the Digitalmars-d-learn
mailing list