DIP66 - Multiple alias this
Mike
slavo5150 at yahoo.com
Wed Sep 30 02:34:27 UTC 2020
On Wednesday, 30 September 2020 at 02:08:17 UTC, Andrei
Alexandrescu wrote:
> On 9/29/20 9:42 PM, Mike wrote:
>> On Wednesday, 30 September 2020 at 01:36:59 UTC, Mike wrote:
>>
>>> So, here are a couple of proposals off the top of my head. I
>>> imagine someone more talented than I can think of a few more:
>>>
>>> 1. Deprecate `alias this` for classes, and implement
>>> multiple `alias this` for structs. That will give users the
>>> composition feature they need, and in addition, because
>>> structs cannot inherit, it removes the complexity Walter
>>> spoke of.
>>>
>>> 2. Add `opImplicit`, implicit copy constructors, or
>>> something of that ilk. Then users only need to forward
>>> members using D's metaprogramming facilities. Both uses of
>>> `alias this` are covered, but no `alias this` is required.
>>> `alias this` can then be deprecated entirely.
>>>
>>> 3. Add struct inheritance like C++.
>>
>> 4. Somehow allow structs to implement interfaces.
>
> I'd love it if interfaces could implement methods. (All MI
> related issues are related to state, not implementation of
> methods.)
FWIW, C# 8 recently added such a feature. They call it "Default
Interface Members":
https://devblogs.microsoft.com/dotnet/default-implementations-in-interfaces/ However, the didn't finish the implementation and deferred this very important component: https://github.com/dotnet/csharplang/issues/2337 I've used this feature quite a bit, but it's only mildly useful until #2337 is addressed.
That being said, I think that is somewhat tangential to the topic
of this thread which I argue can be boiled down to "multiple
alias this (or some other feature) is needed to do composition
well with structs".
More information about the Digitalmars-d
mailing list