Those line numbers don't seem to match up because you have only posted 135 lines of code. It is much easier to determine the cause of a problem when ALL of the code in a module is posted so that we can find the relevant line.
The following lines do not look correct to me :
typename std::map<K,V>::const_iterator itBegin;
typename std::map<K,V>::const_iterator itEnd;
typename std::map<K,V>::const_iterator extraIt = itEnd;
typename std::map<K,V>::const_iterator beforeMid = itBegin;
because the
typename
statements don't belong there.
When I see repeated instances of a non-trivial type I usually define a type or make a using statement for it. This is what I would do for that type :
using mapKVcitr = std::map<K,V>::const_iterator;
mapKVcitr itBegin;
The using statement must appear within the template declaration since it uses the types K and V.