Skip to content

Commit

Permalink
implemented issue 5945
Browse files Browse the repository at this point in the history
  • Loading branch information
JackStouffer committed Sep 3, 2015
1 parent 6df5d55 commit 0f05183
Showing 1 changed file with 25 additions and 0 deletions.
25 changes: 25 additions & 0 deletions std/container/rbtree.d
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ Authors: Steven Schveighoffer, $(WEB erdani.com, Andrei Alexandrescu)
module std.container.rbtree;

import std.functional : binaryFun;
import std.format;

public import std.container.util;

Expand Down Expand Up @@ -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
* initialize the tree with.
Expand Down Expand Up @@ -1825,6 +1836,7 @@ pure unittest
pure unittest
{
import std.array : array;

auto rt1 = redBlackTree(5, 4, 3, 2, 1);
assert(rt1.length == 5);
assert(array(rt1[]) == [1, 2, 3, 4, 5]);
Expand All @@ -1842,6 +1854,19 @@ pure unittest
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
unittest
{
Expand Down

1 comment on commit 0f05183

@JohanEngelen
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@JackStouffer This breaks creation of rbtrees of classes that used to work:

class A {}
RedBlackTree!(A, "cast(void*)a < cast(void*)b") tree;

Thanks a lot for a bug fix.

See https://issues.dlang.org/show_bug.cgi?id=15941.

Please sign in to comment.