Bug 18634 – std.container.rbtree does not work with delegate comparators

Status
RESOLVED
Resolution
FIXED
Severity
trivial
Priority
P5
Component
phobos
Product
D
Version
D2
Platform
All
OS
All
Creation time
2018-03-19T22:21:31Z
Last change time
2018-03-21T22:54:10Z
Assigned to
No Owner
Creator
viktor.ivanov

Comments

Comment #0 by viktor.ivanov — 2018-03-19T22:21:31Z
The RedBlackTree does not work with delegate comparators due to RedBlackTree.opEquals() forcing a function when doing the equality comparison. The following test shows the issue: import std.algorithm.comparison : equal; auto t = new RedBlackTree!(int, delegate (a, b) => a > b); t.insert([1, 3, 5, 4, 2]); assert(t[].equal([5, 4, 3, 2, 1]));
Comment #1 by greensunny12 — 2018-03-19T22:46:16Z
PR https://github.com/dlang/phobos/pull/6304 (it's a good practice to mention/link the PR to avoid duplicate work)
Comment #2 by github-bugzilla — 2018-03-21T22:54:09Z
Commits pushed to master at https://github.com/dlang/phobos https://github.com/dlang/phobos/commit/a3f8992766b1baf4d4dd2d57043a734db29c221b Fix issue 18634 - support for delegate comparators in rbtree RedBlackTree.opEquals() was preventing the use of delegates by explicitly forcing the equal() check to go through a function. https://github.com/dlang/phobos/commit/63397e57a95c33dd3f8207822cff34bbabbbcfd4 Merge pull request #6304 from chvor/rbtree-delegate Fix issue 18634 - support for delegate comparators in rbtree merged-on-behalf-of: Sebastian Wilzbach <[email protected]>