<div dir="ltr"><div>Just yet another in the endless stream of cases why ref should be part of the type and not a 'storage class'! Literally everything ref touches gets more complex than it should.</div><div><b><font size="6">🎉</font></b><br></div></div><br><div class="gmail_quote gmail_quote_container"><div dir="ltr" class="gmail_attr">On Fri, 21 Feb 2025 at 09:26, Quirin Schroll via Digitalmars-d <<a href="mailto:digitalmars-d@puremagic.com">digitalmars-d@puremagic.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">Function templates with `auto ref` parameters can’t be explicitly <br>
instantiated, but must be IFTI’d to infer `ref`-ness of `auto <br>
ref` parameters.<br>
<br>
When doing meta-programming, that is annoying. Some template <br>
might have verified that some alias refers to a function template <br>
and that it can be called with the kinds of arguments the <br>
template wants to use. Great job, D, for making this rather easy! <br>
However, for some reason, we need a function pointer (or <br>
delegate) to the respective instance. That is always possible, <br>
except if the alias is to a function template with `auto ref` <br>
parameters.<br>
<br>
We should find a solution to this. It does not have to be pretty, <br>
there should be just *some* way to do it.<br>
<br>
The ideal test case is a function template with a sequence <br>
parameter and `auto ref` on non-template-argument-type parameters:<br>
```d<br>
void example(Ts...)(auto ref int arg, auto ref Ts args) { }<br>
<br>
auto fp = &example/*YOUR IDEA*/;<br>
```<br>
<br>
One way I thought could work is just passing `ref T`: <br>
`example!(ref long)`, but that doesn’t work for the `int` <br>
parameter.<br>
<br>
While I think the following looks okay, it occupies the syntax <br>
`![]` which we might use for something more useful:<br>
<br>
```d<br>
auto fp1 = &example![ref](); // void function(ref int)<br>
auto fp2 = &example![auto](); // void function(int)<br>
<br>
auto fp1 = &example; // void <br>
function(ref int, char, ref wchar)<br>
auto fp2 = &example; // void <br>
function(int, ref char, wchar)<br>
```<br>
<br>
While required for explicit function template instantiation, even <br>
IFTI can profit from it: Not every lvalue argument should be <br>
passed by reference.<br>
```d<br>
int x;<br>
example(x); // Full IFTI: `ref`, Ts empty<br>
example!()(x); // Partial IFTI: infers `ref`, Ts empty, same as <br>
above<br>
example![ref]()(x); // No IFTI: `ref` explicit, Ts empty, same as <br>
above<br>
example![auto]()(x); // No IFTI: `auto` means not `ref`. Pass `x` <br>
by value/copy<br>
<br>
```<br>
</blockquote></div>