function type parameter inference not working

Ali Çehreli via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Tue Apr 25 12:57:30 PDT 2017


On 04/25/2017 12:19 PM, XavierAP wrote:

 > void assembleMass1D(Mat, Vec)(ref Mat M, const ref Vec x)
 > { /* ... */ }
 >
 > Matrix!(2,2) M;
 > Vector!2     V;
 > assembleMass1D(M, V);          // OK
 > assembleMass1D(M, Vector!2()); // ERROR template cannot deduce function
 >
 >
 > Is this a bug?

This is an intentional limitation of D. It's not possible to bind 
rvalues (temporaries) to reference parameters. The best option here is 
'auto ref':

void assembleMass1D(Mat, Vec)(auto ref Mat M, auto ref const(Vec) x)
{ /* ... */ }

Ali



More information about the Digitalmars-d-learn mailing list