Skip to content

Commit 5cad257

Browse files
committed
Update the docs re: new enum_ behaviour
1 parent e87ee19 commit 5cad257

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

docs/classes.rst

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -443,3 +443,14 @@ The entries defined by the enumeration type are exposed in the ``__members__`` p
443443
...
444444
445445
By default, these are omitted to conserve space.
446+
447+
In order to define additional methods on the enum class in Python, use `into_class()`
448+
method of the `enum_` object which will yield a `class_` instance:
449+
450+
.. code-block:: cpp
451+
452+
py::enum_<Pet::Kind>(pet, "Kind")
453+
.value("Dog", Pet::Kind::Dog)
454+
.value("Cat", Pet::Kind::Cat)
455+
.into_class()
456+
.def("is_cat", [](const Pet::Kind& kind) { return kind == Pet::Kind::Cat; });

0 commit comments

Comments
 (0)