Struct-typing in Phobos
Dicebot
public at dicebot.lv
Tue Feb 4 05:01:27 PST 2014
I find structs completely superior to classes as design base and
only resort to latter if find myself in need of polymorphic
behavior. There is an issue of bad constraint error messages but
that is exactly that - implementation flaw that needs to be
fixed, not a conceptual flaw.
Mostly agree with Jakob have said, few extra tips:
1) you can use `foo(T : Stuff)(T t)` instead of `foo(T)(T t) if
(isImplicitlyConvertible!(T, Stuff))`
2) You can extend structs no only with UFCS but also via `alias
this`:
struct One
{
void foo() {}
}
struct Two
{
private One one;
alias one this;
void bar() {}
}
void main()
{
Two two;
two.foo(); two.bar();
}
Aliasing members as this can be considered a form of single
inheritance in this context.
More information about the Digitalmars-d
mailing list