title: Templated struct should contain subtype, but compiler says it doesn't
body: <p>I am trying to play around with C++ metaprogramming and everything was going fairly well, except when I try to compile this reproducer:</p>
  
  <pre><code>struct _0 {
    template&lt;typename F, typename X&gt;
    using apply = X;
  };
  
  struct Z {
    template&lt;typename F&gt;
    struct impl {
      struct C {
        template&lt;typename X&gt;
        struct closure {
          template&lt;typename V&gt;
          struct impl {
            // Broken out to help with debugging
            using XX = typename X::template apply&lt;X&gt;;
            using XXV = typename XX::template apply&lt;V&gt;;
          };
          template&lt;typename V&gt;
          using apply = typename impl&lt;V&gt;::XXV;
        };
        template&lt;typename X&gt;
        using apply = typename F::template apply&lt;closure&lt;X&gt;&gt;;
      };
      using exec = typename C::template apply&lt;C&gt;;
    };
    template&lt;typename F&gt;
    using apply = typename impl&lt;F&gt;::exec;
  };
  
  struct True {
    template&lt;typename Consequent, typename Alternative&gt;
    using apply = Consequent;
  };
  
  struct False {
    template&lt;typename Consequent, typename Alternative&gt;
    using apply = Alternative;
  };
  
  struct zero {
    struct constantly_false {
      template&lt;typename&gt;
      using apply = False;
    };
  
    template&lt;typename N&gt;
    using apply = typename N::template apply&lt;constantly_false, True&gt;;
  };
  
  struct mintest {
    template&lt;typename F&gt;
    struct closure {
      template&lt;typename N&gt;
      using apply =
        typename zero::apply&lt;N&gt;::template apply&lt;
        _0, typename F::template apply&lt;_0&gt;&gt;;
    };
    template&lt;typename F&gt;
    using apply = closure&lt;F&gt;;
  };
  using test = Z::apply&lt;mintest&gt;;
  
  using F = test::apply&lt;_0&gt;;
  
  int main() {
    return 0;
  };
  </code></pre>
  
  <p>I end up getting the errors:</p>
  
  <pre><code>reproducer.cc: In instantiation of ‘struct Z::impl&lt;mintest&gt;::C::closure&lt;Z::impl&lt;mintest&gt;::C&gt;::impl&lt;_0&gt;’:
  reproducer.cc:19:44:   required by substitution of ‘template&lt;class F&gt; template&lt;class X&gt; template&lt;class V&gt; using apply = typename Z::impl&lt;F&gt;::C::closure&lt;X&gt;::impl::XXV [with V = _0; X = Z::impl&lt;mintest&gt;::C; F = mintest]’
  reproducer.cc:56:42:   required from ‘struct mintest::closure&lt;Z::impl&lt;mintest&gt;::C::closure&lt;Z::impl&lt;mintest&gt;::C&gt; &gt;’
  reproducer.cc:63:15:   required from here
  reproducer.cc:16:53: error: no class template named ‘apply’ in ‘using XX = Z::impl&lt;mintest&gt;::C::apply&lt;Z::impl&lt;mintest&gt;::C&gt; {aka struct mintest::closure&lt;Z::impl&lt;mintest&gt;::C::closure&lt;Z::impl&lt;mintest&gt;::C&gt; &gt;}’
             using XXV = typename XX::template apply&lt;V&gt;;
  </code></pre>
  
  <p>Which make no sense to me. There are no specializations of mintest::closure so every instantiation should, I'd think, have apply in it. I tried with Clang and got the same error, which was my clue that there was just something i don't understand.</p>
  
  <p>Thank you.</p>