title: C++: Error outputting a custom hash key value from unordered_map to std::cout
body: <p>I am trying to build an <code>std::unordered_map</code> with a custom type as a key. The custom type is a simple <code>std::vector&lt;double&gt;</code>. The idea is that it will function as a convenient container for 2D points on a grid. Everything is working correctly except for outputting the hashed key. Here is a sample I put together to illustrate the idea:</p>
  
  <pre><code>#include &lt;iostream&gt;
  #include &lt;vector&gt;
  #include &lt;unordered_map&gt;
  #include &lt;boost/functional/hash.hpp&gt;
  #include &lt;chrono&gt;
  
  namespace std
  {
      template&lt;typename Container&gt;
      struct hash {
              std::size_t operator()(Container const&amp; v) const
              {
                  return boost::hash_range(v.begin(), v.end());
              }
      };
  }
  
  int main()
  {
  
      std::unordered_map&lt;std::vector&lt;double&gt;, double&gt; test;
  
      unsigned long t = (unsigned long) std::chrono::system_clock::now().time_since_epoch().count();
      std::srand(t);
      for (uint i = 0; i &lt; 100 ; ++i)
      {
          double d1 = i/200.0;
          double d2 = i/200.0;
          std::vector&lt;double&gt; v({d1, d2});
          test[v] = d1;
      }
  
      std::cout &lt;&lt; "Size:" &lt;&lt; test.size() &lt;&lt; std::endl;
      for (const auto&amp; it : test )
      {
          std::cout &lt;&lt; it.first &lt;&lt; ":" &lt;&lt; it.second &lt;&lt; std::endl;
      }
  
      return 0;
  }
  </code></pre>
  
  <p>The hash specialisation template is courtesy of another SO thread. The trouble is that g++ spits out the following error when I try to compile the above:</p>
  
  <pre><code>cannot bind 'std::ostream {aka std::basic_ostream&lt;char&gt;}' lvalue to 'std::basic_ostream&lt;char&gt;&amp;&amp;'
     std::cout &lt;&lt; it.first &lt;&lt; ":" &lt;&lt; it.second &lt;&lt; std::endl;
                     ^
  </code></pre>
  
  <p>It is obvious that it stumbles on <code>it.first</code>. The code compiles and runs correctly if I remove <code>it.first</code>. I understand that the output will <em>not</em> be a vector of doubles. I did look around SO for quite a while, but I couldn't find a definitive answer on how to <code>std::cout</code> the hash value from an unordered map with a custom key type. Any feedback will be highly appreciated.</p>
  
  <p>Thank you in advance!</p>
  
  <p>Edit:</p>
  
  <p>Thank you everyone for your input. This was my first encounter with non-primitive types as hashed keys, so I had the wrong idea about how the key/value pairs were stored (I assumed that the hashed value is the key, whereas in fact it is the actual custom type).</p>