Retrieve the return type of the current function
Jacob Carlborg
doob at me.com
Wed May 6 08:04:16 UTC 2020
On 2020-05-05 19:11, learner wrote:
> On Tuesday, 5 May 2020 at 16:41:06 UTC, Adam D. Ruppe wrote:
>
>> typeof(return)
>
> Thank you, that was indeed easy!
>
> Is it possible to retrieve also the caller return type? Something like:
Yes, kind of:
void foo(string caller = __FUNCTION__)()
{
import std.traits : ReturnType;
alias R = ReturnType!(mixin(caller));
static assert(is(R == int));
}
int bar()
{
foo();
return 0;
}
--
/Jacob Carlborg
More information about the Digitalmars-d-learn
mailing list