dimanche 5 janvier 2020

How to get variable no of argument with its size in C++ using variadic template

I need to create a function which take variable no of argument. The objective of this function will be to get argument and print the data. I have succeeded in implementing this function using variadic template whose code is given below:

void print(T var1, Types... var2) 
{ 
        cout << "DATA:"<<var1<< endl ;      
        print(var2...) ; 
}

But now i want to print the size of argument as well . For e.g:

char empname[15+1];
print(empname);

It should print size of empname : 16 . But it print 8 as it is printing size of datatype of template argument.

Any way out to get size of each argument in parameter pack as i am still learning C++11 variadic template.

Aucun commentaire:

Enregistrer un commentaire