Wrapping template template parameter class with SWIG

為{幸葍}努か 提交于 2020-01-03 10:58:15

问题


I have a C++ class like the following:

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

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>;

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 ;

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.

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.

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


回答1:


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

template<class ContainerType, typename MemberType>


来源:https://stackoverflow.com/questions/6215165/wrapping-template-template-parameter-class-with-swig

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!