How to #include hash with ext, tr1, or __gnu_cxx i

2019-08-06 19:30发布

问题:

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;


标签: c++ xcode hash map