2012-01-26 12 views
2

boost :: regex_replaceを呼び出すときにカスタム書式関数を呼び出すにはどうすればよいですか?boost regex formatter、カスタム関数の使い方

私のコードは次のとおりです。

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用テンプレート引数を推定できませんでした」。 - 実際にISは何ですか?

+1

あなたの関数名は無効です。参照してください[ここ](http://stackoverflow.com/questions/228783/what-using-the-rules-about-using-an-underscore-in-ac-identifier) –

+0

@BenjaminLindley Meh変更...しかし、そのdosen本当に何かを変えてはいけません(本当にローカル関数を識別するための新しいPREfixが必要です)。 – paul23

+1

現在のエラー以外のコードを有効なC++に変更します。 –

答えて

0

あなたがここに明らかにされていないいくつかの理由で、あなたのfmt機能にテンプレートを使用しての柔軟性を必要とする場合を除き、代わりにこれを試してみてください。

std::string fmt(boost::smatch match) 
関連する問題