[Issue 16343] Incorrectly requiring this pointer for a free function
    d-bugmail at puremagic.com 
    d-bugmail at puremagic.com
       
    Sun Nov 19 08:34:22 UTC 2017
    
    
  
https://issues.dlang.org/show_bug.cgi?id=16343
--- Comment #5 from Jonathan M Davis <issues.dlang at jmdavisProg.com> ---
I just hit this issue again - with an alias parameter this time. This code
============
struct S
{
    int i;
}
void main()
{
    foreach(memberName; __traits(allMembers, S))
    {
        func!(__traits(getMember, S, memberName))();
    }
}
void func(alias member)()
{
    auto protection = __traits(getProtection, member);
    alias Type = typeof(member);
    auto name = __traits(identifier, member);
}
============
gives this error
q.d(10): Error: need 'this' for 'func' of type 'pure nothrow @nogc @safe
void()'
whereas moving the contents of the free function into main works just fine. The
lack of ability to pass the member to a template for introspection makes it a
lot harder to avoid code duplication when writing code that does type
introspection.
--
    
    
More information about the Digitalmars-d-bugs
mailing list