implemented issue 5945

This commit is contained in:
Jack Stouffer 2015-08-22 11:38:03 -04:00
parent 6df5d551fd
commit 0f05183f5c

View file

@ -20,6 +20,7 @@ Authors: Steven Schveighoffer, $(WEB erdani.com, Andrei Alexandrescu)
module std.container.rbtree; module std.container.rbtree;
import std.functional : binaryFun; import std.functional : binaryFun;
import std.format;
public import std.container.util; public import std.container.util;
@ -1669,6 +1670,16 @@ 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(")");
}
/** /**
* Constructor. Pass in an array of elements, or individual elements to * Constructor. Pass in an array of elements, or individual elements to
* initialize the tree with. * initialize the tree with.
@ -1825,6 +1836,7 @@ pure unittest
pure unittest pure unittest
{ {
import std.array : array; import std.array : array;
auto rt1 = redBlackTree(5, 4, 3, 2, 1); auto rt1 = redBlackTree(5, 4, 3, 2, 1);
assert(rt1.length == 5); assert(rt1.length == 5);
assert(array(rt1[]) == [1, 2, 3, 4, 5]); assert(array(rt1[]) == [1, 2, 3, 4, 5]);
@ -1842,6 +1854,19 @@ pure unittest
assert(array(rt4[]) == ["hello"]); assert(array(rt4[]) == ["hello"]);
} }
unittest {
import std.conv : to;
auto rt1 = redBlackTree!string();
assert(rt1.to!string == "RedBlackTree([])");
auto rt2 = redBlackTree!string("hello");
assert(rt2.to!string == "RedBlackTree([\"hello\"])");
auto rt3 = redBlackTree!string("hello", "world", "!");
assert(rt3.to!string == "RedBlackTree([\"!\", \"hello\", \"world\"])");
}
//constness checks //constness checks
unittest unittest
{ {