How to return a reference to structs?

Andrey Zherikov andrey.zherikov at
Thu Nov 4 11:26:30 UTC 2021

I have the following code example:

struct A{}

A[5] a;
ulong[] idx = [1,3,4];

auto get()
     return!(_ => a[_]);

foreach(i; 0 .. a.length)
     write(&a[i], " ");

foreach(ref b; get())
     write(&b, " ");

How can I change `get` function so it returns the references to 
the content in `a`?

Is there a good documentation describing how to avoid copying of 
structs in the code?

More information about the Digitalmars-d-learn mailing list