Skip to content

Commit a0c31b4

Browse files
committed
refactored code + cleanup
[SVN r19508]
1 parent 5fb677c commit a0c31b4

1 file changed

Lines changed: 3 additions & 29 deletions

File tree

include/boost/python/indexing/indexing_suite.hpp

Lines changed: 3 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
# include <boost/python/class.hpp>
1111
# include <boost/python/register_ptr_to_python.hpp>
1212
# include <boost/python/indexing/detail/indexing_suite_detail.hpp>
13+
# include <boost/python/indexing/py_container_utils.hpp>
1314
# include <boost/python/return_internal_reference.hpp>
1415
# include <boost/python/iterator.hpp>
1516
# include <boost/mpl/or.hpp>
@@ -303,37 +304,10 @@ namespace boost { namespace python {
303304
static void
304305
base_extend(Container& container, PyObject* v)
305306
{
306-
// v must be a list or some container
307+
std::vector<Element> temp;
307308
handle<> l_(borrowed(v));
308309
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);
337311
DerivedPolicies::extend(container, temp.begin(), temp.end());
338312
}
339313
};

0 commit comments

Comments
 (0)