title: Overload operator<< for nested class template
body: <p>I have the following setup:</p>
  
  <pre><code>template&lt; class T &gt;
  struct Foo {
  
    struct Bar {
      Bar ( const T &amp;t ) : otherT_( t ) {}
  
      T otherT_;
    };
  
    Foo ( const T &amp;t ) : myT_( t ) {}
  
    T myT_;
  };
  </code></pre>
  
  <p>Now, I want to make instances of <code>Foo&lt; T &gt;::Bar</code> streamable to std::cout and friends. I tried this:</p>
  
  <pre><code>template&lt; class T &gt;
  std::ostream&amp; operator&lt;&lt; ( std::ostream &amp;os, 
                             const typename Foo&lt; T &gt;::Bar &amp;bar ) {
    os &lt;&lt; "&lt;bar: " &lt;&lt; bar.otherT_ &lt;&lt; "&gt;";
    return os;
  }
  </code></pre>
  
  <p>But the following code does not compile:</p>
  
  <pre><code>  Foo&lt; int &gt; foo( 5 );
    Foo&lt; int &gt;::Bar bar( 7 );
  
    std::cout &lt;&lt; bar &lt;&lt; std::endl;
  </code></pre>
  
  <p>I guess that the compiler is not able to deduce the type <code>T</code> or something. Is there a way to make such instances of the nested class behave well with <code>operator&lt;&lt;</code>?</p>
  
  <p>Thank you!</p>