Mixin template confusion / compiler error.

Chris Katko via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Thu Jan 19 00:41:53 PST 2017


Thank you!

So:

1 - Is there any way TO get the output 64,64? It seems like being 
able to get a comma out of a mixin is a useful feature.

2 - Is this very non-standard / unrecommended practice and 
there's a much better way to do this?

For example, in my actual code, I have an enumerator:

enum MAP_SIZE
     {
     PLANET = 2048,
     SHIP = 256,
     SHUTTLE = 64,
     (etc)
     } //this could also be translated to an array lookup. ala 
SHIP = 0, SHUTTLE = 1, etc. with an array holding the sizes.

and then I pass MAP_SIZE, into a map class, which then builds 
layers into that map based on the MAP_SIZE. The layers are 
statically sized at compile-time by translating a given MAP_SIZE 
down to the actual required dimensions.

So in plain English: Based on a MAP_SIZE, the inner structures 
are all sized appropriately at compile-time.

So, for example:

map_t!(MAP_SIZE.SHIP) x;

goes into

map_t(MAP_SIZE s)
     {
     layer_t!(mixin(sizer2D!(s))) layer;
     }

which becomes

map_t(MAP_SIZE s)
     {
     layer_t!(64,64) layer;
     }

and in layer_t:

layer_t(int width, int height)
     {
     int [width][height] data;
     }


Is there a different way to go about this? Should I be building 
some sort of function inside a template that "decides" / 
"translates" a passed template parameter MAP_SIZE to width and 
height values?

I guess I could try putting the mixin inside layer_t and put the 
values into the square brackets, instead of commas. But again, 
"no commas" seem so arbitrary from an abstract, novice 
perspective. What if I was pre-processing English statements 
which include commas?

Thank you for your assistance. I appreciate it.




More information about the Digitalmars-d-learn mailing list