I have a function in c++ who returns a list of complex:
#include <complex>
std::list< std::complex<double> > func(...);
what should i do in the '*.i' file ?
Thank you every body.
=================
Following are details:
the function i would like to use in python in x.h:
std::list<std::complex<double> > roots1(const double& d, const double& e);
I have tried some ways:
(1) x.i:
%include <std_list.i>
%include <std_complex.i>
than I try in IPython:
tmp = x.roots1(1.0, 2.0)
len(tmp)
and I got:
---------------------------------------------------------------------------
TypeError Traceback (most recent call last)
<ipython-input-5-9ebf7dab7cd9> in <module>()
----> 1 len(tmp)
TypeError: object of type 'SwigPyObject' has no len()
and:
dir(tmp)
returns:
[
...
'acquire',
'append',
'disown',
'next',
'own']
(2) x.i:
%include <std_list.i>
%include <std_complex.i>
namespace std {
%template(ComplexDouble) complex<double>;
}
than, i got compile error:
error: command 'swig' failed with exit status 1
make: *** [py] Error 1
(3) in x.i:
%include <std_list.i>
%include <std_complex.i>
namespace std {
%template(ComplexDouble) list<complex<double> >;
}
or:
%include <std_list.i>
%include <std_complex.i>
namespace std {
%template(ComplexDouble) list<complex>;
}
and I got:
x_wrap.cpp:5673:32: error: ‘complex’ was not declared in this scope
template <> struct traits<complex > {
^
================================================
(Mr./Ms./Mrs) m7thon help me find the problem. In my python context:
Ubuntu: 45~14.04.1
Python: 3.4.3
SWIG: SWIG Version 2.0.11
Compiled with g++ [x86_64-unknown-linux-gnu]
Configured options: +pcre
if define the x.i as:
%include <std_list.i>
%include <std_complex.i>
namespace std {
%template(ComplexList) list<complex<double> >;
}
there will be compiling error. But it works if x.i:
%include <std_list.i>
%include <std_complex.i>
%template(ComplexList) std::list< std::complex<double> >;
Thank you m7thon.