On Friday, 8 May 2020 at 22:03:47 UTC, NaN wrote:
void bar()
{
bam(foo(1));
}
if you change the declaration of foo or bam to "ref T x", ie..
auto foo(T)(ref T x)
auto bam(T)(ref T x)
then the compiler complains thus...
ldc 1.17.0 (Editor #1, Compiler #1) D#1 with ldc 1.17.0
<source>(23): Error: template `test.foo` cannot deduce function
from argument types `!()(int)`, candidates are:
<source>(7): `test.foo(T)(ref T x)`
Compiler returned: 1
Why would ref make any difference to deciding what function to
use, it even says there's only one candidate?
Cheers
The integer literal `1` is an rvalue, and can't be passed by
reference.
If you explicitly instantiate the templates foo and bar in the
function call, you get a more informative error message:
bam!int(foo!int(1));
Error: function onlineapp.foo!int.foo(ref int x) is not callable
using argument types (int)
cannot pass rvalue argument 1 of type int to parameter ref
int x