title: Can a friend of A<T> be also a friend of A<A<T>>?
body: <p>Consider the following code:</p>
  
  <pre><code>#include &lt;vector&gt;
  
  template&lt;typename T&gt; class Container;
  template&lt;typename T&gt; Container&lt;Container&lt;T&gt;&gt; make_double_container(const std::vector&lt;std::vector&lt;T&gt;&gt;&amp;);
  
  template&lt;typename T&gt;
  class Container {
      std::vector&lt;T&gt; v;
      friend Container&lt;Container&lt;T&gt;&gt; make_double_container&lt;T&gt;(const std::vector&lt;std::vector&lt;T&gt;&gt;&amp;);
  
  public:
      Container() {}
      explicit Container(std::vector&lt;T&gt; v) : v(v) {}
  };
  
  template&lt;typename T&gt;
  Container&lt;Container&lt;T&gt;&gt; make_double_container(const std::vector&lt;std::vector&lt;T&gt;&gt;&amp; v) {
      Container&lt;Container&lt;T&gt;&gt; c;
      for(const auto&amp; x : v) {
          c.v.push_back(Container&lt;T&gt;(x));
      }
      return c;
  }
  
  int main() {
      std::vector&lt;std::vector&lt;int&gt;&gt; v{{1,2,3},{4,5,6}};
      auto c = make_double_container(v);
      return 0;
  }
  </code></pre>
  
  <p>The compiler tells me that:</p>
  
  <pre><code>main.cpp: In instantiation of 'Container&lt;Container&lt;T&gt; &gt; make_double_container(const std::vector&lt;std::vector&lt;T&gt; &gt;&amp;) [with T = int]':
  main.cpp:27:37:   required from here
  main.cpp:8:20: error: 'std::vector&lt;Container&lt;int&gt;, std::allocator&lt;Container&lt;int&gt; &gt; &gt; Container&lt;Container&lt;int&gt; &gt;::v' is private
       std::vector&lt;T&gt; v;
                      ^
  main.cpp:20:9: error: within this context
           c.v.push_back(Container&lt;T&gt;(x));
  </code></pre>
  
  <p>Which I believe to be correct, because <code>make_double_container</code> is friend of <code>Container&lt;T&gt;</code>, but not of <code>Container&lt;Container&lt;T&gt;&gt;</code>. How can I make <code>make_double_container</code> work in this situation?</p>