4646#include " options.h"
4747#include " detail/class.h"
4848#include " detail/init.h"
49- #include " detail/typeid.h"
5049
5150#include < memory>
5251#include < vector>
@@ -1570,23 +1569,6 @@ inline str enum_name(handle arg) {
15701569 return " ???" ;
15711570}
15721571
1573- template <typename Type, typename Scalar, bool is_convertible = true >
1574- struct enum_value {
1575- static Scalar run (handle arg) {
1576- Type value = pybind11::cast<Type>(arg);
1577- return static_cast <Scalar>(value);
1578- }
1579- };
1580-
1581- template <typename Type, typename Scalar>
1582- struct enum_value <Type, Scalar, false > {
1583- static Scalar run (handle) {
1584- throw pybind11::cast_error (
1585- " Enum for " + type_id<Type>() + " is not convertible to " +
1586- type_id<Scalar>());
1587- }
1588- };
1589-
15901572struct enum_base {
15911573 enum_base (handle base, handle parent) : m_base(base), m_parent(parent) { }
15921574
@@ -1737,6 +1719,7 @@ template <typename Type> class enum_ : public class_<Type> {
17371719 using Base = class_<Type>;
17381720 using Base::def;
17391721 using Base::attr;
1722+ using Base::def_property;
17401723 using Base::def_property_readonly;
17411724 using Base::def_property_readonly_static;
17421725 using Scalar = typename std::underlying_type<Type>::type;
@@ -1746,15 +1729,10 @@ template <typename Type> class enum_ : public class_<Type> {
17461729 : class_<Type>(scope, name, extra...), m_base(*this , scope) {
17471730 constexpr bool is_arithmetic = detail::any_of<std::is_same<arithmetic, Extra>...>::value;
17481731 constexpr bool is_convertible = std::is_convertible<Type, Scalar>::value;
1749- auto property = handle ((PyObject *) &PyProperty_Type);
17501732 m_base.init (is_arithmetic, is_convertible);
17511733
1752- attr (" value" ) = property (
1753- cpp_function (
1754- &detail::enum_value<Type, Scalar, is_convertible>::run,
1755- pybind11::name (" value" ), is_method (*this )));
1756-
17571734 def (init ([](Scalar i) { return static_cast <Type>(i); }), arg (" value" ));
1735+ def_property (" value" , [](Type value) { return (Scalar) value; }, nullptr );
17581736 def (" __int__" , [](Type value) { return (Scalar) value; });
17591737 #if PY_MAJOR_VERSION < 3
17601738 def (" __long__" , [](Type value) { return (Scalar) value; });
0 commit comments