This is the mail archive of the
libstdc++@gcc.gnu.org
mailing list for the libstdc++ project.
Re: hash_map<char*,T> default EqualKey
- To: libstdc++ at gcc dot gnu dot org
- Subject: Re: hash_map<char*,T> default EqualKey
- From: Falk Hueffner <falk dot hueffner at student dot uni-tuebingen dot de>
- Date: 21 May 2001 16:48:01 +0200
- References: <3B0904F9.C92865FB@aero.polimi.it>
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