gpt4 book ai didi

c++ - constexpr 和函数体 = 删除 : what's the purpose?

转载 作者:搜寻专家 更新时间:2023-10-31 00:56:16 25 4
gpt4 key购买 nike

根据[dcl.constexpr/3] :

The definition of a constexpr function shall satisfy the following requirements:
[...]
- its function-body shall be = delete, = default, or [...]

这意味着下面的类片段是有效的:

struct S {
constexpr void f() = delete;
};

删除 constexpr 函数的目的是什么?
如果有的话,定义它 constexpr 有什么好处?

我想不出任何原因,但事实是在标准中允许它比禁止它更容易。

最佳答案

这是基于 CWG 1199 .丹尼尔·克鲁格勒写道:

it could be useful to allow this form in a case where a single piece of code is used in multiple configurations, in some of which the function is constexpr and others deleted; having to update all declarations of the function to remove the constexpr specifier is unnecessarily onerous.

关于c++ - constexpr 和函数体 = 删除 : what's the purpose?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40031140/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com