My thoughts & experiences with D so far, as a novice D coder

deadalnix deadalnix at gmail.com
Wed Mar 27 10:46:09 PDT 2013


On Wednesday, 27 March 2013 at 17:23:01 UTC, Timon Gehr wrote:
> I strongly disagree. What would be an example of the problems 
> you are apparently experiencing?
>

T foo(alias fallback)() {
     // Do some processing return the result. If an error occurs 
use fallback mechanism.
}

Reasonable thing to do as fallback is to try another method 
workaround the error, throw, whatever.

The problem is that the fallback type inference makes it painful 
to work with, especially if fallback is a template itself.

For instance, in SDC, you can parse ambiguous things as follow :
parseTypeOrExpression!((parsed) {
     static if(is(typeof(parsed) : Expression)) {
         // Do something
     } else {
         throw SomeException();
     }
})(tokenRange);

This is bound to fail. When a function never return, it make no 
sens to force a type on it and the magic subtype typeof(null) 
should be used (as typeof(null) can cast to anything, it is valid 
to call the function in any condition).


More information about the Digitalmars-d mailing list