Last active
August 29, 2015 14:04
-
-
Save JakobOvrum/535fb87526d8807851f8 to your computer and use it in GitHub Desktop.
Equality and ordering
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import std.algorithm, std.container, std.uni; | |
struct S | |
{ | |
string str; | |
int opCmp(const S other) const | |
{ | |
return icmp(str, other.str); | |
} | |
} | |
void main() | |
{ | |
auto data = [S("c"), S("B"), S("a")]; | |
auto sorted = sort(data); | |
assert(sorted.equal([S("a"), S("B"), S("c")])); // Cool, this is what I wanted! | |
// Meanwhile, somewhere else... | |
auto rbt = redBlackTree(data); | |
assert(S("C") in rbt); // Wait what, I never asked for this! | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment