[Cython] Exposing C++'s <iterator>

Kevin Thornton krthornt at uci.edu
Fri Oct 16 15:50:41 EDT 2015


Hello,

I was wanting to use C++s' back_inserter in Cython, and I got it working.
I'm writing the list to ask about what more I should do before submitting a
pull request.

In short, the following definitions were sufficient:

##Define the basic iterator types (this is incomplete)
cdef extern from "<iterator>" namespace "std":
    cdef cppclass iterator[Category,T,Distance,Pointer,Reference]:
        pass
    cdef cppclass output_iterator_tag:
        pass
    #The goal here is to get back_inserter working, as it is handy.
    cdef cppclass
back_insert_iterator[T](iterator[output_iterator_tag,void,void,void,void]):
        pass
    back_insert_iterator[CONTAINER] back_inserter[CONTAINER](CONTAINER &)

##Not shown here, but I've gotten C++11's move algorithm to work, too,
##using same kind of prototype
cdef extern from "<algorithm>" namespace "std":
    OUTPUT copy[INPUT,OUTPUT](INPUT,INPUT,OUTPUT)

I've worked up a tiny test package that is on GitHub:
https://github.com/molpopgen/cython_cpp_iterators

The tests work, and I can indeed copy amongst C++ containers.

I've also gotten the C++ move algorithm to work.  The prototype is the same
as for 'copy' above.

I'd be willing to define the remaining classes from <iterator> and add a
.pxd file.

Any input would be appreciated.

Thanks,

Kevin
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/cython-devel/attachments/20151016/e36ab989/attachment.html>


More information about the cython-devel mailing list