Enumerations

clair-c2py automatically wraps C++ enumerations (both enum and enum class) as Python strings, subject to the same customization rules as classes and functions (see Customization).

Let us show a simple example with two enumerations and functions that use them:

my_enums.cpp
#include <c2py/c2py.hpp>

enum class E1 { a, b, c };
enum E2 { A, B, C };

E1 f1(E1 x) { return x; }
E2 f2(E2 x) { return x; }

In Python, we get:

>>> import my_enums as M
>>> M.f1("a")
'a'
>>> M.f2("A")
'A'

Invalid values raise TypeError:

>>> M.f1("AA")
Traceback (most recent call last):
...
TypeError: ...
...
The string "AA" is not in a,b,c