www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - if static member then call

reply Engine Machine <EM EM.com> writes:
auto ref foo(T, Args...)(args)
{
     static if (hasStaticMember!(T, "foo"))
         return T.foo!(T)(args);
}

Basically I want to forward the *static* call to T if possible(if 
foo exists in T). The main problem is actually calling T.foo as 
the syntax here doesn't work. I also need to be able to check to 
see if a method is static, since I have no object.
Aug 13 2016
next sibling parent Cauterite <cauterite gmail.com> writes:
On Saturday, 13 August 2016 at 18:34:43 UTC, Engine Machine wrote:
 auto ref foo(T, Args...)(args)
 {
     static if (hasStaticMember!(T, "foo"))
         return T.foo!(T)(args);
 }

 Basically I want to forward the *static* call to T if 
 possible(if foo exists in T). The main problem is actually 
 calling T.foo as the syntax here doesn't work. I also need to 
 be able to check to see if a method is static, since I have no 
 object.
you're probably gonna want something like, if i understand your question correctly: return __traits(getMember, T, "foo")(args);
Aug 13 2016
prev sibling parent reply Cauterite <cauterite gmail.com> writes:
On Saturday, 13 August 2016 at 18:34:43 UTC, Engine Machine wrote:
     static if (hasStaticMember!(T, "foo"))
Here I suspect you're looking for this: __traits(isStaticFunction, __traits(getMember, T, "foo"))
Aug 13 2016
parent Engine Machine <EM EM.com> writes:
On Saturday, 13 August 2016 at 18:42:50 UTC, Cauterite wrote:
 On Saturday, 13 August 2016 at 18:34:43 UTC, Engine Machine 
 wrote:
     static if (hasStaticMember!(T, "foo"))
Here I suspect you're looking for this: __traits(isStaticFunction, __traits(getMember, T, "foo"))
Thanks. It needs to be something like static if (hasMemeber!(T, "foo") && __traits(isStaticFunction, __traits(getMember, T, "foo")))
Aug 13 2016