contracts scope

Daniel Keep daniel.keep+lists at gmail.com
Wed Jan 17 22:13:59 PST 2007


Serg Kovrov wrote:
> It would be nice to have some sort of 'contracts scope' shared between 
> `in` and `out`.
> I'm looking a way to implement something like this:
> 
> ubyte[] foo(ubyte[] src, inout ubyte[] dst)
> in
> {
>     auto ptr = dst.ptr;
> }
> out
> {
>     if (ptr != dst.ptr) wtitefln("dst reallocated");
> }
> body
> {
>     ....
> 

The only thing I can think of is maybe use a private global variable.

private ubyte[] _foo_ptr;
ubyte[] foo(ubyte[] src, inout ubyte[] dst)
in
{
     _foo_ptr = dst.ptr;
}
out
{
     if (_foo_ptr != dst.ptr) writefln("dst reallocated");
}
body
{
     ....

Not an ideal solution, and it's not thread-safe, but should be OK.

     -- Daniel



More information about the Digitalmars-d mailing list