开发者

Wrapping template template parameter class with SWIG

开发者 https://www.devze.com 2023-03-09 20:18 出处:网络
I have a C++ class like the following: template< template<typename> class ContainerType, typename MemberType>

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 tha开发者_开发问答t 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


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

template<class ContainerType, typename MemberType>
0

精彩评论

暂无评论...
验证码 换一张
取 消