【问题标题】:c++ variadic templates and template template arguments: error: type/value mismatch at argument 1 in template parameter listc ++可变参数模板和模板模板参数:错误:模板参数列表中参数1的类型/值不匹配
【发布时间】:2019-01-19 19:26:58
【问题描述】:

当我编译以下代码时,我得到 error: type/value mismatch at argument 1 in template parameter list...。编译器是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++ c++11 variadic-templates


    【解决方案1】:

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

    但是由于在标准中添加了P0522R0,规则不那么严格了,这段代码可以编译。

    到目前为止,我认为只有 GCC 实现了它,您需要指定标准:gcc -std=c++17see here

    【讨论】:

      猜你喜欢
      • 2023-04-02
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-11-22
      • 2016-12-01
      • 1970-01-01
      相关资源
      最近更新 更多