Copying array with const correctness

Vindex9 tech.vindex at gmail.com
Tue Oct 7 22:15:00 UTC 2025


So far, the simplest solution is to create a separate function 
for a two-dimensional array:

```d
auto copy2DArray(T)(const T[][] arr) if (!is(T == class)) {
     T[][] copy;
     foreach(row; arr) {
         T[] tmp;
         foreach(field; row) {
             tmp ~= field;
         }
         copy ~= tmp;
     }
     return copy;
}
```

However, the metamorphoses of the types from my first example are 
very mysterious.


More information about the Digitalmars-d-learn mailing list