Finding out ref-ness of the return of an auto ref function
Arafel
er.krali at gmail.com
Sat Jun 13 09:13:36 UTC 2020
On 12/6/20 20:34, Stanislav Blinov wrote:
> On Friday, 12 June 2020 at 17:50:43 UTC, Arafel wrote:
>
>> All in all, I still think something like `__traits(isRef,return)`
>> would still be worth adding! After all the compiler already has all
>> the information, so it's just about exposing it. I'm trying to think
>> of a library solution, but I find it very hard to express "the
>> hypothetical result of calling the current function with the current
>> parameters in the current context".
>>
>> A.
>
> If you're wrapping a function you can use a 'getFunctionAttributes'
> trait [1], which would contain a "ref" if that function returns ref.
>
> 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 :)
>
> [1] https://dlang.org/spec/traits.html#getFunctionAttributes
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.
Also there could be a better and more straightforward way of checking if
an expression would be an l-value... it seems it's not the first time it
has appeared:
https://issues.dlang.org/show_bug.cgi?id=15634
The forum thread linked in the bug report is also quite interesting.
More information about the Digitalmars-d-learn
mailing list