title: C++11 Hash function for any enum type
body: <p>I am writing a hash function for my object. I already can hash containers, and combine hashes, thanks to <a href="https://stackoverflow.com/questions/6899392/generic-hash-function-for-all-stl-containers">Generic Hash function for all STL-containers</a>. But my classes also have enums. Of course I can create a hash function for every enum, but it does not seem like a good idea. Is it possible to create some generic specification for <code>std::hash</code>, so that it could be applied to every enum? Something like that, using <code>std::enable_if</code> and <code>std::is_enum</code></p>
  
  <pre><code>namespace std {
    template &lt;class E&gt;
    class hash&lt;typename std::enable_if&lt;std::is_enum&lt;E&gt;::value, E&gt;::type&gt; {
    public:
      size_t operator()( const E&amp; e ) const {
        return std::hash&lt;std::underlying_type&lt;E&gt;::type&gt;()( e );
      }
    };
  };
  </code></pre>
  
  <p>PS. This code does not compile </p>
  
  <pre><code>error: template parameters not used in partial specialization:
  error:         ‘E’
  </code></pre>