regex tr1 constructor

From the boost headers I can see that it picks up the wrong costructor, since
Dear all, Peter Becker's book 'the c++ standard library extensions' describes various tr1::regex constructors. One of them is the following (16.4.2, p.387): char expr1[] = "abc[d-f]"; regex rgx2(expr1, 3); the constructor with length specification has 3 arguments (and the last has no default specification). Who is wrong? I am using Visual Studio 2003 and boost 1.34.0.

I also notice that Pete Becker uses empty strings for construction, but this
throws with boost regex (or by use of header

and another one: the regex::ECMAScript has value 0, so it can not be tested for in the following way: void show_flags(const std::tr1::regex& rrgx) { if ((rrgx.flags() & std::tr1::regex::ECMAScript) == std::tr1::regex::ECMAScript) { //always true, since it has value 0 } }

gast128 wrote:
and another one: the regex::ECMAScript has value 0, so it can not be tested for in the following way:
void show_flags(const std::tr1::regex& rrgx) { if ((rrgx.flags() & std::tr1::regex::ECMAScript) == std::tr1::regex::ECMAScript) { //always true, since it has value 0 } }
The value of zero is intentional: it was something that users were asking for and ensures that: regex e("text", perl|icase); and regex e("text, icase); are equivalent (perl and ECMAScript expressions are treated the same in Boost.Regex). If you really want to extract out the regular expression "type" then use: (e.flags() & (ECMAScript|basic|extended|awk|grep|egrep)) == ECMAScript HTH, John.

gast128 wrote:
I also notice that Pete Becker uses empty strings for construction, but this throws with boost regex (or by use of header
), e.g.: std::tr1::regex rgx(""); //throws, intended???
It was intended: since you can't really do much with "" as a pattern, but this appears to be in conflict with the ECMAScript std, I'll add to the TODO list for Boost.Regex. John.

gast128 wrote:
Dear all,
Peter Becker's book 'the c++ standard library extensions' describes various tr1::regex constructors. One of them is the following (16.4.2, p.387):
char expr1[] = "abc[d-f]"; regex rgx2(expr1, 3);
From the boost headers I can see that it picks up the wrong costructor, since the constructor with length specification has 3 arguments (and the last has no default specification). Who is wrong?
Well, since I wrote that section of TR1 (as well as Boost.Regex), and also helped proofread Pete's book, I guess you can blame me either way :-) The relevent constructors taken straight out of TR1 are: explicit basic_regex(const charT* p, flag_type f = regex_constants::ECMAScript); basic_regex(const charT* p, size_t len, flag_type f); So the version that takes a length always needs 3 arguments (this is also the case in the current draft for the next std). HTH, John.
participants (2)
-
gast128
-
John Maddock