14 enum UnscopedEnum { EOne = 1, ETwo, EThree };
15 py::enum_<UnscopedEnum>(
m,
"UnscopedEnum", py::arithmetic(),
"An unscoped enumeration")
16 .
value(
"EOne", EOne,
"Docstring for EOne")
17 .value(
"ETwo", ETwo,
"Docstring for ETwo")
18 .value(
"EThree", EThree,
"Docstring for EThree")
22 enum class ScopedEnum { Two = 2, Three };
23 py::enum_<ScopedEnum>(
m,
"ScopedEnum", py::arithmetic())
24 .
value(
"Two", ScopedEnum::Two)
25 .value(
"Three", ScopedEnum::Three);
27 m.def(
"test_scoped_enum", [](ScopedEnum
z) {
28 return "ScopedEnum::" + std::string(z == ScopedEnum::Two ?
"Two" :
"Three");
32 enum Flags { Read = 4, Write = 2, Execute = 1 };
33 py::enum_<Flags>(
m,
"Flags", py::arithmetic())
34 .
value(
"Read", Flags::Read)
35 .value(
"Write", Flags::Write)
36 .value(
"Execute", Flags::Execute)
40 class ClassWithUnscopedEnum {
42 enum EMode { EFirstMode = 1, ESecondMode };
44 static EMode test_function(EMode
mode) {
return mode; }
46 py::class_<ClassWithUnscopedEnum> exenum_class(m,
"ClassWithUnscopedEnum");
47 exenum_class.def_static(
"test_function", &ClassWithUnscopedEnum::test_function);
48 py::enum_<ClassWithUnscopedEnum::EMode>(exenum_class,
"EMode")
49 .
value(
"EFirstMode", ClassWithUnscopedEnum::EFirstMode)
50 .value(
"ESecondMode", ClassWithUnscopedEnum::ESecondMode)
54 m.def(
"test_enum_to_int", [](
int) {});
55 m.def(
"test_enum_to_uint", [](
uint32_t) {});
56 m.def(
"test_enum_to_long_long", [](
long long) {});
59 enum SimpleEnum { ONE, TWO, THREE };
61 m.def(
"register_bad_enum", [m]() {
62 py::enum_<SimpleEnum>(
m,
"SimpleEnum")
63 .
value(
"ONE", SimpleEnum::ONE)
65 .value(
"ONE", SimpleEnum::TWO)
66 .value(
"ONE", SimpleEnum::THREE)
71 enum UnscopedUCharEnum :
unsigned char {};
72 enum class ScopedShortEnum : short {};
73 enum class ScopedLongEnum : long {};
81 "Error during the deduction of enum's scalar type with normal integer underlying");
84 enum class ScopedCharEnum : char { Zero, Positive };
85 enum class ScopedWCharEnum : wchar_t { Zero, Positive };
86 enum class ScopedChar32Enum : char32_t { Zero, Positive };
87 enum class ScopedChar16Enum : char16_t { Zero, Positive };
96 "char should be cast to either signed char or unsigned char");
99 "wchar_t should be either 16 bits (Windows) or 32 (everywhere else)");
104 "char32_t, char16_t (and char8_t)'s size, signedness, and alignment is determined");
105 #if defined(PYBIND11_HAS_U8STRING) 106 enum class ScopedChar8Enum : char8_t { Zero, Positive };
111 py::enum_<ScopedCharEnum>(
m,
"ScopedCharEnum")
112 .
value(
"Zero", ScopedCharEnum::Zero)
113 .value(
"Positive", ScopedCharEnum::Positive);
114 py::enum_<ScopedWCharEnum>(
m,
"ScopedWCharEnum")
115 .
value(
"Zero", ScopedWCharEnum::Zero)
116 .value(
"Positive", ScopedWCharEnum::Positive);
117 py::enum_<ScopedChar32Enum>(
m,
"ScopedChar32Enum")
118 .
value(
"Zero", ScopedChar32Enum::Zero)
119 .value(
"Positive", ScopedChar32Enum::Positive);
120 py::enum_<ScopedChar16Enum>(
m,
"ScopedChar16Enum")
121 .
value(
"Zero", ScopedChar16Enum::Zero)
122 .value(
"Positive", ScopedChar16Enum::Positive);
125 enum class ScopedBoolEnum : bool {
FALSE,
TRUE };
130 py::enum_<ScopedBoolEnum>(
m,
"ScopedBoolEnum")
unsigned __int64 uint64_t
std::is_same< bools< Ts::value..., true >, bools< true, Ts::value... > > all_of
static const DiscreteKey mode(modeKey, 2)
negation< all_of< negation< Ts >... > > any_of