How I could read the args of this variadic template, as it can be any number of arguments?
#include <tuple>
#include <string>
#include <iostream>
enum class traceErr
{
err1, err2
};
template <typename... Args>
void TraceErr(traceErr err, Args&&... args)
{
auto pack = std::make_tuple(std::forward<Args>(args)...);
std::string str;
switch (err)
{
case traceErr::err1:
str = "Err: " + std::to_string(std::get<0>(pack));
break;
case traceErr::err2:
str = "Err: " + std::to_string(std::get<0>(pack)) + " "
+ std::get<1>(pack);
break;
}
std::cout << str << std::endl;
}
int main()
{
TraceErr(traceErr::err1, 1);
TraceErr(traceErr::err2, 2, "etc");
}
In the example above I'm getting these errors:
static_assert failed: 'tuple index out of bounds
'get': no matching overload function found
Because the number of args being passed are different, how i could 'fix' it to work with any number of args?