In C++, I’m trying to figure out how one can deduce the size of the parameter pack for a function, and further how one can deduce the number of parameters of a particular type (e.g. ints)
template<int N, int N_ints, typename... Ts>
void foo(Ts... ts){
...
}
So that I could call it like
foo(1,2,'3')
and that would be the same as
foo<3,2>(1,2,'3')
I couldnt even get the basic problem to work, i.e.
template<int N, class... Ts>
std::array<int, N> foo(Ts... ts)
{
constexpr int n = sizeof...(ts);
std::array<int, n> out;
return out;
}
int main()
{
auto a = foo(1, 2, 3, '4', 5);
return 0;
}
fails because it can’t deduce N
.
New contributor
Varchas Gopalaswamy is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.