diff --git a/include/boost/python/class.hpp b/include/boost/python/class.hpp index a98226f0..870f644c 100644 --- a/include/boost/python/class.hpp +++ b/include/boost/python/class.hpp @@ -230,8 +230,19 @@ class class_ : public objects::class_base } // Property creation - self& add_property(char const* name, object const& fget); - self& add_property(char const* name, object const& fget, object const& fset); + template + self& add_property(char const* name, Get const& fget) + { + base::add_property(name, object(fget)); + return *this; + } + + template + self& add_property(char const* name, Get const& fget, Set const& fset) + { + base::add_property(name, object(fget), object(fset)); + return *this; + } template self& setattr(char const* name, U const& x) @@ -367,20 +378,6 @@ inline class_::class_(char const* name, char const* doc, no_init_t) this->def_no_init(); } -template -inline class_& class_::add_property(char const* name, object const& fget) -{ - base::add_property(name, fget); - return *this; -} - -template -inline class_& class_::add_property(char const* name, object const& fget, object const& fset) -{ - base::add_property(name, fget, fset); - return *this; -} - namespace detail { // This is an mpl BinaryMetaFunction object with a runtime behavior, diff --git a/test/data_members.cpp b/test/data_members.cpp index 5092bba9..2ee9c45d 100644 --- a/test/data_members.cpp +++ b/test/data_members.cpp @@ -26,7 +26,7 @@ BOOST_PYTHON_MODULE_INIT(data_members_ext) .def("value", &X::value) .def("set", &X::set) .def_readonly("x", &X::x) - .add_property("get_fair_value", object(&get_fair_value)) + .add_property("fair_value", &get_fair_value) ; class_("Y", args()) diff --git a/test/data_members.py b/test/data_members.py index 598d1373..ab79a90a 100644 --- a/test/data_members.py +++ b/test/data_members.py @@ -7,6 +7,9 @@ ... except AttributeError: pass ... else: print 'no error' +>>> x.fair_value +42.0 + >>> y = Y(69) >>> y.x 69