template+alias as an object's "namespace"

F i L witte2008 at gmail.com
Wed Apr 18 16:41:41 PDT 2012


kennytm wrote:
> struct Foo1 {
>     struct Unsafe {
>     static:
>         void bar() { ... }
>     }
> }
> Foo1 f;
> f.Unsafe.bar();

That fails when you add variables though:

   struct Foo {
     struct Unsafe {
       string name;
       static void bar() {
         writeln(name); // error: needs 'this'
       }
     }
   }

Like I said, it's completely possible with templates today, you 
just have to alias them for nice syntax. Parameterless templates 
would just be sugar, but that sugar would be nice when you want 
to use classifications like this in real code.


More information about the Digitalmars-d mailing list