question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Support for C++ scoped enum class

See original GitHub issue

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

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Reactions:5
  • Comments:8 (2 by maintainers)

github_iconTop GitHub Comments

3reactions
kb-1000commented, Aug 24, 2017

I think this workaround is also good:

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

And then:

cdef void f(rofl arg)
    pass

f(rofl.SOMETHING)
2reactions
justinfxcommented, Mar 16, 2020

I had this same problem and came to the same workaround solution back in 2013: https://stackoverflow.com/a/15566540/496445

Someone brought this up to me today and I had a poke around to see if anything has improved around this since that time, but then I came across this ticket with the same workarounds.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Scoped (class) enums: fundamentals and examples - nextptr
Scoped enums (enum class/struct) are strongly typed enumerations introduced in C++11. They address several shortcomings of the old C-style (C++ ...
Read more >
Scope of enum in C vs C++ - Stack Overflow
In C, there is simply no rule for scope for enums and struct. The place where you define your enum doesn't have any...
Read more >
Get to Know C++11 Scoped and Based Enum Types
C ++11 offers two new categories of enum types: scoped enums and based enums. Enumerators of a scoped enum require a qualified name...
Read more >
Enumeration declaration - cppreference.com
An enumeration is a distinct type whose value is restricted to a range of values (see below for details), which may include several ......
Read more >
10.4 — Scoped enumerations (enum classes) - Learn C++
Introduced in C++20, a using enum statement imports all of the enumerators from an enum into the current scope. When used with an...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found