Generating a tree structure

monarch_dodra via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Thu Aug 21 08:11:36 PDT 2014


On Thursday, 21 August 2014 at 14:09:24 UTC, Ricky C wrote:
> TileTree* self;

Don't do that. D has banned internal pointers to implement its 
move semantics.

> branches[index] = tile_trees[index];

This will make a *value-copy* of your TileTree nodes. There are 
good chances it'll break your tree.

As a rule of thumbn when managing an Node-like structure, try to 
avoid storing them by value in a container. Unless you are 
*exceptionally* about not copying the nodes from one container to 
another, you'll usually end up shooting yourself in the foot. 
This is particularly relevant what when you have an internal 
pointer, as the copy will point to the old node, not itself.

Try to rewrite your code to use TileTree* objects instead:
http://dpaste.dzfl.pl/13194a966c07


More information about the Digitalmars-d-learn mailing list