传递具有依赖嵌套参数类型的模板模板参数时出错
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, "???");
ADDED:此外,编译器无法推断等专业化中的类型
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...
精确匹配,只需要与它们兼容即可。
活生生的例子。
相关文章:
- 为 NewObjectA() 函数创建 jvalues 的参数数组时出错 - JNI Invocation API
- 将成员函数作为构造函数参数调用时出错 "Variable is not a type name"
- 使用一个参数的模板函数时出错(适用于 2)
- 为什么在函数参数前面添加 const 会出错?
- 变量用作C中的函数参数后出错
- 将私有数据成员作为默认参数传递给该类的公共方法时出错
- 使用 cvThreshold 时报告参数时出错
- STL 容器在函数中作为模板参数,在调用中出错
- 使用模板模板参数时出错
- 方法的参数列表出错
- 将 std::bind 应用于带有参数 <boost::asio::ip::tcp::socket> 时出错?
- 使用模板函数传递模板参数时出错
- 在 c++ 中调用将字符串作为参数传递的函数时出错
- 在运算符中将联合作为参数传递时出错<<
- 在C 中使用Caffe;无法将Caffe ::求解参数仪发挥作用而不会出错
- 尝试使用浮点参数运行重载函数时出错
- 尝试将 C++11 代码转换为 C++03 时默认函数模板参数出错
- Lua c++ lib sethook:钩子函数参数出错
- 在 Unix 中编译 c++ 时嵌套模板参数出错
- uniform_real_distribution c++的最小/最大参数出错