John:

I can iterate over the struct elements with the traits FieldTypeTuple!foo,

In such iteration you are using a static foreach. Types are compile-time constructs in D. If you need run-time entities you need to get their typeinfo.


I can iterate over the the string that represents the elements I want to shove in the struct,

This is a "dynamic" (regular) foreach.


but when I try to loop over *both* of these at the same time
with zip(...) I get an error.

zip only works on run time values. So you can't zip a built-in typetuple of types with a range of values.


I'm not sure if it's actually a range? I assumed it would be a range of some kind,

It's not a range. FieldTypeTuple returns a built-in typetuple that in this case is really a built-in of types, that are purely compile-time entities.


and each of the elements would have a supertype of something like 'type' since that's what they are.

They are types (and they aren't other things like uninstantiated templates that in D are another kind), but not even in our dreams there is a supertype for them :-)


It could infer that now you have two ranges, one of 'type' and one of 'string'.

Nope.


If I'm able to foreach over two things, shouldn't I be able to foreach over the paired ranges with zip? It seems so simple...

If you turn the built-in typetuple of types into an array or lazy range of typeinfo, then you can zip them. But I don't think this is a good idea. It's better to forget the zipping and use a static foreach on the types, using also an index, and use such index to access the second array of run time values.

Bye,
bearophile

Reply via email to