0
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);

同样的问题。

4

1 回答 1

2

尝试使用 aregex_iterator<char const*>而不是 a regex_iterator<std::string::const_iterator>。(另外,你打电话的方式在make_regex_iterator很大程度上是不必要的冗长。)

假设linestd::string,试试这个:

regex_it = boost::make_regex_iterator(line.c_str(), re);

或这个:

regex_it = boost::cregex_iterator(line.data(), line.data() + line.size(), re);
于 2011-06-14T22:14:08.423 回答