How to #include hash with ext, tr1, or __gnu_cxx in XCode, C++

╄→尐↘猪︶ㄣ 提交于 2020-01-05 05:53:28

问题


I'm trying to work with the google-sparsehash library and I'd like to include the hash library described in the link,

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

and I've tried one of each:

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

which none worked with XCode. I've also "using", where I was told that __gnu_cxx does not contain "hash". How do I describe this library to XCode (3.2.6) on OS X (10.6.8)?

Or more generally, where is this hash function described in a Mac / XCode?


回答1:


In C++11:

#include <functional>
using std::hash;

In C++03 with TR1:

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



回答2:


So far as I can tell, it doesn't seem possible to get at the hash functors without also pulling in definitions for the various hash tables. At least not without fooling around with library internal headers.

Try:

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

or:

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


来源:https://stackoverflow.com/questions/9005256/how-to-include-hash-with-ext-tr1-or-gnu-cxx-in-xcode-c

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