auto ref and non-templated functions

Dmitry Olshansky dmitry.olsh at gmail.com
Tue Dec 25 10:03:29 PST 2012


12/25/2012 6:15 PM, Peter Alexander пишет:
> On Tuesday, 25 December 2012 at 14:09:13 UTC, Andrei Alexandrescu wrote:
[snip]
>>>
>>> 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.

+1
I think that was pretty much the conclusion of the last ref-to-rvalue 
thread. Just make sure proper scoping rules are followed.


-- 
Dmitry Olshansky


More information about the Digitalmars-d mailing list