Question
Is there a way to create a Python wrapper for Cython-wrapped C++ class with templates? (i.e. do exactly what is show here but with templates: http://docs.cython.org/src/userguide/wrapping_CPlusPlus.html#create-cython-wrapper-class).
I know about the fused types workaround (https://groups.google.com/forum/#!topic/cython-users/qQpMo3hGQqI) but that doesn't allow you to instatiate classes like vector<vector<int>>
: the fused types have, quite unsurprisingly, no notion of recursion.
Rephrasing
What I would like to achieve is for a wrapped class like:
cdef extern from "header.h":
cdef cppclass Foo[T]:
Foo(T param)
# ...
create a simple Python wrapper:
cdef class PyFoo[T]: # I know the '[T]' can't be here, it's a wish
cdef Foo[T] *thisptr
def __cinit__(self, param):
self.thisptr = new Foo[T](param)
# ...
I'm quite certain that Cython doesn't support that per se, but maybe someone can think of a workaround. I'm not looking for idiomatic or nice examples, I'm just wondering if that's possible in any way.
See Question&Answers more detail:os