module pind.samples.ja.lambda.lambda_10; import std.stdio; import std.string; struct Point { int x; int y; string toString() const { return format("(%s,%s)", x, y); } } struct Color { ubyte r; ubyte g; ubyte b; string toString() const { return format("RGB:%s,%s,%s", r, g, b); } } struct ColoredPoint { Color color; Point point; string toString() const { /* Color.toStringおよび * Point.toStringを活用: */ return format("{%s;%s}", color, point); } } struct Polygon { ColoredPoint[] points; string toString() const { /* ColoredPoint.toStringを活用: */ return format("%s", points); } } void main() { auto polygon = Polygon( [ ColoredPoint(Color(10, 10, 10), Point(1, 1)), ColoredPoint(Color(20, 20, 20), Point(2, 2)), ColoredPoint(Color(30, 30, 30), Point(3, 3)) ]); writeln(polygon); }