【发布时间】:2012-02-19 22:16:36
【问题描述】:
那么在调用 boost::regex_replace 时如何调用自定义格式化函数?
我的代码如下:
template <typename T>
std::string fmt(boost::match_results<T> match) {
auto str = match[1];
if (str == ".") {
return "\".\"";
} else {
return str;
}
}
void __ConvertEscapeChar(std::string& action, std::string regex) {
boost::regex re(regex);
action = boost::regex_replace(action, re, &fmt, boost::regex_constants::match_all);
}
但是它显示错误,“无法推断 __fmt 的模板参数”。 - 那么 T 实际上是什么?
【问题讨论】:
-
您的函数名无效。见here
-
@BenjaminLindley Meh 改变了......但这并没有真正改变任何东西......(现在真的需要一个新的 PREfix 来识别本地函数)。
-
它将您的代码更改为有效的 C++,而不是您当前的错误。
-
如果“本地函数”是指在当前编译单元(.cc/.o 文件)之外不应该看到的函数,则可以将其放在匿名命名空间中:
namespace { ConvertEscapeChar(...) {...} }.
标签: c++ regex boost boost-regex