Re: [cython-users] Wrapping C++ template struct

333 views
Skip to first unread message

Robert Bradshaw

unread,
Aug 27, 2012, 2:04:13 PM8/27/12
to cython...@googlegroups.com
Call it a cppclass. In C++ struct are classes and classes are structs,
the only difference is the default visibility of members.

That being said, we currently only support parameterization on types.
You can fake this with

cdef extern from *:
ctypedef int TWO "2"
cdef cppclass Data[T]:
...

cdef Data[TWO] my_data_var;

but it's rather limited and ugly.

- Robert


On Sun, Aug 26, 2012 at 7:33 PM, Jeff Wiens <jeffrey...@gmail.com> wrote:
> I am attempting to access the struct
>
> template <int dim>
> struct Data {
> double X[dim];
> double Val[dim];
> };
>
> in cython. I was guessing the correct syntax should be something like:
>
> cdef extern from "Lib.h" namespace "LIB":
> cdef struct Data[int dim]:
> double X[dim];
> double Val[dim];
>
> However, I am getting an syntax error. What is the correct syntax? I can't
> seem to find anything in the cython documentation. I could just be looking
> in the wrong location.
Reply all
Reply to author
Forward
0 new messages