[Issue 5399] Return the result of a nonvoid function in a void function

d-bugmail at puremagic.com d-bugmail at puremagic.com
Sun Jan 2 07:48:41 PST 2011


http://d.puremagic.com/issues/show_bug.cgi?id=5399



--- Comment #6 from nfxjfg at gmail.com 2011-01-02 07:46:29 PST ---
I think the issue is with allowing stuff like this:

Result wrapCall(alias call, Result, Args...)(Args args) {
   return call(args);
}

And then making it work even if the result of the call is void:

wrapCall(&something, void, int, int)(1, 2);

That requires that you can return a void value. Returning a void normally
wouldn't make sense, but as you can see it simplifies generic programming.

Somehow it made sense in Walter's head to allow returning _anything_ from a
void function. (It would make sense if void would work like Scala's Unit, but
void doesn't.)

Walter, please explain.

By the way if D were really orthogonal and would follow any logic, you wouldn't
have any problem with this code:

Result wrapCall(alias call, Result, Args...)(Args args) {
   try {
      return call(args);
   } catch {
      writefln("call failed!");
      return Result.init;
   }
}

This works, except when Result is void. Then you have to use static if,
duplicate the core code around the actual call if that is more complicated than
in the given example, and so on. (I had this in real world code.)

Sure makes a lot of sense.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------


More information about the Digitalmars-d-bugs mailing list