Skip to content

Commit 6f571c5

Browse files
std.container.rbtree: Fix support for less predicates taking ref const (#10792)
1 parent c7e0f6c commit 6f571c5

File tree

1 file changed

+12
-1
lines changed

1 file changed

+12
-1
lines changed

std/container/rbtree.d

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -747,7 +747,7 @@ private struct RBRange(N)
747747
* inserted after all existing duplicate elements.
748748
*/
749749
final class RedBlackTree(T, alias less = "a < b", bool allowDuplicates = false)
750-
if (is(typeof(binaryFun!less(T.init, T.init))))
750+
if (is(typeof((ref const T a) => binaryFun!less(a, a))))
751751
{
752752
import std.meta : allSatisfy;
753753
import std.range : Take;
@@ -2260,3 +2260,14 @@ if ( is(typeof(binaryFun!less((ElementType!Stuff).init, (ElementType!Stuff).init
22602260
t.insert([1, 3, 5, 4, 2]);
22612261
assert(t[].equal([5, 4, 3, 2, 1]));
22622262
}
2263+
2264+
// should support `less` predicate taking `ref const`
2265+
@safe pure unittest
2266+
{
2267+
struct S
2268+
{
2269+
int* value;
2270+
}
2271+
2272+
cast(void) new RedBlackTree!(S, (ref const S a, ref const S b) => a.value > b.value);
2273+
}

0 commit comments

Comments
 (0)