Can we just have struct inheritence already?
Radu
void at null.pt
Tue Jun 11 10:56:21 UTC 2019
On Sunday, 9 June 2019 at 08:05:34 UTC, Manu wrote:
> I am really really tired of this pattern:
>
> struct DerivedStruct
> {
> static if (BaseStruct.tupleof.length > 0)
> BaseStruct base;
> else
> ref inout(BaseStruct) base() inout { return
> *cast(inout(BaseStruct)*)&this; }
> alias base this;
>
> // derived members
> //...
> }
>
> Imagine if we could just write:
>
> struct DerivedStruct : BaseStruct
> {
> // derived members
> //...
> }
>
> Just imagine!
I like the idea! I use the `alias this` idiom everywhere, and it
is not too evident to new people coming from other languages,
there is an overhead in explaining and understanding what that
thing does, which is simple by itself.
However, I do see some issues with using the existing inheritance
syntax, as it creates some confusions and maybe some false
expectations.
I would like to have something like:
struct Derived mixin Base
{
}
which is more clear in the intent and reuses a well established
concept in the language.
More information about the Digitalmars-d
mailing list