Idea: function contracts + CTFE

dennis luehring dl.soluz at gmx.net
Fri Jun 20 12:13:01 PDT 2008


dennis luehring schrieb:
>  >Jarrett Billingsley schrieb:
>  >....
>> If I call fork(30), this is obviously an error, but won't be reported 
>> until runtime, and even then, *only in debug mode*.
>> ...
>> It seems like a cool idea anyway.  I wonder, in practice, how often 
>> the compiler would be able to evaluate the contracts, and if it would 
>> be of practical use.  Or if there would be a better way to do this 
>> (like extending the new template parameter constraints to functions: 
>> "void fork(int x) if(x  >= 0 && x < 20)"). 
> 
> if got the same for assert itselfe
> 
> why do assert not act like an static assert if the evaluated is a 
> compiletime value
> 
> something like
> 
> better_assert( predicat, text )
> {
>   static if compile_time_value( predicate )
>     static assert( predicate, text )
>   else
>     assert( predicate, text )
> }
> 
> function test( int value )
> {
>    better_assert( value == 4 );
>    // bla bla
> }
> 
> test( 5 ); // compiletime error
> test( non_const_wrong_value_variable ); // runtime assert
> 
> and this does not realy help in this small testcase
> 
> but think of the 1000 in/out checks and normal asserts in your projects
> 
> do realy want to see the problem only when you actualy call a specific 
> function?
> 
> ciao dennis

and don't want to change assert - maybe another(ouch!) keyword	for 
example "predication"

so i and jarett can use predication (or predicate?) as a
replacement for assert in in/out contracts and the other positions im 
currrently using assert




More information about the Digitalmars-d mailing list