SWIG %ignore doesn't match template with typedef

。_饼干妹妹 提交于 2019-12-23 02:07:07

问题


I have a templated Vector (as in a mathematical vector, not a std::vector) class which can be instantiated with a size between 2 and 4. The definition is something like:

template <uint32_t Size, typename StorageType>
class Vector
{
public:
  Vector(StorageType x, StorageType y);
  Vector(StorageType x, StorageType y, StorageType z);
  Vector(StorageType x, StorageType y, StorageType z, StorageType w);
  ...
};

In my SWIG file, I want to wrap a version which has a Size of 3 and a StorageType of int8_t and so I do

%module Vector
%{
#include "Vector.h"
%}

%include "stdint.i"
%include "Vector.h"

%ignore Vector(int8_t, int8_t);
%ignore Vector(int8_t, int8_t, int8_t, int8_t);
%template(Vector3DInt8) PolyVox::Vector<3,int8_t>;

But it fails to %ignore the requested constructors.

It seems that SWIG, inside the %template macro automatically 'strips off' typedefs from template parameters and so %template(Vector3DInt8) PolyVox::Vector<3,int8_t>; actually gets converted to %template(Vector3DInt8) PolyVox::Vector<3,unsigned char>;. Because of this, the %ignore doesn't match since unsigned char doesn't match int8_t.

If I add a static_assert() inside one of the functions I want to be ignored, I get:

source/Vector.inl: In constructor ‘Vector<Size, StorageType>::Vector(StorageType, StorageType) [with unsigned int Size = 3u, StorageType = signed char]’:
build/PolyVoxCorePYTHON_wrap.cxx:6446:100:   instantiated from here
source/Vector.inl:56:3: error: static assertion failed: "This constructor should only be used for vectors with two elements."

I've also tried to use -notemplatereduce but it seems to have no effect.

Is there a way to get SWIG to correctly ignore the unwanted constructors?

Edit: I'm using GCC 4.5 with SWIG 2.0.8

Edit 2: Added stdint.i to .i file as it is needed for Python typemaps. Without the stdint.i, the %ignore works correctly but it is needed to actually use the bindings in Python.

来源:https://stackoverflow.com/questions/13569939/swig-ignore-doesnt-match-template-with-typedef

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