<div dir="ltr">I'm running into consistent problems with default args and argument deduction in templates.<div>There seem to be 2 consistent classes of problem:</div><div><br></div><div>struct S(size_t len = 10)</div><div>
{</div><div>  ubyte[len] data;</div><div>}</div><div><br></div><div>S!100 x; // this works fine</div><div>S y; // this doesn't work (!)</div><div>S!() z; // this works</div><div><br></div><div>The template arg has a default arg, why require !() ??</div>
<div>This causes problems in meta code, where you want to create an instance of some T, and T may be a normal type with no template args, in which case !() is invalid, but a template type with default args should also be acceptable, but it doesn't work because the meta code doesn't specify !().</div>
<div><br></div><div><br></div><div>The other case I am running in to is when I have 'struct S(T)' or 'class C(T)', where T can be inferred from the constructor, but it isn't.</div><div><br></div><div>struct S(T)</div>
<div>{</div><div>  this(T t)</div><div>  {</div><div>    m = t;</div><div>  }</div><div><br></div><div>  T m;</div><div>}</div><div><br></div><div>int myThing;</div><div>auto s = S(myThing); // error!</div><div>auto s = S!(typeof(myThing))(myThing); // works, but horrible, and breaks down again when used in place of non-template counterparts in meta code.<br>
</div><div><br></div><div><br></div><div>My main gripe here is that in both these cases which require special treatment for basic instantiation, they break down when used in meta code without loads of hacks and ugly mess throughout the meta to handle these cases.</div>
<div><br></div><div>Why these restrictions? Can these cases be fixed?</div><div>I have quite a lot of code that would be sanitised by these changes.</div></div>