相关疑难解决方法(0)

使用外部类的可变参数模板中的args部分特化可变参数模板内部类是否合法

考虑一下代码:

#include <iostream>

template <class... Ts>
struct outer {
   template <class... ITs>
   struct inner {
      static constexpr bool value = false;
   };

   template <class... ITs>
   struct inner<Ts..., ITs...> {   
      static constexpr bool value = true;
   };
};

int main() {
   std::cout << outer<int, float, double>::inner<int, float, double, int>::value << std::endl;
}
Run Code Online (Sandbox Code Playgroud)

代码用clang ++编译但不用g ++编译产生错误:

temp3.cc:11:11:错误:参数包参数'Ts ...'必须位于模板参数列表的末尾

struct inner<Ts..., ITs...> {
       ^
Run Code Online (Sandbox Code Playgroud)

正如我已经在这里建立的那样,内部阶级的部分专业化应该是合法的.

编辑: 为了完整性,值得补充一点,上面代码的clang警告他可能在推导IT参数时遇到问题,但没有任何问题......

c++ templates template-specialization variadic-templates c++11

13
推荐指数
1
解决办法
321
查看次数