title: How to std::hash an unordered std::pair
body: <p>I want to be able to use a <code>std::pair</code> as a key in an unordered_container. I know that I could do this the following way:</p>
  
  <pre><code>template&lt;typename T&gt;
  void
  hash_combine(std::size_t &amp;seed, T const &amp;key) {
    std::hash&lt;T&gt; hasher;
    seed ^= hasher(key) + 0x9e3779b9 + (seed &lt;&lt; 6) + (seed &gt;&gt; 2);
  }
  
  namespace std {
    template&lt;typename T1, typename T2&gt;
    struct hash&lt;std::pair&lt;T1, T2&gt;&gt; {
      std::size_t operator()(std::pair&lt;T1, T2&gt; const &amp;p) const {
        std::size_t seed(0);
        ::hash_combine(seed, p.first);
        ::hash_combine(seed, p.second);
        return seed;
      }
    };
  }
  </code></pre>
  
  <p>However, I want the hashing to ignore the order of the elements in the <code>std::pair</code> (i.e., to return the same seed for <code>std::pair&lt;A, B&gt;</code> and <code>std::pair&lt;B, A&gt;)</code>.</p>
  
  <p>One way I thought to achieve this is to apply some kind of ordering when creating my <code>std::pair&lt;A, B&gt;</code> (i.e., some kind of custom <code>std::make_pair</code>).
  But this is too restrictive since objects <code>A, B</code> might not have an order.</p>
  
  <h2>Q:</h2>
  
  <p>Is there a standard way to hash a <code>std::pair</code>, such that the order of elements is ignored and the same seed is returned either for <code>std::pair&lt;A, B&gt;</code> and <code>std::pair&lt;B, A&gt;</code>?</p>