I am using a template in C++ to display the vector content in Matlab with mexPrintf. Similar to printf, mexPrintf need an input of the type (%d or %g). As a prior, I know the type of the vector. Do I have a method to judge the type in the template? I want to mexPrintf(" %d", V[i]) for vector<int>, and mexPrintf(" %g", V[i]) for vector<double>.Is it possible? My example code is below.
template<typename T> void display(T& V)
{
for (int j = 0; j < V.size(); j++)
{
//if
mexPrintf("\n data is %d\n", V[j]);//int
//else
mexPrintf("\n data is %g\n", V[j]);//double
}
}
I may need the judgement for my if & else. Or any suggestion to another solution?