Compile-time exceptions

bearophile bearophileHUGS at lycos.com
Tue Nov 25 01:57:47 PST 2008


Christopher Wright Wrote:
> assert (!is (typeof (nest(1, 1, 1)))); // int is not callable

I have just used a static assert version of that in about one hundred places in my dlibs, with good results, thank you :-) It has replaced lot of commented out and mostly useless lines of code with actual code that can spot problems at compile time. This begs for compiler (or standard lib) support, I think.

On the topic of idioms: I may also use an idiom just shown to me by downs, to allow "passing" "function templates" to other functions:
_sum { T opCall(T)(T[] array) { ... } } _sum sum;
That's another situation where I think some built-in syntactic sugar can be useful. Do you have ideas regarding a possible syntax/statement?

Bye,
bearophile



More information about the Digitalmars-d mailing list