On Monday, 5 November 2012 at 08:01:57 UTC, Jonathan M Davis wrote:
auto ref's current semantics can't possibly work with non-templated functions, and it's clear that there are good reasons for keeping auto ref as it is now for templates. So, either we make it work with non-templated functions with different (albeit similar) semantics, or we need a new attribute for doing what
we want to do with non-templated functions.

I agree that the current auto ref semantics are only useful for templates since "auto ref T" is replaced by either a reference (ref T for lvalues) or a value (T for rvalues), two very different things. I don't know how auto ref for templates is currently implemented, i.e., if, given a function

void foo(T)(auto ref T x, auto ref T y) {}

the compiler would instantiate the template max 2^2 times for each used type T to cover all lvalue/rvalue combinations for x and y. In that case, treating a non-templated function

void foo(auto ref MyStruct x, auto ref MyStruct y) {}

as implicit template (without template parameters) would be a viable option imho, i.e.,

void foo()(auto ref MyStruct x, auto ref MyStruct y) {}

If that kind of auto-templating is not what we want, I'd definitely opt for allowing rvalues as "in ref" parameters to keep things simple.

Reply via email to