title: No match for ‘operator<<’ (operand types are ‘std::ostream’ {aka ‘std::basic_ostream<char>’} and ‘const std::type_index’)
body: <p>Actually, I'm trying to use the visitor pattern with some templates.</p>
  <p>I want to parse my <code>unordered_map</code> which contains <code>type_index</code> and the <code>function</code> variable but I get a compilation error that I don't understand even after reading a lot of topics about it.</p>
  <blockquote>
  <p>error: no match for ‘operator&lt;&lt;’ (operand types are ‘std::ostream’ {aka ‘std::basic_ostream’} and ‘const std::type_index’)
  std::cout &lt;&lt; i.first &lt;&lt; i.second &lt;&lt; std::endl;</p>
  </blockquote>
  <p>Here is my loop which doesn't compile</p>
  <pre><code>for (auto i : functions) {
        std::cout &lt;&lt; i.first &lt;&lt; i.second &lt;&lt; std::endl;
  }
  </code></pre>
  <p>Here is my code snippet with my loop to parse and display what is inside the <code>unordered_map</code></p>
  <pre><code>template &lt;typename TReturn&gt; struct AnyVisitor {
    using typeInfoRef = std::reference_wrapper&lt;const std::type_info&gt;;
    using function = std::function&lt;TReturn(std::any &amp;)&gt;;
    std::unordered_map&lt;std::type_index, function&gt; functions;
  
    template &lt;typename TArg&gt; void accept(std::function&lt;TReturn(TArg &amp;)&gt; f) {
      functions.insert(std::make_pair(std::type_index(typeid(TArg)),
                                      function([&amp;f](std::any &amp;x) -&gt; TReturn {
                                        return f(std::any_cast&lt;TArg &amp;&gt;(x));
                                      })));
  
      for (auto i : functions) {
        std::cout &lt;&lt; i.first &lt;&lt; i.second &lt;&lt; std::endl;
      }
    }
  
    TReturn operator()(std::any &amp;x) {
      try {
        auto function = functions.at(std::type_index(x.type()));
  
        return function(x);
      } catch (...) {
        throw std::runtime_error(&quot;No visitor registered&quot;);
      }
    }
  };
  </code></pre>
  <p>If anyone has an idea of how to resolve it, I'll gladly take it! Thanks</p>