title: Using C++11 unordered_set in Visual C++ and clang
body: <p>I'am trying to use std::unordered_set in cross-platform C++ application. It compiles and works like a charm in Visual C++ under Windows, but generates a fatal compilation error on clang under Mac OS X.</p>
  
  <p>I want to know why it happens and what is the right way to get this working.</p>
  
  <p>Example code:</p>
  
  <pre><code>// 
  // Clang build cmdline:
  // $ clang++ ./set.cpp -Wall -Werror -Wfatal-errors -std=c++11 -stdlib=libc++ -o set.out
  // 
  
  #include &lt;iostream&gt;
  #include &lt;unordered_set&gt;
  
  struct Point {
      int x, y;
      Point(int x = 0, int y = 0) {
          this-&gt;x = x;
          this-&gt;y = y;
      }
      bool operator==(Point const&amp; p) const {
          return this-&gt;x == p.x &amp;&amp; this-&gt;y == p.y;
      }
      operator std::size_t () const {
          return std::hash&lt;int&gt;()(x) ^ std::hash&lt;int&gt;()(y);
      }
  };
  
  typedef std::unordered_set&lt;Point&gt; points_set_t;
  
  int main() {
      Point point1(1, 5);
      Point point2(1, 1);
      Point point3(1, 5);
      points_set_t points;
      points.insert(point1);
      points.insert(point2);
      points.insert(point3);
      for (points_set_t::const_iterator it = points.begin(); it != points.end(); it++) {
          std::cout &lt;&lt; it-&gt;x &lt;&lt; ":" &lt;&lt; it-&gt;y &lt;&lt; std::endl;
      }
  }
  </code></pre>
  
  <p>Clang output:</p>
  
  <pre><code>In file included from ./set.cpp:6:
  In file included from /usr/bin/../lib/c++/v1/iostream:38:
  In file included from /usr/bin/../lib/c++/v1/ios:216:
  In file included from /usr/bin/../lib/c++/v1/__locale:15:
  In file included from /usr/bin/../lib/c++/v1/string:434:
  In file included from /usr/bin/../lib/c++/v1/algorithm:591:
  /usr/bin/../lib/c++/v1/type_traits:748:38: fatal error: implicit instantiation of undefined template 'std::__1::hash&lt;Point&gt;'
      : public integral_constant&lt;bool, __is_empty(_Tp)&gt; {};
                                       ^
  /usr/bin/../lib/c++/v1/memory:1948:40: note: in instantiation of template class 'std::__1::is_empty&lt;std::__1::hash&lt;Point&gt; &gt;'
        requested here
                                  bool = is_empty&lt;_T2&gt;::value
                                         ^
  /usr/bin/../lib/c++/v1/memory:1970:44: note: in instantiation of default argument for '__libcpp_compressed_pair_switch&lt;unsigned
        long, std::__1::hash&lt;Point&gt;, false, false&gt;' required here
  template &lt;class _T1, class _T2, unsigned = __libcpp_compressed_pair_switch&lt;_T1, _T2&gt;::value&gt;
                                             ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  /usr/bin/../lib/c++/v1/memory:2354:15: note: in instantiation of default argument for '__libcpp_compressed_pair_imp&lt;unsigned long,
  
        std::__1::hash&lt;Point&gt; &gt;' required here
      : private __libcpp_compressed_pair_imp&lt;_T1, _T2&gt;
                ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  /usr/bin/../lib/c++/v1/__hash_table:527:55: note: in instantiation of template class 'std::__1::__compressed_pair&lt;unsigned long,
        std::__1::hash&lt;Point&gt; &gt;' requested here
      __compressed_pair&lt;size_type, hasher&gt;              __p2_;
                                                        ^
  /usr/bin/../lib/c++/v1/unordered_set:330:13: note: in instantiation of template class 'std::__1::__hash_table&lt;Point,
        std::__1::hash&lt;Point&gt;, std::__1::equal_to&lt;Point&gt;, std::__1::allocator&lt;Point&gt; &gt;' requested here
      __table __table_;
              ^
  ./set.cpp:28:18: note: in instantiation of template class 'std::__1::unordered_set&lt;Point, std::__1::hash&lt;Point&gt;,
        std::__1::equal_to&lt;Point&gt;, std::__1::allocator&lt;Point&gt; &gt;' requested here
      points_set_t points;
                   ^
  /usr/bin/../lib/c++/v1/memory:3076:29: note: template is declared here
  template &lt;class _Tp&gt; struct hash;
                              ^
  1 error generated.      
  </code></pre>
  
  <p><strong>UPD</strong> Working implementation using @mfontanini's suggestion: <a href="https://gist.github.com/vbo/6090142">https://gist.github.com/vbo/6090142</a>.</p>