In Cython, internal C ++ typings are possible?

In C ++, you can declare aliases of types that are members of a class or structure:

struct Foo
{
    // internal type alias
    typedef int DataType;

    // ...
};

Is there a way to do the same in Keaton? I tried the most obvious approach:

cdef struct Foo:
    ctypedef int DataType

But this does not work:

Error compiling Cython file:
------------------------------------------------------------
...
# distutils: language=c++

cdef struct Foo:
    ctypedef int DataType
   ^
------------------------------------------------------------

internal_typedefs_example.pyx:4:4: Expected an identifier, found 'ctypedef'

Is this just a fundamental limitation of Cython (I'm using v0.21.2), or is there a workaround?


Why bother with internal typedefs? There are several common reasons: this previous SO question covers some of them.

A specific case that interests me is packaging a set of C ++ template classes that look something like this:

struct FooDataset
{
    typedef int DataType;
    typedef float ReturnType;

    // methods, other important stuff
};

struct BarDataset
{
    typedef long DataType;
    typedef double ReturnType;

    // methods, other important stuff
};

template <class Dataset>
class DataProcessor{

    DataProcessor(Dataset& input_data);

    typedef typename Dataset::DataType T;
    typedef typename Dataset::ReturnType R;

    T getDataItem();
    R computeSomething(); /* etc. */

    // do some other stuff that might involve T and/or R
};

typedef (s), , , ( Dataset), Dataset plus T, R, ..., Dataset.

, - , typedefs Cython.

+4
1

, Cython. ?

Cython ++, python. - , ++ python.

0

All Articles