The year is 2019

Mike Franklin slavo5150 at yahoo.com
Sat Jul 27 09:38:20 UTC 2019


On Saturday, 27 July 2019 at 05:09:11 UTC, XavierAP wrote:

> I was thinking of something simpler. And also new to the 
> language, not that could or should be implemented by lowering 
> (specially not lowering to alias this).
>
> Again leaving multiple aside:
>
>     interface IPrintable
>     {
>         string toString();
>     }

I like the idea of using interfaces, but I'm not sure how to 
implement such a thing for structs.  Is it just a compile-time 
contract?  How does it work at runtime when we call a function 
like `void foo(IPrintable p);` with an instance of `XY` or 
`ParallelXY`?

>     struct XY : IPrintable
>     {
>         @disable this();
>         real x, y;
>         string toString() { /*...*/ }
>         // implicitly final always; virtual illegal in structs.
>     }
>     struct ParallelXY : XY
>     {
>         uint universe;
>         void warp() { ++universe; }
>     }
>
> Implement the same simple thing (including @disable this() for 
> every type) with current D (alias this) and see how much more 
> typing and overhead.

Are you suggesting the body of `XY` simply be copied into 
`ParallelXY`?  I think that can already be done with template 
mixins.


More information about the Digitalmars-d mailing list