boost regex格式化程序,如何使用自定义函数

boost regex formatter, how to use a custom function

本文关键字:何使用 自定义函数 程序 regex 格式化 boost      更新时间:2023-10-16

调用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是什么?

除非您出于某种原因需要在fmt函数中灵活使用模板,否则请尝试以下操作:

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