Re: Struct template cannot deduce function from argument types

2018-06-27 Thread Luka Aleksic via Digitalmars-d-learn
On Wednesday, 27 June 2018 at 17:07:52 UTC, Jonathan M Davis 
wrote:
On Wednesday, June 27, 2018 16:19:56 Luka Aleksic via 
Digitalmars-d-learn wrote:

[...]



[...]


Well, for one, what's on the left side of the = doesn't 
normally affect the type of what's on the right. It does in 
some cases with literals - e.g.


[...]


Thank you very much for a clear explanation and examples of how 
to do this sort of thing idiomatically. Very useful and cleared 
up all I was confused about.


Struct template cannot deduce function from argument types

2018-06-27 Thread Luka Aleksic via Digitalmars-d-learn

Hello,

In the following code:

struct pair(T, U) {
T first;
U second;

this(T arg_first, U arg_second) {
first = arg_first;
second = arg_second;
}
};

void main() {

pair!(char, uint) p1 = pair('a', 1);

}

I am getting the following error:

scratch.d(14): Error: struct scratch.pair cannot deduce function 
from argument types !()(char, int), candidates are:

scratch.d(2):scratch.pair(T, U)
Failed: ["/usr/bin/dmd", "-v", "-o-", "scratch.d", "-I."]

Changing the offending line to:

pair!(char, uint) p1 = pair!(char, uint)('a', 1);

fixes the issue.

However I am interested to know why the first code couldn't 
deduce the types-- and why does it even have to try to deduce 
them, when I explicitly stated that p1 was of the type "pair of 
char and uint"?


Thanks,
L. Aleksic