Any way to do a binary tree traversal without `opApply` and allocations?
solidstate1991
laszloszeremi at outlook.com
Thu Mar 26 23:17:58 UTC 2026
On Thursday, 26 March 2026 at 22:48:22 UTC, Kapendev wrote:
>
> https://forum.dlang.org/thread/shqwthzzrrorowdqczzs@forum.dlang.org
>
> I think theres better ways to do it then this gist but
> intrusive lists
>
> Im unsure what problems you have with the anti-work keywords,
> but you have at least three options with what ive seen:
>
> smart handles: mixin+index, limits you to 1 array but elements
> know where root is implicitly
>
> add indexes to your types: assume the root is index 0 or 1,
> then you should be able to generate a range from the array
>
> add an index array to your datastructure.
It's a binary tree, where the "indexes" are keys, not exact
locations, so that won't work.
I think I'll try again tomorrow, and also write a DIP to get
around this issue, likely some change to the `opApply` function
itself.
In the meanwhile, I might just add some Rust-style foreach with a
template and a lambda.
More information about the Digitalmars-d-learn
mailing list