typeof(func!0) != typeof(func!0())
Andrey Zherikov
andrey.zherikov at gmail.com
Mon Aug 22 11:22:54 UTC 2022
On Monday, 22 August 2022 at 05:25:50 UTC, Ali Çehreli wrote:
> This is where the @property keyword makes a difference:
>
> @property auto ref func(int i)() { return this; }
>
> Now U().func!0 will be a call in your expression.
Is original `U().func!0` not a call?
> But I think std.traits.ReturnType is more explicit and does
> work in this case:
>
> import std.traits;
> alias type = ReturnType!(U().func!0);
This works but looks strange - I'm checking the type of UDA
expression:
```d
@(U().func!0) int b;
pragma(msg, __traits(getAttributes, b)); //
tuple(U().func)
pragma(msg, typeof(__traits(getAttributes, b)[0])); // pure
nothrow @nogc ref @safe U() return
pragma(msg, ReturnType!(__traits(getAttributes, b)[0])); // U
pragma(msg, is(typeof(__traits(getAttributes, b)[0]) : U)); //
false
pragma(msg, hasUDA!(b, U)); // false
```
More information about the Digitalmars-d-learn
mailing list