sregex_token_iterator bug?

gcc 3.3.3 with boost 1.31.0 on GNU/Linux: [3/19/2004 Fri 8:16.41 PM stl@nuwen ~/boost] [14 33 47]
cat moo.cc #include <iostream> #include <string> #include <boost/regex.hpp> using namespace std; using namespace boost;
int main() { string s; getline(cin, s); sregex_token_iterator i(s.begin(), s.end(), regex("\\s+"), -1); cout << "x" << *i << "x" << endl; ++i; cout << "x" << *i << "x" << endl; ++i; cout << "x" << *i << "x" << endl; } [3/19/2004 Fri 8:16.46 PM stl@nuwen ~/boost] [14 33 47]
g++ -Wall -W moo.cc -o moo -lboost_regex
[3/19/2004 Fri 8:16.57 PM stl@nuwen ~/boost] [14 33 47]
moo 1 2 3 x1x Segmentation fault
[3/19/2004 Fri 8:17.01 PM stl@nuwen ~/boost] [14 33 47]
However, the first example given in http://boost.org/libs/regex/doc/regex_token_iterator.html works fine, so I don't know what's going on. Stephan T. Lavavej http://nuwen.net

int main() { string s; getline(cin, s); sregex_token_iterator i(s.begin(), s.end(), regex("\\s+"), -1); // error here: temporary passed to constructor!
However, the first example given in http://boost.org/libs/regex/doc/regex_token_iterator.html works fine, so I don't know what's going on.
You're passing a temporary regex object to the iterator, the regex object must exist for the lifetime of the iterator (before you suggest it.... in a future regex release, I want to make regex copying O(1) and store a copy rather than a reference here). I made this requirement clear in the regex_iterator docs, but apparently not in the regex_token_iterator docs, so I'll get them updated ASAP, Thanks, John.
participants (2)
-
John Maddock
-
Stephan T. Lavavej