http://d.puremagic.com/issues/show_bug.cgi?id=10404
[email protected] changed: What |Removed |Added ---------------------------------------------------------------------------- CC| |[email protected] --- Comment #1 from [email protected] 2013-06-19 05:25:03 PDT --- (In reply to comment #0) > Given a struct S with state and methods, Class!S should be a type that: Can you list some use cases? > * contains exactly one member, having type S Is this going to waste some space because of struct alignment sometimes being higher than the alignment of its members? Also D classes are free to reorder their fields to pack them (see Issue 8873 ), but if you put the whole D inside the class you lose that optimization. ----------------- Is it a good idea to also add optional interfaces to Class, as shown below? import std.stdio, std.math; interface Shape {} struct CircleS { int x, y, r; } alias Circle = Class!(CircleS, Shape); struct RectS { int x, y, w, h; } alias Rect = Circle!(RectS, Shape); real area(in Shape s) { if (cast(Circle)s) { const c = cast(Circle)s; return c.r ^^ 2 * PI; } else { const r = cast(Rect)s; return r.w * r.h; } } void main() { new Circle(5, 10, 20).area.writeln; } This is a bit like an Algebraic(Circle, Rect) where Circle and Rect are by reference... ----------------- Similarly this is a ClassTuple, it's defined with the syntax of std.typecon.Tuple: alias Circle2 = ClassTuple!(int,"x", int,"y", int,"r"); But probably this is enough, no need for a ClassTuple: alias Circle3 = Class!(Tuple!(int,"x", int,"y", int,"r")); -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: -------
