Created on 2009-02-02.00:00:00 last changed 162 months ago
Proposed resolution:
Add the following declarations to the synopsis of <memory> in [memory]
// [util.smartptr.hash] hash support template <class T> struct hash; template <class T, class D> struct hash<unique_ptr<T,D>>; template <class T> struct hash<shared_ptr<T>>;
Add a new subclause under [util.smartptr] called hash support
hash support [util.smartptr.hash]
template <class T, class D> struct hash<unique_ptr<T,D>>;Specialization meeting the requirements of class template hash ([unord.hash]). For an object p of type UP, where UP is a type unique_ptr<T,D>, hash<UP>()(p) shall evaluate to the same value as hash<typename UP::pointer>()(p.get()). The specialization hash<typename UP::pointer> is required to be well-formed.
template <class T> struct hash<shared_ptr<T>>;Specialization meeting the requirements of class template hash ([unord.hash]). For an object p of type shared_ptr<T>, hash<shared_ptr<T>>()(p) shall evaluate to the same value as hash<T*>()(p.get()).
[ 2010-02-09 Moved to Tentatively Ready after 5 positive votes on c++std-lib. ]
[ 2010-02-08 Beman updates wording. ]
[ 2009-11-16 Moved from Ready to Open: ]
Pete writes:
As far as I can see, "...suitable for using this type as key in unordered associative containers..." doesn't define any semantics. It's advice to the reader, and if it's present at all it should be in a note. But we have far too much of this sort of editorial commentary as it is.
And in the resolution of 978 it's clearly wrong: it says that if there is no hash specialization available for D::pointer, the implementation may provide hash<unique_ptr<T,D>> if the result is not suitable for use in unordered containers.
Howard writes:
Is this a request to pull 978 from Ready?
Barry writes:
I read this as more than a request. The PE says it's wrong, so it can't be Ready.
[ 2009-10 Santa Cruz: ]
Move to Ready.
[ 2009-07-28 Alisdair provides wording. ]
[ 2009-05-31 Peter adds: ]
Howard points out that the client can always supply a custom hash function.
Not entirely true. The client cannot supply the function that hashes the address of the control block (the equivalent of the old operator<, now proudly carrying the awkward name of 'owner_before'). Only the implementation can do that, not necessarily via specializing hash<>, of course.
This hash function makes sense in certain situations for shared_ptr (when one needs to switch from set/map using ownership ordering to unordered_set/map) and is the only hash function that makes sense for weak_ptr.
[ Batavia (2009-05): ]
Howard points out that the client can always supply a custom hash function.
Alisdair replies that the smart pointer classes are highly likely to be frequently used as hash keys.
Bill would prefer to be conservative.
Alisdair mentions that this issue may also be viewed as a subissue or duplicate of issue 1025.
Move to Open, and recommend the issue be deferred until after the next Committee Draft is issued.
Addresses UK 208
I don't see an open issue on supporting std::hash for smart pointers (unique_ptr and shared_ptr at least).
It seems reasonable to at least expect support for the smart pointers, especially as they support comparison for use in ordered associative containers.
History | |||
---|---|---|---|
Date | User | Action | Args |
2011-08-23 20:07:26 | admin | set | status: wp -> c++11 |
2010-10-21 18:28:33 | admin | set | messages: + msg4663 |
2010-10-21 18:28:33 | admin | set | messages: + msg4662 |
2010-10-21 18:28:33 | admin | set | messages: + msg4661 |
2010-10-21 18:28:33 | admin | set | messages: + msg4660 |
2010-10-21 18:28:33 | admin | set | messages: + msg4659 |
2010-10-21 18:28:33 | admin | set | messages: + msg4658 |
2010-10-21 18:28:33 | admin | set | messages: + msg4657 |
2010-10-21 18:28:33 | admin | set | messages: + msg4656 |
2010-10-21 18:28:33 | admin | set | messages: + msg4655 |
2009-02-02 00:00:00 | admin | create |