MattCoder:
I want to know if there is a way to pass variadic arguments as
reference? DMD says no!
I wrote the snippet code below, but what I want to do in fact
is assign the sum back to respective variables to use somewhere
else.
One way to do it, but beware of template bloat:
import std.stdio;
void sum(TArgs...)(double value, ref TArgs numbers) {
foreach (ref num; numbers) // Note: this is a static foreach.
num += value;
}
void main() {
auto a = 1, b = 2, c = 3;
writeln(a, " ", b, " ", c);
sum(10, a, b, c);
writeln(a, " ", b, " ", c);
}
Bye,
bearophile