c++ - 为什么 std::array 的 operator==() 没有标记为 constexpr?

标签 c++ c++11 comparison constexpr stdarray

它是 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/

相关文章:

r - 找到两个非常相似的值之间差异的第一个有效数字

c++ - 获取存储在 blob 中的 MySQL 图像大小

c++ - 将 Visual Studio C++ 控制台应用程序连接到 Microsoft SQL Server 时如何修复 “SQL Server does not exist or access denied.”

c++ - C++0x 标准如何定义 C++ Auto 多重声明?

c++ - 如何将 constexpr 函数的参数标记为未使用?

shell - 计算大列表中的不同元素太慢

C++ Try Catch block 不捕获异常

c++ - 在 C++ 中不允许变量的默认值是非静态方法或类成员的原因是什么?

c++11 - Rust 中的 C+11 类类型衰减

PHP语法问题