我知道需求的差异,我最感兴趣的是它带来的代码质量带来的好处。
我能想到的几件事:
constevalfns 在运行时从不使用(这是推测性的,我没有这方面的真实数据)注意:如果代码质量太模糊,我理解有些人可能想要结束这个问题,对我来说代码质量并不是那么模糊的术语,但是......
例如,其中constexpr故障被延迟到运行时:
constexpr int div_cx(int a, int b)
{
assert(b!=0);
return a/b;
}
int main()
{
static constexpr int result = div_cx(5,0); // compile time error, div by 0
std::cout << result;
std::cout << div_cx(5,0) ; // runtime error :(
}
Run Code Online (Sandbox Code Playgroud)