enum_: fix implicit conversion on Python 2.7

Enumerations on Python 2.7 were not always implicitly converted to
integers (depending on the target size). This patch adds a __long__
conversion function (only enabled on 2.7) which fixes this issue.

The attached test case fails without this patch.
This commit is contained in:
Wenzel Jakob
2017-04-28 14:46:52 +02:00
parent 51d18aa252
commit e6fd2cd5ab
4 changed files with 19 additions and 1 deletions

View File

@@ -65,4 +65,8 @@ test_initializer enums([](py::module &m) {
.value("EFirstMode", ClassWithUnscopedEnum::EFirstMode)
.value("ESecondMode", ClassWithUnscopedEnum::ESecondMode)
.export_values();
m.def("test_enum_to_int", [](int) { });
m.def("test_enum_to_uint", [](uint32_t) { });
m.def("test_enum_to_long_long", [](long long) { });
});