Re: Constraints error messages [Was: Re: Constrained Templates]

2010-06-15 Thread bearophile
BCS: I like the idea, but how should it interact with overloaded templates? The syntax/semantics I have shown is just a starting point, there are probably way better ways to reach the same goal. For example a kind of run-time error/exception for templates that shows an error message and

Constraints error messages [Was: Re: Constrained Templates]

2010-06-14 Thread bearophile
Yao G.: Something I would like to see with template constraints, is the ability to show text messages, like when static if is used. This is a problem I too have. In D1 I used to write code like: template Foo(T) { static assert(condition1, error message1); static assert(condition2, error

Re: Constraints error messages [Was: Re: Constrained Templates]

2010-06-14 Thread BCS
Hello bearophile, A syntax like the following allows to add the user-defined error messages too, but it's bad looking, so probably something quite better can be invented: template Foo(T) if (condition1) else pragma(msg, error message1) if (condition2) else pragma(msg, error message2) { } I