digitalmars.D - detecting function pointer types
- Benjamin Thaut (25/25) Sep 15 2011 I tried writing a template function that detects function pointer types ...
- David Nadlinger (11/14) Sep 15 2011 ---
I tried writing a template function that detects function pointer types but it
does not work for function marked wiht any extern qualifier.
I tried around but couldn't find a way to make it work.
Any suggestions on this?
template isFunctionPointer(T){
pragma(msg,T);
static if(is(T VAR == RET function(ARGS),RET,ARGS...)){
enum bool isFunctionPointer = true;
}
else {
enum bool isFunctionPointer = false;
}
}
alias void function() func1;
extern(C) alias void function() func2;
extern(Windows) alias void function() func3;
extern(C++) alias void function() func4;
pragma(msg,isFunctionPointer!(func1)); //true
pragma(msg,isFunctionPointer!(func2)); //false
pragma(msg,isFunctionPointer!(func3)); //false
pragma(msg,isFunctionPointer!(func4)); //false
void main(string[] args){
}
Kind Regards
Benjamin Thaut
Sep 15 2011
On 9/15/11 7:59 PM, Benjamin Thaut wrote:I tried writing a template function that detects function pointer types but it does not work for function marked wiht any extern qualifier. I tried around but couldn't find a way to make it work.--- template isFunctionPointer(T) { enum isFunctionPointer = false; } template isFunctionPointer(T : U*, U) if (is(U == function)) { enum isFunctionPointer = true; } --- Could also be implemented using static ifs, if you prefer that. David
Sep 15 2011








David Nadlinger <see klickverbot.at>