[Doubt] Variadic arguments as reference (Possible?)
MattCodrr
mattcoder at gmail.com
Fri Jun 14 07:01:01 PDT 2013
On Friday, 14 June 2013 at 13:24:18 UTC, bearophile wrote:
> 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);
> }
Hi bearophile,
I know that I don't specified on my first post, but since I need
a generic type parameter on my real problem, your ref TArgs seems
to fit nicely.
Thanks.
More information about the Digitalmars-d-learn
mailing list