Get pointer or reference of an element in Array(struct)

Arun Chandrasekaran aruncxy at gmail.com
Sat Dec 9 06:15:16 UTC 2017


Is there a way to get the pointer or reference of an element in 
Array(T)?

https://run.dlang.io/gist/70fd499afe8438d4877f57aec90c3091?compiler=dmd

The assertion seems to fail below. Value copy is not is intended 
here.

module test;

void main()
{
     struct Data
     {
         int id;
     }

     import std.container.array;
     Array!Data gallery;

     Data d1;
     gallery.insertBack(d1);

     auto d2 = gallery[0];
     d2.id = 1;
     assert(d2.id == gallery[0].id, "neither ref nor pointer");
}



More information about the Digitalmars-d-learn mailing list