[C++-sig] Boost iterators

David Abrahams david.abrahams at rcn.com
Fri Apr 12 23:02:30 CEST 2002


----- Original Message -----
From: "Martin Casado" <casado2 at llnl.gov>

>  I have two questions:
>
>  1. How can I get an exception to Python without causing Boost to
barf?
>     To signify that the iterator has reached the end of the container
>     I must set, StopIteration, but boost assumes the following is
>     an internal error.
>
>      PyErr_SetString(PyExc_StopIteration,"done iterating");
>
>      and  prints the following:
>
>     XXX undetected error
>     Traceback (most recent call last):
>       File "<stdin>", line 1, in ?
>     StopIteration: done iterating

It's not boost reporting "undetected error", but Python. Try the
following:

#include <boost/python/errors.hpp>
...

    PyErr_SetString(PyExc_StopIteration,"done iterating");
    throw boost::python::error_already_set();


>  2. Currently, I have to add a function in my C++ class to return a
newly
>     constructed PyIter.  Is there a way to have boost create the
>     type given an accessor method to the container or the container
itself?

Could you be more specific? What did you have in mind?

-Dave






More information about the Cplusplus-sig mailing list