gpt4 book ai didi

c++ - boost 正则表达式格式化程序,如何使用自定义函数

转载 作者:塔克拉玛干 更新时间:2023-11-03 08:00:18 29 4
gpt4 key购买 nike

那么在调用 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)

关于c++ - boost 正则表达式格式化程序,如何使用自定义函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9024586/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com