Hi,
it works exactly the same as for old style enums, you only have to prepend the
enum class scope (color::) to reference the values in the c++ code.
enum class color { red = 1, green = 2, blue = 4 };
color identity_(color x) { return x; }
BOOST_PYTHON_MODULE(enums)
{
enum_<color>("color")
.value("red", color::red)
.value("green", color::green)
.export_values()
.value("blue", color::blue)
;
def("identity", identity_);
}
What you can't do this way is to create new style python enums (see
http://docs.python.org/3.4/library/enum.html), but as the documentation says,
the python class is derived
from Python's int type.
Regards
Martin
Von: Cplusplus-sig
[mailto:[email protected]] Im
Auftrag von Deepankar Sharma
Gesendet: Samstag, 8. März 2014 21:18
An: [email protected]
Betreff: [C++-sig] How to wrap class enums
Any pointers on how to expose class enums to Python? Given the following enum
what would the boost code to expose it to python look like? The page at
http://www.boost.org/doc/libs/1_55_0/libs/python/doc/v2/enum.html only lists
examples of old style enums.
enum class t_functions
{
ADD, SUB, MUL, DIV
};
_______________________________________________
Cplusplus-sig mailing list
[email protected]
https://mail.python.org/mailman/listinfo/cplusplus-sig