digitalmars.D.learn - The best way to store a structure by reference
- drug (3/3) Nov 27 2015 I need to store a struct like a reference type. Now I use pointer for
- =?UTF-8?Q?Ali_=c3=87ehreli?= (3/6) Nov 27 2015 Agreed but that's the only way.
- Kagamin (2/2) Nov 27 2015 I use this http://dpaste.dzfl.pl/b926ff181709 to simulate
- rsw0x (4/8) Nov 27 2015 if you own the resource, consider std.typecons.unique or
- B.Basile (4/8) Nov 27 2015 One thing: take care when comparing pointer to struct, it'll only
- drug (2/5) Nov 27 2015 Thank to all for answer. I stay with pointers in my case.
- H. S. Teoh via Digitalmars-d-learn (7/10) Nov 27 2015 There's nothing strange about pointers in D code. They're relatively
I need to store a struct like a reference type. Now I use pointer for this, is it the best D way? This pointer is private and access to it is safe, but it's just unusual for me to see pointers in D code.
Nov 27 2015
On 11/27/2015 12:38 AM, drug wrote:I need to store a struct like a reference type. Now I use pointer for this, is it the best D way? This pointer is private and access to it is safe, but it's just unusual for me to see pointers in D code.Agreed but that's the only way. Ali
Nov 27 2015
I use this http://dpaste.dzfl.pl/b926ff181709 to simulate reference types.
Nov 27 2015
On Friday, 27 November 2015 at 08:38:29 UTC, drug wrote:I need to store a struct like a reference type. Now I use pointer for this, is it the best D way? This pointer is private and access to it is safe, but it's just unusual for me to see pointers in D code.if you own the resource, consider std.typecons.unique or std.typecons.refcounted otherwise consider std.typecons.nullableref
Nov 27 2015
On Friday, 27 November 2015 at 08:38:29 UTC, drug wrote:I need to store a struct like a reference type. Now I use pointer for this, is it the best D way? This pointer is private and access to it is safe, but it's just unusual for me to see pointers in D code.One thing: take care when comparing pointer to struct, it'll only compare the memory address and never call a custom opEquals for example... You have to explicitly compare the dereferenced stuff.
Nov 27 2015
On 27.11.2015 11:38, drug wrote:I need to store a struct like a reference type. Now I use pointer for this, is it the best D way? This pointer is private and access to it is safe, but it's just unusual for me to see pointers in D code.Thank to all for answer. I stay with pointers in my case.
Nov 27 2015
On Fri, Nov 27, 2015 at 11:38:28AM +0300, drug via Digitalmars-d-learn wrote:I need to store a struct like a reference type. Now I use pointer for this, is it the best D way? This pointer is private and access to it is safe, but it's just unusual for me to see pointers in D code.There's nothing strange about pointers in D code. They're relatively rare thanks to the various nice abstractions D offers, but you do still see them from time to time (e.g., in expressions like `x in aa`). T -- He who laughs last thinks slowest.
Nov 27 2015