c++ - 使用 C++11 中的 unordered_map 需要哪个 gcc 版本?

标签 c++ c++11 gcc unordered-map

我目前使用的是安装了 gcc 4.1 的 RHEL 5.4,但我想使用 unordered_map。据我所知,这仅在 C++11 中引入到标准中,因此不可用。一种替代方法是使用 __gnu_cxx::hash_map,但我更愿意使用标准。

在另一台开发主机上,我碰巧有 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 版本。我知道向 GCC 提供 -std=c++0x 可以修复上述错误,但我不知道“实验性”警告意味着什么我不应该这样做正在使用 unordered_map

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

...那我该怎么办?

最佳答案

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

如果您害怕实验并且无法更新编译器 - 请不要使用 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已经被批准,但支持仍然是过期的。

我不知道为什么它仍然是实验性的,例如在 clang 网站上:

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 支持是实验性的。

关于c++ - 使用 C++11 中的 unordered_map 需要哪个 gcc 版本?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29144518/

相关文章:

c++ - 如何制作一个 const 引用的元组?

C++ 信号量 (semi *lockfree*),我在哪里可以得到一个?

c++ - 相同的 C++ 'if' 语句,在 Linux/Windows 上的结果不同

c++ - Windows - SQLite 事件临界区

c++ - 求解具有大矩阵的稀疏线性系统时的写访问冲突

python - 如何在 python 中规范化 vector ?

c - 从 OS X 上 C 中的 dlopen()ed 动态库访问主程序全局结构/指针

c++ - 有没有人能够正确使用 libsensors?

c++ - 我什么时候应该使用 std::thread::detach?

c++ - C++ 代码中的 volatile 相关错误