On Tuesday, 25 December 2012 at 14:09:13 UTC, Andrei Alexandrescu wrote:
On 12/25/12 12:34 AM, Zhenya wrote:
On Tuesday, 25 December 2012 at 01:40:16 UTC, Peter Alexander wrote:
On Tuesday, 25 December 2012 at 00:56:44 UTC, Peter Alexander wrote:
On Monday, 24 December 2012 at 17:40:54 UTC, Jonathan M Davis wrote:
And if that doesn't work, can we simply make it so that the compiler automatically creates a variable when you pass an rvalue to a
non-templated
auto ref function?

I don't see any problems with this, but I admittedly haven't thought
too much about it.

If there are no problems with this way, then what I want to know is why the template version of auto ref wasn't implemented this way. The way auto ref is currently implemented for templates is a bit of a mess.
Maybe it's difficult to generate both versions because for the function
like this

void foo(auto ref S s1,auto ref S s2,...,auto ref s10)

compiler should generate 2^10 versions of function foo.

The compiler will only generate as many versions as there are compatible calls.

If it were a template. Jonathan's (first) proposal is that they are all generated eagerly, so that they can be used as virtual functions (among other things). Generating them lazily like template defeats the purpose of his proposal (to do that, just use templates!)

The first proposal is a dead end. I think his second proposal is more interesting, so I will repeat it here:

"Can we simply make it so that the compiler automatically creates a variable when you pass an rvalue to a non-templated auto ref function?"

So non-template auto ref parameters are just like ref parameters, except they will automatically convert rvalues to lvalues on call by creating a local variable. Normal ref parameters will still need lvalues.

Reply via email to