|
10 | 10 | # include <boost/python/class.hpp> |
11 | 11 | # include <boost/python/register_ptr_to_python.hpp> |
12 | 12 | # include <boost/python/indexing/detail/indexing_suite_detail.hpp> |
| 13 | +# include <boost/python/indexing/py_container_utils.hpp> |
13 | 14 | # include <boost/python/return_internal_reference.hpp> |
14 | 15 | # include <boost/python/iterator.hpp> |
15 | 16 | # include <boost/mpl/or.hpp> |
@@ -303,37 +304,10 @@ namespace boost { namespace python { |
303 | 304 | static void |
304 | 305 | base_extend(Container& container, PyObject* v) |
305 | 306 | { |
306 | | - // v must be a list or some container |
| 307 | + std::vector<Element> temp; |
307 | 308 | handle<> l_(borrowed(v)); |
308 | 309 | object l(l_); |
309 | | - |
310 | | - std::vector<Element> temp; |
311 | | - for (int i = 0; i < l.attr("__len__")(); i++) |
312 | | - { |
313 | | - object elem(l[i]); |
314 | | - extract<Element const&> x(elem); |
315 | | - // try if elem is an exact Element type |
316 | | - if (x.check()) |
317 | | - { |
318 | | - temp.push_back(x()); |
319 | | - } |
320 | | - else |
321 | | - { |
322 | | - // try to convert elem to Element type |
323 | | - extract<Element> x(elem); |
324 | | - if (x.check()) |
325 | | - { |
326 | | - temp.push_back(x()); |
327 | | - } |
328 | | - else |
329 | | - { |
330 | | - PyErr_SetString(PyExc_TypeError, |
331 | | - "Invalid list element"); |
332 | | - throw_error_already_set(); |
333 | | - } |
334 | | - } |
335 | | - } |
336 | | - |
| 310 | + container_utils::extend_container(temp, l); |
337 | 311 | DerivedPolicies::extend(container, temp.begin(), temp.end()); |
338 | 312 | } |
339 | 313 | }; |
|
0 commit comments