[C++-sig] FW: boost.python internal references on basic types

Renaud Lepere renaud.lepere at alma.fr
Wed Jun 18 08:24:07 CEST 2008


> > class Foo
> > {
> > public:
> >     const int & get_x() { return m_x; }
> >     int m_x;
> > };
> > BOOST_PYTHON_MODULE(hello)
> > {
> >    class_<Foo>("Foo")
> >        .def("get_x", &Foo::get_x, 
> >              return_internal_reference< >() )
> >        ;
> > }
> > 
> > If I replace "int" with a proxy class containing the int 
> everything is 
> > ok ; but I would prefer not to change the c++ code.
> > 
> > Can someone have an idea if what I try to do is possible ?
> 
> Remove the "return_internal_reference". Trying to share int 
> references isn't something Python supports without adding 
> additional hand-crafted wrapper code.

I replaced it with  "return_value_policy<copy_const_reference>()" 
and it seems to be ok in this case. The other problem is for 
a non const function, that can be used to modify internals such 
as "int & x()", but i think i will not show it in python.
Thanks!



More information about the Cplusplus-sig mailing list