[C++-sig] Re: std::complex<double>?

David Abrahams dave at boost-consulting.com
Fri Jan 9 17:41:56 CET 2004


Jonathan Brandmeyer <jbrandmeyer at earthlink.net> writes:

> On Fri, 2004-01-09 at 08:07, Neal D. Becker wrote:
>> How do I reflect std::complex<double> into python?
>
> Well, there isn't any prebuilt suite for exporting that type to Python,
> so you would have to write something along the lines of
>
> template<typename T>
> void
> wrap_std_complex( std::string name)
> {
>     class_<std::complex<T> >(name, init<T, optional<T> >())
>          .def( "imag", &std::complex<T>::imag)
>          .def( self + self)
>          // ... and so on and so forth
>          ;
> }
>
> The upside is that you will only have to do it once since you will be
> able to reuse that template by calling different versions of it from the
> module definition.

It won't work.  Why do I get the feeling everyone's ignoring my posts?
Have I been silent too long?  I did design this library, y'know! ;->

There's a built-in specializations of the to_python converter for
complex<double> which turns it into a Python complex object, so no
dynamic class registration will help when it comes to converting
return values.

-- 
Dave Abrahams
Boost Consulting
www.boost-consulting.com





More information about the Cplusplus-sig mailing list