RedBlackTree and myClass

Jonathan M Davis via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Sun Jan 3 06:30:02 PST 2016


On Sunday, January 03, 2016 10:55:05 AntonSotov via Digitalmars-d-learn wrote:
> import std.container.rbtree;
>
> class myClass {
>      string str;
> }
>
>
> int main()
> {
>      auto tree = new RedBlackTree!myClass;
>      return 0;
> }
>
>
> Error: mutable method object.Object.opCmp is not callable using a
> inout object
> Error: template instance std.functional.binaryFun!("a < b", "a",
> "b").binaryFun!(inout(myClass), myClass) error instantiating
> /////////////////////////////////////////
>
> How to use RedBlackTree of the objects of of its class?

You either have to define opCmp on your class so that it can be compared
with the < operator, or you need to provide RedBlackTree's constructor a
function to use to compare instead of using <.

- Jonathan M Davis



More information about the Digitalmars-d-learn mailing list