I am trying to write a template function that will take an STL container and will display all the occurrences of the elements in it and the number that they have occurred. I am planning to use a map, iterate through the container and either add a new element if it does not exist or increment the count of occurrences for the element.
Declaration:
template < typename Container_t >
void findOccurrences (const Container_t& inContainer);
My question is: can I somehow get the type specifier of the element that the container holds?
So when I create my map the key value would be the element in the inContainer
.
Something like :
map < typeid ( * inContainer.begin()), int > occurrences;
Or would I have to change my template to something like this:
template < typename Container_t , typename Element_t >
void findOccurrences ( const Container_t & inContainer , Element_t dummy )
{
map < Element_t , int > occurrences;
}
Thanks