On Wednesday, 15 March 2017 at 02:33:36 UTC, ketmar wrote:
Q. Schroll wrote:
void test(T)(T* arg);
void test(T)(ref T arg);
Let p be any pointer. Why is test(p) not an ambiguity error?
Why is the second overload chosen?
'cause `ref T` is more generic than `T*`. think of it as
"greedy match
Q. Schroll wrote:
void test(T)(T* arg);
void test(T)(ref T arg);
Let p be any pointer. Why is test(p) not an ambiguity error? Why is the
second overload chosen?
'cause `ref T` is more generic than `T*`. think of it as "greedy matching":
compiler first tries to match `int*`, and if that fail
void test(T)(T* arg);
void test(T)(ref T arg);
Let p be any pointer. Why is test(p) not an ambiguity error? Why
is the second overload chosen?
Making the first one take auto ref T* lets the compiler choose
the first.
Making the second one non-ref lets the compiler give me an
ambiguity error.