Typed variadic template syntax?
Stanislav Blinov
stanislav.blinov at gmail.com
Tue Jan 28 16:24:06 PST 2014
On Wednesday, 29 January 2014 at 00:14:31 UTC, bearophile wrote:
> On the other hand I don't know how much common are template
> instantiations with values all of the same type (like all ints
> as in this case) in D code.
>
> Opinions welcome.
>
> Bye,
> bearophile
Well, if you're going for a direct translation, that would be
more like
template value(ints...) {
static if (!ints.length) enum value = 0;
else static if (!is(ints[0] == int)) static assert(false);
else enum value = ints[0] + 10*value!(ints[1..$]);
}
But that indeed illustrates a certain disconcert: we can already
have variadic functions of the same type (void foo(int[] a...)).
It would certainly be nice to have the same for template
parameters.
More information about the Digitalmars-d
mailing list