Thread overview
Get static fields!
Jun 16, 2018
DigitalDesigns
Jun 16, 2018
Bauss
Jun 16, 2018
DigitalDesigns
Jun 19, 2018
Simen Kjærås
June 16, 2018
tupleof does not return static fields as does not Fields. Currently the only method seems to be use allMembers, but that returns members requiring filtering, which there is no good filtering checks. I'd simply like to get all the fields of a type, static and non-static.
June 16, 2018
On Saturday, 16 June 2018 at 05:05:19 UTC, DigitalDesigns wrote:
> tupleof does not return static fields as does not Fields. Currently the only method seems to be use allMembers, but that returns members requiring filtering, which there is no good filtering checks. I'd simply like to get all the fields of a type, static and non-static.

What about derivedMembers?
June 16, 2018
On Saturday, 16 June 2018 at 07:56:22 UTC, Bauss wrote:
> On Saturday, 16 June 2018 at 05:05:19 UTC, DigitalDesigns wrote:
>> tupleof does not return static fields as does not Fields. Currently the only method seems to be use allMembers, but that returns members requiring filtering, which there is no good filtering checks. I'd simply like to get all the fields of a type, static and non-static.
>
> What about derivedMembers?

But I don't want derived members!

June 19, 2018
On Saturday, 16 June 2018 at 05:05:19 UTC, DigitalDesigns wrote:
> tupleof does not return static fields as does not Fields. Currently the only method seems to be use allMembers, but that returns members requiring filtering, which there is no good filtering checks. I'd simply like to get all the fields of a type, static and non-static.

std.traits.hasStaticMember is your friend:

import std.meta : Filter, staticMap, Alias, ApplyLeft;
import std.traits : hasStaticMember;
alias FilterMembers(T, alias Fn) = Filter!(ApplyLeft!(Fn, T), __traits(allMembers, T));
alias StaticNamesTuple(T) = FilterMembers!(T, hasStaticMember);

And if you want them as aliases:

alias getMember(T, string name) = Alias!(__traits(getMember, T, name));
alias GetMembers(T, names...) = staticMap!(ApplyLeft!(getMember, T), names);
alias StaticMembersTuple(T) = GetMembers!(T, StaticNamesTuple!T);

--
  Simen