From b56d7c0539e398ec74d4e354f36beaaa2c758514 Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Mon, 19 Jun 2017 20:32:32 +0100 Subject: [PATCH] Python builtin C++11 STL fixes Compilation fixes for std::multimap, std::unordered_map and std::unordered_multimap. --- Lib/python/std_multimap.i | 10 ++++++++++ Lib/python/std_unordered_map.i | 10 ++++++++++ Lib/python/std_unordered_multimap.i | 10 ++++++++++ 3 files changed, 30 insertions(+) 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)); }