代码之家  ›  专栏  ›  技术社区  ›  prehistoricpenguin

字符串参考的boost regex匹配

  •  0
  • prehistoricpenguin  · 技术社区  · 5 年前

    我正在使用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::匹配结果&const boost::basic_regex&, boost::regex_constants::match_flag_type)
    ||布尔正则表达式匹配(bidiiterator first,bidiiterator last,
    白细胞介素
    /usr/include/boost/regex/v4/regex_match.hpp 44 col 6注意:模板 参数扣除/替换失败:
    regex.cpp 161 col 58注意:为参数推导的冲突类型 “迭代器”(“const char*”和“\uu gnu cxx::\uu normal\u iterator>”)

    1 回复  |  直到 5 年前
        1
  •  0
  •   prehistoricpenguin    5 年前

    boost::smatch 是的别名 match_results<std::string::const_iterator> ,那么解决方案:

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