11

Replacing boost::regex with std::regex since we are using gcc 4.6 in the company I ran into an issue with empty () method of that class - it basically didn't make it from boost::regex into std::regex class. I am not sure whether this is a gcc's issue or this method didn't make it into C++11 standard at all, but that piece of code was heavily depending on this feature. So the question is - is there a way in C++11 std::regex to check if expression was ever set or I should stick to boost::regex for the rest of my life?

  • @PlasmaHH: Really? I thought it is. It is in MSVC, wikipedia mentions it as well here - http://en.wikipedia.org/wiki/C%2B%2B11#Regular_expressions So it didn't finally make it into the standard last minute? –  Oct 17 '11 at 22:16
  • 1
    @VladLazarenko I'm looking at N3290 and can't find it. – pmr Oct 17 '11 at 22:34
  • @pmr: ... but it was in TR1.. Do you know what the heck is going on? –  Oct 18 '11 at 00:11
  • 1
    "or I should stick to boost::regex for the rest of my life? " ... if the use of `empty()` isn't completely sprinkled all over your project, you might be able to quite easily refactor the code using it to use a combination of the regexp and a `boost::optional` (or some variant of this feature) – Martin Ba Oct 18 '11 at 07:07
  • @Martin: That's what I though, too. But I don't really want to refactor for the sake of refactoring. Replacing is one thing, but spending time refactoring for no good reason is another :) –  Oct 18 '11 at 12:10
  • @Vlad: You're not refactoring for the sake of refactoring. You're refactoring because you "want" to use std::regex and it isn't fully compatible with boost:regex. – Martin Ba Oct 18 '11 at 13:01
  • No, the goal is to profit, not to use std::regex, actually. I tried to replace it with `std` because I thought it won't hurt to get less dependencies on Boost. But thing didn't work out, and it is not really worth it to spend time on this. Just got curious about what the hell those guys at committee thought before getting rid of `empty ()`. –  Oct 18 '11 at 13:16

1 Answers1

14

empty() got removed from std::regex a long time ago. N1507 (2003-09-16) was the original paper to suggest its removal (search for "What is an invalid/empty regular expression?"). This issue was directed at what then was std::tr1:regex. It was recorded in the LWG tr1 issues lists as issue 7.28 and contained the following resolution:

Discussed at Kona. The LWG agrees that the default constructor should be equivalent to construction from an empty string. Leaving this open for now partly because we need wording expressing that, and partly because it’s not clear that there’s any point to having the empty() member function in the first place.

N1711 (2004-11-04) was the first TR1 draft to lack basic_regex::empty(). From there it got imported from TR1 into C++11 with no further discussion.

Alexis Wilke
  • 19,179
  • 10
  • 84
  • 156
Howard Hinnant
  • 206,506
  • 52
  • 449
  • 577