cannot alias array ;/

Ali Çehreli via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Thu Jan 19 00:04:00 PST 2017


On 01/18/2017 11:48 PM, Jot wrote:
> alias a = myarray[k];
>
> fails
>
> myarray is a multidimensial array that I want to reduce writing it every
> time but D complains that it can't alias it.
>
> I simply want it to do a direct substitution, nothing fancy, just to
> reducing typing.
>

Nested functions work pretty well in some cases:

import std.stdio;

void foo() {
     int[double][char][string] aa;
     aa["hello"]['b'][ 3.5] = 35;

     auto a = "hello";
     char b = 'b';

     // Works like an alias:
     ref theOne() {
         return aa[a][b];
     }

     theOne[1.5] = 15;
     theOne[2.5] = 25;

     writeln(aa);
}

void main() {
     foo();
}

Ali



More information about the Digitalmars-d-learn mailing list