[C++-sig] return value policy for returning same python object...

Ralf W. Grosse-Kunstleve rwgk at yahoo.com
Sun Jun 8 22:13:11 CEST 2003


--- Milind Patil <milind_patil at hotmail.com> wrote:
> const Y&
> do_iadd (int other)
> {
>   *this += Y_FromInt(other);
>    return *this
> }
> 
> BOOST_PYTHON_MODULE(hello)
> {
>   ...
> .def("__iadd__", (const Y& Y_Wrapper::*) &do_iadd(int),
> return_value_policy<>(??? which one ???))
> ...
> }

I am not sure if there is a return policy for doing what you want, but I am
fairly sure you can do it a different way. Along the lines of:

  boost::python::object
  do_iadd(boost::python::object const& o, int)
  {
    // use extract<Y&> or similar to get a reference to the wrapped C++ object
    // manipulate the extracted object
    return o;
  }

Note that this version of do_iadd() is not a member function. If you want to
keep it inside your Y_wrapper make the do_iadd() function static.

Ralf


__________________________________
Do you Yahoo!?
Yahoo! Calendar - Free online calendar with sync to Outlook(TM).
http://calendar.yahoo.com




More information about the Cplusplus-sig mailing list