[C++-sig] pyste and return reference problem

Nicodemus nicodemus at esss.com.br
Wed Nov 17 00:27:05 CET 2004


Hi Jonh,

John Hunter wrote:

>I have found what looks like pyste bug.  pyste wraps the following
>struct
>
>  struct C {
>    const C& func(double val) {return *this;}
>    double func() {return 0.0;}
>  };
>
>as
>
>    class_< C >("C", init<  >())
>        .def(init< const C& >())
>        .def("func", (const C& (C::*)(double) )&C::func, return_value_policy< copy_const_reference >())
>        .def("func", (double (C::*)() )&C::func, return_value_policy< copy_const_reference >())
>    ;
> 
>
>
>Note that (double (C::*)() )&C::func has a call policy of
>return_value_policy< copy_const_reference >()).  
>
>If you reverse the order of the method definitions in C, ie
>
>
>  struct C {
>    double func() {return 0.0;}
>    const C& func(double val) {return *this;}
>  };
>
>pyste gets it right
>
>    class_< C >("C", init<  >())
>        .def(init< const C& >())
>        .def("func", (double (C::*)() )&C::func)
>        .def("func", (const C& (C::*)(double) )&C::func, return_value_policy< copy_const_reference >())
>    ;
>

Yeah, sounds like a bug... unfortunately I don't have time to dig into 
the code to solve this one. :/

>This leads me to a question related to one of my earlier questions:
>when wrapping overloaded functions as above, is there a way to
>differentially set the call policies in pyste for the different
>signatures.  I know one can use as described in the docs
>
>    set_policy(f, return_internal_reference())
>    set_policy(C.foo, return_value_policy(manage_new_object))
>
>How does one do this for overloaded functions?
>

If I'm not mistaken Pyste doesn't currently support that. Sorry.

>Sorry for the deluge of mail!  I'm going home now :-)
>

That's alright; Sorry again for taking so long to respond.

Regards,
Bruno.



More information about the Cplusplus-sig mailing list