Support for C++ scoped enum class #1603

Open
TheJJ opened this Issue Feb 12, 2017 · 1 comment

Projects

None yet

2 participants

@TheJJ
TheJJ commented Feb 12, 2017 edited

There is currently no sane way to represent enum class in .pxd.

namespace lol {
enum class rofl : int {
    SOMETHING,
    MOAR = 1337
};

// at this point, accessible as rofl::MOAR
}
// here, accessible as lol::rofl::MOAR

A possible way of representing it would be:

cdef extern from "headername.h" namespace "lol":
    cdef enumclass rofl:
        SOMETHING
        MOAR

# accessed as
rofl.MOAR

Related: #1567

@mic-e
Contributor
mic-e commented Feb 12, 2017 edited

The best workaround for this issue that I found with current Cython:

cdef extern from "headername.h" namespace "lol":
    cdef cppclass rofl:
        pass
        
    cdef rofl rofl_SOMETHING "rofl::SOMETHING"
    cdef rofl rofl_MOAR "rofl::MOAR"

This can be used in the pyx file like this:

cdef void f(rofl arg):
    pass

f(rofl_SOMETHING)

Which will generate the correct C++ code.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment