www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - Templated Function can't deduce function arguments

reply Jonathan Crapuchettes <jcrapuchettes gmail.com> writes:
Can anyone tell me why this doesn't compile? Dmd 2.062 says that it 
cannot deduce the template function from arguments types.

import std.stdio;

void main()
{
	test!(dchar, int)('b', 6, 'a', 54);
}

template test(Types...)
{
    void test(T...)(const Types v, const T values...)
    {
        writefln("%s,%s", v);
        foreach (s; values)
            writefln("%s,%s", s);
    }
}

Thank you,
Jonathan
May 22 2013
parent reply "Steven Schveighoffer" <schveiguy yahoo.com> writes:
On Wed, 22 May 2013 21:16:44 -0400, Jonathan Crapuchettes  
<jcrapuchettes gmail.com> wrote:

 Can anyone tell me why this doesn't compile? Dmd 2.062 says that it
 cannot deduce the template function from arguments types.

 import std.stdio;

 void main()
 {
 	test!(dchar, int)('b', 6, 'a', 54);
 }

 template test(Types...)
 {
     void test(T...)(const Types v, const T values...)
Do you need that last elipsis? I thought you didn't, but not sure. -Steve
May 22 2013
parent reply "Jonathan M Davis" <jmdavisProg gmx.com> writes:
On Wednesday, May 22, 2013 21:31:53 Steven Schveighoffer wrote:
 On Wed, 22 May 2013 21:16:44 -0400, Jonathan Crapuchettes
 
 <jcrapuchettes gmail.com> wrote:
 Can anyone tell me why this doesn't compile? Dmd 2.062 says that it
 cannot deduce the template function from arguments types.
 
 import std.stdio;
 
 void main()
 {
 
 test!(dchar, int)('b', 6, 'a', 54);
 
 }
 
 template test(Types...)
 {
 
 void test(T...)(const Types v, const T values...)
Do you need that last elipsis? I thought you didn't, but not sure.
You don't, and I'm surprised that it compiles, since I don't think that the elipsis is actually legal there. AFAIK, the only time that an elipsis is legal in the function arguments is with array variadics; e.g. auto foo(int[] bar...) {...} - Jonathan M Davis
May 22 2013
parent reply Jonathan Crapuchettes <jcrapuchettes gmail.com> writes:
On Wed, 22 May 2013 23:28:21 -0400, Jonathan M Davis wrote:

 On Wednesday, May 22, 2013 21:31:53 Steven Schveighoffer wrote:
 On Wed, 22 May 2013 21:16:44 -0400, Jonathan Crapuchettes
 
 <jcrapuchettes gmail.com> wrote:
 Can anyone tell me why this doesn't compile? Dmd 2.062 says that it
 cannot deduce the template function from arguments types.
 
 import std.stdio;
 
 void main()
 {
 
 test!(dchar, int)('b', 6, 'a', 54);
 
 }
 
 template test(Types...)
 {
 
 void test(T...)(const Types v, const T values...)
Do you need that last elipsis? I thought you didn't, but not sure.
You don't, and I'm surprised that it compiles, since I don't think that the elipsis is actually legal there. AFAIK, the only time that an elipsis is legal in the function arguments is with array variadics; e.g. auto foo(int[] bar...) {...} - Jonathan M Davis
The last ellipsis was a remnant of testing. Thank you for pointing that out. Removing it still doesn't help the compiler deduce the argument types. It appears that the issue has to do with the usage of the "Types" TypeTuple. If the const Types v is swapped out for const dchar v1, const int v2 the code compiles just fine. This makes me wonder if dmd is not interpreting the Types TypeTuple correctly in the inner-function. Jonathan
May 23 2013
parent reply Timon Gehr <timon.gehr gmx.ch> writes:
On 05/23/2013 07:21 PM, Jonathan Crapuchettes wrote:
 On Wed, 22 May 2013 23:28:21 -0400, Jonathan M Davis wrote:

 On Wednesday, May 22, 2013 21:31:53 Steven Schveighoffer wrote:
 On Wed, 22 May 2013 21:16:44 -0400, Jonathan Crapuchettes

 <jcrapuchettes gmail.com> wrote:
 Can anyone tell me why this doesn't compile? Dmd 2.062 says that it
 cannot deduce the template function from arguments types.

 import std.stdio;

 void main()
 {

 test!(dchar, int)('b', 6, 'a', 54);

 }

 template test(Types...)
 {

 void test(T...)(const Types v, const T values...)
Do you need that last elipsis? I thought you didn't, but not sure.
You don't, and I'm surprised that it compiles, since I don't think that the elipsis is actually legal there. AFAIK, the only time that an elipsis is legal in the function arguments is with array variadics; e.g. auto foo(int[] bar...) {...} - Jonathan M Davis
The last ellipsis was a remnant of testing. Thank you for pointing that out. Removing it still doesn't help the compiler deduce the argument types. It appears that the issue has to do with the usage of the "Types" TypeTuple. If the const Types v is swapped out for const dchar v1, const int v2 the code compiles just fine. This makes me wonder if dmd is not interpreting the Types TypeTuple correctly in the inner-function. Jonathan
Yes, this is indeed a compiler bug. http://d.puremagic.com/issues/
May 23 2013
parent Jonathan Crapuchettes <jcrapuchettes gmail.com> writes:
Thank you for the help. Bug report at http://d.puremagic.com/issues/
show_bug.cgi?id=10156
May 23 2013