After reading the discussion on operator< for std::weak_ptr, I can't see any reason why defining std::hash to use the control block for std::weak_ptr wouldn't work. I also can't believe that this was ignored by the standards committee. Has anybody read the relevant discussion on the topic?
Edit: Discussion on operator< for std::weak_ptr http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2004/n1590.html
I am somewhat familiar with the history. There's another later paper you should also read:
http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2008/n2637.pdf
And I believe this later paper is what is actually in the current draft. In summary, shared_ptr has value-based operator<() and ownership-based member functions owner_before. weak_ptr has only the latter.
My best guess is that hash-support for weak_ptr simply got dropped. No one proposed hash support for weak_ptr to the best of my knowledge. There have been many, many issues in bringing C++0x to standardization, a limited amount of time and resources to work the issues, and no doubt there will be mistakes and missing pieces.
I also think to add hash support for weak_ptr it would have to be done analogously to owner_before: Add the member function owner_hash to both shared_ptr and weak_ptr. I suspect it is too late to do this for C++0x, but this seems like a plausible TR2 proposal.
It turns out that Japan complained about this (see lwg issue 1406), and that exactly what Howard suggests in his answer was proposed as the resolution. Unfortunately, it was postponed (presumably because of time constraints).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With