March 07, 2020 Re: use of struct vs class | ||||
---|---|---|---|---|
| ||||
Posted in reply to Steven Schveighoffer | Steve, thank you once again. Now it compiles & runs! I now create my tree like this: auto debs = new RedBlackTree!(Deb, (a, b) => a.name < b.name); (I feel that the rbtree docs are inadequate regarding creating new empty trees, so have submitted a bug report: https://issues.dlang.org/show_bug.cgi?id=20646 ) The other problem I had was that the Deb I created on the stack had its own internal rbtree that was always null. To address this I changed tags in the Deb struct to this: auto tags = new RedBlackTree!string; so it always creates a new empty tree. And I renamed clear to reset and now do this: void reset() { name = ""; ... tags = new RedBlackTree!string; ... } I assume that I can safely rely on the GC to clean up for me. So now I think I can safely use the pattern (1., repeat 2.1, ... ) described earlier: certainly it builds and runs. Next I'll have to try really populating the Debs including their tag trees and populating the debs tree of Debs structs. Thank you. |
Copyright © 1999-2021 by the D Language Foundation