如何解决SWIG中模板参数的数学运算?

时间:2019-05-26 16:18:59

标签: swig

我想在SWIG中将一些C ++代码转换为Java代码。在某些C ++模板中,有一些关于模板参数的数学运算。如:

template<size_t nbits, size_t es>
  value<1 + 2 * (nbits - es)> fma(const posit<nbits, es>& a, const posit<nbits, es>& b, const posit<nbits, es>& c);

参数nbits和es用于计算模板类值的参数<...>。 当我想使用%template(...)实例化模板函数fma时,如下所示:

%template(fma_32_2) sw::unum::fma<32,2>;

但是,它失败并显示:

error: 'nbits' was not declared in this scope
   SwigValueWrapper< sw::unum::value< 1+2*(nbits-es) > > result;
                                           ^~~~~
error: 'es' was not declared in this scope
   SwigValueWrapper< sw::unum::value< 1+2*(nbits-es) > > result;
                                                 ^~
error: template argument 1 is invalid
   SwigValueWrapper< sw::unum::value< 1+2*(nbits-es) > > result;
                                                     ^
error: template argument 1 is invalid
   SwigValueWrapper< sw::unum::value< 1+2*(nbits-es) > > result;

那么,有什么办法可以解决它?

0 个答案:

没有答案