Enum arguments?

Fawzi Mohamed fawzi at gmx.ch
Wed Mar 31 07:37:43 PDT 2010


well you can always use Varargs...

void convolve(int n,mask...)(...)

Fawzi
On 31-mar-10, at 13:28, bearophile wrote:

> Max Samukha:
>
>> Actually, they are allowed via an additional alias:<
>
> This doesn't compile:
>
>
> void convolve(float[N][M] mask, N, M)(float[][] a, float[][] b) {
>    //...
> }
> void main() {
>    float[][] outmat = [[0.0]];
>    enum float[1][2] mask = [[1.0],[1.0]];
>    convolve!mask([[1.0, 1.0]], outmat);
> }
>
>
> You have to use an alias plus static asserts:
>
> void convolve(alias mask)(float[][] a, float[][] b) {
>    static assert(__traits(isStaticArray, typeof(mask)));
>    static assert(__traits(isStaticArray, typeof(mask[0])));
>    //...
> }
> void main() {
>    float[][] outmat = [[0.0]];
>    enum float[1][2] mask = [[1.0],[1.0]];
>    convolve!mask([[1.0, 1.0]], outmat);
> }
>
>
> While with an array of dchar (4 bytes each) compiles:
>
> void foo(immutable(dchar)[] s)() {}
> void main() {
>    immutable(dchar)[] s1 = "Hello"d;
>    foo!(s1)();
> }
>
>
> So I'd like arrays too to be allowd as template parameters.
>
> (The other thing I've asked in that post (the enum argument type for  
> functions) I've seen is similar to the "static" arguments in the  
> "The future of D", that I think was tried and abandoned because too  
> much hard to implement. So it's probably an useless request, sorry.)
>
> Bye,
> bearophile




More information about the Digitalmars-d mailing list