For regular function matching, an int argument can be automatically converted to a size_t. But if IFTI is in play, then the difference between int and size_t in the function's parameter list causes IFTI to fail to find a match.
-------
import std.stdio : writefln;
void simple_func(char[] s, size_t i)
{
writefln(s, i);
}
void simple_func_t(T)(T s, size_t i)
{
writefln(s, i);
}
void main(char[][] args)
{
// ok as basic function
simple_func(args[0], 3);
// ok with explicit type
simple_func_t!(char[])(args[0], 3);
// ok with exact match on non-template param
simple_func_t!(char[])(args[0], 3u);
// Fails to to match with IFTI:
// "template template_deduction.simple_func_t(T) does not
// match any template declaration
// template template_deduction.simple_func_t(T) cannot
// deduce template function from argument types (char[],int)"
simple_func_t(args[0], 3);
}
Comment #1 by thomas-dloop — 2006-11-29T15:36:27Z
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
[email protected] schrieb am 2006-11-28:
> http://d.puremagic.com/issues/show_bug.cgi?id=617
> For regular function matching, an int argument can be automatically converted
> to a size_t. But if IFTI is in play, then the difference between int and
> size_t in the function's parameter list causes IFTI to fail to find a match.
>
> -------
> import std.stdio : writefln;
>
> void simple_func(char[] s, size_t i)
> {
> writefln(s, i);
> }
> void simple_func_t(T)(T s, size_t i)
> {
> writefln(s, i);
> }
>
>
> void main(char[][] args)
> {
> // ok as basic function
> simple_func(args[0], 3);
>
> // ok with explicit type
> simple_func_t!(char[])(args[0], 3);
>
> // ok with exact match on non-template param
> simple_func_t!(char[])(args[0], 3u);
>
> // Fails to to match with IFTI:
> // "template template_deduction.simple_func_t(T) does not
> // match any template declaration
> // template template_deduction.simple_func_t(T) cannot
> // deduce template function from argument types (char[],int)"
> simple_func_t(args[0], 3);
> }
Added to DStress as
http://dstress.kuehne.cn/run/t/template_49_A.dhttp://dstress.kuehne.cn/run/t/template_49_B.dhttp://dstress.kuehne.cn/run/t/template_49_C.d
Thomas
-----BEGIN PGP SIGNATURE-----
iD8DBQFFbf+NLK5blCcjpWoRAsoKAJ4k/a8BP67hinQp3+Ae82LZEuIQsgCeKqwZ
/AJVkA45XnK8ddpPf1M0BPY=
=4yoq
-----END PGP SIGNATURE-----
*** Bug 1178 has been marked as a duplicate of this bug. ***
Comment #4 by larsivar — 2008-01-22T16:47:39Z
Just noting that this bug (when propagated to GDC), means that code that should be portable to 64 bit targets isn't, and requires casts as a workaround.
Examples include
foo(cast(size_t)3)
instead of
foo(3u).