我在boost::regex_replace
. 我可以调用它的一个参数版本,但不能调用两个参数:
e = "(^|>)([^<>]+)";
h_str = regex_replace(h_str, e, repl_quot, boost::match_default);
其中repl_quot
定义为
std::string const &repl_quot(boost::smatch const &what) {
boost::regex e("\"");
std::string repl(""");
static std::string;
str = regex_replace(what[0].str(), e, repl, boost::match_default);
return str;
}
以上工作,但我真的不想使用那个静态变量,所以我尝试了我认为是可接受的两个参数替代版本:
std::string const &repl_quot2(boost::smatch const &what, std::string &out) {
boost::regex e("\"");
std::string repl(""");
out = regex_replace(what[0].str(), e, repl, boost::match_default);
return out;
}
但是 regex_replace 不会接受这个(一个复杂的编译器错误)。我正在尝试根据Boost::Regex
文档中的以下内容使用两个参数版本:
模板 basic_string regex_replace(const basic_string& s, const basic_regex& e, Formatter fmt, match_flag_type flags = match_default);
要求类型 Formatter 必须是...一个从函数调用计算替换字符串的一元、二元或三元仿函数:要么是 fmt(what),它必须返回一个 char_type 的容器以用作替换文本,要么是 fmt (what, out) 或 fmt(what, out, flags),两者都将替换文本写入 *out,然后返回新的 OutputIterator 位置。在每种情况下,代表找到的匹配项的 match_results 对象是什么。
已经多次请求编译器错误消息,所以这里是(小心你要求的):
c:\boost\boost\regex\v4\regex_format.hpp 在成员函数`OutputIter boost::re_detail::format_functor_container::operator()(const Match&, OutputIter, boost::regex_constants::match_flag_type, const Traits&) [with OutputIter = boost::re_detail::string_out_iterator, std::allocator >>, Container = const std::string&(*)(const boost::smatch&, std::string&), Match = boost::match_results<__gnu_cxx:: __normal_iterator, std::allocator > >, std::allocator, std::allocator > > > > >, Traits = boost::regex_traits_wrapper > >]':
356 c:\boost\boost\regex\v4\match_results.hpp 从 `OutputIterator boost::match_results::format(OutputIterator, Functor, boost::regex_constants::match_flag_type, const RegexT&) 实例化re_detail::string_out_iterator, std::allocator >>, Functor = const std::string&(*)(const boost::smatch&, std::string&), RegexT = boost::basic_regex >>, BidiIterator = __gnu_cxx::__normal_iterator , std::allocator > >, Allocator = std::allocator, std::allocator > > > >]'
60 c:\boost\boost\regex\v4\regex_replace.hpp 从`OutputIterator boost::regex_replace(OutputIterator, BidirectionalIterator, BidirectionalIterator, const boost::basic_regex&, Formatter, boost::regex_constants::match_flag_type) [with OutputIterator = boost::re_detail::string_out_iterator, std::allocator >>, BidirectionalIterator = __gnu_cxx::__normal_iterator, std::allocator >>, traits = boost::regex_traits >, charT = char, Formatter = const std::string&(* )(const boost::smatch&, std::string&)]'
80 c:\boost\boost\regex\v4\regex_replace.hpp 从`std::basic_string, std::allocator<_T2> > boost::regex_replace(const std::basic_string, std::allocator<_T2> > &, const boost::basic_regex&, Formatter, boost::regex_constants::match_flag_type) [with traits = boost::regex_traits >, charT = char, Formatter = const std::string&(*)(const boost::smatch&, std ::细绳&)]'
327 C:\Dev-Cpp\Examples\wordrad\xhtml_open.cpp 从这里实例化
第1064
begin' in
章boost::regex_traits_wrapper > > >*)this)->boost::re_detail::format_functor_container, std::allocator > >, std::allocator, std::allocator > > > > >, boost::regex_traits_wrapper > > > ::func',它是非类类型 `const std::string&(* const)(const boost::smatch&, std::string&)'第1064
end' in
章boost::regex_traits_wrapper > > >*)this)->boost::re_detail::format_functor_container, std::allocator > >, std::allocator, std::allocator > > > > >, boost::regex_traits_wrapper > > > ::func',它是非类类型 `const std::string&(* const)(const boost::smatch&, std::string&)'