<div dir="ltr"><div class="gmail_extra"><div class="gmail_quote">On 24 July 2014 21:30, Manu <span dir="ltr"><<a href="mailto:turkeyman@gmail.com" target="_blank">turkeyman@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">
<div dir="ltr"><div><div class="h5"><div class="gmail_extra"><div class="gmail_quote">On 24 July 2014 21:25, Manu <span dir="ltr"><<a href="mailto:turkeyman@gmail.com" target="_blank">turkeyman@gmail.com</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">
<div dir="ltr"><div><div><div class="gmail_extra"><div class="gmail_quote">On 24 July 2014 19:37, John Colvin via Digitalmars-d <span dir="ltr"><<a href="mailto:digitalmars-d@puremagic.com" target="_blank">digitalmars-d@puremagic.com</a>></span> wrote:<br>


<blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex"><div>On Thursday, 24 July 2014 at 04:53:41 UTC, Manu via Digitalmars-d wrote:<br>

</div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex"><div>
I'm running into consistent problems with default args and argument<br>
deduction in templates.<br>
There seem to be 2 consistent classes of problem:<br>
<br></div><div>
struct S(size_t len = 10)<br>
{<br>
  ubyte[len] data;<br>
}<br>
<br>
S!100 x; // this works fine<br>
S y; // this doesn't work (!)<br>
S!() z; // this works<br>
<br>
The template arg has a default arg, why require !() ??<br></div><div>
This causes problems in meta code, where you want to create an instance of<br>
some T, and T may be a normal type with no template args, in which case !()<br>
is invalid, but a template type with default args should also be<br>
acceptable, but it doesn't work because the meta code doesn't specify !().<br>
</div></blockquote>
<br>
This opens a whole can of worms. It's very useful to be able to distinguish between templates and their instantiations. Seeing as D's alias system works on a pass-by-name system, you can't have a system where simply referring to a template instantiates it with no arguments.<br>



<br>
Apart from anything else it would break *so* much code.<br>
</blockquote></div><br></div></div></div><div class="gmail_extra">Isn't the call to the constructor enough to distinguish it is an instantiation rather than a reference to the template itself?</div><div class="gmail_extra">

<br></div>
<div class="gmail_extra">S is a template</div><div class="gmail_extra">S!() is a type</div><div class="gmail_extra">S(x,y,z) is a call to it's constructor, the expression has a type</div><div class="gmail_extra"><br>

</div>
<div class="gmail_extra">What is the useful distinction between S!()(x,y,z) and S(x,y,z)? How does either one of them make referring to the template 'S' difficult?</div><div class="gmail_extra">Is there some conflicting syntax where the parentheses mean something else when S perceived as a template? Why isn't the same problem applicable to function templates?</div>


</div>
</blockquote></div><br></div></div></div><div class="gmail_extra">Ack! Sorry! I misread, your response as being related to the constructor case, not the default arg case >_<</div><div class="gmail_extra"><br></div>
<div class="gmail_extra">
I see the problem with the default arg case. It's a real shame, because it has rather annoying side effects in generic code, and it doesn't appear to follow the same logical rules as with functions.</div><div class="gmail_extra">

This is precisely the sort of thing Scott Myers would be unhappy about... Someone will need to 'explain' this for years to come, I don't think it's intuitive ;)</div></div>
</blockquote></div><br></div><div class="gmail_extra">Although... the more I think about it, the more I wonder why it matters if the syntax is ambiguous when the name is taken in isolation, that never actually happens...</div>
<div class="gmail_extra">Why can't it just mean 'either the template, or the default arg instantiation', and be resolved when it's actually used?</div><div class="gmail_extra">Is it possible for templates or types to both appear in the same context and create an actual ambiguity? What would that expression look like?</div>
<div class="gmail_extra">The only place I can imagine a conflict could occur would be within an is() expression, but I'm not sure... can a uninstantiated template be used in an is() expression where a type would also be a meaningful fit?</div>
<div class="gmail_extra"><br></div><div class="gmail_extra">Generally, templates do this:</div><div class="gmail_extra">  T!()</div><div class="gmail_extra">And types do this:</div><div class="gmail_extra">  T var;</div><div class="gmail_extra">
<br></div><div class="gmail_extra">It's clear syntactically from 'T!()' that T is not a default args instantiation of T, because it's involved in a template instantiation expression.</div><div class="gmail_extra">
It's also clear from 'T var' that T is not a template, because a variable needs to have a type.</div></div>