【问题标题】:Boost regex_match for string_ref提升 string_ref 的 regex_match
【发布时间】:2019-08-04 20:51:59
【问题描述】:

我将 boost::regex_match 与 boost::string_ref 一起使用,但由于模板推断错误导致构建失败,我该如何解决?

 boost::smatch base;                                                                                                                      
  boost::string_ref sr = "4f000000-4f015000 r-xp 00000000 03:01 12845071   /lib/ld-2.3.2.so";                                              
  boost::regex                                                                                                                             
    re(R"(^([[:xdigit:]]+)-([[:xdigit:]]+)\s+..x.\s+([[:xdigit:]]+)\s+\S+:\S+\s+\d+\s+(\S+\.(so|dll|dylib|bundle)((\.\d+)+\w*(\.\d+){0,3})?)$)");                                                                                                                                     
  if (boost::regex_match(sr.cbegin(), sr.cend(), base, re)) {                                                                              
    std::cout << base[0] << std::endl;                                                                                                      
  }

编译器错误:

/usr/include/boost/regex/v4/regex_match.hpp|44 col 6|注:候选人: 模板 bool boost::regex_match(BidiIterator, BidiIterator, boost::match_results&, 常量 boost::basic_regex&, boost::regex_constants::match_flag_type)
|| bool regex_match(BidiIterator first, BidiIterator last,
|| ^
/usr/include/boost/regex/v4/regex_match.hpp|44 col 6|注:模板 参数推导/替换失败:
正则表达式.cpp|161 列 58|注意:推断参数的冲突类型 'Iterator' ('const char*' 和 '__gnu_cxx::__normal_iterator >')

【问题讨论】:

    标签: c++ boost


    【解决方案1】:

    boost::smatchmatch_results&lt;std::string::const_iterator&gt; 的别名,所以解决方法:

    boost::match_results<boost::string_ref::const_iterator> base;
    

    【讨论】:

      猜你喜欢
      • 2017-01-08
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-07-18
      • 1970-01-01
      • 1970-01-01
      • 2023-02-16
      相关资源
      最近更新 更多