On Monday, 17 June 2013 at 12:21:31 UTC, Artur Skawina wrote:
A more correct, but a bit less readable version (the types of
'values' and 'arr'
elements do not have to match) would be:
void bar(T...)(T values) {
static if (T.length) {
NTup!(T.length, typeof(arr[T[0].init])) tmp;
foreach (i, ref v; values)
tmp[i] = arr[v]*10;
foo(tmp);
}
else
foo();
}
template NTup(size_t N, T...) {
static if (N>1)
alias NTup = NTup!(N-1, T, T[$-1]);
else
alias NTup = T;
}
artur
Argh, that's a lot of boilerplate. Thanks for pointing this out.
I didn't notice in your previous example that the expression
types had to match with the parameter types. Now I really do
think that we need the C++ ellipsis notation (it's just the
ellipsis can be omitted when it would be right next to the tuple):
void bar(T...)(T values)
{
foo((arr[values] * 10)...);
}