On Monday, 22 October 2018 at 10:49:10 UTC, test wrote:

test1.d
=====================
alias Fn1       = void function();
struct XX {
        alias Fn        = Fn1;
        // ...
}

'Fn' is not a static function, it's a type. I.e. you can declare a function pointer with it:

Fn func;

test2.d
=====================
import test1;
void GetPub(BaseType)(){
    // ...
}


My code works fine with your struct XX, with dmd 2.082.

std.traits.hasMember expects an aggregate *type*, but you're trying to pass as instance.

A revised GetPub:

void GetPub(BaseType)(){
static foreach (name; __traits(allMembers, BaseType)) static if( name[0] !is '_' && is(typeof(__traits(getMember, BaseType, name))) && __traits(getProtection, __traits(getMember, BaseType, name)) == "public" ) {
                //static assert( hasMember!(BaseType.init, name));
                static assert(hasMember!(BaseType, name));
static if( __traits(isStaticFunction, __traits(getMember, BaseType, name)) ) { pragma(msg, BaseType.stringof ~ "." ~ name);
                }
        }
}

note the added check that the member is not a type: is(typeof(__traits(getMember, BaseType, name))). You'll still need to iterate overloads if you want to get all static functions.

Reply via email to