Despite the undoubtedly interesting answer by @Columbo, I want to suggest another viable solution based on constexpr
'd template variables:
#include <cstddef>
template<std::size_t, std::size_t V>
constexpr std::size_t repeat_value = V;
template<std::size_t... N_i>
class A {
template<typename... Args>
void bar(Args&&...) { }
public:
void foo() {
// repeat N_i times value 0
bar(repeat_value<N_i, 0>...);
}
};
int main() {
A<0, 1, 2, 3, 4> a;
a.foo();
}
I find it easier to read at least, even if it's bad in terms of performance at compile-time.
You can easily generalize it as it follows:
template<std::size_t, typename T, T V>
constexpr T repeat_value = V;
The invokation in the specific case is this:
bar(repeat_value<N_i, int, 0>...);