title: unordered_set storing elements as pointers
body: <p>To narrow it down: I'm currently using <a href="http://www.boost.org/doc/libs/1_49_0/doc/html/unordered.html" rel="nofollow">Boost.Unordered</a>. I see two possible solutions:</p>
  
  <ol>
  <li><p>Define my own <a href="http://www.boost.org/doc/libs/1_49_0/doc/html/unordered/hash_equality.html" rel="nofollow">Equality Predicates and Hash Functions</a> and to utilize templates (maybe <code>is_pointer</code>) to distinct between pointers and instances;</p></li>
  <li><p>Simply to extend <code>boost::hash</code> by providing <code>hash_value(Type* const&amp; x)</code> as for hashing; and add <code>==</code> operator overload as free function with <code>(Type* const&amp; x, Type* const&amp; y)</code> parameters as for equality checking.</p></li>
  </ol>
  
  <p>I'm not sure whether both variations are actually possible, since I didn't test them. I would like to find out you handle this problem. Implementations are welcome :)</p>
  
  <p><strong>EDIT 1:</strong>
  What about this?</p>
  
  <pre><code>template&lt;class T&gt;
  struct Equals: std::binary_function&lt;T, T, bool&gt; {
      bool operator()(T const&amp; left, T const&amp; right) const {
          return left == right;
      }
  };
  
  template&lt;class T&gt;
  struct Equals&lt;T*&gt; : std::binary_function&lt;T*, T*, bool&gt; {
      bool operator()(T* const&amp; left, T* const&amp; right) const {
          return *left == *right;
      }
  };
  </code></pre>
  
  <p><strong>EDIT 2:</strong></p>
  
  <p>I've just defined:</p>
  
  <pre><code>friend std::size_t hash_value(Base const&amp; base) {
      boost::hash&lt;std::string&gt; hash;
  
      return hash(base.string_);
  }
  
  friend std::size_t hash_value(Base* const&amp; base) {
      return hash_value(*base);
  }
  </code></pre>
  
  <p>And then:</p>
  
  <pre><code>Derived d1("x");
  Derived d2("x");
  
  unordered_set&lt;Base*&gt; set;
  
  set.insert(&amp;d1);
  
  assert(set.find(&amp;d2) == end());
  </code></pre>
  
  <p>Debugger says that <code>friend std::size_t hash_value(Base* const&amp; base)</code> is never called (GCC 4.7). Why is that?</p>
  
  <p><strong>EDIT 3:</strong>
  I found out that <code>template &lt;class T&gt; std::size_t hash_value(T* const&amp; v)</code> in <code>boost/functional/hash.hpp</code> on line #215 (Boost 1.49) is Boost's specialization for pointers and it simply masks your custom implementation of <code>hash_value</code> such as mine in <strong>EDIT 2</strong>. 
  Therefore, it seems like the only way here is to create a custom Hash Functor.</p>