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/