contract programming without a function

BCS ao at pathlink.com
Sun May 20 13:22:23 PDT 2007


Reply to Ary,

> It's gone from the documentation, but luckily I've got an old one
> (this is from DMD 0.176). In the "Contracts" section it was said:
> 
> | The in-out statement can also be used inside a function, for
> example,
> | it can be used to check the results of a loop:
> |
> | in
> | {
> |     assert(j == 0);
> | }
> | out
> | {
> |     assert(j == 10);
> | }
> | body
> | {
> |     for (i = 0; i < 10; i++)
> | 	j++;
> | }
> |
> | This is not implemented at this time.
> I guess this is exactly what you want in the example you gave. I don't
> know why it's gone from the documentation, though. Maybe these feature
> was dropped from future plans?
> 

you can fake this with scope(exit)


|assert(j == 0);
|{
|    scope(exit) assert(j == 10);
|    for (i = 0; i < 10; i++)
|        j++;
|}




More information about the Digitalmars-d-learn mailing list