[英]Error when passing template template parameter with dependent nested parameters types
为什么这个结构不起作用?
Visual Studio 显示错误 C3201:类模板“AA”的模板参数列表与模板参数“C”的模板参数列表不匹配。 但在这两种情况下它似乎都是<int, char, bool>
。
template<int I, char C, bool B>
struct AA
{
static const int i = I;
static const char c = C;
static const bool b = B;
};
template<typename... T>
struct outer
{
template <template<T... > typename C>
struct inner
{
template<T... X>
using type = C<X...>;
};
};
static_assert(outer<int, char, bool>::inner<AA>::type<5, 'a', true>::i == 5, "???");
添加:此外,编译器无法推断像这样的专业化类型
template<class T, template<T> class C, T X>
struct A<C<X>> { ... };
标准是否禁止此类技巧,还是仅仅是编译器限制?
我怀疑这是允许的,这只是编译器搞砸了。 当我尝试使用它来获得解决方法时,我遇到了很多内部编译器错误; 这通常表明它没有被故意拒绝,而且错误消息毫无意义。
在c++20 中,我可以生成此解决方法。
template<int I, char C, bool B>
struct AA
{
static const int i = I;
static const char c = C;
static const bool b = B;
};
template<template<auto... > typename C, typename... Ts>
struct outer_base
{
struct inner
{
template<Ts... X>
using type = C<X...>;
};
};
template<typename... Ts>
struct outer
{
template <template<auto... > typename C>
using inner = typename outer_base<C, Ts...>::inner;
};
static_assert(outer<int, char, bool>::inner<AA>::type<5, 'a', true>::i == 5, "???");
这比您可能喜欢的要少一些,因为它不需要C
来匹配类型Ts...
确切地说,只需与它们兼容即可。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.