2015-03-19 45 views
2

我目前在RHEL 5.4上安装了gcc 4.1,但我想用unordered_map。正如我发现的,这只是在C++ 11中引入的标准,因此不可用。一种替代方法是使用__gnu_cxx::hash_map,但我宁愿使用标准。需要哪个gcc版本才能使用C++ 11中的unordered_map?

在另一个开发主机我happend有RHEL 6.4和gcc 4.4,哪知道unordered_map,但给出了以下警告:

../include/c++/4.4.7/c++0x_warning.h:31:2: error: #error This file requires compiler and library support for the upcoming ISO C++ standard, C++0x. This support is currently experimental, and must be enabled with the -std=c++0x or -std=gnu++0x compiler options.

从GCC homepage我似乎无法找出哪些gcc版本支持unordered_map

澄清我的问题: 由于客户要求,我坚持使用几种操作系统及其版本,因此我不能总是更新到最新的GCC版本并且很高兴。我需要在所有平台上保持我的软件的兼容性。

因此,我在寻找使用unordered_map所需的最小GCC版本。我是知道的供应-std=c++0x到GCC修正上述错误的事实,但我不知道的“实验”警告多远意味着我不应该使用unordered_map

this thread一些人强烈建议不要使用这个实验C++ 11实现

...所以我应该怎么办?

+2

你真的*读过*错误吗?特别是关于编译器选项的最后一点。 – Biffen 2015-03-19 12:27:21

+0

是的,我*已经*读取了警告,并且我完全意识到警告会随着上述选项而消失。然而,非常自然的问题是,“实验”的含义是什么,如果我只想从C++ 11中使用'unordered_map',这对我来说是否有任何顾虑。 – user826955 2015-03-19 12:32:12

+0

没有任何借口使用gcc 4。1代表C++ 11。只需获取*最新*版本。 – Walter 2015-03-19 12:34:47

回答

1

您无法在gcc页面上找到此类信息。有关于library features的信息,但仅关于当前版本的gcc。在你的gcc 4.4中,你可以简单地使用-std=c++0x标志来没有警告。

如果您害怕expirement并且无法更新编译器 - 只是不要使用C++ 11中的unordered_map。你可以自己写,使用tr1之一,或者使用boost,无论如何。

如果你只是看GCC网站 - 有消息有:

Important: GCC's support for C++11 is still experimental. Some features were implemented based on early proposals, and no attempt will be made to maintain backward compatibility when they are updated to match the final C++11 standard.

通过的方式,C++ 11标准中的所有功能,在GCC中实现,它实际上是旧的标准,因为现在C + +14已被批准,但支持仍然过期。

我不知道为什么它仍然expiremental,例如在铛网站:

Clang fully implements all published ISO C++ standards including C++11, as well as the upcoming C++14 standard, and some parts of the fledgling C++1z standard, and is considered a production-quality C++ compiler.

而且只有C++ 1Z支持expiremental。

+0

好,那么这个*实验*与'unordered_map'有关坏​​了,还是这个类完全实现了,我可以用它来快乐? – user826955 2015-03-19 12:42:52

+0

@ user826955秒。所有对C++ 11的支持在gcc中仍然是实验性的,但你可以使用它。 – ForEveR 2015-03-19 12:46:52

+0

请在原帖中看到我的评论 – user826955 2015-03-20 07:12:59

0

如果可以的话,您应该升级到gcc 4.9.2。否则使用gcc 4.4。他们都需要-std=c++0x选项。

+4

实际上,使用'4.9.2',你应该使用'-std = C++ 11',而不是'0x'。 – Angew 2015-03-19 12:40:30

相关问题