【问题标题】:How to #include hash with ext, tr1, or __gnu_cxx in XCode, C++如何在 XCode、C++ 中使用 ext、tr1 或 __gnu_cxx #include 散列
【发布时间】:2012-02-18 18:53:33
【问题描述】:

我正在尝试使用google-sparsehash library,我想包含链接中描述的哈希库,

using ext::hash;  // or __gnu_cxx::hash, or maybe tr1::hash, depending on your OS

我已经尝试了其中的一种:

#include <ext/hash>
#include <ext>
#include <__gnu_cxx>
#include <tr1>

没有一个适用于 XCode。我也“使用”过,有人告诉我 __gnu_cxx 不包含“哈希”。如何在 OS X (10.6.8) 上向 XCode (3.2.6) 描述这个库?

或者更一般地说,这个哈希函数在 Mac/XCode 中描述在哪里?

【问题讨论】:

  • 如果我错了,请纠正我,但 XCode 和 iOS 不是用于 Objective C 的吗?谷歌哈希图似乎与属于 C++ 的 STL 相关
  • @AJG85:XCode 也支持 C 和 C++。以及除 iOS 之外的 MacOS 开发
  • @Managu 啊,谢谢,我已经好几年没见过 Apple 产品了,所以我不确定。
  • 是的,它绝对支持 C 和 C++,我在 Apple 机器上使用 XCode 进行 C++ 开发

标签: c++ xcode hash map


【解决方案1】:

在 C++11 中:

#include <functional>
using std::hash;

在带有 TR1 的 C++03 中:

#include <tr1/functional>
using std::tr1::hash;

【讨论】:

  • &lt;tr1/functional&gt; 真的定义了std::tr1::hash 吗?我怀疑是这样,但找不到任何文件可以确认。
  • @Managu:如果不花钱购买过时的文件,我无法确认;但它肯定存在于 GNU 实现中,并且在 C++11 中肯定以&lt;functional&gt; 结尾。所有标准函数对象都定义在&lt;functional&gt;中。
【解决方案2】:

据我所知,如果不引入各种哈希表的定义,似乎不可能获得哈希函子。至少在不使用库内部标头的情况下并非如此。

试试:

#include <ext/hash_map>
using __gnu_cxx::hash;

或:

#include <tr1/unordered_map>
using std::tr1::hash;

【讨论】:

    猜你喜欢
    • 2011-05-29
    • 2010-11-10
    • 2012-05-11
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-01-13
    • 2021-01-20
    • 2018-10-27
    相关资源
    最近更新 更多