Why can't we derive struct's?

Manu turkeyman at gmail.com
Thu Dec 20 02:23:47 UTC 2018

On Wed, Dec 19, 2018 at 6:10 PM Basile B. via Digitalmars-d
<digitalmars-d at puremagic.com> wrote:
> On Thursday, 20 December 2018 at 01:40:02 UTC, Manu wrote:
> > 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`,
> Yes but another possible semantic for a struct inheritance list
> would be the structural conformance, i.e duck types, but this
> will never happen in D since we use constraints for that.
> This could even be used as a primitive, simple and clean template
> system, although restricted to struct/union:
>      @dummy struct Base { void required(); }
>      struct Foo : Base { void required(){} }
>      // we don't expect a Base as param, but something that's
> conform with Base,
>      // i.e something that can be statically verified to have
> `void required();`
>      void call(@dummy Base base){}
> Which in D translates to much, really much verbose and complex
> code:
>      struct Base { void required(); }
>      struct Foo  { void required(){} }
>      void call(B)(B base)
>      if (__traits(hasMember, B, "required") &&
>          isSomeFuncion(...) &&
>          is(ReturnType!(...) == void))
>      {}
> let's say if you want to be 100% exact because nowadays I tend
> not to use template constraints anymore excepted when they are
> needed for the correct dispatching to an overload, they are a
> loss of time otherwise (i know some will hate this alternative
> point of view... )

I think strong traits are a different thing, otherwise you're
conflating syntax with class inheritance, and nobody will expect that.
I mean, I love strong traits, but make them a proper thing.
Your suggestion is just kinda weird and nobody would anticipate that.
I see no good reason to collide with normal class inheritance syntax
that way.

And that said, I don't think your answer is a comment on *why* it's
not possible today :)
I'd like to know the reason it doesn't just work already.

More information about the Digitalmars-d mailing list