www.digitalmars.com         C & C++   DMDScript  

digitalmars.D - contracts scope

reply Serg Kovrov <kovrov no.spam> writes:
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
{
     ....

-- 
serg.
Jan 17 2007
parent Daniel Keep <daniel.keep+lists gmail.com> writes:
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
Jan 17 2007