如果您有一个出现在用于实例化函数的指令%rename
之前的指令,您可能会遇到此警告,如下所示:%template
%module some_module
%rename("%(undercase)s", %$isfunction) "";
// equivalently %rename("%(utitle)s", %$isfunction) "";
%inline %{
template<class T>
void MyFunction(){}
%}
// ...
%template(MyIntFunction) MyFunction<int>;
警告 503:除非重命名为有效标识符,否则无法包装 'my_function< int >'
而且您不能尝试在以下内容中预期重命名%template
:
%template(MyIntFunction) my_function<int>;
因为那样你会得到
错误:模板“myfunction”未定义。
Which is very frustrating if you're applying global renaming rules, and you really only need to "ignore renaming" for just a few things. Unlike typemaps, rename directives live for all-time. It'd be nice to be able to turn them off, even temporarily.
The only workaround for this I've come up with is to go back to the %rename
and update it to explicitly only match (or rather, not match) the template functions you've declared inline. Like so:
// don't rename functions starting with "MyFunction"
%rename("%(undercase)s", %$isfunction, notregexmatch$name="^MyFunction") "";
It's not perfect, but it's a workaround.
(This was all done in SWIG 4.0)