Get the return type of the function
xtreak via Digitalmars-d-learn
digitalmars-d-learn at puremagic.com
Wed Feb 3 10:40:27 PST 2016
On Wednesday, 3 February 2016 at 17:40:23 UTC, Meta wrote:
> 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));
Thanks. I was trying to get the return type of lambdas. I was
trying the following and got an error. I was using dpaste with
dmd 2.070
writeln(ReturnType!(a =(a *a)))
Error: template instance f662.main.ReturnType!((a) => a * a) does
not match template declaration ReturnType(func...) if
(func.length == 1 && isCallable!func)
More information about the Digitalmars-d-learn
mailing list