Suppose I have the following function template:
int bar();
template <std::size_t... Is>
void foo()
{
constexpr auto N = sizeof...(Is);
int a[N] {/* magic here, like bar()... */};
}
I want to initialize the array a
with N
bar()
s. The first solution I came up with is like the following:
int a[N] {(Is, bar())...};
But it results in some "expression result unused" warnings.
How can I get rid of these warnings if I don't want to turn off the -Wunused-value
flag? Or is there any other way to write N
bar()
s? It is better that the solution works not only for bar()
, but also for any expression that does not depend on Is
.
Edit: the use of initializing an array is only an example. There are many other contexts that require such a sequence of expressions (for example, use for arguments of another template). So what I really want is how to generate such a sequence rather than to initialize the array.