The year is 2019

XavierAP n3minis-git at yahoo.es
Sat Jul 27 05:09:11 UTC 2019


On Saturday, 27 July 2019 at 04:26:01 UTC, Mike Franklin wrote:
>
> struct IOStream
> {
>     IStream i;
>     OStream o;
>
>     // Generating the following functions can be automated with 
> D's awesome
>     // metaprogramming facilities
>     string read() { return i.read(); }
>     void write(string s) { o.write(s); }
>
>     // But how do we implicitly convert from `IOStream` to 
> `IStream` or
>     // `OStream` without `alias this`, `opImplicitCast` or some 
> other?
>     alias i this;
>     alias o this; // mulitple `alias this` currently not 
> implemented, so
>                   // this doesn't work
> }

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();
     }
     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.


More information about the Digitalmars-d mailing list