mirror of
https://github.com/pybind/pybind11.git
synced 2026-05-13 09:46:10 +00:00
Fix scoped enums and add scoped enum example
PR #309 broke scoped enums, which failed to compile because the added: value == value2 comparison isn't valid for a scoped enum (they aren't implicitly convertible to the underlying type). This commit fixes it by explicitly converting the enum value to its underlying type before doing the comparison. It also adds a scoped enum example to the constants-and-functions example that triggers the problem fixed in this commit.
This commit is contained in:
@@ -1019,9 +1019,9 @@ public:
|
||||
this->def("__init__", [](Type& value, UnderlyingType i) { new (&value) Type((Type) i); });
|
||||
this->def("__int__", [](Type value) { return (UnderlyingType) value; });
|
||||
this->def("__eq__", [](const Type &value, Type *value2) { return value2 && value == *value2; });
|
||||
this->def("__eq__", [](const Type &value, UnderlyingType value2) { return value == value2; });
|
||||
this->def("__eq__", [](const Type &value, UnderlyingType value2) { return (UnderlyingType) value == value2; });
|
||||
this->def("__ne__", [](const Type &value, Type *value2) { return !value2 || value != *value2; });
|
||||
this->def("__ne__", [](const Type &value, UnderlyingType value2) { return value != value2; });
|
||||
this->def("__ne__", [](const Type &value, UnderlyingType value2) { return (UnderlyingType) value != value2; });
|
||||
this->def("__hash__", [](const Type &value) { return (UnderlyingType) value; });
|
||||
m_entries = entries;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user