Implementing interfaces using alias this
Balagopal Komarath via Digitalmars-d-learn
digitalmars-d-learn at puremagic.com
Wed Jun 14 15:29:08 PDT 2017
On Wednesday, 14 June 2017 at 21:04:55 UTC, basile b. wrote:
> The way to do that in D is with mixins:
That is an interesting solution.
However, my original goal was to figure out whether one can make
struct types behave polymorphically (Which is not mentioned in my
original question). I know that this is not supported by design.
I want to keep the original struct types but also allow functions
to accept those struct types and do runtime dispatch. The
following code should give a better idea by what I mean by this.
https://dpaste.dzfl.pl/051f6a4da059
The user need only define Duck1, Duck2 ... with appropriate
functions and mixin toDuck. Then a function that accepts a Duck
can accept DuckLike (for dynamic dispatch) or templatize on the
type of Duck.
More information about the Digitalmars-d-learn
mailing list