检查后的防护参数包是否会导致程序格式错误? [英] Are checked guard parameter packs cause of ill-formed programs?

查看:56
本文介绍了检查后的防护参数包是否会导致程序格式错误?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

不止一次(甚至在SO上),我也看到过这样的代码:

More than once (even on SO) I've seen code like this:

template<typename U, typename... G, typename T = Traits<U>>
struct {
    static_assert(sizeof...(G) == 0, "!");
    // ...
};

或者这个:

template<typename T, typename... G, typename = std::enable_if_t<condition<T>>
void func(T &&t) {
    static_assert(sizeof...(G) == 0, "!");
    // ....
}

目的是通过执行以下操作来避免用户破坏游戏规则:

The intent was to avoid users break the rule of the game by doing something like this:

template<typename T, typename = std::enable_if_t<std::is_same<T, int>>
void func(T &&t) {
    // ....
}

// ...

func<int&, void>(my_int);

使用保护参数包,不能覆盖默认值.
另一方面,对大小的检查避免了无用参数对专业化的污染.

With the guard parameter pack, the defaulted value cannot be overridden.
On the other side, the check on the size avoids pollution of the specializations with useless parameters.

无论如何,由于 [temp.res/8] ,我们有那个:

Anyway, because of [temp.res/8], we have that:

该程序格式错误,如果满足以下条件,则无需进行诊断:
[...]
-可变参数模板的每个有效专业化都需要一个空的模板参数包,或者
[...]

The program is ill-formed, no diagnostic required, if:
[...]
- every valid specialization of a variadic template requires an empty template parameter pack, or
[...]

因此,包含上述摘录的程序是否格式错误?

Therefore, are the programs that contain the above mentioned snippets ill-formed or not?

推荐答案

技巧"导致程序格式错误,不需要诊断.

The "trick" results in an ill formed program, no diagnostic required.

该标准在您引用的部分中有明确说明.

The standard states it clearly in the section you quoted.

这篇关于检查后的防护参数包是否会导致程序格式错误?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆