[C++-sig] boost.python: implicit type conversion
Mihail Konstantinov
kmihail at rocketmail.com
Tue Dec 2 20:20:44 CET 2008
> 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?
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.
> > Can I modify the declaration inside BOOST_PYTHON_MODULE so that the implicit
> conversion is recognized and the above call boost_ext.printme(b) succeeds?
>
> Yes: http://www.boost.org/doc/libs/1_37_0/libs/python/doc/v2/implicit.html
This looks very helpful. But I don't understand the C++ module definition example on that page. It ends with
> implicitly_convertible<X,int>();
> implicitly_convertible<int,X>();
>}
I see that an int can be implicitly converted to X. But how can an X be converted to an int? I can't believe that boost.python searches all implemented functions to find that make_x is capable of converting an int to X?
Thank you
Mihail
More information about the Cplusplus-sig
mailing list