@@ -65,6 +65,7 @@ namespace boost { namespace python {
6565 .def (" append" , &base_append)
6666 .def (" count" , &base_count)
6767 .def (" extend" , &base_extend)
68+ .def (" remove" , &base_remove)
6869 ;
6970 }
7071
@@ -265,6 +266,42 @@ namespace boost { namespace python {
265266 base_extend (container, v);
266267 return object (container);
267268 }
269+
270+ static void
271+ base_remove (Container& container, object v)
272+ {
273+ extract<data_type&> key (v);
274+ if (key.check ())
275+ {
276+ auto i = std::find (container.begin (), container.end (), key ());
277+ if (i == container.end ())
278+ {
279+ PyErr_SetString (PyExc_ValueError, " remove(x): x not in vector_indexing_suite" );
280+ throw_error_already_set ();
281+ }
282+ container.erase (i);
283+ }
284+ else
285+ {
286+ extract<data_type> key (v);
287+ if (key.check ())
288+ {
289+ auto i = std::find (container.begin (), container.end (), key ());
290+ if (i == container.end ())
291+ {
292+ PyErr_SetString (PyExc_ValueError, " remove(x): x not in vector_indexing_suite" );
293+ throw_error_already_set ();
294+ }
295+ container.erase (i);
296+ }
297+ else
298+ {
299+ PyErr_SetString (PyExc_TypeError,
300+ " Attempting to remove an invalid type" );
301+ throw_error_already_set ();
302+ }
303+ }
304+ }
268305 };
269306
270307}} // namespace boost::python
0 commit comments