diff --git a/Lib/python/std_multimap.i b/Lib/python/std_multimap.i index 3209fb0f8..21c84b009 100644 --- a/Lib/python/std_multimap.i +++ b/Lib/python/std_multimap.i @@ -68,7 +68,17 @@ %define %swig_multimap_methods(Type...) %swig_map_common(Type); + +#if defined(SWIGPYTHON_BUILTIN) + %feature("python:slot", "mp_ass_subscript", functype="objobjargproc") __setitem__; +#endif + %extend { + // This will be called through the mp_ass_subscript slot to delete an entry. + void __setitem__(const key_type& key) { + self->erase(key); + } + void __setitem__(const key_type& key, const mapped_type& x) throw (std::out_of_range) { self->insert(Type::value_type(key,x)); } diff --git a/Lib/python/std_unordered_map.i b/Lib/python/std_unordered_map.i index 6bd34077b..53f6aa283 100644 --- a/Lib/python/std_unordered_map.i +++ b/Lib/python/std_unordered_map.i @@ -226,7 +226,17 @@ %define %swig_unordered_map_methods(Map...) %swig_unordered_map_common(Map) + +#if defined(SWIGPYTHON_BUILTIN) + %feature("python:slot", "mp_ass_subscript", functype="objobjargproc") __setitem__; +#endif + %extend { + // This will be called through the mp_ass_subscript slot to delete an entry. + void __setitem__(const key_type& key) { + self->erase(key); + } + void __setitem__(const key_type& key, const mapped_type& x) throw (std::out_of_range) { (*self)[key] = x; } diff --git a/Lib/python/std_unordered_multimap.i b/Lib/python/std_unordered_multimap.i index 312b29e61..4dbc2a4dd 100644 --- a/Lib/python/std_unordered_multimap.i +++ b/Lib/python/std_unordered_multimap.i @@ -75,7 +75,17 @@ %define %swig_unordered_multimap_methods(Type...) %swig_unordered_map_common(Type); + +#if defined(SWIGPYTHON_BUILTIN) + %feature("python:slot", "mp_ass_subscript", functype="objobjargproc") __setitem__; +#endif + %extend { + // This will be called through the mp_ass_subscript slot to delete an entry. + void __setitem__(const key_type& key) { + self->erase(key); + } + void __setitem__(const key_type& key, const mapped_type& x) throw (std::out_of_range) { self->insert(Type::value_type(key,x)); }