为什么std::isnan 不是 constexpr?
Why is std::isnan not constexpr?
截至C++20 std::isnan 不是 constexpr。
这有技术原因吗?
我能想到的只是它在"C header"中,所以没有人费心去修复它(<limits>
处理浮点数的函数是constexpr,但不幸的是numeric_limits
不包含isnan check)。
答案基本上是"因为提案尚未合并到标准中">
P0533 提出你所问的问题,它没有进入C++20。
其中一个阻碍是,也许这个提议有点大......允许<cmath>
或<cstdlib>
中的某些函数设置全局错误代码,这使整个"constexpr
所有事物"提案变得复杂*
我认为这些分类功能应该没有任何问题;std::isnan
及其同级std::fpclassify
被定义为分别与 C 宏isnan
和fpclassify
的行为相同。这将需要略有改变。
*(旁白:p2043"不要constexpr
所有的事情"在这里是切线相关的,但它只是在谈论元编程)
相关文章:
- 为什么std::isnan 不是 constexpr?
- 为什么reinterpret_cast不是 constexpr?
- 为什么我的 constexpr 对象在我的函数中不是 constexpr?
- 比较两个 constexpr 指针不是 constexpr?
- constexpr 函数在编译时获取值,即使我的变量不是 constexpr
- Constexpr变量不是编译时值
- 当迭代器(输入参数)通常不是constexpr时,constexpr算法真的有用吗
- 为什么非成员静态 constexpr 变量不是隐式内联的?
- const(但不是constexpr)用作内置数组大小
- 现在允许重新定义 constexpr 静态数据成员吗?(但不是内联常量)?
- std::可选的默认构造函数不是 gcc 中的 constexpr?
- __LINE__不是 MSVC 中的 constexpr
- 获取 constexpr 全局变量(不是静态成员)的链接器符号
- Clang声称通用lambda参数的constexpr成员不是constexpr
- Clang说is_same_v<int,double>的用法不是constexpr,不知道它怎么不是
- 为什么默认的构造函数在这里不是 constexpr
- constexpr(但不是真正的)构造函数在GCC中编译,而不是在Clang中编译
- 为什么可变参数函数模板中的这个 constexpr 不是常数?
- C++:为什么这个 constexpr 不是编译时常数
- 为什么constexpr不是自动的