[C++-sig] Re: std::complex<double>?
Jonathan Brandmeyer
jbrandmeyer at earthlink.net
Fri Jan 9 18:20:30 CET 2004
On Fri, 2004-01-09 at 11:41, David Abrahams wrote:
> 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! ;->
Sorry :)
> 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.
I didn't realize by the comment "... instead of like an int (ie, a type
with an immutable python counterpart)" that it was already set up that
way for std::complex. Now I understand that what you meant is that it
*should* have worked and returned a Python complex object rather than
raising the exception "TypeError: No Python class registered for C++
class std::complex<double>"
My apologies,
Jonathan Brandmeyer
More information about the Cplusplus-sig
mailing list