aboutsummaryrefslogtreecommitdiffstats
path: root/include/multimapwdef.h
diff options
context:
space:
mode:
Diffstat (limited to 'include/multimapwdef.h')
-rw-r--r--include/multimapwdef.h7
1 files changed, 7 insertions, 0 deletions
diff --git a/include/multimapwdef.h b/include/multimapwdef.h
index fbab567..d3f8f90 100644
--- a/include/multimapwdef.h
+++ b/include/multimapwdef.h
@@ -11,6 +11,13 @@ template <class Key, class T, class Compare>
class multimapwithdefault : public multimap<Key, T, Compare> {
public:
typedef pair<const Key, T> value_type;
+ T& getWithDefault(const Key& k, const T& defaultValue) {
+ if (find(k) == end()) {
+ insert(value_type(k, defaultValue));
+ }
+ return (*(find(k))).second;
+ }
+
T& operator[](const Key& k) {
if (find(k) == end()) {
insert(value_type(k, T()));