Boost C++ Libraries: Ticket #7489: No hash function for classes containing conversion operation to ordinary type https://svn.boost.org/trac10/ticket/7489 <p> Hi </p> <p> It seems boost::hash no longer supports calculating hashes for classes that are convertible to int. It used to work with previous versions of boost::hash </p> <p> Please see the following example (based on example from bug<a class="closed ticket" href="https://svn.boost.org/trac10/ticket/7437" title="#7437: Bugs: No hash function for enums in Boost 1.51 (closed: fixed)">#7437</a>), which compiles fine with boost::hash up to version 1.50, but fails to compile with boost 1.51 </p> <pre class="wiki">#include &lt;boost/unordered_map.hpp&gt; class MyClass { public: MyClass(int i=0): v(i) {} operator int() const {return v;} private: int v; }; typedef boost::unordered_map&lt;MyClass,std::string&gt; MyMap; int main(int argc, char* argv[]) { MyMap m; MyMap::value_type v(MyClass(1),"apples"); m.insert(v); return 0; } </pre><p> The error is: </p> <pre class="wiki">/opt//boost_1_51_0/include/boost/functional/hash/extensions.hpp:257: error: no matching function for call to 'hash_value(const MyClass&amp;)' </pre> en-us Boost C++ Libraries /htdocs/site/boost.png https://svn.boost.org/trac10/ticket/7489 Trac 1.4.3 anonymous Tue, 09 Oct 2012 21:18:22 GMT <link>https://svn.boost.org/trac10/ticket/7489#comment:1 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/7489#comment:1</guid> <description> <p> This is deliberate, implicit conversions can cause subtle errors. For a case like this it's pretty easy to add support with something like: </p> <pre class="wiki">friend std::size_t hash_value(MyClass const&amp; v) { return (int) v; } </pre> </description> <category>Ticket</category> </item> <item> <dc:creator>Daniel James</dc:creator> <pubDate>Sun, 03 Mar 2013 14:03:07 GMT</pubDate> <title>status changed; resolution set https://svn.boost.org/trac10/ticket/7489#comment:2 https://svn.boost.org/trac10/ticket/7489#comment:2 <ul> <li><strong>status</strong> <span class="trac-field-old">new</span> → <span class="trac-field-new">closed</span> </li> <li><strong>resolution</strong> → <span class="trac-field-new">wontfix</span> </li> </ul> Ticket