C++ 如何在模板声明中删除重复的模板参数

C++ 如何在模板声明中删除重复的模板参数,c++,c++11,templates,using-declaration,C++,C++11,Templates,Using Declaration,为了简洁起见,我只想在显式实例化中为模板参数命名一次,但我遇到了一个编译器错误。我试图使用C++语法在类型别名、别名模板< /代码>中描述的CPRISTY语句。以下是我的示例代码: struct M {}; template< typename T1 > struct S {}; template< typename T2, typename T3 > struct N {}; // type alias used to hide a template param

为了简洁起见,我只想在显式实例化中为模板参数命名一次,但我遇到了一个编译器错误。我试图使用C++语法在类型别名、别名模板< /代码>中描述的CPRISTY语句。以下是我的示例代码:

struct M {};

template< typename T1 >
struct S {};

template< typename T2, typename T3 > 
struct N {};

// type alias used to hide a template parameter (from cppreference under 'Type alias, alias template')
//template< typename U1, typename U2 >
//using NN = N< U1, U2< U1 > >; // error: attempt at applying alias syntax: error C2947: expecting '>' to terminate template-argument-list, found '<'

int main()
{
  N< M, S< M > > nn1; // OK: explicit instantiation with full declaration, but would like to not have to use M twice
  // NN< M, S > nn2; // desired declaration, error: error C2947: expecting '>' to terminate template-argument-list, found '<'

  return 0;
}
struct M{};
模板
结构S{};
模板
结构N{};
//用于隐藏模板参数的类型别名(来自“类型别名,别名模板”下的cppreference)
//模板

//使用NN=N;//错误:尝试应用别名语法:错误C2947:预期'>'终止模板参数列表,发现'>'终止模板参数列表,发现'
typename U2
是一个typename,而不是模板。因此,
U2
没有意义。将其替换为模板参数:

template< typename U1, template<typename> class U2 >
using NN = N< U1, U2< U1 > >;
template
使用NN=N

类型名U2
是一个类型名,而不是模板。因此,
U2
没有意义。将其替换为模板参数:

template< typename U1, template<typename> class U2 >
using NN = N< U1, U2< U1 > >;
template
使用NN=N