Constructing a tuple dynamically
thedeemon via Digitalmars-d-learn
digitalmars-d-learn at puremagic.com
Tue Feb 3 21:40:36 PST 2015
On Tuesday, 3 February 2015 at 10:32:47 UTC, Pena wrote:
> How can I use this code or something similar to dynamically
> construct a tuple containing types of fields marked as
> @Cloneable?
import std.traits, std.typetuple;
template CloneableTypes(S) {
template IsCloneable(string M) {
enum IsCloneable = staticIndexOf!(Cloneable,
__traits(getAttributes, __traits(getMember, S, M))) >= 0;
}
template FieldType(string M) {
alias FieldType = typeof(__traits(getMember, S, M));
}
alias CloneableTypes = staticMap!(FieldType,
Filter!(IsCloneable, __traits(allMembers, S)));
}
Then CloneableTypes!Foo is a TypeTuple (int, string).
More information about the Digitalmars-d-learn
mailing list