Relocatable objects and internal pointers

Matt Elkins via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Fri Jan 29 18:35:21 PST 2016


On Saturday, 30 January 2016 at 02:09:55 UTC, Steven 
Schveighoffer wrote:
> I figured out a way to have them. You just have to guarantee 
> you don't copy the actual "pointer" out of the struct:
>
> https://forum.dlang.org/post/mk5k4l$s5r$1@digitalmars.com

Unfortunately, that won't work for what I was trying to do. The 
stuff I elided in the comments were more pointers to other Foo 
instances, used to create a linked-list (of stack-allocated 
objects); these would still break under the conditions Ali 
described. I was only storing the this pointer so that blitted 
objects could deduce where they came from (trying to turn the 
post-blit constructor into a copy-constructor).

Thanks, though. I'm thinking that maybe D just can't express 
these semantics without substantial overhead. While somewhat 
disappointing (I came into D with stars in my eyes :)), it's not 
enough by itself to make me go back to C++, at least not just 
yet. Not when I can just use a few static ifs to do what 
previously required careful template crafting that I wouldn't 
understand 3 months later. On the other hand, I'm falling behind 
on my library books since I no longer have any time for reading 
during compilations ;).


More information about the Digitalmars-d-learn mailing list