Function template argument deduction

Ali Çehreli acehreli at yahoo.com
Sat Apr 7 06:41:33 UTC 2018


On 04/06/2018 11:26 PM, Uknown wrote:
 > On Saturday, 7 April 2018 at 05:58:10 UTC, Paul Backus wrote:
 >> On Saturday, 7 April 2018 at 05:46:07 UTC, Uknown wrote:
 >>> I don't see the error you are talking about:
 >>> https://run.dlang.io/is/XWPIc1
 >>>
 >>> Are you using the latest compiler?
 >>
 >> Compile with -unittest.
 >>
 >> And yes; I'm using DMD 2.079.0.
 >
 > Now I feel silly. Anyway, I played around with your code. One thing I
 > found was `cons.head` returns a `T`, which can't be appended to a
 > string. You can fix this with `cons.head.to!string`, where `to` is from
 > std.conv. I'm not sure why IFTI isn't deducing `T` to be `int` though.
 > Hopefully some one else can help out here.
 >
 > What I did notice though is that when
 > `string list2string(T)(List!T list)` was changed to
 > `string list2string(T)(VariantN!(16LU, Nil, Tuple!(T, "head", This*,
 > "tail")) list)`
 > The compiler correctly deduce `T` to be `int`

I played with it as well by hacking the following:

string list2string(L)(L list)
{
     import std.traits : TemplateArgsOf;
     alias T = TemplateArgsOf!L[2][0];

     // ...
}

I hit the same problem that you describe. (Additionally, list2string 
does not return anything.)

Ali



More information about the Digitalmars-d-learn mailing list