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:
Jason Rhinelander
2016-08-03 23:45:08 -04:00
parent 39ff2d0140
commit 613541947a
4 changed files with 22 additions and 2 deletions

View File

@@ -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;
}