使用SWIG封装模板模板参数类

问题描述:

我有一个类似下面的C ++类:

I have a C++ class like the following:

template< template<typename> class ContainerType, typename MemberType>
class MyClass
{
  public:
    MyClass(ContainerType<MemberType>* volData);
}

My MyClass.i如下所示:

which I am trying to wrap with SWIG. My MyClass.i looks like:

%module MyClass
%{
  #include "SimpleContainer.h"
  #include "MyClass.h"
%}

%include "SimpleContainer.h"
%include "MyClass.h"

%template(MyClass_SimpleContainer_Int) MyClass<SimpleContainer, int>;

但是,SWIG似乎有模板模板参数的问题。当编译它时出现错误信息:

However, SWIG seems to have problems with the template template parameter. When compiling it complains with the error message:

MyClassPYTHON_wrap.cxx:30545:3: error: ‘ContainerType’ was not declared in this scope

查看生成的代码中的该行,它包含以下行:

Looking at that line in the generated code, it contains the line:

ContainerType< int > *arg1 = (ContainerType< int > *) 0 ;

由于某种原因,它使用伪模板名称作为类的名称, ve告诉它这个类的实例化应该有一个Container类型的SimpleContainer。

For some reason it's using verbatim the dummy template name as the name of the class, even though I've told it that this instantiation of the class should have a ContainterType of SimpleContainer.

有没有什么办法,我可以绕过这个bug?我发现在 SWIG跟踪器中提到它,但我无法

Is there any way that I can get around this bug? I found mention of it in the SWIG tracker but I couldn't understand the workaround mentioned in the last post and also that bug is 4 years old.

我在openSUSE 11.4上使用SWIG 1.3.40和GCC 4.5.1。 / p>

I'm using SWIG 1.3.40 and GCC 4.5.1 on openSUSE 11.4

你的C ++头文件的第一行看起来很奇怪。尝试以下操作:

The first line of your C++ header looks strange to me. Try the following:

template<class ContainerType, typename MemberType>