What part of regex is supported by GCC 4.9?

|▌冷眼眸甩不掉的悲伤 提交于 2019-12-18 09:24:51

问题


I don't get this. GCC is supposed to support but accoriding to their http://gcc.gnu.org/onlinedocs/libstdc++/manual/status.html#status.iso.tr1

Status page "7 Regular Expressions are not supported".

But then at "28 Regular expressions" - they are checked as supported

http://gcc.gnu.org/onlinedocs/libstdc++/manual/status.html#status.iso.2011

Could you please explain what is actually the standard and what is not?


回答1:


GCC 4.9 does indeed support the C++11 <regex> functionality but not the tr1 version. Note that the difference is that parts (all?) of the latter exist within a tr1:: namespace while the C++11 <regex> is within namespace std. There's not much point to going backwards and adding in tr1 support when C++11 has been published for some time now.




回答2:


Following information can be found from GCC 4.9 release notes:

"Support for various C++14 additions have been added to the C++ Front End, on the standard C++ library side the most important addition is support for the C++11 regex"

If you want to install the latest GCC4.9 version to try by yourself you can follow below SO link:

How do I compile and run GCC 4.9.x?

Here is the sample program which has compiled using gcc4.9 and subsequent run.

//Sample Program
#include <regex>
#include <iostream>
using namespace std;

int main() {
    regex  reg("[0-9]+");
    if (regex_match("123000", reg)) {
        cout << "It's a match!" <<endl;
    }
 return 0;
}
$g++ -std=c++11 foo.cpp -o foo
$ g++ -v
Using built-in specs.
COLLECT_GCC=/home/mantosh/gcc-4.9.0/bin/g++
COLLECT_LTO_WRAPPER=/home/mantosh/gcc-4.9.0/libexec/gcc/x86_64-unknown-linux-gnu/4.9.0/lto-wrapper
Target: x86_64-unknown-linux-gnu
Configured with: /home/mantosh/objdir/../gcc-4.9.0/configure --disable-multilib --prefix=/home/mantosh/gcc-4.9.0
Thread model: posix
gcc version 4.9.0 (GCC)
$ ./foo
It's a match!


来源:https://stackoverflow.com/questions/23474121/what-part-of-regex-is-supported-by-gcc-4-9

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!