[英]Boost::regex_iterator constructor fails but make_regex_iterator function succeeds
std::string line;
這會拋出std::runtime_error what(): Memory exhausted
:
regex_it = boost::sregex_iterator(line.begin(), line.end(), re);
這工作正常:
regex_it = boost::make_regex_iterator(line, re);
有誰知道導致性能差異的原因是什么? boost::regex 庫以默認非遞歸模式在 Linux 上編譯。
編輯:也試過
regex_it = boost::cregex_iterator(line.data(), line.data()+line.size(), re);
同樣的問題。
嘗試使用regex_iterator<char const*>
而不是regex_iterator<std::string::const_iterator>
。 (此外,您調用make_regex_iterator
的方式在很大程度上是不必要的冗長。)
假設line
是std::string
,試試這個:
regex_it = boost::make_regex_iterator(line.c_str(), re);
或這個:
regex_it = boost::cregex_iterator(line.data(), line.data() + line.size(), re);
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.