I tried creating a template with an argument called T
.
But, the problem is that the compiler said that the identifier is undefined when I'm trying to use it.
I tried doing this (len.hpp
):
#include <iostream>
#include <vector>
template<typename T>
unsigned int len(T item[]){
unsigned int res = 0;
try{
for (unsigned int i = 0; true; i++){
item[i];
res = i;
}
}
catch(...){}
return res + 1;
}
unsigned int len(std::string str){
return str.length();
}
unsigned int len(std::vector<T> vec){
return len(vec.data());
}