Type of receiver

bitwise via Digitalmars-d digitalmars-d at puremagic.com
Sat Oct 24 11:25:29 PDT 2015


On Saturday, 24 October 2015 at 16:05:15 UTC, bitwise wrote:
> [...]
> class TypeInfo {}
> class TypeInfoImpl(T) : TypeInfo {}
>
> class BaseObject {
>     static TypeInfo typeInfo(this This)() {
>         return TypeInfoImpl!This();
>     }
>
>     static TypeInfo info = typeInfo();
> }
> class Foo : BaseObject {
>     // also has 'info' with correct info for 'Foo'.
> }
> [...]
>     Bit

Realizing now that this was a little bit of a brain fart...

My point is though, that it would be awesome if we could have 
functionality automatically generated by the compiler for all 
subclasses...but have it useable as a virtual method.

Maybe:

class Base {
     /* virtual function that is automatically
          instantiated for all subclasses */
     synthesized void foo(this This)() {
         doSomething!This;
     }
}
class Derived : Base {
     // foo automatically overridden for this class.
}

     Bit


More information about the Digitalmars-d mailing list