In C ++, you can declare aliases of types that are members of a class or structure:
struct Foo
{
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;
};
struct BarDataset
{
typedef long DataType;
typedef double ReturnType;
};
template <class Dataset>
class DataProcessor{
DataProcessor(Dataset& input_data);
typedef typename Dataset::DataType T;
typedef typename Dataset::ReturnType R;
T getDataItem();
R computeSomething();
};
typedef (s), , , ( Dataset), Dataset plus T, R, ..., Dataset.
, - , typedefs Cython.