c++ - regex_token_iterator issue in Visual Studio 2015 Update 2 RC -
i installed visual studio 2015 update 2 release candidate , seem have problem use of sregex_token_iterator far seemed work fine. verify tried following sample code cppreference.com (note changed variable text have white space @ end):
#include <iostream> #include <regex> int main() { std::string text = "quick brown fox "; // tokenization (non-matched fragments) // note regex matched 2 times: when third value obtained // iterator suffix iterator. std::regex ws_re("\\s+"); // whitespace std::copy(std::sregex_token_iterator(text.begin(), text.end(), ws_re, -1), std::sregex_token_iterator(), std::ostream_iterator<std::string>(std::cout, "\n")); } running gives following assertion:
debug assertion failed! program: c:\windows\system32\msvcp140d.dll file: c:\program files (x86)\microsoft visual studio 14.0\vc\include\xstring line: 247 expression: string iterators incompatible information on how program can cause assertion failure, see visual c++ documentation on asserts. is bug in visual studio stl implementation or example regex_token_iterator wrong?
sorry -- part of performance fixes did in <regex> update 2, don't make ton of temporary string objects longer; if sub_match instance doesn't match something, make value-initialized iterators behave "as if" there empty string match.
this program should valid of c++14 (and morally what's happening inside regex_token_iterator); see "null forward iterators":
#include <stdio.h> #include <string> int main() { // value constructed iterators conceptually point empty container std::string::iterator beginit{}; std::string::iterator endit{}; printf("this should zero: %zu\n", endit - beginit); } ... our debug asserts prohibited this. regex_token_iterator happens trip on it.
note in release builds (with debug asserts turned off) work fine; bug in iterator debugging machinery, not in iterators' behavior.
this bug fixed in 2015 update 2 rtm.
Comments
Post a Comment