Fun with templates
Manu
turkeyman at gmail.com
Sat Jul 6 16:11:13 PDT 2013
On 7 July 2013 00:49, Timon Gehr <timon.gehr at gmx.ch> wrote:
> On 07/06/2013 04:06 PM, Manu wrote:
>
>> ...
>>
>> It seems that your code works if you put the Template Type explicit:
>> ----
>> import std.stdio;
>> import std.traits : Unqual;
>>
>> void foo(T)(Unqual!T a) {
>> writeln(typeof(a).stringof, " <-> ", T.stringof);
>> }
>>
>> void main() {
>> int a;
>> const int b;
>> immutable int c;
>>
>> //foo(c); /// Error
>> foo!(typeof(a))(a);
>> foo!(typeof(b))(b);
>> foo!(typeof(c))(c);
>> }
>> ----
>>
>>
>> Indeed, hence my point that the type deduction is the key issue here.
>> It should be possible... maybe a bit tricky though.
>>
>
> The key issue is that the syntax void foo(T)(Unqual!T a); denotes roughly
> the opposite of what you think it denotes. Basically, inference is
> instructed to find a T, such that Unqual!T is the argument type.
>
Perhaps what you say is true, but does that mean something to the effect of
what I'm trying to demonstrate is impossible? I feel like it would be a
much cleaner solution than any of the others presented in this thread...
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.puremagic.com/pipermail/digitalmars-d/attachments/20130707/665b45c0/attachment.html>
More information about the Digitalmars-d
mailing list