传递具有依赖嵌套参数类型的模板模板参数时出错
Error when passing template template parameter with dependent nested parameters types
为什么这个构造不起作用?
Visual Studio 显示错误 C3201:class 模板 '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...
,只需要与它们兼容。
为什么这个构造不起作用?
Visual Studio 显示错误 C3201:class 模板 '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...
,只需要与它们兼容。