Checking if a function exists

Tyler Knott tywebmail at mailcity.com
Wed Feb 21 13:01:13 PST 2007


Michiel wrote:
> I'm not quite sure how to do this, but I'm sure one of you does. I need
> something like:
> 
> static if ( functionExists(char[] .toString(T)) ) { ... }
> 
> static if ( functionExists(char[] T.toString()) ) { ... }
> 
> What is the real way to do this static check?
> 
> Thanks!
> 
Check out this 
(http://www.digitalmars.com/webnews/newsgroups.php?art_group=digitalmars.D.learn&article_id=6577) 
thread in digitalmars.D.learn.  It answers your question exactly.  For 
non-static member functions of classes you'll need to test against a reference 
to that class (although it doesn't need to be initialized).  To get the return 
and parameter types you can use the templates in std.traits (note: those 
templates (and DMD itself) will only reveal the first overload of a function; 
there is no way to get the parameter list for others).



More information about the Digitalmars-d mailing list