gcc 支持 boost::unordered_map

发布于 2024-08-31 00:47:55 字数 101 浏览 3 评论 0原文

gcc 何时添加 unoreded_map 支持?

我使用的是 RHEL 5.3 附带的 gcc 4.1.1。 看起来 unored_map 丢失了。有没有办法手动添加?

When unoreded_map support was added to gcc?

I'm using gcc 4.1.1 shipped with RHEL 5.3.
It looks like unoreded_map is missing. Is there a way to add it manually?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

沙与沫 2024-09-07 00:47:55

gcc 没有 boost::unordered_map — 它是 Boost 的一部分。它有 std::tr1::unordered_map。至少从 4.0 开始就包含了它。

要使用 std::tr1::unordered_map,请包含此标头:

#include <tr1/unordered_map>

boost::unordered_mapstd::tr1::unordered_map 的接口应该相似,因为后者是从前者创建的。

gcc doesn't have boost::unordered_map — it is part of Boost. It has std::tr1::unordered_map. It is included at least since 4.0.

To use std::tr1::unordered_map, include this header:

#include <tr1/unordered_map>

The interface of boost::unordered_map and std::tr1::unordered_map should be similar since the latter is created from the former.

老街孤人 2024-09-07 00:47:55

在较旧的 gcc 版本上,您还可以使用 hash_map,这可能“足够好”。

#include <ext/hash_map> // Gnu gcc specific!
...

// allow the gnu hash_map to work on std::string
namespace __gnu_cxx {
   template<> struct hash< std::string > {
      size_t operator()(const std::string& s) const {
         return hash< const char* >()( s.c_str() );
      }
   }; /* gcc.gnu.org/ml/libstdc++/2002-04/msg00107.html */
}

// this is what we would love to have:
typedef __gnu_cxx::hash_map<std::string, int> Hash;
....

后来

Hash hash;
string this_string;

...

hash[ this_string ]++;

...

我经常使用它并取得了成功。

问候

rbo

On older gcc versions, you could also use a hash_map, which might be "good enough".

#include <ext/hash_map> // Gnu gcc specific!
...

// allow the gnu hash_map to work on std::string
namespace __gnu_cxx {
   template<> struct hash< std::string > {
      size_t operator()(const std::string& s) const {
         return hash< const char* >()( s.c_str() );
      }
   }; /* gcc.gnu.org/ml/libstdc++/2002-04/msg00107.html */
}

// this is what we would love to have:
typedef __gnu_cxx::hash_map<std::string, int> Hash;
....

and later

Hash hash;
string this_string;

...

hash[ this_string ]++;

...

which I did use often and with success.

Regards

rbo

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文