make arithmetic operators of enum_ optional (#508)

Following commit 90d278, the object code generated by the python
bindings of nanogui (github.com/wjakob/nanogui) went up by a whopping
12%. It turns out that that project has quite a few enums where we don't
really care about arithmetic operators.

This commit thus partially reverts the effects of #503 by introducing
an additional attribute py::arithmetic() that must be specified if the
arithmetic operators are desired.
This commit is contained in:
Wenzel Jakob
2016-11-17 23:24:47 +01:00
committed by GitHub
parent 99ddc9ac1a
commit 405f6d1dfd
5 changed files with 71 additions and 40 deletions

View File

@@ -44,22 +44,20 @@ std::string test_scoped_enum(ScopedEnum z) {
test_initializer enums([](py::module &m) {
m.def("test_scoped_enum", &test_scoped_enum);
py::enum_<UnscopedEnum>(m, "UnscopedEnum")
py::enum_<UnscopedEnum>(m, "UnscopedEnum", py::arithmetic())
.value("EOne", EOne)
.value("ETwo", ETwo)
.export_values();
py::enum_<ScopedEnum>(m, "ScopedEnum")
py::enum_<ScopedEnum>(m, "ScopedEnum", py::arithmetic())
.value("Two", ScopedEnum::Two)
.value("Three", ScopedEnum::Three)
;
.value("Three", ScopedEnum::Three);
py::enum_<Flags>(m, "Flags")
py::enum_<Flags>(m, "Flags", py::arithmetic())
.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);