C ++ TR1 regular expressions not available
I am trying to use the 'TR1' regex extensions to do some parsing of C ++ strings. I read that for this
requires<regex>
header and namespace std :: tr1.
I can compile the header <regex>
(although it forces me to use either a flag -std=c++0x
or -std=gnu++0x
)
However, when I try to use the namespace std::tr1
in my program, compilation fails with the message that tr1 is "not a namespace name". I cannot do things like
std::tr1::regex rx("mypattern");
I read that TR1 regular expressions are supported as of gcc 4.3.0. I am using g ++ via gcc 4.4.5.
Did I miss something?
source to share
g ++ 4.7 doesn't implement regular expressions yet.
Despite this, in C ++ 11 it regex
was moved from namespace std::tr1
to std
. So, instead, std::tr1::regex
you should write std::regex
:
std::regex rx("mypattern");
I don't know for which versions of g ++ before 4.7 this also applies. But this ideological example compiles just fine with g ++ 4.7. However, remember that the implementation of this regular expression is not implemented in this version of the compiler.
source to share