Main Page | Namespace List | Class Hierarchy | Class List | File List | Class Members | File Members

maputil.h

Go to the documentation of this file.
00001 #ifndef MAPUTIL_H 00002 #define MAPUTIL_H 00003 00004 #include <map> 00005 #include <exception> 00006 #include <assert.h> 00007 00008 #include <iostream> // just for debugging 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 // Note: I'm not totally positive that eraserPos remains valid after we do 00035 // this erase(...) operation, so if we're having trouble, verify this code... 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

Generated on Fri Nov 12 15:15:21 2004 for Borealis by doxygen 1.3.8