title: glm::ivec2 as key in unordered map
body: <p>lately I am more a user of the Scala Programming Language than C++, And now I am frustrated in porting a very simple line of code</p>
  
  <pre><code>val map = new HashMap[Vec2i,Entity]
  </code></pre>
  
  <p>it simply refuses to compile in C++ with strange template errors. The equivalent of Vec2i in C++ is glm::ivec2, it is basicly a struct with two integers and some operators for math.</p>
  
  <p>this is how far i got:</p>
  
  <pre><code>#include &lt;iostream&gt;
  #include &lt;unordered_map&gt;
  #include &lt;glm/glm.hpp&gt;
  
  using namespace std;
  using namespace glm;
  
  struct KeyTraits {
  size_t operator()(const ivec2&amp; k) {
          return std::hash&lt;int&gt;()(k.x) ^ std::hash&lt;int&gt;()(k.y);
      }
  
  bool operator()(const ivec2&amp; a, const ivec2&amp; b) {
          return a.x == b.x &amp;&amp; a.y == b.y;
      }
  };
  
  typedef unordered_map&lt;ivec2,int,KeyTraits,KeyTraits&gt; MyMap;
  
  int main(int argc, char **argv)
  {
      MyMap map;
  
      map[ivec2(2,3)] = 7;
      map[ivec2(3,4)] = 8;
  
      for(auto it = map.begin(); it != map.end(); it++) {
          cout &lt;&lt; it-&gt;second &lt;&lt; endl;
      }
  }
  </code></pre>
  
  <p>The current compile error is:</p>
  
  <pre><code>In file included from /usr/include/c++/4.5/bits/hashtable.h:35:0,
               from /usr/include/c++/4.5/unordered_map:45,
               from /home/arne/codelite/LanguageTest/main.cpp:2:
  /usr/include/c++/4.5/bits/hashtable_policy.h: In member function ‘std::__detail::_Hash_code_base&lt;_Key, _Value, _ExtractKey, _Equal, _H1, _H2, std::__detail::_Default_ranged_hash, false&gt;::_Hash_code_type std::__detail::_Hash_code_base&lt;_Key, _Value, _ExtractKey, _Equal, _H1, _H2, std::__detail::_Default_ranged_hash, false&gt;::_M_hash_code(const _Key&amp;) const [with _Key = glm::detail::tvec2&lt;int&gt;, _Value = std::pair&lt;const glm::detail::tvec2&lt;int&gt;, int&gt;, _ExtractKey = std::_Select1st&lt;std::pair&lt;const glm::detail::tvec2&lt;int&gt;, int&gt; &gt;, _Equal = KeyTraits, _H1 = KeyTraits, _H2 = std::__detail::_Mod_range_hashing, std::__detail::_Hash_code_base&lt;_Key, _Value, _ExtractKey, _Equal, _H1, _H2, std::__detail::_Default_ranged_hash, false&gt;::_Hash_code_type = long unsigned int]’:
  /usr/include/c++/4.5/bits/hashtable_policy.h:535:74:   instantiated from ‘std::__detail::_Map_base&lt;_Key, _Pair, std::_Select1st&lt;_Pair&gt;, true, _Hashtable&gt;::mapped_type&amp; std::__detail::_Map_base&lt;_Key, _Pair, std::_Select1st&lt;_Pair&gt;, true, _Hashtable&gt;::operator[](const _Key&amp;) [with _Key = glm::detail::tvec2&lt;int&gt;, _Pair = std::pair&lt;const glm::detail::tvec2&lt;int&gt;, int&gt;, _Hashtable = std::_Hashtable&lt;glm::detail::tvec2&lt;int&gt;, std::pair&lt;const glm::detail::tvec2&lt;int&gt;, int&gt;, std::allocator&lt;std::pair&lt;const glm::detail::tvec2&lt;int&gt;, int&gt; &gt;, std::_Select1st&lt;std::pair&lt;const glm::detail::tvec2&lt;int&gt;, int&gt; &gt;, KeyTraits, KeyTraits, std::__detail::_Mod_range_hashing, std::__detail::_Default_ranged_hash, std::__detail::_Prime_rehash_policy, false, false, true&gt;, std::__detail::_Map_base&lt;_Key, _Pair, std::_Select1st&lt;_Pair&gt;, true, _Hashtable&gt;::mapped_type = int]’
  /home/arne/codelite/LanguageTest/main.cpp:24:16:   instantiated from here
  /usr/include/c++/4.5/bits/hashtable_policy.h:727:25: error: passing ‘const KeyTraits’ as ‘this’ argument of ‘size_t KeyTraits::operator()(const glm::core::type::ivec2&amp;)’ discards qualifiers
  /usr/include/c++/4.5/bits/hashtable_policy.h: In member function ‘bool std::__detail::_Hash_code_base&lt;_Key, _Value, _ExtractKey, _Equal, _H1, _H2, std::__detail::_Default_ranged_hash, false&gt;::_M_compare(const _Key&amp;, std::__detail::_Hash_code_base&lt;_Key, _Value, _ExtractKey, _Equal, _H1, _H2, std::__detail::_Default_ranged_hash, false&gt;::_Hash_code_type, std::__detail::_Hash_node&lt;_Value, false&gt;*) const [with _Key = glm::detail::tvec2&lt;int&gt;, _Value = std::pair&lt;const glm::detail::tvec2&lt;int&gt;, int&gt;, _ExtractKey = std::_Select1st&lt;std::pair&lt;const glm::detail::tvec2&lt;int&gt;, int&gt; &gt;, _Equal = KeyTraits, _H1 = KeyTraits, _H2 = std::__detail::_Mod_range_hashing, std::__detail::_Hash_code_base&lt;_Key, _Value, _ExtractKey, _Equal, _H1, _H2, std::__detail::_Default_ranged_hash, false&gt;::_Hash_code_type = long unsigned int]’:
  /usr/include/c++/4.5/bits/hashtable.h:879:2:   instantiated from ‘std::_Hashtable&lt;_Key, _Value, _Allocator, _ExtractKey, _Equal, _H1, _H2, _Hash, _RehashPolicy, __cache_hash_code, __constant_iterators, __unique_keys&gt;::_Node* std::_Hashtable&lt;_Key, _Value, _Allocator, _ExtractKey, _Equal, _H1, _H2, _Hash, _RehashPolicy, __cache_hash_code, __constant_iterators, __unique_keys&gt;::_M_find_node(std::_Hashtable&lt;_Key, _Value, _Allocator, _ExtractKey, _Equal, _H1, _H2, _Hash, _RehashPolicy, __cache_hash_code, __constant_iterators, __unique_keys&gt;::_Node*, const key_type&amp;, typename std::_Hashtable&lt;_Key, _Value, _Allocator, _ExtractKey, _Equal, _H1, _H2, _Hash, _RehashPolicy, __cache_hash_code, __constant_iterators, __unique_keys&gt;::_Hash_code_type) const [with _Key = glm::detail::tvec2&lt;int&gt;, _Value = std::pair&lt;const glm::detail::tvec2&lt;int&gt;, int&gt;, _Allocator = std::allocator&lt;std::pair&lt;const glm::detail::tvec2&lt;int&gt;, int&gt; &gt;, _ExtractKey = std::_Select1st&lt;std::pair&lt;const glm::detail::tvec2&lt;int&gt;, int&gt; &gt;, _Equal = KeyTraits, _H1 = KeyTraits, _H2 = std::__detail::_Mod_range_hashing, _Hash = std::__detail::_Default_ranged_hash, _RehashPolicy = std::__detail::_Prime_rehash_policy, bool __cache_hash_code = false, bool __constant_iterators = false, bool __unique_keys = true, std::_Hashtable&lt;_Key, _Value, _Allocator, _ExtractKey, _Equal, _H1, _H2, _Hash, _RehashPolicy, __cache_hash_code, __constant_iterators, __unique_keys&gt;::_Node = std::__detail::_Hash_node&lt;std::pair&lt;const glm::detail::tvec2&lt;int&gt;, int&gt;, false&gt;, key_type = glm::detail::tvec2&lt;int&gt;, typename std::_Hashtable&lt;_Key, _Value, _Allocator, _ExtractKey, _Equal, _H1, _H2, _Hash, _RehashPolicy, __cache_hash_code, __constant_iterators, __unique_keys&gt;::_Hash_code_type = long unsigned int]’
  /usr/include/c++/4.5/bits/hashtable_policy.h:540:53:   instantiated from ‘std::__detail::_Map_base&lt;_Key, _Pair, std::_Select1st&lt;_Pair&gt;, true, _Hashtable&gt;::mapped_type&amp; std::__detail::_Map_base&lt;_Key, _Pair, std::_Select1st&lt;_Pair&gt;, true, _Hashtable&gt;::operator[](const _Key&amp;) [with _Key = glm::detail::tvec2&lt;int&gt;, _Pair = std::pair&lt;const glm::detail::tvec2&lt;int&gt;, int&gt;, _Hashtable = std::_Hashtable&lt;glm::detail::tvec2&lt;int&gt;, std::pair&lt;const glm::detail::tvec2&lt;int&gt;, int&gt;, std::allocator&lt;std::pair&lt;const glm::detail::tvec2&lt;int&gt;, int&gt; &gt;, std::_Select1st&lt;std::pair&lt;const glm::detail::tvec2&lt;int&gt;, int&gt; &gt;, KeyTraits, KeyTraits, std::__detail::_Mod_range_hashing, std::__detail::_Default_ranged_hash, std::__detail::_Prime_rehash_policy, false, false, true&gt;, std::__detail::_Map_base&lt;_Key, _Pair, std::_Select1st&lt;_Pair&gt;, true, _Hashtable&gt;::mapped_type = int]’
  /home/arne/codelite/LanguageTest/main.cpp:24:16:   instantiated from here
  /usr/include/c++/4.5/bits/hashtable_policy.h:742:48: error: passing ‘const KeyTraits’ as ‘this’ argument of ‘bool KeyTraits::operator()(const glm::core::type::ivec2&amp;, const glm::core::type::ivec2&amp;)’ discards qualifiers
  /usr/include/c++/4.5/bits/hashtable_policy.h: In member function ‘size_t std::__detail::_Hash_code_base&lt;_Key, _Value, _ExtractKey, _Equal, _H1, _H2, std::__detail::_Default_ranged_hash, false&gt;::_M_bucket_index(const std::__detail::_Hash_node&lt;_Value, false&gt;*, size_t) const [with _Key = glm::detail::tvec2&lt;int&gt;, _Value = std::pair&lt;const glm::detail::tvec2&lt;int&gt;, int&gt;, _ExtractKey = std::_Select1st&lt;std::pair&lt;const glm::detail::tvec2&lt;int&gt;, int&gt; &gt;, _Equal = KeyTraits, _H1 = KeyTraits, _H2 = std::__detail::_Mod_range_hashing, size_t = long unsigned int]’:
  /usr/include/c++/4.5/bits/hashtable.h:1170:59:   instantiated from ‘void std::_Hashtable&lt;_Key, _Value, _Allocator, _ExtractKey, _Equal, _H1, _H2, _Hash, _RehashPolicy, __cache_hash_code, __constant_iterators, __unique_keys&gt;::_M_rehash(std::_Hashtable::size_type) [with _Key = glm::detail::tvec2&lt;int&gt;, _Value = std::pair&lt;const glm::detail::tvec2&lt;int&gt;, int&gt;, _Allocator = std::allocator&lt;std::pair&lt;const glm::detail::tvec2&lt;int&gt;, int&gt; &gt;, _ExtractKey = std::_Select1st&lt;std::pair&lt;const glm::detail::tvec2&lt;int&gt;, int&gt; &gt;, _Equal = KeyTraits, _H1 = KeyTraits, _H2 = std::__detail::_Mod_range_hashing, _Hash = std::__detail::_Default_ranged_hash, _RehashPolicy = std::__detail::_Prime_rehash_policy, bool __cache_hash_code = false, bool __constant_iterators = false, bool __unique_keys = true, std::_Hashtable::size_type = long unsigned int]’
  /usr/include/c++/4.5/bits/hashtable.h:911:8:   instantiated from ‘std::_Hashtable&lt;_Key, _Value, _Allocator, _ExtractKey, _Equal, _H1, _H2, _Hash, _RehashPolicy, __cache_hash_code, __constant_iterators, __unique_keys&gt;::iterator std::_Hashtable&lt;_Key, _Value, _Allocator, _ExtractKey, _Equal, _H1, _H2, _Hash, _RehashPolicy, __cache_hash_code, __constant_iterators, __unique_keys&gt;::_M_insert_bucket(const value_type&amp;, std::_Hashtable::size_type, typename std::_Hashtable&lt;_Key, _Value, _Allocator, _ExtractKey, _Equal, _H1, _H2, _Hash, _RehashPolicy, __cache_hash_code, __constant_iterators, __unique_keys&gt;::_Hash_code_type) [with _Key = glm::detail::tvec2&lt;int&gt;, _Value = std::pair&lt;const glm::detail::tvec2&lt;int&gt;, int&gt;, _Allocator = std::allocator&lt;std::pair&lt;const glm::detail::tvec2&lt;int&gt;, int&gt; &gt;, _ExtractKey = std::_Select1st&lt;std::pair&lt;const glm::detail::tvec2&lt;int&gt;, int&gt; &gt;, _Equal = KeyTraits, _H1 = KeyTraits, _H2 = std::__detail::_Mod_range_hashing, _Hash = std::__detail::_Default_ranged_hash, _RehashPolicy = std::__detail::_Prime_rehash_policy, bool __cache_hash_code = false, bool __constant_iterators = false, bool __unique_keys = true, std::_Hashtable&lt;_Key, _Value, _Allocator, _ExtractKey, _Equal, _H1, _H2, _Hash, _RehashPolicy, __cache_hash_code, __constant_iterators, __unique_keys&gt;::iterator = std::__detail::_Hashtable_iterator&lt;std::pair&lt;const glm::detail::tvec2&lt;int&gt;, int&gt;, false, false&gt;, value_type = std::pair&lt;const glm::detail::tvec2&lt;int&gt;, int&gt;, std::_Hashtable::size_type = long unsigned int, typename std::_Hashtable&lt;_Key, _Value, _Allocator, _ExtractKey, _Equal, _H1, _H2, _Hash, _RehashPolicy, __cache_hash_code, __constant_iterators, __unique_keys&gt;::_Hash_code_type = long unsigned int]’
  /usr/include/c++/4.5/bits/hashtable_policy.h:543:24:   instantiated from ‘std::__detail::_Map_base&lt;_Key, _Pair, std::_Select1st&lt;_Pair&gt;, true, _Hashtable&gt;::mapped_type&amp; std::__detail::_Map_base&lt;_Key, _Pair, std::_Select1st&lt;_Pair&gt;, true, _Hashtable&gt;::operator[](const _Key&amp;) [with _Key = glm::detail::tvec2&lt;int&gt;, _Pair = std::pair&lt;const glm::detail::tvec2&lt;int&gt;, int&gt;, _Hashtable = std::_Hashtable&lt;glm::detail::tvec2&lt;int&gt;, std::pair&lt;const glm::detail::tvec2&lt;int&gt;, int&gt;, std::allocator&lt;std::pair&lt;const glm::detail::tvec2&lt;int&gt;, int&gt; &gt;, std::_Select1st&lt;std::pair&lt;const glm::detail::tvec2&lt;int&gt;, int&gt; &gt;, KeyTraits, KeyTraits, std::__detail::_Mod_range_hashing, std::__detail::_Default_ranged_hash, std::__detail::_Prime_rehash_policy, false, false, true&gt;, std::__detail::_Map_base&lt;_Key, _Pair, std::_Select1st&lt;_Pair&gt;, true, _Hashtable&gt;::mapped_type = int]’
  /home/arne/codelite/LanguageTest/main.cpp:24:16:   instantiated from here
  /usr/include/c++/4.5/bits/hashtable_policy.h:737:55: error: passing ‘const KeyTraits’ as ‘this’ argument of ‘size_t KeyTraits::operator()(const glm::core::type::ivec2&amp;)’ discards qualifiers
  </code></pre>