class_<>::add_property() on CVS-HEAD
The following example demonstrates a method of using add_property that works with Boost.Python 1.30 but not CVS-HEAD (from sourceforge CVS). The example posted is somewhat useless as-is, but demonstrates something that I started using for properties with non-trivial accessors. Is there a replacement for this functionality? Thanks, Jonathan Brandmeyer -------------------------------------------------------------- #include <boost/python.hpp> namespace test { // Hmm. return_internal_reference<>() wants to wrap a real class. class ret_type { public: double i; }; class crash_me { private: ret_type i; public: ret_type& get_i() { return i; } }; } BOOST_PYTHON_MODULE( crash_test) { using namespace boost::python; class_< test::ret_type>( "ret_type") .def_readwrite( "i", &test::ret_type::i) ; class_< test::crash_me> crash_me_wrapper( "crash_me"); crash_me_wrapper .def( "get_i", &test::crash_me::get_i , return_internal_reference<>()) ; // The following works under Boost 1.30, but not CVS-HEAD // (sourceforge repository). crash_me_wrapper.add_property( "i", crash_me_wrapper.attr("get_i")); } -------------------------------------------------------- Testing with G++ 3.3.2 (Debian) results in the following error using CVS-HEAD: /home/jonathan/src/boost-CVS-HEAD/boost/boost/python/class.hpp: In member function `boost::python::api::object boost::python::class_<T, X1, X2, X3>::make_fn(const F&) [with F = boost::python::api::proxy<boost::python::api::attribute_policies>, T = test::crash_me, X1 = boost::python::detail::not_specified, X2 = boost::python::detail::not_specified, X3 = boost::python::detail::not_specified]': /home/jonathan/src/boost-CVS-HEAD/boost/boost/python/class.hpp:365: instantiated from `boost::python::class_<T, X1, X2, X3>& boost::python::class_<T, X1, X2, X3>::add_property(const char*, Get) [with Get = boost::python::api::proxy<boost::python::api::attribute_policies>, T = test::crash_me, X1 = boost::python::detail::not_specified, X2 = boost::python::detail::not_specified, X3 = boost::python::detail::not_specified]' crashme.cpp:38: instantiated from here /home/jonathan/src/boost-CVS-HEAD/boost/boost/python/class.hpp:429: error: no matching function for call to `get_signature(const boost::python::api::proxy<boost::python::api::attribute_policies>&, test::crash_me*)'
Jonathan Brandmeyer <jbrandmeyer@earthlink.net> writes:
Is there a replacement for this functionality?
Thanks, Jonathan Brandmeyer
-------------------------------------------------------------- #include <boost/python.hpp>
namespace test {
// Hmm. return_internal_reference<>() wants to wrap a real class. class ret_type { public: double i; };
class crash_me { private: ret_type i; public: ret_type& get_i() { return i; } };
}
BOOST_PYTHON_MODULE( crash_test) { using namespace boost::python;
class_< test::ret_type>( "ret_type") .def_readwrite( "i", &test::ret_type::i) ;
class_< test::crash_me> crash_me_wrapper( "crash_me");
crash_me_wrapper .def( "get_i", &test::crash_me::get_i , return_internal_reference<>()) ;
// The following works under Boost 1.30, but not CVS-HEAD // (sourceforge repository). crash_me_wrapper.add_property( "i", crash_me_wrapper.attr("get_i")); }
Jonathan, Sorry it took so long to respond; I'll fix it in CVS momentarily. In the meantime, you can use: crash_me_wrapper.add_property( "i", object(crash_me_wrapper.attr("get_i")) ); -- Dave Abrahams Boost Consulting www.boost-consulting.com
Jonathan Brandmeyer <jbrandmeyer@earthlink.net> writes:
The following example demonstrates a method of using add_property that works with Boost.Python 1.30 but not CVS-HEAD (from sourceforge CVS). The example posted is somewhat useless as-is, but demonstrates something that I started using for properties with non-trivial accessors.
Is there a replacement for this functionality?
Should be fixed now. -- Dave Abrahams Boost Consulting www.boost-consulting.com
On Fri, 2004-01-02 at 13:16, David Abrahams wrote:
Jonathan Brandmeyer <jbrandmeyer@earthlink.net> writes:
The following example demonstrates a method of using add_property that works with Boost.Python 1.30 but not CVS-HEAD (from sourceforge CVS). The example posted is somewhat useless as-is, but demonstrates something that I started using for properties with non-trivial accessors.
Is there a replacement for this functionality?
Should be fixed now.
Works for me. Thanks, Jonathan Brandmeyer
participants (2)
-
David Abrahams -
Jonathan Brandmeyer