[C++-sig] boost.python: implicit type conversion

Roman Yakovenko roman.yakovenko at gmail.com
Tue Dec 2 20:32:47 CET 2008


On Tue, Dec 2, 2008 at 9:20 PM, Mihail Konstantinov
<kmihail at rocketmail.com> wrote:
>> Roman Yakovenko wrote:
>> It is not a good idea. Python string is immutable. May be you should
>> consider custom converter.
>> http://www.boost.org/doc/libs/1_37_0/libs/python/doc/v2/faq.html#custom_string
>
> I don't see why it is not a good idea. I am nowhere accessing any string derived classes in a mutable fashion, am I?

May in the code you posted you don't. May be you don't change it in
the whole project. But if you do, it breaks too many Python
assumptions.

> Also I have no option to change the class hierarchy. The code fragments I am posting are simplified from a large project that I try to pythonify, reduced to what I think is the cause of the problems. I want to avoid modifying the underlying project under all circumstances.

I understand. I suggest you to reconsider registration of std::string
as a base class of your classes.

Also, Boost.Python has built-in functionality to convert Python string
and std::basic_string. I don't know what effect class_< std::string >
registration will have.

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


More information about the Cplusplus-sig mailing list