typeof(func!0) != typeof(func!0())

Steven Schveighoffer schveiguy at gmail.com
Mon Aug 22 14:28:13 UTC 2022


On 8/22/22 8:04 AM, Paul Backus wrote:
> On Monday, 22 August 2022 at 11:24:59 UTC, Andrey Zherikov wrote:
>> On Monday, 22 August 2022 at 06:01:11 UTC, JG wrote:
>>> Why not just change to:
>>> alias type = typeof(U().func!0());
>>
>> This is user's code and `U().func!0` is legit syntax.
> 
> Workaround: wrap it in a lambda.
> 
> 
> ```d
> import std.traits;
> 
> alias type = ReturnType!(() => U().func!0);
> ```

Or without having to import phobos:

```d
alias type = typeof((() => U().func!0)());
```

I actually created a small utility for this in my code:

```d
auto ref eval(T)(auto ref T expr) { return expr; }
```

so now I can just do:

```d
alias type = typeof(eval(U().func!0)));
```

-Steve


More information about the Digitalmars-d-learn mailing list