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

Reply via email to