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: mgoldshteyn@… 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

Change History (1)

comment:1 by Eric Niebler, 14 years ago

Resolution: wontfix
Status: newclosed

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:

  assert(std::string().empty());    // OK
  assert(std::string("").empty());  // OK
  assert(boost::regex().empty());   // Is this true???
  assert(boost::regex("").empty()); // How about this???

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...

template<class Iter>
bool is_invalid(xpressive::basic_regex<Iter> const &rex)
{
  return 0 == rex.regex_id();
}
Note: See TracTickets for help on using tickets.