Contracts for delegates

bearophile bearophileHUGS at lycos.com
Tue Jan 8 06:58:36 PST 2013


Dmitry Olshansky:

> Then it has to be part of the type (a meta-info bound to it)...

In the first case the contracts are shared by all delegates, so 
there is no need for code equality:

void main() {
     void delegate(int x) foo
     in {
         assert(x > 0);
     };

     foo = (x) {};
}


If the contracts are attached to the function, can't you just 
trust the programmers to use compatible contracts, so again 
there's no need to compare code?

void main() {
     void delegate(int) foo;

     foo = (x)
     in {
         assert(x > 0);
     } body {
     };
}


Bye,
bearophile


More information about the Digitalmars-d-learn mailing list