Showing with 19 additions and 7 deletions.
  1. +19 −7 std/container/rbtree.d
26 changes: 19 additions & 7 deletions std/container/rbtree.d
Original file line number Diff line number Diff line change
Expand Up @@ -1711,13 +1711,18 @@ assert(equal(rbt[], [5]));
}

/**
Formats the RedBlackTree into a sink function. For more info see
$(D std.format.formatValue)
*/
void toString(scope void delegate(const(char)[]) sink, FormatSpec!char fmt) const {
sink("RedBlackTree(");
sink.formatValue(this[], fmt);
sink(")");
Formats the RedBlackTree into a sink function. For more info see $(D
std.format.formatValue). Note that this only is available when the
element type can be formatted. Otherwise, the default toString from
Object is used.
*/
static if(is(typeof((){FormatSpec!(char) fmt; formatValue((const(char)[]) {}, ConstRange.init, fmt);})))
{
void toString(scope void delegate(const(char)[]) sink, FormatSpec!char fmt) const {
sink("RedBlackTree(");
sink.formatValue(this[], fmt);
sink(")");
}
}

/**
Expand Down Expand Up @@ -2044,3 +2049,10 @@ unittest
import std.algorithm : equal;
assert(rt1.upperBound(2).equal([3, 4, 5]));
}

// issue 15941
unittest
{
class C {}
RedBlackTree!(C, "cast(void*)a < cast(void*)b") tree;
}