Modifiable typesafe variadic arguments

Deewiant deewiant.doesnotlike.spam at gmail.com
Thu Jun 15 02:19:50 PDT 2006


Trying to do something like this doesn't work:

void foo(int[] arr...) {
	for (int i = 0; i < arr.length; ++i)
		arr[i] = 3;
}

foo(x, y, z);

The variables passed retain their original values. Defining arr as inout or out
doesn't work, since that would be modifying the array reference, and as such the
compiler doesn't allow it.

Is there any way of doing it other than using pointers, like in the following?

void foo(int*[] arr...) {
	for (int i = 0; i < arr.length; ++i)
		*arr[i] = 3;
}

foo(&x, &y, &z);

My guess is there isn't, since std.stream.InputStream.readf, for instance, uses
pointers for this as well. Any ideas?



More information about the Digitalmars-d-learn mailing list