Can we just have struct inheritence already?

bioinfornatics bioinfornatics at fedoraproject.org
Mon Jun 24 16:13:05 UTC 2019


On Saturday, 22 June 2019 at 07:10:26 UTC, XavierAP wrote:
> If we want multiple inheritance or even virtual methods in 
> structs, completely new and severe problems appear. And I don't 
> think these patterns have utility that justifies these problems 
> or even their existence alone.
>
> Single struct inheritance with no virtual methods presents in 
> my opinion no problems, and it would be in many cases a better, 
> more concise, boilerplate-less, clearer, cleaner way to 
> accomplish the type extension and not repeating oneself that 
> currently we can do only by composition and explicit 
> forwarding, alias this, or macro-ish template mixins.
>
> On Saturday, 22 June 2019 at 06:29:43 UTC, Ola Fosheim Grøstad 
> wrote:
>> On Friday, 21 June 2019 at 22:19:12 UTC, bioinfornatics wrote:
>>> struct Employee{
>>>   delegate: get_age, to: _person
>>>   delegate: get_experience, to: _career
>>>
>>>   immutable Person _person;
>>>   immutable Career _career;
>>
>> Listing all methods isn't very helpful, if that is the 
>> suggestion. Then a more consistent syntax would be
>>
>> struct Employee {
>> alias getage = _person.getage;
>> alias get_experience = _career.get_experience;
>
> Explicit forwarding is already/always possible. These syntaxes 
> are not so more concise than
>
> auto getAge() { return _person.getAge(); }
>
> So I'd see no point in burdening D with adding such candy 
> features.

Thanks for your insight.
So I have a question what solve the struct inheritance which can 
not be done by the use of method forwarding?

To me the template proxy is the way to go. They are no needs to 
extend the dlang syntax.

Case 1: too few people know it
Case 2: struct inheritance solve things that can not be done 
using the proxy

https://dlang.org/library/std/typecons/proxy.html



More information about the Digitalmars-d mailing list