[Boost-bugs] [Boost C++ Libraries] #7489: No hash function for classes containing conversion operation to ordinary type

Subject: [Boost-bugs] [Boost C++ Libraries] #7489: No hash function for classes containing conversion operation to ordinary type
From: Boost C++ Libraries (noreply_at_[hidden])
Date: 2012-10-09 21:08:44


#7489: No hash function for classes containing conversion operation to ordinary
type
------------------------------------------------+---------------------------
 Reporter: Robert Luberda <robert@…> | Owner: danieljames
     Type: Bugs | Status: new
Milestone: To Be Determined | Component: hash
  Version: Boost 1.51.0 | Severity: Problem
 Keywords: |
------------------------------------------------+---------------------------
 Hi

 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

 Please see the following example (based on example from bug#7437), which
 compiles fine with boost::hash up to version 1.50, but fails to compile
 with boost 1.51

 {{{
 #include <boost/unordered_map.hpp>

 class MyClass
 {
 public:
     MyClass(int i=0): v(i) {}
     operator int() const {return v;}
 private:
     int v;
 };

 typedef boost::unordered_map<MyClass,std::string> MyMap;

 int main(int argc, char* argv[])
 {
     MyMap m;
     MyMap::value_type v(MyClass(1),"apples");
     m.insert(v);

     return 0;
 }

 }}}

 The error is:
 {{{
 /opt//boost_1_51_0/include/boost/functional/hash/extensions.hpp:257:
 error: no matching function for call to 'hash_value(const MyClass&)'
 }}}

-- 
Ticket URL: <https://svn.boost.org/trac/boost/ticket/7489>
Boost C++ Libraries <http://www.boost.org/>
Boost provides free peer-reviewed portable C++ source libraries.

This archive was generated by hypermail 2.1.7 : 2017-02-16 18:50:10 UTC