SGI STL

Joe Buck jbuck@synopsys.com
Thu Feb 12 20:07:00 GMT 1998


On Thu, Feb 12, 1998 at 11:02:07AM -0500, Anand Raman wrote:

> 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.  Unfortunately, it comes up with a whole
> lot of errors and template functions that the loader is unable to
> find.

There is only one function missing (which ideally should be provided).
Fortunately it is very short.

Add the following to your code:

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

It will then work, using the same hashing function for string as for
const char * .

By the way, you can make a hashtable of any type by writing something
like the above, defining a specialization of the hash template for your
type.  It should map the object into a size_t .




More information about the Gcc mailing list