www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - .stringof might call function?

reply "simendsjo" <simendsjo gmail.com> writes:
Why is the function called in the template at the line of 
.stringof?

template t(alias fn) {
     static if(fn.stringof) // f(int i) isn't callable using ()
         enum t = true;
     else
         enum t = false;
}

void main() {
     void f(int i) {}
     t!f;
}
Mar 16 2013
next sibling parent "simendsjo" <simendsjo gmail.com> writes:
On Saturday, 16 March 2013 at 13:01:44 UTC, simendsjo wrote:
 Why is the function called in the template at the line of 
 .stringof?

 template t(alias fn) {
     static if(fn.stringof) // f(int i) isn't callable using ()
         enum t = true;
     else
         enum t = false;
 }

 void main() {
     void f(int i) {}
     t!f;
 }
Seems pragma(msg, fn) also has the same behavior. Guess this is because all functions can be called using property syntax. It really hurts my generic code though..
Mar 16 2013
prev sibling parent Andrej Mitrovic <andrej.mitrovich gmail.com> writes:
On 3/16/13, simendsjo <simendsjo gmail.com> wrote:
 Why is the function called in the template at the line of
 .stringof?

 template t(alias fn) {
      static if(fn.stringof) // f(int i) isn't callable using ()
Use __traits(identifier, fn).
Mar 16 2013