std.unittests for (final?) review

Lutger Blijdestijn lutger.blijdestijn at gmail.com
Thu Jan 6 05:44:33 PST 2011


Michel Fortin wrote:

> On 2011-01-06 06:45:41 -0500, Lutger Blijdestijn
> <lutger.blijdestijn at gmail.com> said:
> 
>> As you said, it is all about the error messages, not replacing assert
>> perse. So this comparison would be more fair, using the syntax suggested
>> by Andrei:
>> 
>> assertPred!">"(a, b);
>> 
>> vs
>> 
>> assert(a > b, format("a > b failed: [%s] is not > [%s]", a, b) );
>> 
>> If you really want the error message, regular asserts are a bit uglier
>> and duplicate code.
> 
> The whole point of my proposal is to make the regular asserts print a
> message similar to yours *by default*, when you don't specify any
> message. This is possible because assert is not a function, it's a
> language construct handled by the compiler. The compiler has access to
> the whole expression tree, and it can rewrite the code to store
> intermediate results in variables it can later give to the assertion
> handler in case of failure.
> 
> 

I understood, but was reacting to the proposition that assertPred is not an 
improvement over the current situation, isn't that what you were saying? 
Just being pragmatic, it's unlikely such big changes to assert are going to 
land in dmd anytime soon. But if they are, yeah that would be cool. 


More information about the Digitalmars-d mailing list