[C++-sig] iterate through boot::python::list

David Abrahams dave at boost-consulting.com
Fri Mar 7 19:52:56 CET 2003


harold fellermann <harold at imb-jena.de> writes:

> Is there any possibility to iterate trough a boost::python::list (or
> dictionary)
> from within C++ ? I could not find anything in the documentation.

Well, for a list you can call x.attr("__len__")() to get its length
and index it.

For a dictionary you can call items() and then do the same.

However, it would be interesting to make a standard input_iterator
that could iterate over the items, e.g.:


     for (
       input_iterator i = begin(some_list_or_dict);
       i != end(some_list_or_dict); 
       ++i)
     {
        whatever(*i);
     }

Nice project for someone who wants to make a contribution.

-- 
Dave Abrahams
Boost Consulting
www.boost-consulting.com





More information about the Cplusplus-sig mailing list