Thread overview
how do I get only static member of a class?
Jan 03, 2018
Marc
Jan 04, 2018
Ali Çehreli
Jan 04, 2018
Marc
January 03, 2018
I found no way with __traits() on std.traits. I found isStaticFunction and isStaticArray but nothing about a member. Is this by desgin?

Give a class like:

> class C { static int a, b, c; int d; }

I'd like to get a, b and c.

I'm using this:
> __traits(allMembers, C)
January 03, 2018
On 01/03/2018 03:48 PM, Marc wrote:
> I found no way with __traits() on std.traits. I found isStaticFunction and isStaticArray but nothing about a member. Is this by desgin?
> 
> Give a class like:
> 
>> class C { static int a, b, c; int d; }
> 
> I'd like to get a, b and c.
> 
> I'm using this:
>> __traits(allMembers, C)


class C { static int a, b, c; int d; }

string[] staticMembers(T)() {
    string[] statics;

    foreach (m; __traits(derivedMembers, T)) {
        import std.traits : hasStaticMember;
        static if (hasStaticMember!(T, m)) {
            statics ~= m;
        }
    }

    return statics;
}

void main() {
    pragma(msg, staticMembers!C);
}

Ali
January 04, 2018
On Thursday, 4 January 2018 at 00:02:24 UTC, Ali Çehreli wrote:
> On 01/03/2018 03:48 PM, Marc wrote:
>> I found no way with __traits() on std.traits. I found isStaticFunction and isStaticArray but nothing about a member. Is this by desgin?
>> 
>> Give a class like:
>> 
>>> class C { static int a, b, c; int d; }
>> 
>> I'd like to get a, b and c.
>> 
>> I'm using this:
>>> __traits(allMembers, C)
>
>
> class C { static int a, b, c; int d; }
>
> string[] staticMembers(T)() {
>     string[] statics;
>
>     foreach (m; __traits(derivedMembers, T)) {
>         import std.traits : hasStaticMember;
>         static if (hasStaticMember!(T, m)) {
>             statics ~= m;
>         }
>     }
>
>     return statics;
> }
>
> void main() {
>     pragma(msg, staticMembers!C);
> }
>
> Ali

Thanks again, Ali