I am mainly a C developer, but starting to use C++ more and more.
I have a templated function below which will search for values in STL containers of different types and do some processing.
I understand that the compiler will generate different functions depending on which data types are passed.
How do I determine the element type here in my situation? I can't use auto because my code should be compiled without the C++11 flag.
template <typename T, typename T_it>
void ProcessContainer(T con, T_it it )
{
typename N;
for (it = con.begin(); it != con.end(); ++it )
{
//auto element = *it; - Can't use auto in my case
// other processing.. not included
}
}
The standard containers have a type member name
value_typethat represents the type of the elements in the container and you can use that to create your object likeThere is also
std::iterator_traitsthat will also give you the type that the iterator points to and that would be used like