SGI STL

Joe Buck jbuck@synopsys.com
Thu Feb 12 18:02:00 GMT 1998


I responded to this earlier but I should say a couple more things:

> I am trying to compile some code using the SGI STL with egcs 1.01.
> In particular I am using hash_map from the STL which is not part of
> the standard library in egcs.

egcs ships with hash_map from SGI.  Are you downloading it again
separately?  That isn't necessary (and could cause problems if you
mix older/newer versions, though currently it's probably the same
file).

Also in your example program you don't use defaults; given a proper
hash<string> you can just write

---------------------
#include <iostream.h>
#include <string>
#include <hash_map>

main() {
  hash_map<string,int> ords;

  ords["one"] = 1;
  cout <<ords["one"] <<endl;

  return 0;
}
---------------------

Finally, the sample implementation of hash<string> I supplied,

template<> struct hash<string> {
    size_t operator()(const string& s) const {
	return __stl_hash_string(s.c_str());
}};

doesn't deal with null characters, which are allowed in strings.
In principle this is OK for a hash function; they aren't that commonly
used and it just means that all strings with nulls in them hash based only
on what precedes the null.  It would be easy enough to write one that
uses s.length() instead of a trailing null.

To support hash<string>, the above definition, together with

#include <stl_hash_fun.h>

could be added to <string>.  (Or it could be more general, to support
wide strings too).  I won't supply a patch because Ulrich or Jason
may have some feelings on how to organize it.




More information about the Gcc mailing list