January 17, 2007 contracts scope | ||||
---|---|---|---|---|
| ||||
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.
|
January 18, 2007 Re: contracts scope | ||||
---|---|---|---|---|
| ||||
Posted in reply to Serg Kovrov | 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
|
Copyright © 1999-2021 by the D Language Foundation