Opened 14 years ago
Closed 14 years ago
#2519 closed Feature Requests (wontfix)
Request for an empty function to be added to boost::xpressive::basic_regex
Reported by: | Owned by: | Eric Niebler | |
---|---|---|---|
Milestone: | Boost 1.38.0 | Component: | xpressive |
Version: | Boost 1.37.0 | Severity: | Problem |
Keywords: | empty xpressive regex | Cc: | eric@… |
Description
Currently the only way to tell if a regex object is empty (i.e., not containing a compiled regex) is to compare the result of its regex_id() function to zero. This is not intuitive to a reader of such code without explicit comments.
It would be much easier to read said code if basic_regex supplied an empty function which internally performed this test. This would transform code that looks like:
if (re.regex_id()!=0)
do_something(re);
to code that reads:
if (!re.empty())
do_something(re);
which is much more intuitive. It seems to me to be a trivial change that makes xpressive regexes even more similar to the regular boost::regex in terms of interface, so it's a win/win.
Thanks for your consideration,
Michael Goldshteyn
boost::regex goes to some length to present itself as a souped up container of characters. You can assign a character range to it, get begin() and end() iterators for stepping through the characters with which the regex was initialized, etc. Given that, see if you can answer this without checking the docs:
Unsurprisingly, regex::empty() is not part of the standard regex interface in C++0x. I don't like regex::empty() and I'm not inclined to add it. Sorry. You already have a way to get the information you're interested in. If you would like to give it a pretty name, by all means...