Alias FilterMembersOf

Filters all the members of a type based on a provided predicate

alias FilterMembersOf(T, alias Fn) = Filter!(ApplyLeft!(Fn,ResolvedType),__traits(allMembers,ResolvedType));

The predicate takes two parameters - the first is the type, the second is the string name of the member being iterated on.


import std.meta: AliasSeq;

struct S {
    int i;
    float f;
    int i2;
    short s;

enum hasInt(T, string name) = is(typeof(__traits(getMember, T, name)) == int);
static assert(FilterMembersOf!(S, hasInt) == AliasSeq!("i", "i2"));