identic ref/inout parameter
Downs
default_357-line at yahoo.de
Fri Sep 14 06:08:07 PDT 2007
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
Regan Heath wrote:
> Wilhelm wrote:
>> Who do I determine in a function (probably with a assert statement)
>> that the function with more the one ref/inout parameters of the same
>> type are not called with the same variable like:
>>
>> private import std.stdio;
>>
>> int main(char[][] args)
>> {
>> int i=3;
>> test( i,i,i,i);
>> return 0;
>> }
>>
>>
>> void test(ref int r1, ref int r2, inout int i1, inout int i2)
>> {
>> writefln (" Ref: r1=%d r2=%d", r1, r2);
>> writefln (" InOut: i1=%d i2=%d", i1, i2);
>> r1 += 2;
>> writefln ("r1 += 2; Ref: r1=%d r2=%d", r1, r2);
>> writefln ("r1 += 2; InOut: i1=%d i2=%d", i1, i2);
>> i2 += 2;
>> writefln ("i1 += 2; Ref: r1=%d r2=%d", r1, r2);
>> writefln ("i1 += 2; InOut: i1=%d i2=%d", i1, i2);
>> }
>>
>> !! That may cause interesting results !!
>
> Maybe...
>
> assert(&r1 != &r2);
> assert(&r1 != &i1);
> assert(&r1 != &i2);
> assert(&r2 != &i1);
> assert(&r2 != &i2);
> assert(&i1 != &i2);
>
> Regan
To clean it up a little
void assertUnique(T)(ref T[] values...) {
foreach (index, ref value; values[0..$-1])
foreach (ref value2; values[index+1..$])
assert(&value != &value2);
}
Untested, but should work.
--downs
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.7 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org
iD8DBQFG6oe3pEPJRr05fBERAviDAJ4ohNm2PvD1pWq9Z9AuZ5AdPqUT8wCeLkkW
skn/AMq7xrLSUaN3vKy/R9c=
=MfLi
-----END PGP SIGNATURE-----
More information about the Digitalmars-d-learn
mailing list