Template with default parameter

Andrey Zherikov andrey.zherikov at gmail.com
Fri Mar 11 04:41:40 UTC 2022


I have simple template:
```d
template T(int i=3)
{
     mixin template M(int m)
     {
	    enum t = i;
     }
}

{
	mixin T!1.M!1;
	pragma(msg, t);   // 1
}
{
	mixin T!().M!1;
	pragma(msg, t);   // 3
}
{
	mixin T.M!1;      // Error: identifier `M` of `T.M` is not 
defined
					  // Error: mixin `M!1` is not defined
	pragma(msg, t);   // Error: undefined identifier `t`
					  //        while evaluating `pragma(msg, t)`
}
```

What should I do to be able to write `T.M!...`? I want to omit 
verbose `!()` for `T`. Note that mixins are essential here.


More information about the Digitalmars-d-learn mailing list