abraham_hilbert abraham_hilbert - 1 year ago 72
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.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download