I want to have a function that takes in a template
for a std::vector
and prints whatever is in the vector provided it is a datatype allowed in std::cout
. I believe this needs to be recursive since what about a vector of vector of a vector.... For example, given a 1d vector
,
template< typename T>
void PrintVector(T vec)
{
for (unsigned int i = 0; i < vec.size(); i++){
std::cout << vec[i] << std::endl;
}
}
There are a few problems I have here with this code.
1. This doesn't work if it is a multi-dimensional vector, I need it to (I guess at this statement: vec[i]
) recursively go and print out that vector and do the same if there is another vector.
2. I also want it to take in a reference to the vector within the template so I don't copy a 3d vector that's like 1gb in size to print it, rather just reference so I don't allocate any memory to do so.
Any help would be appreciated!