Opened 12 years ago
Closed 12 years ago
#5216 closed Bugs (fixed)
boost::hash<boost::shared_ptr<T>> Returns Only Two Values
Reported by: | Owned by: | Peter Dimov | |
---|---|---|---|
Milestone: | To Be Determined | Component: | smart_ptr |
Version: | Boost 1.44.0 | Severity: | Problem |
Keywords: | shared_ptr hash | Cc: |
Description
The attached program demonstrates that a null shared_ptr<int> produces a hash value of zero and that (ostensibly) all non-null instances produce a hash value of one.
Attachments (1)
Change History (5)
by , 12 years ago
Attachment: | bad_hash.cpp added |
---|
comment:1 by , 12 years ago
Defining BOOST_HASH_NO_IMPLICIT_CASTS produces a static assertion failure which is better than the silent misbehavior.
The following makes things work, regardless of whether BOOST_HASH_NO_IMPLICIT_CASTS is defined:
namespace boost { template <class T> std::size_t hash_value(boost::shared_ptr<T> const & _ptr) { return boost::hash_value(_ptr.get()); } }
comment:2 by , 12 years ago
comment:3 by , 12 years ago
Status: | new → assigned |
---|
comment:4 by , 12 years ago
Resolution: | → fixed |
---|---|
Status: | assigned → closed |
Note:
See TracTickets
for help on using tickets.
Bug demonstration program