how to get the struct member as delegate type ?

Newbie2019 newbie2019 at gmail.com
Tue Jul 30 10:06:21 UTC 2019


I need to check on struct members is match a delegate type.  for 
example;

alias Type = scope void delegate(int) @nogc  ;
struct S {
      void onMatch1(int) scope @nogc {
     }

      void onNotMatch2(int) scope  {
     }

     void onNotMatch2(int, int) scope @nogc {
     }

      Type not_match3;
}

please notify not_match3 member is should return false, I try 
this template but not work:



template isDelegateMember(S, string name, D) if(is(S == struct) 
&& __traits(hasMember, S, name) && is( D == delegate ) ) {
     alias Fn    = typeof( __traits(getMember, S.init, name) );
     static assert( isFunction!Fn );
     pragma(msg, D);
     pragma(msg, typeof(D.init.funcptr));
     pragma(msg, Fn );
     pragma(msg, __traits(isSame, Fn, typeof(D.init.funcptr)) );
     enum isDelegateMember = is( Fn == typeof(D.init.funcptr) ) ;
}


More information about the Digitalmars-d-learn mailing list