Finding out ref-ness of the return of an auto ref function

Stanislav Blinov stanislav.blinov at gmail.com
Sat Jun 13 10:40:33 UTC 2020


On Saturday, 13 June 2020 at 09:13:36 UTC, Arafel wrote:

>> If, however, you're wrapping a function template, however, you 
>> won't know until you actually instantiate it, which is 
>> basically going back to Paul Backus' solution. So the compiler 
>> doesn't always have all the information :)
>
> Well, the compiler can know `typeof (return)`, so at that point 
> and under the same circumstances it has know (and thus it could 
> expose) the ref-ness.

And it does, for functions, via the aforementioned trait. It 
can't for templates until those templates are instantiated, which 
you can only do correctly by actually forwarding arguments to it 
(because a function template may have auto ref parameters).

Steven's issue report doesn't account for templates, nor 
overloading, and correctly testing the latter would pretty much 
require you to match argument types and ref-ness by hand anyway 
(yuck).


More information about the Digitalmars-d-learn mailing list