문제

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).

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top