Creating a RedBlackTree
    Bogdan 
    olar.bogdan.dev at gmail.com
       
    Wed May 15 13:42:14 UTC 2019
    
    
  
On Wednesday, 15 May 2019 at 13:15:50 UTC, Stefan Koch wrote:
> Key controller cannot be compared by less
> which is why it fails, give it an opCmp and it'll work.
Works fine, thank you! For some reason, I thought that this 
template uses references:
```
enum KeyID: uint
{
	KEY_A,
	KEY_S,
	KEY_D,
	KEY_W
}
struct KeyController
{
	KeyID ID;
	bool isDown;
	int opCmp(ref const KeyController other) const {return this.ID - 
other.ID;}
}
void main()
{
	KeyController[] monitoredKeys = [{KeyID.KEY_A}];
	auto rbt = redBlackTree!KeyController;
	rbt.insert(monitoredKeys);
	writeln(rbt);
	monitoredKeys[0].isDown = true;
	writeln(rbt);
}
```
Output:
```
RedBlackTree([const(KeyController)(KEY_A, false)])
RedBlackTree([const(KeyController)(KEY_A, false)])
```
    
    
More information about the Digitalmars-d-learn
mailing list