diff --git a/include/pybind11/pybind11.h b/include/pybind11/pybind11.h index 0f2b72cff..efe301e01 100644 --- a/include/pybind11/pybind11.h +++ b/include/pybind11/pybind11.h @@ -13,6 +13,7 @@ #include "detail/class.h" #include "detail/dynamic_raw_ptr_cast_if_possible.h" #include "detail/init.h" +#include "detail/native_enum_data.h" #include "detail/using_smart_holder.h" #include "attr.h" #include "gil.h" @@ -1352,6 +1353,11 @@ public: // For Python 2, reinterpret_borrow was correct. return reinterpret_borrow(m); } + + module_ &operator+=(const detail::native_enum_data &data) { + detail::native_enum_add_to_parent(*this, data); + return *this; + } }; PYBIND11_NAMESPACE_BEGIN(detail) @@ -2161,6 +2167,11 @@ public: return *this; } + class_ &operator+=(const detail::native_enum_data &data) { + detail::native_enum_add_to_parent(*this, data); + return *this; + } + private: /// Initialize holder object, variant 1: object derives from enable_shared_from_this template @@ -2619,6 +2630,14 @@ public: template enum_(const handle &scope, const char *name, const Extra &...extra) : class_(scope, name, extra...), m_base(*this, scope) { + { + if (detail::global_internals_native_enum_type_map_contains( + std::type_index(typeid(Type)))) { + pybind11_fail("pybind11::enum_ \"" + std::string(name) + + "\" is already registered as a pybind11::native_enum!"); + } + } + constexpr bool is_arithmetic = detail::any_of...>::value; constexpr bool is_convertible = std::is_convertible::value; m_base.init(is_arithmetic, is_convertible);