auto ref is on the docket

Walter Bright via Digitalmars-d digitalmars-d at puremagic.com
Sun Jun 21 22:25:57 PDT 2015


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);

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.

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.


More information about the Digitalmars-d mailing list