www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - Cannot distinguish between template function wtih 0 args and 1 arg

reply Engine Machine <EM EM.com> writes:
This really makes no sense

Error: template Mem cannot deduce function from argument types 
!(cast(eException)1280L, "main.d", 38u, "main.WinMain")(int), 
candidates are:
Mem(T, B = eX, string file = __FILE__, uint line = __LINE__, 
string func = __FUNCTION__)(size_t bytes)
Mem(T, B = eX, string file = __FILE__, uint line = __LINE__, 
string func = __FUNCTION__)()

Shouldn't these template functions be completely distinguished?

I tried to calling it with and without a value but same error. It 
is the only error.

This only occurs when I call it with the non-default template 
values:

I call it simply like Mem!(T, B, file, line, func)(34).

It seems if the template parameters match, that the compiler 
doesn't test the arguments.

Mem!T(34) works fine.
Aug 07 2016
next sibling parent Cauterite <cauterite gmail.com> writes:
On Monday, 8 August 2016 at 02:36:24 UTC, Engine Machine wrote:
 Error: template Mem cannot deduce function from argument types 
 !(cast(eException)1280L, "main.d", 38u, "main.WinMain")(int), 
 candidates are:
 Mem(T, B = eX, string file = __FILE__, uint line = __LINE__, 
 string func = __FUNCTION__)(size_t bytes)
 Mem(T, B = eX, string file = __FILE__, uint line = __LINE__, 
 string func = __FUNCTION__)()
From this error message it looks like the `B = eX` parameter is not getting matched up against the value `cast(eException)1280L` as you are hoping for. Probably because `1280L` is a value and it's expecting a type. Try replacing it with something like `alias B = eX` or `enum B = eX`.
Aug 08 2016
prev sibling parent ag0aep6g <anonymous example.com> writes:
On 08/08/2016 04:36 AM, Engine Machine wrote:
 This really makes no sense

 Error: template Mem cannot deduce function from argument types
 !(cast(eException)1280L, "main.d", 38u, "main.WinMain")(int), candidates
 are:
 Mem(T, B = eX, string file = __FILE__, uint line = __LINE__, string func
 = __FUNCTION__)(size_t bytes)
 Mem(T, B = eX, string file = __FILE__, uint line = __LINE__, string func
 = __FUNCTION__)()
Going backwards: func is "main.Winmain" - ok. line is 38u - ok. file is "main.d" - ok. B is cast(eException)1280L - B seems to be a type parameter, can't be a value. T is missing. The compiler goes forwards, not backwards, of course, so everything is mismatched. [...]
 This only occurs when I call it with the non-default template values:

 I call it simply like Mem!(T, B, file, line, func)(34).
That doesn't look like the instantiation that causes the error. You've got five template arguments here, but in the error there are only four. Can you post more complete code? Something doesn't add up here.
Aug 08 2016