Boost Python properties/getter functions for strings

Shawn McGrath shawn.mcgrath at gmail.com
Mon Mar 19 15:17:39 EDT 2007


On Mar 19, 12:49 pm, "Jon Clements" <jon... at googlemail.com> wrote:
> On 19 Mar, 16:40, "Shawn  McGrath" <shawn.mcgr... at gmail.com> wrote:
>
> > On Mar 19, 12:00 pm, "Shawn  McGrath" <shawn.mcgr... at gmail.com> wrote:
>
> > > I forgot to mention, getname is defined as:
> > > const std::string &Entity::getName() const;
>
> > After more reading I found the copy_const_reference, and replaced:
> >  boost::python::return_internal_reference<>());
> > with:
>
> > boost::python::return_value_policy<boost::python::copy_const_reference>());
>
> > and it fixed my problem.  Is there any downside to using
> > copy_const_reference over return_internal_reference?
>
> You might get some answers here; if not, can I suggesthttp://mail.python.org/mailman/listinfo/c++-sig? I think a lot of the
> Boost.Python developers hang around on that list.
>
> hth,
>
> Jon.

Cool thanks a lot.

The problem is actually due to python's strings being immutable (I
knew this, but I thought returning const std::string& would do it).
return_internal_reference<> works for other pointers/references, just
not strings.

(I just answered it so if it gets searched later on people will find
the solution)

-Shawn.




More information about the Python-list mailing list