diff --git a/Lib/python/std_map.i b/Lib/python/std_map.i index 9e5f50512..b4951f846 100644 --- a/Lib/python/std_map.i +++ b/Lib/python/std_map.i @@ -132,7 +132,7 @@ } } -%define %swig_map_methods(Map...) +%define %swig_map_common(Map...) %swig_sequence_iterator(Map); %swig_container_methods(Map) @@ -145,10 +145,6 @@ throw std::out_of_range("key not found"); } - void __setitem__(const key_type& key, const mapped_type& x) throw (std::out_of_range) { - self->insert(Map::value_type(key,x)); - } - void __delitem__(const key_type& key) throw (std::out_of_range) { Map::iterator i = self->find(key); if (i != self->end()) @@ -238,5 +234,14 @@ } %enddef +%define %swig_map_methods(Map...) + %swig_map_common(Map) + %extend { + void __setitem__(const key_type& key, const mapped_type& x) throw (std::out_of_range) { + (*self)[key] = x; + } + } +%enddef + %include diff --git a/Lib/python/std_multimap.i b/Lib/python/std_multimap.i index 1b159dc3c..5a6facb58 100644 --- a/Lib/python/std_multimap.i +++ b/Lib/python/std_multimap.i @@ -66,7 +66,14 @@ } } -#define %swig_multimap_methods(Type...) %swig_map_methods(Type) +%define %swig_multimap_methods(Type...) + %swig_map_common(Type); + %extend { + void __setitem__(const key_type& key, const mapped_type& x) throw (std::out_of_range) { + self->insert(Type::value_type(key,x)); + } + } +%enddef %include