boost::python and automatic conversion for const std::string&

G

gabriel.becedillas

I have a lot of functions returning "const std::string&". Every time I
wrap one of those I have to do it like this:

class_.def("name", &someclass::bla,
boost::python::return_value_policy<boost::python::copy_const_reference>()
);

Is there a way to register a return value conversion for "const
std::string&" so I can omit it every time I have to wrap functions
returning "const std::string&" ? I wan't those strings to be copied to
python as new strings (I don't want to hold a pointer to them).
Thanks
 
R

Roman Yakovenko

I have a lot of functions returning "const std::string&". Every time I
wrap one of those I have to do it like this:

class_.def("name", &someclass::bla,
boost::python::return_value_policy<boost::python::copy_const_reference>()
);

Is there a way to register a return value conversion for "const
std::string&" so I can omit it every time I have to wrap functions
returning "const std::string&" ? I wan't those strings to be copied to
python as new strings (I don't want to hold a pointer to them).

I am not sure, you'd better ask this question o Boost.Python mailing list:
http://mail.python.org/mailman/listinfo/c++-sig/
Py++, Boost.Python code generator, does it for you: http://tinyurl.com/ygwdkz
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,260
Messages
2,571,038
Members
48,768
Latest member
first4landlord

Latest Threads

Top