它是 very natural想比较std::array
是在编译时;和它的 operator==()
显然是constexpr
'有能力的。然而 - 它 isn't标记 constexpr
.这是故意的还是疏忽的?并且 - 保留这种方式的原因是什么(显然在 C++17 中也是如此)?
最佳答案
P0031解释为什么它没有提出 constexpr
比较:
Currently comparisons and
swap
/fill
may be implemented with the help of algorithms from<algorithm>
header. Marking comparisons with constexpr will break that ability and will potentially lead to performance degradations.
例如,
==
可以按照std::equal
来实现, 在适当的情况下 - 可以调用高度优化但决定不- constexpr
memcmp
.制作 constexpr
为 ==
将在没有特殊编译器帮助的情况下排除此优化。
关于c++ - 为什么 std::array 的 operator==() 没有标记为 constexpr?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45783344/