From 05d6717de903c8ee0ab413060f8d75999ffaa8fc Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Fri, 21 Sep 2018 19:19:01 +0100 Subject: [PATCH] Python builtin - add indexing support to std::set --- Examples/test-suite/python/li_std_set_runme.py | 2 ++ Lib/python/std_set.i | 6 +++--- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/Examples/test-suite/python/li_std_set_runme.py b/Examples/test-suite/python/li_std_set_runme.py index ad3c6d881..f6fad5561 100644 --- a/Examples/test-suite/python/li_std_set_runme.py +++ b/Examples/test-suite/python/li_std_set_runme.py @@ -54,6 +54,8 @@ if i.next() != 2: if i.next() != 3: raise RuntimeError +if si[0] != 1: + raise RuntimeError i = s.begin() i.next() diff --git a/Lib/python/std_set.i b/Lib/python/std_set.i index e80daee7e..0ef011998 100644 --- a/Lib/python/std_set.i +++ b/Lib/python/std_set.i @@ -37,10 +37,11 @@ %swig_container_methods(set); #if defined(SWIGPYTHON_BUILTIN) + %feature("python:slot", "mp_subscript", functype="binaryfunc") __getitem__; %feature("python:slot", "sq_contains", functype="objobjproc") __contains__; #endif - %extend { + %extend { void append(value_type x) { self->insert(x); } @@ -60,8 +61,7 @@ void discard(value_type x) { self->erase(x); } - - }; + } %enddef %include