mirror of
https://github.com/pybind/pybind11.git
synced 2026-05-11 17:00:34 +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:
@@ -6,6 +6,7 @@ sys.path.append('.')
|
||||
from example import test_function
|
||||
from example import some_constant
|
||||
from example import EMyEnumeration
|
||||
from example import ECMyEnum, test_ecenum
|
||||
from example import EFirstEntry
|
||||
from example import ExampleWithEnum
|
||||
from example import return_bytes
|
||||
@@ -20,6 +21,8 @@ print(test_function())
|
||||
print(test_function(7))
|
||||
print(test_function(EMyEnumeration.EFirstEntry))
|
||||
print(test_function(EMyEnumeration.ESecondEntry))
|
||||
test_ecenum(ECMyEnum.Three)
|
||||
test_ecenum(ECMyEnum.Two)
|
||||
print("enum->integer = %i" % int(EMyEnumeration.ESecondEntry))
|
||||
print("integer->enum = %s" % str(EMyEnumeration(2)))
|
||||
|
||||
|
||||
Reference in New Issue
Block a user