This repository has been archived on 2022-11-20. You can view files and clone it, but cannot push or open issues or pull requests.
patterns/templatemethod/sort/duck.d

38 lines
652 B
D
Raw Normal View History

2022-11-17 07:16:54 +00:00
module duck;
import std.conv : to;
import std.stdio : writeln;
class Duck
{
private string name;
private int weight;
this(string name, int weight)
{
this.name = name;
this.weight = weight;
}
override string toString() const @safe pure nothrow
{
return name ~ " weighs " ~ weight.to!string;
}
int opCmp(const Duck otherDuck) const @safe pure nothrow
{
if (weight < otherDuck.weight)
{
return -1;
}
else if (weight == otherDuck.weight)
{
return 0;
}
else
{
return 1;
}
}
}