how to get the struct member as delegate type ?

Newbie2019 newbie2019 at gmail.com
Tue Jul 30 10:08:55 UTC 2019


On Tuesday, 30 July 2019 at 10:06:21 UTC, Newbie2019 wrote:
>
> 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) ) ;
> }


foreach(int name_index, name; __traits(allMembers, S) ) static 
if( isDelegateMember!(S, name, Type) ) {
     enum Rules = getUDAs!( __traits(getMember, S, name) , Rule);
      // handle the member is match this rules.
}



More information about the Digitalmars-d-learn mailing list