abraham_hilbert abraham_hilbert - 9 months ago 49
C++ Question

Generating a sequence of zeros at compile time

I have the following problem:

template< size_t... N_i >
class A

// ...

void foo()
bar( /* 0,...,0 <- sizeof...(N_i) times */);

I want to call a function
and pass
many arguments to it which are all zeros, e.g.,
in case
sizeof...(N_i) == 3
Does anyone know how this can be implemented ?

Many thanks in advance.

Answer Source
bar(((void)N_i, 0)...);

The comma operator will discard N_i, yielding just the right-hand operand's value (0). The cast is to prevent a warning about N_i being discarded.