rocketas
rocketas

Reputation: 1707

C++ TR1 Regular Expressions Not Available

I'm trying to utilize the 'TR1' regular expression extensions for some C++ string parsing. I've read that the <regex> header and namespace std::tr1 are required for this

I can compile with the <regex> header present(though it forces me to use either the flag, -std=c++0x or -std=gnu++0x)

However, when I attempt to use the std::tr1 namespace in my program, compiling fails with message that tr1 "is not a namespace name". I cant do things like,

std::tr1::regex rx("mypattern");

I've read that TR1 regular expressions have been supported since gcc 4.3.0. I'm using g++ through gcc 4.4.5.

Am I missing something?

Upvotes: 3

Views: 4062

Answers (1)

leemes
leemes

Reputation: 45715

g++ 4.7 doesn't implement regular expressions yet.

But despite that fact, in C++11 regex has been moved from the namespace std::tr1 to std. So, instead of std::tr1::regex, you should write std::regex:

std::regex rx("mypattern");

I don't know for which g++ versions before 4.7 this applies, too. But this ideone example compiles fine with g++ 4.7. However, remember that the regex implementation isn't implemented in this compiler version.

Upvotes: 8

Related Questions