This is the mail archive of the
libstdc++@gcc.gnu.org
mailing list for the libstdc++ project.
Re: hash container unordered_map is defective for key='const char*', key='string' and key='const string'
- From: Paolo Carlini <paolo dot carlini at oracle dot com>
- To: Karsten Burger <karsten_burger at gmx dot de>
- Cc: libstdc++ at gcc dot gnu dot org
- Date: Thu, 30 Oct 2008 14:28:02 +0100
- Subject: Re: hash container unordered_map is defective for key='const char*', key='string' and key='const string'
- References: <20081030125445.217080@gmx.net>
Hi,
> Conclusion:
> * in my opinion we should add the specialization for 'char*' and 'const char*' to avoid unexpected results. also migration to the new container is much easier and performance much better.
>
Well, we should consider that the current CD Standard (N2798) is rather
clear about this: at variance with the legacy hashed containers, there
is no concept of char array of C string, only of pointers. I don't think
the implementor can add a specialization for char* or const char*
comparing the pointed chars instead of the pointers themselves and
remain conforming.
> * specialization of hash<string> should not pass a string value but a reference instead.
>
Again, the CD (20.7.1.7) is pretty clear about by-value.
> * if possible hash<string&> and hash<const string&> should be provided as inline code.
>
Yes, probably. We'll see what we can do.
> * even with the additional specialization of hash<const char*> the new container is still a bit slower then the old one. (The performance is the same with compile option -DNDEBUG.)
>
That is interesting but we badly need more specific hints, a bit of
profiling would probably help.
Paolo.