2

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は実際には何ですか?

4

1 に答える 1

0

fmtここで明らかではない何らかの理由で関数でテンプレートを使用する柔軟性が必要でない限り、代わりにこれを試してください。

std::string fmt(boost::smatch match)
于 2012-08-23T20:41:07.143 に答える