Two struct objects with their own Redblack trees seem to be incorrectly joining trees values?

FeepingCreature feepingcreature at gmail.com
Mon Mar 24 17:45:25 UTC 2025


On Monday, 24 March 2025 at 17:39:34 UTC, WhatMeWorry wrote:
> ```
>     void setName(string n) { this.name = n; }
>
>     string name;
>
>     uint[Location] aa;  // associative array
>
>     auto rbt = new RedBlackTree!(Node, "a.f < b.f", true); // 
> true: allowDuplicates

You would *think* that this would create a new instance every 
time that the struct is instantiated.

Unfortunately what it does in fact do, is create a RedBlackTree 
instance *at compiletime*, emit it into the binary, and assign 
its reference as the default initializer of the `rbt` field.

I think probably the easiest fix is make Bag a class and assign 
`new RedBlackTree` in the constructor.


More information about the Digitalmars-d-learn mailing list