[C++-sig] type conversion

Ralf W. Grosse-Kunstleve rwgk at yahoo.com
Fri Feb 6 21:00:44 CET 2004


--- Uwe Schmitt <schmitt at num.uni-sb.de> wrote:
> how can I instruct boost to convert std::pair<int,int> to a
> Python tuple ??? I did not find anything in the archive...

Converting to a Python tuple is easy:

http://www.boost.org/libs/python/doc/v2/to_python_converter.html

In anticipation of the next question, "how can I do it the other way around",
you can do that with a "custom converter". It's a bit tricky but not actually
hard. Here is the solution for a similar problem:

http://www.boost.org/libs/python/doc/v2/faq.html#custom_string

This technique is very powerful if you have may functions with
std::pair<int,int> as an argument. If you only have a few it is easier to write
"thin wrappers" for your functions or member functions. E.g.:

http://www.boost.org/libs/python/doc/v2/faq.html#voidptr

This is not the best example but I hope you get the idea. It should be obvious
after reading the tutorial.

Ralf


__________________________________
Do you Yahoo!?
Yahoo! Finance: Get your refund fast by filing online.
http://taxes.yahoo.com/filing.html




More information about the Cplusplus-sig mailing list