title: How can I use a custom type for keys in a boost::unordered_map?
body: <p>I'm using Boost's implementation of a hash map in a project right now, and I'm trying to implement a custom type for keys. I have four unsigned integers which I'd like to combine into a single 128-bit datatype to use as a key.</p>
  
  <p>I've created a struct with a 32-bit integer array of four elements, which serves as my storage. To be honest, I'm not sure how Boost's hash map works, so I'm not sure what I'm doing here, but I followed the Boost documentation (<a href="http://www.boost.org/doc/libs/1_37_0/doc/html/hash/custom.html" rel="nofollow noreferrer">http://www.boost.org/doc/libs/1_37_0/doc/html/hash/custom.html</a>) for extending boost::hash, and I created a hash function, as well as a custom comparison operator.</p>
  
  <p>I have this custom type defined in a header. This is my code:</p>
  
  <pre><code>#ifndef INT128_H_
  #define INT128_H_
  
  // Custom 128-bit datatype used to store and compare the results of a weakened hash operation.
  struct int128
  {
      unsigned int storage[4];
  
      /* Assignment operation that takes a 32-bit integer array of four elements.
      This makes assignment of values a shorter and less painful operation. */
      void operator=(const unsigned int input[4])
      {
          for(int i = 0; i &lt; 4; i++)
              storage[i] = input[i];
      }
  };
  
  bool operator==(int128 const &amp;o1, int128 const &amp;o2)
  {
      if(o1.storage[0] == o2.storage[0] &amp;&amp; o1.storage[1] == o2.storage[1] &amp;&amp; 
         o1.storage[2] == o2.storage[2] &amp;&amp; o1.storage[3] == o2.storage[3])
          return true;
  
      return false;
  }
  
  // Hash function to make int128 work with boost::hash.
  std::size_t hash_value(int128 const &amp;input)
  {
      boost::hash&lt;unsigned long long&gt; hasher;
      unsigned long long hashVal = input.storage[0];
  
      for(int i = 1; i &lt; 3; i++)
      {
          hashVal *= 37;
          hashVal += input.storage[1];
      }
  
      return hasher(hashVal);
  }
  
  #endif
  </code></pre>
  
  <p>Now when I actually use this type in Boost's unordered map, my code compiles, but fails to link. The linker claims that I have a symbol defined multiple times in several object files. I'd really like to get my 128-bit type working with this map. Any tips on what I'm screwing up, or a better way to do this?</p>