<div dir="ltr">On 6 July 2013 11:45, Timon Gehr <span dir="ltr"><<a href="mailto:timon.gehr@gmx.ch" target="_blank">timon.gehr@gmx.ch</a>></span> wrote:<br><div class="gmail_extra"><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<div class="im">On 07/06/2013 03:34 AM, Manu wrote:<br>
</div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div class="im">
Okay, so I feel like this should be possible, but I can't make it work...<br></div><div class="im">
I want to use template deduction to deduce the argument type, but I want<br>
the function arg to be Unqual!T of the deduced type, rather than the<br>
verbatim type of the argument given.<br>
<br>
I've tried: void f(T : Unqual!U, U)(T a) {}<br>
and: void f(T)(Unqual!T a) {}<br>
<br>
Ie, if called with:<br>
   const int x;<br>
   f(x);<br>
Then f() should be generated void f(int) rather than void f(const int).<br>
<br>
I don't want a million permutations of the template function for each<br>
combination of const/immutabe/shared/etc, which especially blows out<br>
when the function has 2 or more args.<br>
<br>
Note: T may only be a primitive type. Obviously const(int*) can never be<br>
passed to int*.<br>
</div></blockquote>
<br>
void f(T)(const(T) a) {}<br>
<br>
This will strip off const, immutable and inout, but not shared.<br>
<br>
I'd have thought that<br>
<br>
void f(T)(const(shared(T)) a) {}<br>
<br>
would strip shared as well, but DMD does not match int to const(shared(int)) at all which I think is incorrect.<br>
</blockquote></div><br></div><div class="gmail_extra" style>So what is the signature of f() in this case? It looks like the function receives const(T), not T.</div><div class="gmail_extra" style>It looks like it sets T to Unqual!T, but it's not T that I'm interested in, it's the function argument being deduced to the correct type.</div>
<div class="gmail_extra" style><br></div><div class="gmail_extra" style>We can do impressive stuff like this:</div><div class="gmail_extra" style>  void f(T : U[N], U, size_t N)(T x); .. but I suppose in that example, T is still the supplied type verbatim, it's just performing a lot of fancy work to decompose it.<br>
</div><div class="gmail_extra" style><br></div><div class="gmail_extra" style>So then I wonder if my question becomes, with parameter type deduction, is it an absolute requirement that the parameter type is taken to be the supplied argument's type verbatim (and not possibly something it is implicitly castable to)?</div>
<div class="gmail_extra" style>Is there ANY way to flex this rule while retaining the functionality of argument type deduction?</div></div>