Can you simplify nested Indexed types?

Sergei Nosov sergei.nosov at gmail.com
Tue Dec 27 15:31:50 UTC 2022


On Tuesday, 27 December 2022 at 15:20:24 UTC, Salih Dincer wrote:
> On Tuesday, 27 December 2022 at 15:09:11 UTC, Sergei Nosov 
> wrote:
>> Consider, I have the following code:
>>
>> ```d
>>     auto a = [3, 6, 2, 1, 5, 4, 0];
>>
>>     auto indicies = iota(3);
>>     auto ai = indexed(a, indicies);
>>     //ai = indexed(ai, iota(2));
>>
>>     writeln(ai);
>> ```
>
> I confuse about comment line that I mark...
>
> SDB at 79

Not sure I'll be more helpful, but I'll try to add more details.

I have an array and I use `indexed` on it. Conceptually, I now 
have a second array, but it doesn't exist in memory explicitly - 
only a function to map indicies from "second array" to "first 
array" is stored; all the values are stored once - in the "first 
array".

Now, I want to have third array that will do the same trick with 
the second array. The problem is that the second array is not 
really an array (but, conceptually, it is an array with random 
access). If I create a new variable with `auto` as type - 
obviously, it works. But can I use the same variable I used to 
store the "second array"? (In the provided code that doesn't work 
because of the type mismatch).


More information about the Digitalmars-d-learn mailing list