I got it working using compiles: A a = new A; foreach (i, type; typeof(A.tupleof)) { enum name = A.tupleof[i].stringof[1 + A.stringof.length + 2 .. $];static if (__traits(compiles, mixin("A." ~ type.stringof))) {
mixin("a." ~ name) = a.new type; } else { mixin("a." ~ name) = new type; } }
It's pretty hacky, but it seems to work. I'd be very interested in a cleaner solution, but this works for now.