This is the mail archive of the libstdc++@gcc.gnu.org mailing list for the libstdc++ project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Re: hash_map<char*,T> default EqualKey


Marco Morandini <morandini@aero.polimi.it> writes:

> As pointed out in 
> 
> http://gcc.gnu.org/ml/gcc-bugs/1998-02/msg00383.html
> 
> while hash_map<char*,T> has a default has_function which is based on
> the contents of the string, its equality function defaults to
> equal_key<char*>, which is based on the address of the string and
> not on his contents.  I found this quite misleading.  Would not be
> better to have equal_to<char*> (as well as not_equal_to, greater,
> less, greater_equal and less_equal) specialized with strcmp and not
> leave this to the user?

No. It should behave like map: If I tell it to store void*, it should
store void*. If I tell it to store char*, it should store char*. It is
already a mistake to have a special hash function for char*, since
perhaps I want to store null pointers, or pointers to
not-'\0'-terminated data etc.

If you want funky semantics, use a class (like std::string) or pass
your own comparison and hash funtions.

So I'd say:

- remove template<> struct hash<char*>
- perhaps add template<> struct hash<std::string> instead

	Falk


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]