On Monday 14 September 2015 21:59, jmh530 wrote: > This approach gives the correct result, but dmd won't deduce the > type of the template. So for instance, the second to the last > line of the unit test requires explicitly stating the types. I > may as well use the alternate version that doesn't use the > variadic function (which is simple for this trivial example, but > maybe not more generally).
You can use a variadic template instead: ---- import std.algorithm : sum; auto test(R, E ...)(R r, E e) { return sum(r, e); } unittest { int[] x = [10, 5, 15, 20, 30]; assert(test(x) == 80); assert(test(x, 0f) == 80f); assert(test(x, 0f) == 80f); } ----