Skip to content

Instantly share code, notes, and snippets.

@JakobOvrum
Last active August 29, 2015 14:04
Show Gist options
  • Save JakobOvrum/535fb87526d8807851f8 to your computer and use it in GitHub Desktop.
Save JakobOvrum/535fb87526d8807851f8 to your computer and use it in GitHub Desktop.
Equality and ordering
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