define new types within templates

teo teo.ubuntu.remove at yahoo.com
Tue Dec 29 14:44:18 PST 2009


There was a way to define new types within templates and I think that I 
have seen that demonstrated here in the newsgroups, but cannot find it 
now. Can someone help me please?

I would like to do something like this:

template MyTemplate(T)
{
  struct T ~ "Struct"  // define FooStruct structure
  {
    int x;
  }
  class T ~ "Class"  // define FooClass class
  {
    void bar(T ~ "Struct" t)
    {
      // ...
    }
  }
}

void main()
{
  mixin MyTemplate!("Foo");
  FooStruct t;
  FooClass f = new FooClass();
  f.bar(t);
}

Hopefully I am not mistaken.


More information about the Digitalmars-d-learn mailing list