[C++-sig] boost::optional to_and_from_python converters (help wanted)

Ralf W. Grosse-Kunstleve rwgk at yahoo.com
Fri Jul 29 16:00:18 CEST 2005


I've whipped up custom Python converters for boost::optional<>, free for
everyone to copy:

http://cvs.sourceforge.net/viewcvs.py/cctbx/boost_adaptbx/optional_conversions.h?rev=1.2&view=auto

Here is the corresponding extension + minimal exercise:

http://cvs.sourceforge.net/viewcvs.py/cctbx/boost_adaptbx/optional_ext.cpp?rev=1.2&view=auto

This is known to work on a large number of platforms. It enables for example
(made up):

boost::optional<double>
safe_acos(double arg)
{
  if (arg < -1 || arg > 1) return boost::optional<double>();
  return boost::optional<double>(std::acos(arg));
}

...

def("safe_acos", save_acos);

In python:

>>> safe_acos(-2)
None
>>> safe_acos(0)
1.5707963267948966

HELP WANTED:

Of course, boost::optional<> converters for the built-in types + std::complex<>
and std::string really should be part of Boost.Python. Could someone out here
help with this project?

Cheers,
        Ralf

__________________________________________________
Do You Yahoo!?
Tired of spam?  Yahoo! Mail has the best spam protection around 
http://mail.yahoo.com 



More information about the Cplusplus-sig mailing list