digitalmars.D.learn - Get static fields!
- DigitalDesigns (5/5) Jun 15 2018 tupleof does not return static fields as does not Fields.
- Bauss (2/7) Jun 16 2018 What about derivedMembers?
- DigitalDesigns (2/9) Jun 16 2018 But I don't want derived members!
- Simen =?UTF-8?B?S2rDpnLDpXM=?= (15/20) Jun 19 2018 std.traits.hasStaticMember is your friend:
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.
Jun 15 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?
Jun 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:But I don't want derived members!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?
Jun 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.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
Jun 19 2018