Boost C++ Libraries: Ticket #5216: boost::hash<boost::shared_ptr<T>> Returns Only Two Values https://svn.boost.org/trac10/ticket/5216 <p> The attached program demonstrates that a null shared_ptr&lt;int&gt; produces a hash value of zero and that (ostensibly) all non-null instances produce a hash value of one. </p> en-us Boost C++ Libraries /htdocs/site/boost.png https://svn.boost.org/trac10/ticket/5216 Trac 1.4.3 Rob Stewart <robert.stewart@…> Wed, 23 Feb 2011 12:02:29 GMT attachment set https://svn.boost.org/trac10/ticket/5216 https://svn.boost.org/trac10/ticket/5216 <ul> <li><strong>attachment</strong> → <span class="trac-field-new">bad_hash.cpp</span> </li> </ul> <p> Bug demonstration program </p> Ticket Rob Stewart <robert.stewart@…> Wed, 23 Feb 2011 12:04:30 GMT <link>https://svn.boost.org/trac10/ticket/5216#comment:1 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/5216#comment:1</guid> <description> <p> Defining BOOST_HASH_NO_IMPLICIT_CASTS produces a static assertion failure which is better than the silent misbehavior. </p> <p> The following makes things work, regardless of whether BOOST_HASH_NO_IMPLICIT_CASTS is defined: </p> <pre class="wiki">namespace boost { template &lt;class T&gt; std::size_t hash_value(boost::shared_ptr&lt;T&gt; const &amp; _ptr) { return boost::hash_value(_ptr.get()); } } </pre> </description> <category>Ticket</category> </item> <item> <dc:creator>Peter Dimov</dc:creator> <pubDate>Thu, 24 Feb 2011 23:24:58 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/5216#comment:2 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/5216#comment:2</guid> <description> <p> (In <a class="changeset" href="https://svn.boost.org/trac10/changeset/69260" title="Add hash_value for shared_ptr; prevents hash_value( bool ) from being ...">[69260]</a>) Add hash_value for shared_ptr; prevents hash_value( bool ) from being used. Refs <a class="closed ticket" href="https://svn.boost.org/trac10/ticket/5216" title="#5216: Bugs: boost::hash&lt;boost::shared_ptr&lt;T&gt;&gt; Returns Only Two Values (closed: fixed)">#5216</a>. </p> </description> <category>Ticket</category> </item> <item> <dc:creator>Peter Dimov</dc:creator> <pubDate>Thu, 24 Feb 2011 23:26:14 GMT</pubDate> <title>status changed https://svn.boost.org/trac10/ticket/5216#comment:3 https://svn.boost.org/trac10/ticket/5216#comment:3 <ul> <li><strong>status</strong> <span class="trac-field-old">new</span> → <span class="trac-field-new">assigned</span> </li> </ul> Ticket Peter Dimov Tue, 22 Mar 2011 23:51:13 GMT status changed; resolution set https://svn.boost.org/trac10/ticket/5216#comment:4 https://svn.boost.org/trac10/ticket/5216#comment:4 <ul> <li><strong>status</strong> <span class="trac-field-old">assigned</span> → <span class="trac-field-new">closed</span> </li> <li><strong>resolution</strong> → <span class="trac-field-new">fixed</span> </li> </ul> <p> (In <a class="changeset" href="https://svn.boost.org/trac10/changeset/70440" title="Merge [69260] to release. Fixes #5216.">[70440]</a>) Merge <a class="changeset" href="https://svn.boost.org/trac10/changeset/69260" title="Add hash_value for shared_ptr; prevents hash_value( bool ) from being ...">[69260]</a> to release. Fixes <a class="closed ticket" href="https://svn.boost.org/trac10/ticket/5216" title="#5216: Bugs: boost::hash&lt;boost::shared_ptr&lt;T&gt;&gt; Returns Only Two Values (closed: fixed)">#5216</a>. </p> Ticket