diff --git a/include/boost/python/class.hpp b/include/boost/python/class.hpp index af4ce1fd..26ca5bfd 100644 --- a/include/boost/python/class.hpp +++ b/include/boost/python/class.hpp @@ -273,19 +273,33 @@ class class_ : public objects::class_base // Property creation template - self& add_property(char const* name, Get const& fget) + self& add_property(char const* name, Get fget) { - base::add_property(name, object(fget)); + base::add_property( + name + , object( + detail::member_function_cast::stage1(fget).stage2((T*)0).stage3(fget) + ) + ); + return *this; } template - self& add_property(char const* name, Get const& fget, Set const& fset) + self& add_property(char const* name, Get fget, Set fset) { - base::add_property(name, object(fget), object(fset)); + base::add_property( + name + , object( + detail::member_function_cast::stage1(fget).stage2((T*)0).stage3(fget) + ) + , object( + detail::member_function_cast::stage1(fset).stage2((T*)0).stage3(fset) + ) + ); return *this; } - + template self& setattr(char const* name, U const& x) { diff --git a/include/boost/python/detail/def_helper.hpp b/include/boost/python/detail/def_helper.hpp index 106f3677..78a1649f 100644 --- a/include/boost/python/detail/def_helper.hpp +++ b/include/boost/python/detail/def_helper.hpp @@ -65,7 +65,7 @@ namespace detail struct tuple_extract_base_select { typedef typename Tuple::head_type head_type; - typedef typename mpl::apply1::type>::type match_t; + typedef typename mpl::apply1::type>::type match_t; BOOST_STATIC_CONSTANT(bool, match = match_t::value); typedef typename tuple_extract_impl::template apply type; }; diff --git a/include/boost/python/detail/indirect_traits.hpp b/include/boost/python/detail/indirect_traits.hpp index cd4ad666..ee361adf 100644 --- a/include/boost/python/detail/indirect_traits.hpp +++ b/include/boost/python/detail/indirect_traits.hpp @@ -47,47 +47,26 @@ struct is_reference_to_const # endif template -struct is_reference_to_function +struct is_reference_to_function : mpl::bool_c +{ +}; + +template +struct is_reference_to_function : is_function +{ +}; + +template +struct is_pointer_to_function : mpl::bool_c { BOOST_STATIC_CONSTANT(bool, value = false); }; +// There's no such thing as a pointer-to-cv-function, so we don't need +// specializations for those template -struct is_reference_to_function +struct is_pointer_to_function : is_function { - BOOST_STATIC_CONSTANT(bool, value = is_function::value); -}; - -# if 0 -template -struct is_reference_to_function -{ - BOOST_STATIC_CONSTANT(bool, value = is_function::value); -}; - -template -struct is_reference_to_function -{ - BOOST_STATIC_CONSTANT(bool, value = is_function::value); -}; - -template -struct is_reference_to_function -{ - BOOST_STATIC_CONSTANT(bool, value = is_function::value); -}; -# endif -template -struct is_pointer_to_function -{ - BOOST_STATIC_CONSTANT(bool, value = false); -}; - -template -struct is_pointer_to_function -{ - // There's no such thing as a pointer-to-cv-function, so we don't need specializations for those - BOOST_STATIC_CONSTANT(bool, value = is_function::value); }; template diff --git a/test/data_members.cpp b/test/data_members.cpp index e5affba4..889ea9d1 100644 --- a/test/data_members.cpp +++ b/test/data_members.cpp @@ -22,11 +22,18 @@ typedef test_class<1> Y; double get_fair_value(X const& x) { return x.value(); } -struct Var + +struct VarBase { - Var(std::string name_) : name(name_), value(), name2(name.c_str()), y(6) {} + VarBase(std::string name_) : name(name_) {} + std::string const name; std::string get_name1() const { return name; } +}; + +struct Var : VarBase +{ + Var(std::string name_) : VarBase(name_), value(), name2(name.c_str()), y(6) {} std::string const& get_name2() const { return name; } float value; char const* name2; @@ -39,7 +46,7 @@ BOOST_PYTHON_MODULE(data_members_ext) .def("value", &X::value) .def("set", &X::set) .def_readonly("x", &X::x) - .add_property("fair_value", &get_fair_value) + .add_property("fair_value", get_fair_value) ; class_("Y", init()) @@ -60,6 +67,8 @@ BOOST_PYTHON_MODULE(data_members_ext) // sense to add the test here. .def("get_name1", &Var::get_name1, return_value_policy()) .def("get_name2", &Var::get_name2, return_value_policy()) + + .add_property("name3", &Var::get_name1) ; } diff --git a/test/data_members.py b/test/data_members.py index 820b4f12..989c3c32 100644 --- a/test/data_members.py +++ b/test/data_members.py @@ -35,6 +35,10 @@ >>> v.y.x = -7 >>> v.y.x -7 + +>>> v.name3 +'pi' + ''' def run(args = None):