I am a little confused about how can I read each argument from the tuple by using variadic templates.
Consider this function:
template<class...A> int func(A...args){
int size = sizeof...(A);
.... }
I call it from the main file like:
func(1,10,100,1000);
Now, I don’t know how I have to extend the body of func to be able to read each argument separately so that I can, for example, store the arguments in an array.
You have to provide overrides for the functions for consuming the first
N(usually one) arguments.When you unpack the variadic parameter it finds the next overload.
Example:
Then next level down we expand the previous
Restand get:And so on until
Restcontains no members in which case unpacking it callsfoo()(the overload with no arguments).Storing the pack if different types
If you want to store the entire argument pack you can use an
std::tupleHowever this seems less useful.
Storing the pack if it’s homogeneous
If all the values in the pack are the same type you can store them all like this:
However this seems even less useful.