0

unoreded_map サポートが gcc に追加されたのはいつですか?

RHEL 5.3 に同梱されている gcc 4.1.1 を使用しています。unoreded_map が欠落しているようです。手動で追加する方法はありますか?

4

2 に答える 2

8

gcc にはありませんboost::unordered_mapBoostの一部です。それは持っていstd::tr1::unordered_mapます。少なくとも 4.0 以降に含まれています。

を使用するstd::tr1::unordered_mapには、次のヘッダーを含めます。

#include <tr1/unordered_map>

boost::unordered_map後者は前者から作成されているため、とのインターフェースはstd::tr1::unordered_map似ているはずです。

于 2010-04-28T19:33:31.413 に答える
2

古い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

于 2010-04-28T19:42:11.870 に答える