How do I pass multidimensional static arrays to functions expecting dynamic arrays?

Andrej Mitrovic andrej.mitrovich at gmail.com
Mon Aug 29 16:29:30 PDT 2011


Take a look:

void main()
{
    int[2] single;
    // foo(single);  // no
    foo(single[]);   // int[2][] slice, ok

    int[2][2] multi;
    // bar(multi);     // int[2][2] no
    // bar(multi[]);   // int[2][] slice, no
    // bar(multi[][]); // int[2][] slice, no
}

void foo(int[] value) {}
void bar(int[][] value) {}

I can easily slice a one-dimensional static array, but I can only
slice a single dimension. So how do I pass a multidimensional static
array to a function expecting a multidimensional dynamic array?


More information about the Digitalmars-d-learn mailing list