Hashing standard containers

View: New views
3 Messages — Rating Filter:   Alert me  

Hashing standard containers

by Christopher Jefferson-2 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Unfortunately both TR1 and it looks like C++0x don't provide an  
overload of std::hash for most templated types, including vector,  
list, pair and tuple.

I find this annoying, as (I believe) while it is legal to overload  
std::hash for my own types, it isn't legal to overload it for standard  
types.

I am not sure if technically it is allows as a QoI issue for standard  
libraries to overload std::hash for the standard containers and  
friends, but it does not seem like an unreasonable thing to do, and I  
would like to do it.

Would such code be acceptable, assuming of course it satisfied all  
necessary testing and quality requirements?

Chris

Re: Hashing standard containers

by Paolo Carlini-3 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Hi,

> Unfortunately both TR1 and it looks like C++0x don't provide an
> overload of std::hash for most templated types, including vector,
> list, pair and tuple.
>
> I find this annoying, as (I believe) while it is legal to overload
> std::hash for my own types, it isn't legal to overload it for standard
> types.
>
> I am not sure if technically it is allows as a QoI issue for standard
> libraries to overload std::hash for the standard containers and
> friends, but it does not seem like an unreasonable thing to do, and I
> would like to do it.
You mean, specialize, right? I don't see why it should be illegal. Note,
I just filed DR 1245, will be in R68, because I don't think it makes
sense to pass by value class types. Besides that, which will require
reworking a bit the existing specializations (I'm also thinking moving a
few inline, at least experimentally, people reported a large performance
improvement for <string> if I remember correctly), I would be certainly
interested in seeing such additional specializations, C++0x only please,
let's try to fiddle as little as possible with TR1 at this point. I
would definitely suggest starting with the mandated ones, thus
std::bitset, and std::vector<bool>...

Paolo.

Re: Hashing standard containers

by Paolo Carlini-3 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

PS: http://www.open-std.org/jtc1/sc22/wg21/docs/lwg-active.html#889 is
now ready: hash<thread::id> belongs to <thread>.

Paolo.