On Tuesday, 5 February 2019 at 10:10:44 UTC, RazvanN wrote:
On Monday, 4 February 2019 at 22:54:01 UTC, James Blachly wrote:
I tried to implement an interval tree backed by std.container.rbtree today and fell flat.

[...]
You can use alias this [1] in your interval element type:

struct IntervalElem
{
    size_t start, end;
    /* ... other declarations */
    alias start this;
}

[1] https://dlang.org/spec/class.html#AliasThis


Thanks -- I always seem to forget about `alias this` !
However, I don't think that this helps me to call functions expecting type Elem with an integer. At least, it failed in my test -- could this be because Elem itself is already an alias?

Q2: Would replacing "Elem" with a generic type "T" in the function signatures for upperBound, lowerBound, and various related fns like _firstGreater / _firstGreaterEqual solve this problem?

[...]
Elem is already a generic type. I don't know how you can make it more generic without adding other template parameters to the class declaration (which means reimplementing RBTree from std.container);

Agree, (although I think I would only need to revise only perhaps 25% of the module in this case) but I definitely wanted to avoid this if possible.


Reply via email to