Home > Software engineering >  How to use a template template argument from a member templated type alias of a struct
How to use a template template argument from a member templated type alias of a struct

Time:09-30

I'm trying to use a template template argument coming from a member type alias of a struct, but I can't find the right syntax:

struct A
{
   template <typename T>
   using type = int;
};

template <template <typename> class C>
struct B
{
   // ...
};

B<typename A::type> b; // Does not compile: error: template argument for template template parameter must be a class template or type alias template
B<typename A::template type> b; // Does not compile: error: expected an identifier or template-id after '::'
B<typename A::template <typename> type> b; // Does not compile
B<typename A::template <typename> class type> b; // Does not compile

CodePudding user response:

A::type is a template, not a typename.

B<A::template type> b1;  // OK
B<A::type> b2;           // OK
  • Related