1

I have the following template

template<class F>
struct A{
  template<int N>
  struct B{
    using type = int;
  };
};

I'd like to make a template alias, however:

//doesn't compile.
template<class F, int N >
using alias_A = typename A<F>::B<N>::type;

GCC:
question.cpp:12:36: error: expected ';' before '::' token
 using alias_A = typename A<F>::B<N>::type;
                                    ^
question.cpp:12:36: error: 'type' in namespace '::' does not name a type

When debugging I find:

//does compile
struct C{};
using alias_B = typename A<C>::B<0>::type;

Can somebody point out what I'm doing wrong? I feel I'm missing something obvious.

Polymer
  • 932
  • 10
  • 13
  • Late note: Clang gives a more helpful `error: use 'template' keyword to treat 'B' as a dependent template name` ([link](http://coliru.stacked-crooked.com/a/1c8d3c351c8c6724)) – gx_ Nov 30 '13 at 17:54

1 Answers1

6

You need to tell C++ that it the inner type B<N> is a template:

template<class F, int N >
using alias_A = typename A<F>::template B<N>::type;

In this case, the compiler parses what you've written as operator<, not as the opening brace for a template parameter.

This post gives an exhaustive rundown on when and why you need to do this.

Community
  • 1
  • 1
Yuushi
  • 22,789
  • 6
  • 58
  • 73