title: Making a hash table of iterators in C++
body: <p>I'm trying to accelerate a specific linked-list operation by hashing some of the node pointers. This is the code I'm using:</p>
  
  <pre><code>unordered_set&lt; typename list&lt; int &gt;::iterator &gt; myhashset;
  </code></pre>
  
  <p>In Visual Studio 2012, I get an "error C2338: The C++ Standard doesn't provide a hash for this type", since the compiler doesn't know how to hash iterators. Therefore, I need to implement my own hash function for list iterators like so:</p>
  
  <pre><code>struct X{int i,j,k;};
  
  struct hash_X{
    size_t operator()(const X &amp;x) const{
      return hash&lt;int&gt;()(x.i) ^ hash&lt;int&gt;()(x.j) ^ hash&lt;int&gt;()(x.k);
    }
  };
  </code></pre>
  
  <p>(<a href="https://en.wikipedia.org/wiki/Unordered_associative_containers_%28C++%29#Custom_hash_functions" rel="noreferrer">wikipedia reference</a>)</p>
  
  <p>I'm having trouble figuring out what members of the iterator guarantee uniqueness (and, therefore, the members that I want to hash). Another concern is that those members may be private.</p>
  
  <p>One solution that comes to mind is re-implementing  and list::iterator, but that seems like a hack and introduces more code to maintain.</p>