c++ variadic templates and template template arguments: error: type/value mismatch at argument 1 in template parameter list

c++ variadic templates and template template arguments: error: type/value mismatch at argument 1 in template parameter list

我在编译以下代码时收到 错误:type/value 模板参数列表中的参数 1 不匹配...。编译器是 gcc 版本 8.2.0.

template<typename>
struct t1 {};

template<typename ...>
struct t2 {};

template<typename, typename ...>
struct t3 {};

template<template<typename> class>
struct tt1 {};

template<template<typename ...> class>
struct tt2{};

template<template<typename, typename ...> class>
struct tt3{};


tt1<t2> _1; // error
tt1<t3> _2; // error
tt2<t1> _3;
tt2<t3> _4;
tt3<t1> _5;
tt3<t2> _6; // error

问题:为什么_3, _4, _5是允许的,而_1_2_6是错误的吗?

这些错误是 C++17 之前的错误。在C++17之前,模板模板实参/形参必须完全匹配。

但自从将 P0522R0 添加到标准后,规则就不那么严格了,并且此代码可以编译。

截至今天,我认为只有 GCC 实现了它,您需要指定标准:gcc -std=c++17 see here