00001 #ifndef MULTIMAPWDEF
00002 #define MULTIMAPWDEF
00003
00004 #include <map>
00005
00006 using namespace std;
00007
00008
00009
00010 template <class Key, class T, class Compare>
00011 class multimapwithdefault : public multimap<Key, T, Compare> {
00012 public:
00013 typedef pair<const Key, T> value_type;
00014 T& operator[](const Key& k) {
00015 if (find(k) == end()) {
00016 insert(value_type(k, T()));
00017 }
00018 return (*(find(k))).second;
00019 }
00020 bool has(const Key& k, const T &val) const {
00021 typename multimap<Key, T, Compare>::const_iterator start = lower_bound(k);
00022 typename multimap<Key, T, Compare>::const_iterator end = upper_bound(k);
00023 for (; start!=end; start++) {
00024 if (start->second == val)
00025 return true;
00026 }
00027 return false;
00028 }
00029 };
00030
00031 #endif