[C++-sig] [pyplusplus] functions returning double&

Roman Yakovenko roman.yakovenko at gmail.com
Sun Jun 14 06:19:33 CEST 2009


On Sat, Jun 13, 2009 at 9:09 PM, Benjamin Koerner<bennie.koerner at web.de> wrote:
> How can one allow Py++ to handle member functions that return a reference to an immutable type?
>
> For example this X::getval function:
> class X{
> double xval;
> public:
>  double& getval(){return xval;}
> };
>
> I don't care about the reference. All I need is the double value, which is only used as an r-value. Can one use a call policy in this situation, or does one have to write custom wrapper code?

Did you read Boost.Python manuals?
http://www.boost.org/doc/libs/1_39_0/libs/python/doc/v2/copy_non_const_reference.html

from pyplusplus.module_builder import call_policies
...
mb.calldef( '::X::getval' ).call_policies =
call_policies.return_value_policy(
call_policies.copy_non_const_reference )

HTH

-- 
Roman Yakovenko
C++ Python language binding
http://www.language-binding.net/


More information about the Cplusplus-sig mailing list