46
46
#include " options.h"
47
47
#include " detail/class.h"
48
48
#include " detail/init.h"
49
- #include " detail/typeid.h"
50
49
51
50
#include < memory>
52
51
#include < vector>
@@ -1570,23 +1569,6 @@ inline str enum_name(handle arg) {
1570
1569
return " ???" ;
1571
1570
}
1572
1571
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
-
1590
1572
struct enum_base {
1591
1573
enum_base (handle base, handle parent) : m_base(base), m_parent(parent) { }
1592
1574
@@ -1737,6 +1719,7 @@ template <typename Type> class enum_ : public class_<Type> {
1737
1719
using Base = class_<Type>;
1738
1720
using Base::def;
1739
1721
using Base::attr;
1722
+ using Base::def_property;
1740
1723
using Base::def_property_readonly;
1741
1724
using Base::def_property_readonly_static;
1742
1725
using Scalar = typename std::underlying_type<Type>::type;
@@ -1746,15 +1729,10 @@ template <typename Type> class enum_ : public class_<Type> {
1746
1729
: class_<Type>(scope, name, extra...), m_base(*this , scope) {
1747
1730
constexpr bool is_arithmetic = detail::any_of<std::is_same<arithmetic, Extra>...>::value;
1748
1731
constexpr bool is_convertible = std::is_convertible<Type, Scalar>::value;
1749
- auto property = handle ((PyObject *) &PyProperty_Type);
1750
1732
m_base.init (is_arithmetic, is_convertible);
1751
1733
1752
- attr (" value" ) = property (
1753
- cpp_function (
1754
- &detail::enum_value<Type, Scalar, is_convertible>::run,
1755
- pybind11::name (" value" ), is_method (*this )));
1756
-
1757
1734
def (init ([](Scalar i) { return static_cast <Type>(i); }), arg (" value" ));
1735
+ def_property (" value" , [](Type value) { return (Scalar) value; }, nullptr );
1758
1736
def (" __int__" , [](Type value) { return (Scalar) value; });
1759
1737
#if PY_MAJOR_VERSION < 3
1760
1738
def (" __long__" , [](Type value) { return (Scalar) value; });
0 commit comments