テンプレート化された Vector (std::vector ではなく、数学的なベクトルのように) クラスがあり、2 ~ 4 のサイズでインスタンス化できます。定義は次のようになります。
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);
...
};
Size
SWIG ファイルで、 of3
とStorageType
ofを持つバージョンをラップしたいint8_t
ので、
%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>;
しかし%ignore
、要求されたコンストラクターには失敗します。
マクロ内の SWIG は、%template
テンプレート パラメータから typedef を自動的に「剥ぎ取り」、%template(Vector3DInt8) PolyVox::Vector<3,int8_t>;
実際には%template(Vector3DInt8) PolyVox::Vector<3,unsigned char>;
. このため、が一致しないため、%ignore
が一致unsigned char
しませんint8_t
。
static_assert()
無視したい関数の中に を追加すると、次のようになります。
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."
私も使ってみまし-notemplatereduce
たが、効果がないようです。
SWIG に不要なコンストラクタを正しく無視させる方法はありますか?
編集:SWIG 2.0.8でGCC 4.5を使用しています
編集 2: Python タイプマップに必要なため、ファイルに追加stdint.i
されました。.i
がなくてもstdint.i
、 は%ignore
正しく機能しますが、実際に Python でバインディングを使用する必要があります。