Boost C++ Libraries: Ticket #2519: Request for an empty function to be added to boost::xpressive::basic_regex https://svn.boost.org/trac10/ticket/2519 <p> 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. </p> <p> 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: </p> <p> if (re.regex_id()!=0) </p> <blockquote> <p> do_something(re); </p> </blockquote> <p> to code that reads: </p> <p> if (!re.empty()) </p> <blockquote> <p> do_something(re); </p> </blockquote> <p> 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. </p> <p> Thanks for your consideration, </p> <p> Michael Goldshteyn </p> en-us Boost C++ Libraries /htdocs/site/boost.png https://svn.boost.org/trac10/ticket/2519 Trac 1.4.3 Eric Niebler Thu, 20 Nov 2008 08:00:17 GMT status changed; resolution set https://svn.boost.org/trac10/ticket/2519#comment:1 https://svn.boost.org/trac10/ticket/2519#comment:1 <ul> <li><strong>status</strong> <span class="trac-field-old">new</span> → <span class="trac-field-new">closed</span> </li> <li><strong>resolution</strong> → <span class="trac-field-new">wontfix</span> </li> </ul> <p> 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: </p> <pre class="wiki"> assert(std::string().empty()); // OK assert(std::string("").empty()); // OK assert(boost::regex().empty()); // Is this true??? assert(boost::regex("").empty()); // How about this??? </pre><p> 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... </p> <pre class="wiki">template&lt;class Iter&gt; bool is_invalid(xpressive::basic_regex&lt;Iter&gt; const &amp;rex) { return 0 == rex.regex_id(); } </pre> Ticket