C 是否允许在变异模板参数之后进行普通参数
Does C++ allow normal parameters after variadic template parameters?
根据cppreference,以下代码是合法的:
lock_guard( MutexTypes&... m, std::adopt_lock_t t );
但是,以下代码无法使用Clang 3.8(-std = C 1Z)编译:
template<typename... Args>
void f(Args&&..., bool)
{}
int main()
{
f(1, 2, 3, true); // error! see below for details.
}
1>main.cpp(59,2): error : no matching function for call to 'f' 1> f(1, 2, 3, true); 1> ^ 1> main.cpp(54,6) : note: candidate function not viable: requires 1 argument, but 4 were provided 1> void f(Args&&..., bool) 1> ^ 1> 1 error generated.
C 是否允许在变化参数后允许普通参数?
您代码中的函数声明是有效的,但是 dectuction 对此类函数模板不正常。请注意,以下代码构成良好,并实例化专业void f(int, int, int, bool)
:
template<typename... Args>
void f(Args&&..., bool) {}
int main() {
f<int, int, int>(1, 2, 3, true);
}
请注意,在C 17中,MutexTypes...
是类本身的模板参数:
template <class... MutexTypes> class lock_guard;
因此,它们是已知的,不需要推导。请注意,带有adopt_lock_t
的构造函数不能用于C 17类模板参数扣除,因为adopt_lock_t
参数发生在参数包之后。如果委员会在C 11中有先见之明,他们将在开始时就将adopt_lock_t
的论点提出来,而不是在最后,但是现在为时已晚。
相关文章:
- 如何反转整数参数包
- 为什么在popback()操作之后,它仍然打印完整的矢量
- 使用C++库在Android项目中修改gradle中的cmake参数,用于插入指令的测试
- 如何使用默认参数等选择模板专业化
- 模板参数替换失败,并且未完成隐式转换
- 具有默认模板参数的多态类的模板推导失败
- lambda参数转换为constexpr技巧,然后获取带链接的数组
- 构造函数参数列表之后的结肠符号
- C 是否允许在变异模板参数之后进行普通参数
- 在计算后,在基类之后调用参数化构造函数
- Cocos2dx.如何在动画序列之后设置回调(传递参数)
- 默认参数之后的可变参数格式是否正确
- 忽略了 NULL 之后的 std::cout 中的参数
- 显式指定位于模板参数包之后的默认模板参数
- 为什么在C++11中的类型参数包之后不允许使用整数值参数包
- 为什么只有一个参数值的函数之后必须为每个参数指定默认值?
- 这是更有效的Qt:构造函数与参数或默认构造函数与setter之后
- 这个指针和所有参数在调用之后都是空的(但在调用之前是ok的)
- 参数之前的常量与函数名称 C++ 之后的常量
- 检查在模板第一个参数之后声明的函数是否为 NULL(传递向量和数组)