Why can't we derive struct's?
Manu
turkeyman at gmail.com
Thu Dec 20 01:40:02 UTC 2018
I've long since become bored of this design decision. Is there good
reason for it?
Why should it be impossible to derive a struct?
It can just be a sugar for an `alias this`, but for a case of simple
inheritance, `alias this` can be tedious to spot and understand when
reading the code.
There's also the special case of an empty base-struct. I
**constantly** have to do this:
struct Derived
{
static if (Base.tupleof.length == 0)
ref inout(Base) base() inout { return *cast(inout(Base)*)&this; }
else
Base base;
alias base this;
// the things...
}
If not that, then the derived class gets an aligned field of nothing
populated by one byte of empty base struct.
It also wastes the single `alias this` slot that we get in a
no-multiple-alias-this world.
As far as I can tell, the decision is arbitrary... can we move past this?
More information about the Digitalmars-d
mailing list