Implicit instantiation of parameterless templates

F i L witte2008 at gmail.com
Fri Oct 5 13:34:59 PDT 2012


Piotr Szturmaj wrote:
> final abstract class Console
> {
>     static:
>     void write() { }
>     void read() { }
> }
>
> Console.write();
>
> P.S. Yes, simultaneous final and abstract actually works :)

Yes, I know there are other ways to do this, like you mentioned 
above. However, parameter-less templates would still be nice for 
scopes withing a Class (like my original example). Like I 
mentioned, it's possible today:

     class Foo
     {
         int bar;

         alias Baz!() baz;
         template Baz()
         {
             int bar;
         }
     }

     auto foo = new Foo();

     foo.bar = 10;
     foo.baz.bar = 10; // Same as..
     foo.Baz!().bar = 10; // ..writing this.

However, like OP is suggesting, it would be nice to have 
syntax-sugar to eliminate the need for extra typing at 
instantiation and at definition (my suggestion). The fact that 
these odd '!()' symbols are required will probably detour 
less-experienced people from using this feature today.


More information about the Digitalmars-d mailing list