Finding out ref-ness of the return of an auto ref function
Stanislav Blinov
stanislav.blinov at gmail.com
Fri Jun 12 18:34:15 UTC 2020
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
More information about the Digitalmars-d-learn
mailing list