digitalmars.D.learn - how to get the struct member as delegate type ?
- Newbie2019 (24/24) Jul 30 2019 I need to check on struct members is match a delegate type. for
- Newbie2019 (6/16) Jul 30 2019 foreach(int name_index, name; __traits(allMembers, S) ) static
- Newbie2019 (8/13) Jul 30 2019 And one more question, how to get the Function address or
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) ) ; }
Jul 30 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. }
Jul 30 2019
On Tuesday, 30 July 2019 at 10:08:55 UTC, Newbie2019 wrote: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. }And one more question, how to get the Function address or delegate address of a struct member on compile time ? struct S { void onMatch(){} } __gshared auto onMatch = (&(S.init)).funcptr ; // this not work
Jul 30 2019