boost regex formatter,如何使用自定义函数

时间:2012-01-26 20:08:14

标签: c++ regex boost boost-regex

那么在调用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的模板参数”。 - 那实际上是什么?

1 个答案:

答案 0 :(得分:0)

除非您需要在fmt函数中使用模板的灵活性由于某种原因而不明显,请尝试以下方法:

std::string fmt(boost::smatch match)