title: Possible to have two keys in an unordered_set, that are considered equal?
body: <p><a href="http://www.cplusplus.com/reference/unordered_set/unordered_set/" rel="nofollow">From here</a>:</p>
  
  <blockquote>
    <p>Pred: The unordered_set object uses this expression to determine whether two element keys are equivalent. No two elements in an unordered_set container can have keys that yield true using this predicate.</p>
  </blockquote>
  
  <p>And also from 23.5.6.1/1:</p>
  
  <blockquote>
    <p>An unordered_set is an unordered associative container that supports unique keys (<strong>an unordered_set contains at most one of each key value</strong>) and in which the elements’ keys are the elements themselves. The unordered_set class supports forward iterators.</p>
  </blockquote>
  
  <p>But I can bypass this if I define my own hasher and equivalent operation that use different features of a class type. </p>
  
  <pre><code>#include &lt;iostream&gt;
  #include &lt;unordered_set&gt; //for unordered_set and unordered_multiset
  
  using namespace std;
  
  struct A{
      A() = default;
      A(int a, int b): x(a), y(b) {}
      int x = 0, y = 0;
  
  };
  
  size_t hasher(const A &amp;sd){
      return hash&lt;int&gt;()(sd.x);
  }
  
  bool eqOp(const A &amp;lhs, const A &amp;rhs){
      return lhs.y == rhs.y;
  }
  
  
  int main(){
  
      unordered_set&lt;A, decltype(hasher)*, decltype(eqOp)*&gt; unorderedA(10, hasher, eqOp);
  
      unorderedA.emplace(2,3);
      unorderedA.emplace(3,3);
  
      for(const auto&amp; c : unorderedA)
          cout &lt;&lt; c.x &lt;&lt; " " &lt;&lt; c.y &lt;&lt; endl;
  }
  </code></pre>
  
  <p>Outputs;</p>
  
  <pre><code>3 3
  2 3
  </code></pre>
  
  <p>I understand what's happening: the hasher places each key in different buckets because of their x value. However those two keys should've been considered equal by my eqOp function due to their y value, but they never get checked for equivalence since they get placed in different buckets. So is it normal functionality that an unordered container can contain two equivalent keys as long as they enter different buckets. Or is it the responsibility of the coder to make sure the hasher and predicate are written to place equivalent keys in the same bucket? Or maybe does my eqOp function violate a rule that the compiler does not detect?</p>
  
  <p>In a set and a map it's clear: the predicate provided to those defines a strict weak ordering and so two keys considered equivalent have only one element associated with them. In an unordered map it's not so clear to me: two equivalent keys can have different elements associated with them so long as those keys are in different buckets. But those sources above feel like they tell me otherwise. </p>