要求模板变量为空的语法是什么?

发布于 2025-01-16 10:58:09 字数 172 浏览 2 评论 0原文

有没有办法编写 requiresrequire 表达式来理解模板参数是否为空?

我相信将 std::is_void_v的值作为模板的参数是合法的。但是,我无法制定语法来检查需求中的这一点 - 是真还是假。

是否可以?该怎么做呢?

Is there a way to write a requires requires expression to apprehend that a template parameter is void?

I believe it is legal to make the value of std::is_void_v<ParmThree> a parameter of the template. However, I cannot formulate a syntax to check this in a requirement - for being either true or false.

Is it possible? How would it be done?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

尴尬癌患者 2025-01-23 10:58:09

requires 有效,因为嵌套的(第二个)requires 返回一个 bool。

由于您已经有了一个 bool,您只需执行 requires std::is_void_v 即可:

template <typename T>
requires std::is_void_v<T>
struct A {};

requires requires works because the nested (second) requires returns a bool.

Since you already have a bool, you can just do requires std::is_void_v<T>:

template <typename T>
requires std::is_void_v<T>
struct A {};
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文