struct Ref1(T) { T storage; alias storage this; } struct Ref2(T) { T storage; @property ref T get(){ return storage; } alias get this; } int front(int[] arr){ return arr[0]; } void popFront(ref int[] arr){ arr = arr[1..$]; } void main() { assert([1,2,3].front == 1); auto r1 = Ref1!(int[])([1,2,3]); // assert(r1.front() == 1); // ng assert(r1.front == 1); // ok // r1.popFront(); // ng r1.storage.popFront(); // ok auto r2 = Ref2!(int[])([1,2,3]); // assert(r2.front() == 1); // ng assert(r2.front == 1); // ok // r2.popFront(); // ng // r2.get.popFront(); // ng r2.get().popFront(); // ok }
https://github.com/D-Programming-Language/dmd/pull/468
https://github.com/D-Programming-Language/dmd/commit/7c193950c9d7fa8798b93961fd00e215998149bc