diff --git a/include/boost/python/suite/indexing/container_utils.hpp b/include/boost/python/suite/indexing/container_utils.hpp index a25185d0..72710bb8 100644 --- a/include/boost/python/suite/indexing/container_utils.hpp +++ b/include/boost/python/suite/indexing/container_utils.hpp @@ -7,9 +7,12 @@ #ifndef PY_CONTAINER_UTILS_JDG20038_HPP # define PY_CONTAINER_UTILS_JDG20038_HPP +# include +# include # include # include # include +# include namespace boost { namespace python { namespace container_utils { @@ -19,11 +22,13 @@ namespace boost { namespace python { namespace container_utils { { typedef typename Container::value_type data_type; - // l must be a list or some container - - for (int i = 0; i < l.attr("__len__")(); i++) + // l must be iterable + BOOST_FOREACH(object elem, + std::make_pair( + boost::python::stl_input_iterator(l), + boost::python::stl_input_iterator() + )) { - object elem(l[i]); extract x(elem); // try if elem is an exact data_type type if (x.check()) diff --git a/test/vector_indexing_suite.py b/test/vector_indexing_suite.py index 9bb75700..5fe2efe4 100644 --- a/test/vector_indexing_suite.py +++ b/test/vector_indexing_suite.py @@ -321,6 +321,19 @@ e >>> print_xvec(v) [ a b c d e f g h i j ] +##################################################################### +# extend using a generator expression +##################################################################### +>>> v[:] = ['a','b','c','d','e'] # reset again +>>> def generator(): +... addlist = ['f','g','h','i','j'] +... for i in addlist: +... if i != 'g': +... yield i +>>> v.extend(generator()) +>>> print_xvec(v) +[ a b c d e f h i j ] + ##################################################################### # vector of strings #####################################################################