Working with arrays (flatten, transpose, verfify rectangular)

anonymouse anony at mouse.com
Fri Jul 22 12:21:13 UTC 2022


On Friday, 22 July 2022 at 05:17:49 UTC, anonymouse wrote:
> On Wednesday, 20 July 2022 at 09:18:29 UTC, anonymouse wrote:
>>
>> As for task 3, while I understand the concept of transposing a 
>> matrix, I'm not sure how to even begin.
>>
>
> By not knowing how to begin, I mean that I don't know how to 
> generalize the algorithm so that it applies to an array of 
> arbitrary dimension/shape.

If figure if I could do something like this, it would work:

```d
static string s;
s ~= FlatElementType!T.stringof;
static foreach (i; a)
     s ~= "[" ~ to!string(i) ~ "]";
mixin(s) var;
```

Here, I'm receiving the shape of the array (```a```), composing a 
string of the actual type, then mixing it in to declare a 
variable of that type. Of course the compiler barfs at the idea 
as coded, but is there a way to accomplish this? Note that if you 
comment out the foreach loop, the variable gets created.

Thanks,
--anonymouse


More information about the Digitalmars-d-learn mailing list