Hi all,

We recently had a discution on #D about copying a struct on the heap and getting a pointer to it.

We come up with the following solution (Thanks to CyberShadow !) :

struct S;
S s; // Allocated locally.
[s].ptr; // Get a pointer to a copy in the heap of the struct

What is going on ? An array of one object is allocated on the heap and the struct copied in it. Then we get a pointer to the first (and only one) element of the array with ptr.

So we have a pointer to a copy of s on the heap.

I have several question on that :
 - Does a idiomatic way to do that exists ?
- Is this intented to do so ? Will this construct risk to be broken in a future version of D ?
 - Is this construct the idiomatic way to do so ?

Reply via email to