cannot alias array ;/
Jot via Digitalmars-d-learn
digitalmars-d-learn at puremagic.com
Thu Jan 19 18:07:44 PST 2017
On Thursday, 19 January 2017 at 12:50:06 UTC, John Colvin wrote:
> On Thursday, 19 January 2017 at 07:48:03 UTC, 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.
>
> Simplest solution, has brackets that you may not like:
>
> void main()
> {
> int[][] a = [[1]];
> size_t k = 0;
> ref foo() { return a[k]; };
> foo() = [3];
> assert(a == [[3]]);
> }
I just use a pointer and dereference ;/
More information about the Digitalmars-d-learn
mailing list