On 6/21/15 10:25 PM, Walter Bright wrote:
On 6/21/2015 10:08 PM, Steven Schveighoffer wrote:
On 6/22/15 12:11 AM, Andrei Alexandrescu wrote:
Walter and I discussed what auto ref for templates
You mean *non-templates*? auto ref for templates has a very well
defined meaning.
And reading your post, I'm unclear what exactly happens. Does this
generate 2
functions from one, and then call the wrapper for auto-ref?
So for instance:
ref int fun(auto ref int x);
What happens here?
auto x = &fun;
x(5);
-Steve
The idea is that fun(5) would be lowered to:
auto tmp = 5;
fun(tmp);
I don't think that lowering is recommended - it prolongs the lifetime of
the temporary through the end of the caller. But that may be actually a
good thing.
But when talking to Andrei I didn't realize that it would be subtly
different behavior than 'auto ref' for template functions, which makes
me concerned that this is not a good idea.
That's fine.
Note that one can always rewrite:
ref int fun(ref int x);
into:
ref int fun()(auto ref int x);
if auto ref is desired.
I don't understand this. My lowering scheme doesn't allow for that.
Andrei