Get the return type of the function

Meta via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Wed Feb 3 09:40:23 PST 2016


On Wednesday, 3 February 2016 at 17:12:03 UTC, xtreak wrote:
> I was reporting a patch for the regression by removing the code 
> that was causing the error. The bug was that map was not 
> accepting multiple lambdas. It was suggested to check for void 
> functions and lambdas. I couldn't find a function to check for 
> return type in the std.traits. I tried the explicit for loop 
> thus checking for the void functions as in the else case. I am 
> D newbie it will be helpful in having the community help me in 
> fixing the issue.
>
> foreach(g, i; fun) {
>   alias k = unaryFun!(fun[g]);
>   static assert(!is(AppliedReturnType!k == void), "Mapping 
> function must not return void.");
> }
>
> Bug report : https://issues.dlang.org/show_bug.cgi?id=15480
> Seems depends on : https://issues.dlang.org/show_bug.cgi?id=5710
> Pull request : 
> https://github.com/D-Programming-Language/phobos/pull/3963
> Introduced as a part of 
> https://github.com/D-Programming-Language/phobos/pull/1917

Unles I'm misunderstanding you, you can get the return type of a 
function by using std.traits.ReturnType:

void test() {}
static assert(is(ReturnType!test == void));


More information about the Digitalmars-d-learn mailing list