Similar to this thread, I'm trying to get the integer index from an iterator but for a map instead of an vector. Atm its causing a large bottle neck in my code and I was wondering if there was a more efficient way to get the index other that what I'm doing currently...
auto itTail = nodesMap.find(tail);
tailNodePos = distance(nodesMap.begin(), itTail);
tailNodePos
? You cannot really use it to insert elements. Just savetail
and use it to find the position again or save the iteratoritTail
. Keep in mind the invalidation on every insert / erase.