This is the mail archive of the
libstdc++@gcc.gnu.org
mailing list for the libstdc++ project.
Re: Compare two regular expressions -> check if empty()
- From: Jonathan Wakely <jwakely dot gcc at gmail dot com>
- To: Stefan Schweter <stefan at schweter dot it>
- Cc: "libstdc++ at gcc dot gnu dot org" <libstdc++ at gcc dot gnu dot org>
- Date: Tue, 7 Oct 2014 10:04:14 +0100
- Subject: Re: Compare two regular expressions -> check if empty()
- Authentication-results: sourceware.org; auth=none
- References: <54330123 dot 5020103 at schweter dot it>
On 6 October 2014 21:52, Stefan Schweter wrote:
> Hi,
>
> when I read the regular expression section in C++11 correctly, there's
> no method called "size", "length" in order to get the length of a
> regular expression or a method "empty(). Using Boost's regex
> implementation e.g. provides empty(). So I need to do a comparison of
> two regexes - consider the following code:
>
> #include <regex>
> #include <iostream>
>
> int main()
> {
> std::regex test("");
>
> std::regex test2("");
You can just call the default constructor to create an empty regex
here, that's going to be more efficient than invoking the compiler to
create a finite state automaton for the string "".
>
> if (test == test2) {
> std::cout << "empty" << std::endl;
> }
>
> return 0;
> }
>
> Won't compile with the latest GCC 5.
We just implement the standard, which gives no meaning to equality of
regex objects.