mirror of
https://github.com/pybind/pybind11.git
synced 2026-04-19 22:39:09 +00:00
Extended enum support (#503)
* Allow enums to be ordered * Support binary operators
This commit is contained in:
committed by
Wenzel Jakob
parent
2e76daa53f
commit
90d27805b9
@@ -19,6 +19,12 @@ enum class ScopedEnum {
|
||||
Three
|
||||
};
|
||||
|
||||
enum Flags {
|
||||
Read = 4,
|
||||
Write = 2,
|
||||
Execute = 1
|
||||
};
|
||||
|
||||
class ClassWithUnscopedEnum {
|
||||
public:
|
||||
enum EMode {
|
||||
@@ -48,6 +54,13 @@ test_initializer enums([](py::module &m) {
|
||||
.value("Three", ScopedEnum::Three)
|
||||
;
|
||||
|
||||
py::enum_<Flags>(m, "Flags")
|
||||
.value("Read", Flags::Read)
|
||||
.value("Write", Flags::Write)
|
||||
.value("Execute", Flags::Execute)
|
||||
.export_values();
|
||||
;
|
||||
|
||||
py::class_<ClassWithUnscopedEnum> exenum_class(m, "ClassWithUnscopedEnum");
|
||||
exenum_class.def_static("test_function", &ClassWithUnscopedEnum::test_function);
|
||||
py::enum_<ClassWithUnscopedEnum::EMode>(exenum_class, "EMode")
|
||||
|
||||
Reference in New Issue
Block a user