整型的std :: isnan和std :: isinf重载 [英] Overloads of std::isnan and std::isinf for integral types

查看:213
本文介绍了整型的std :: isnan和std :: isinf重载的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Cppreference提到 std :: isnan的重载 std :: isinf (可能还有其他)用于整数类型。这使得以下调用明确

Cppreference mentions the overloads of std::isnan and std::isinf (and maybe others) for integral types. This makes the following call unambiguous:

std::isnan(1);

但是,我找不到C ++标准中提到的任何此类重载。我检查了C ++ 11和当前草案,仅是 float double long double 的重载。

However, I cannot find any such overloads mentioned in the C++ Standard. I checked C++11 and the current draft, and there are only overloads for float, double, and long double.

对于编译器行为, GCC C语都可以编译代码,但是 MSVC不。谁是对的?

As for compiler behavior, GCC and Clang both compile the code, but MSVC does not. Who is right? Where did the integral overload on cppreference come from?

推荐答案

在cppreference上的积分重载从何而来? = http://www.eel.is/c++draft/cmath.syn#2 rel = nofollow noreferrer> cmath :

There is a paragraph at the end of the standard page for cmath:


对于< cmath> 中的每组重载函数,除了 abs ,则应该有足够的额外重载来确保:

For each set of overloaded functions within <cmath>, with the exception of abs, there shall be additional overloads sufficient to ensure:

2。否则,如果与double参数对应的算术类型的任何参数具有double类型或整数类型,则将与double参数对应的所有算术类型的参数有效地转换为

2. Otherwise, if any argument of arithmetic type corresponding to a double parameter has type double or an integer type, then all arguments of arithmetic type corresponding to double parameters are effectively cast to double.

整数重载是强制性的,否则您将在三个浮点重载之间得到模棱两可的调用,但是如何实现这种重载未指定。

The integral overloads are mandatory, otherwise you would get ambiguous calls between the three floating point overloads, but how such overloads are implemented is unspecified.

请注意< cmath> 标头中的其他函数具有正确的重载对于整数类型,例如

Notice that other functions in the <cmath> header have correct overloads for integral types, e.g.,

std::atan(1)

调用模板版本 double atan< int,void>(int)

这篇关于整型的std :: isnan和std :: isinf重载的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆