显然,swig 会自动std::vector<std::vector<double> >
转换为元组的元组。我想防止这种情况发生,并且我希望类型保持原样。我怎样才能实现它?我尝试为类型指定一个定义
%template(StdVectorStdVectorDouble) std::vector<std::vector<double> >;
但显然它不起作用。
两种技术:
%clear
SWIG 处理函数之前的类型的类型映射。%template
之后声明。%module x
%begin %{
#pragma warning(disable:4127 4211 4701 4706)
%}
%include <std_vector.i>
%template(vd) std::vector<double>;
%template(vvd) std::vector<std::vector<double> >;
%clear std::vector<std::vector<double> >;
%inline %{
#include<vector>
std::vector<std::vector<double> > func()
{
std::vector<std::vector<double> > temp;
std::vector<double> a;
a.push_back(1.5);
temp.push_back(a);
return temp;
}
%}
%module x
%begin %{
#pragma warning(disable:4127 4211 4701 4706)
%}
%include <std_vector.i>
%inline %{
#include<vector>
std::vector<std::vector<double> > func()
{
std::vector<std::vector<double> > temp;
std::vector<double> a;
a.push_back(1.5);
temp.push_back(a);
return temp;
}
%}
%template(vd) std::vector<double>;
%template(vvd) std::vector<std::vector<double> >;
Python 3.3.0 (v3.3.0:bd8afb90ebf2, Sep 29 2012, 10:57:17) [MSC v.1600 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import x
>>> x.func()
<x.vvd; proxy of <Swig Object of type 'std::vector< std::vector< double,std::allocator<double > > > *' at 0x00000000025F6900> >