Enum arguments?
bearophile
bearophileHUGS at lycos.com
Tue Mar 30 17:04:49 PDT 2010
This is a function that convolves a 2D rectangular matrix with another given rectangular matrix, and puts the result into an output matrix. Among other things, the precondition makes sure that outmat is already the same size of mat:
void convolve(float[][] mat, float[][] mask, float[][] outmat);
In the program mask is a compile-time constant (an enum), so to use a static foreach with Range I'd like to be able to mark an argument as enum:
void convolve(const float[][] mat, enum float[][] mask, float[][] outmat);
(After the call to convolve outmat will keep its outer length/ptr, but in the postcondition I'd like to assert that outmat has not changed all its length and ptr fields.)
Now in D2 I can use:
void convolve(alias mask)(const float[][] mat, float[][] outmat);
followed by a static assert that makes sure mask is a static array of static arrays.
D templates allow as compile-time arguments both floating point values and strings of 8,16,32 bit chars, but I don't know why arrays are not allowed.
Bye,
bearophile
More information about the Digitalmars-d
mailing list