identic ref/inout parameter

Downs default_357-line at yahoo.de
Fri Sep 14 14:19:38 PDT 2007


-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Jarrett Billingsley wrote:
> "Downs" <default_357-line at yahoo.de> wrote in message 
> news:fce15c$1h7e$1 at digitalmars.com...
> 
>> 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);
>> }
> 
> Probably not _quite_ what you'd expect.  "ref T[]" means "ref(T[])", not 
> "(ref T)[]".  That is, a reference to an array, not an array of references. 
> So it'd have to be "T*[] values..." instead, and called as 
> "assertUnique(&r1, &r2, &i1, &i2)". 
> 
> 
Damn, you're right.
How about this?

void assertUnique(T...)(ref T tuple) {
  foreach (index, ref v1; tuple[0..$-1])
    foreach (ref v2; tuple[index+1..$])
      assert(&v1 != &v2);
}
 --downs
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.7 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

iD8DBQFG6vrqpEPJRr05fBERAsaGAKCYdvYlmyrI7ZnXend63q4YFMthwQCeLKNx
wLtitWH8V2R4bCu5SBRTcZ0=
=L2tS
-----END PGP SIGNATURE-----


More information about the Digitalmars-d-learn mailing list