00001
#ifndef MAPUTIL_H
00002
#define MAPUTIL_H
00003
00004
#include <map>
00005
#include <exception>
00006
#include <assert.h>
00007
00008
#include <iostream>
00009
00010
using namespace std;
00011
00018
template<
typename TKey,
typename TValue>
00019 int multimapEraseExact(multimap<TKey, TValue> & mm,
const pair<TKey, TValue> & p)
00020
throw (std::exception)
00021 {
00022
int numErased = 0;
00023
00024 pair<
00025
typename multimap<TKey, TValue>::iterator,
00026
typename multimap<TKey, TValue>::iterator > bounds = mm.equal_range(p.first);
00027
00028
typename multimap<TKey, TValue>::iterator & eraserPos = bounds.first;
00029
00030
while (eraserPos != bounds.second)
00031 {
00032
if ((eraserPos->second) == p.second)
00033 {
00034
00035
00036
typename multimap<TKey, TValue>::iterator victimPos = eraserPos;
00037 eraserPos++;
00038 mm.erase(victimPos);
00039 numErased++;
00040 }
00041
else
00042 {
00043 eraserPos++;
00044 }
00045 }
00046
00047
return numErased;
00048 }
00049
00050
00051
#endif