swig提供的默认类型映射期望将python列表作为构建集而不是本机Python集的输入(请参见here)。确实,
%include "std_set.i"
%template(IntSet) std::set<int>;
将在python中触发以下行为:
>>> import MyClass
>>> MyClass.IntSet([1,2,3,4]) # works
>>> MyClass.IntSet({1,2,3,4}) # does not work
我试图创建一个自定义的类型映射,但是到目前为止我还是失败了。这是我当前的Swig文件:
%module MyClass
%{
#include "MyClass.h"
%}
%include <typemaps.i>
%typemap(in) setin {$1 = PySequence_List($input);}
%typemap(out) setout {$result = PySet_New($1);}
%include "std_set.i"
%template(IntSet) std::set<int>;
%include "MyClass.h"
你知道怎么做吗?