|
Boost : |
From: Peter.Bienstman_at_[hidden]
Date: 2001-07-06 08:50:25
Hi,
This simple patch adds automatic type conversions from Python ints,
longs and doubles to C++ complex numbers.
Useful for me, but useful enough to be included in a future release?
*** boost_orig/boost_1_22_0/boost/python/conversions.hpp Mon
May 28 17:11:56
2001
--- boost_1_22_0/boost/python/conversions.hpp Fri Jul 6 15:22:18
2001
***************
*** 93,98 ****
--- 93,105 ----
template <class T>
std::complex<T> complex_from_python(PyObject* p,
boost::python::type<T>)
{
+ if (PyInt_Check(p))
+ return static_cast<T>(PyInt_AS_LONG(p));
+ if (PyLong_Check(p))
+ return static_cast<T>(PyLong_AsLong(p));
+ if (PyFloat_Check(p))
+ return static_cast<T>(PyFloat_AS_DOUBLE(p));
+
expect_complex(p);
return std::complex<T>(
-------------------------------------
Peter Bienstman
Department of Information Technology
INTEC/IMEC - Ghent University
St.-Pietersnieuwstraat 41
B-9000 Gent - Belgium
E-mail: Peter.Bienstman_at_[hidden]
Tel: +32 9 264 3445
Fax: +32 9 264 3593
-------------------------------------
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk