I am kind of startled, especially after reading this.
I use
template <class T>
int GetPosition(vector<T> mVec, T element)
{
return find(mVec.begin(), mVec.end(), element) - mVec.begin();
}
and
template <class T>
int GetPosition(map<T, int> mMap, T element)
{
return mMap.find(element)->second;
}
as template functions to get the index of a specific element in my vector respectivly list.
Elements are unique pointers to objects, of which i want to retrieve the index off.
I then use this template in a for-loop like
for(int i = 0; i < myCount; i++)
{
index = GetPosition(myVector, elements[i]) //or GetPosition(myMap, elements[i])
}
While all bits of information i gathered suggested to use a map, the map implementation is several orders of magnitude slower: 57 ms using the vector variant in comparision 70000ms using the map.
Something is severly borked here, but i do not know what. Do you?
Development plattform is MS VS 2008 Standard sp1, on windows XP