I\'m using boost python to create a binding to a c++ library. A number of classes in this library have virtual methods which accept iterator/const_iterator types as argument
Documentation on virtual functions you reference is related to wrapping virtual functions which can be further overridden in python -- i.e. in python classes deriving from the c++ class. The logic is such that c++ only handles virtual resolution in c++; if it lands on the wrapper class (from which your python classes derive), this->get_override(..)
will further look if the python class overrides that particular function.
It is not clear whether this is really what you need (i.e. deriving python classes from c++ classes). If you only want to expose regular c++ virtual functions, virtual resolution is handled automatically.
Further, I don't understand what kind of data your functions take. Can you give a more specific example? If you have data you want to iterate over in the c++ class already, define special python functions __iter__
, which will return an proxy iterator object (you define the iterator class in c++ and wrap it in python as well); this proxy iterator must hold internally iteration state and define __iter__
(returning self), next
(returning next container item), and raise StopIteraton at the end. Such is the python iteration protocol and all usual constructs (for
etc) will work automagically. (see e.g. here, iterator class here for an example)
(Remark) don't pass vector<int>
as argument, avoid copying with const vector<int>&
. Converters for vector<int>
from python (if you define them) will work just fine.