Brainstorming: Explicit instantiation of function template with `auto ref` parameters
Dukc
ajieskola at gmail.com
Mon Feb 24 16:41:00 UTC 2025
On Thursday, 20 February 2025 at 23:24:10 UTC, Quirin Schroll
wrote:
> Function templates with `auto ref` parameters can’t be
> explicitly instantiated, but must be IFTI’d to infer `ref`-ness
> of `auto ref` parameters.
I thought you could at least do it if I was willing to jump
through the hoops to completely specify the function type I was
trying to instantiate:
```D
void example(Ts...)(auto ref int arg, auto ref Ts args)
{ import std.stdio;
writeln(is(typeof(&arg))? "lvalue " : "rvalue ", arg);
}
void main()
{ void function(int) fPtr1 = &example!();
void function(ref int) fPtr2 = &example!();
fPtr1(10);
fPtr2(*new int(20));
}
```
. But the compiler plain out stated
```
app.d(1): Error: cannot explicitly instantiate template function
with `auto ref` parameter
```
, so this problem is even worse than I thought. I agree some sort
of solution is needed, though I don't have a good idea what it
should be like.
More information about the Digitalmars-d
mailing list