开发者

Boost::regex_iterator constructor fails but make_regex_iterator function succeeds

std::string line;

This throws std::runtime_error what(): Memory exhausted:

regex_it =  boost::sregex_iterator(line.begin(), line.end(), re);

This works fine:

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

Does anyone know what is causing the difference in performance? The boost::regex lib is compiled on Linux in default non-recursive mode.开发者_Python百科

EDIT: Also tried

regex_it = boost::cregex_iterator(line.data(), line.data()+line.size(), re);

same problem.


Try working with a regex_iterator<char const*> rather than a regex_iterator<std::string::const_iterator>. (Also, the way you're calling make_regex_iterator is unnecessarily verbose by a large measure.)

Assuming line is a std::string, try this:

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

or this:

regex_it = boost::cregex_iterator(line.data(), line.data() + line.size(), re);
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜