auto ref and non-templated functions

Andrei Alexandrescu SeeWebsiteForEmail at erdani.org
Tue Dec 25 06:11:14 PST 2012


On 12/25/12 5:36 AM, Jonathan M Davis wrote:
> On Tuesday, December 25, 2012 11:14:40 Namespace wrote:
>>> What does this generate?
>>>
>>> auto foo(auto ref S a, auto ref S b, auto ref S c, auto ref S
>>> d) { ... }
>>>
>>> 16 different functions, one for each combination? Sounds like a
>>> bad idea.
>>
>> In my opinion, this should produce only two functions:
>> #1: auto foo(ref S a, ref S b, ref S c, ref S d) { ... }
>> #2: auto foo(S a, S b, S c, S d) { ... }
>
> So, you'd take the performance hit of copying all of your function arguments
> simply because one of them was an rvalue?
>
> No. I think that Peter's point shows exactly why this is a bad idea.
>
> However, creating only one version of the function which takes all refs and
> specifcally creating variables underneath the hood for any rvalues so that
> they can be passed to the function still seems like it could work.

Yes, that does work and is easy to implement.

Andrei



More information about the Digitalmars-d mailing list