Fun with templates

Manu turkeyman at gmail.com
Sun Jul 7 19:10:35 PDT 2013


On 7 July 2013 22:31, Dmitry Olshansky <dmitry.olsh at gmail.com> wrote:

> 06-Jul-2013 05:34, Manu пишет:
>
>> Okay, so I feel like this should be possible, but I can't make it work...
>> I want to use template deduction to deduce the argument type, but I want
>> the function arg to be Unqual!T of the deduced type, rather than the
>> verbatim type of the argument given.
>>
>> I've tried: void f(T : Unqual!U, U)(T a) {}
>> and: void f(T)(Unqual!T a) {}
>>
>
> The thing is that if even if you somehow force your way past IFTI what
> would be generated is:
>
> f!(const int)(int arg);
> f!(immutable int)(int arg);
> f!(shared int)(int arg);
> f!(const shared int)(int arg);
>
> Which IMHO falls short of desired goal.
> Short of using a forwarding thunk (that you don't like, but if there was
> force_inline?) we'd have to hack the compiler.


Hmmm, this is an interesting point.
I initially thought this was desirable, it could be useful.
But now that you point it out, I guess the point you are making is that
they will all mangle separately anyway?
That seems problematic, because since all have the same return value and
physical arguments, how does the compiler choose an overload to call in
various circumstances?
I think I (mistakenly?) presumed they would all mangle the same, since they
have the same physical signature (return value + physical args), and
therefore all be the same function (eliminating the duplicates).
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.puremagic.com/pipermail/digitalmars-d/attachments/20130708/95c1ab39/attachment.html>


More information about the Digitalmars-d mailing list