is_integral与is_integer:其中之一是否多余? [英] is_integral vs is_integer: is one of them redundant?
问题描述
is_integral and is_integer seem to answer the same thing in the same way.
在相关文档页面的链接中, is_integral
似乎缺少以下类型的专业化
From the links to the related documentation pages, is_integral
seems to be missing specializations for the following types
signed char
unsigned char
unsigned short
unsigned int
unsigned long
unsigned long long
还有一个编译示例,(当然)还显示了它们在这些类型上的相同行为:>
Yet a compiled example, shows (of course) their identical behaviour on those types as well:
#include <iostream>
#include <type_traits>
using namespace std;
int main()
{
cout << is_integral<signed char >::value << endl;
cout << is_integral<unsigned char >::value << endl;
cout << is_integral<unsigned short >::value << endl;
cout << is_integral<unsigned int >::value << endl;
cout << is_integral<unsigned long >::value << endl;
cout << is_integral<unsigned long long>::value << endl;
return 0;
}
因此,如果它们的行为也相同,那么在C ++ 11中引入它们的意义何在?
So if they also behave the same, what was the point of introducing both of them in C++11?
因此,如果它们的行为也相同,那么在c ++ 11中引入它们的意义何在?
没用指出,短语包括任何有符号,无符号和cv限定的变体 is_integral
文档页面上的em>表明,即使它们的规范也是完全匹配的.
As Useless points out, the phrase including any signed, unsigned, and cv-qualified variants from the is_integral
doc page reveals that even their specifications are a complete match.
推荐答案
std :: numeric_limits< T> :: is_integer
不是C ++ 11引入的.刚刚更新为使用新的 constexpr
限定符.
std::numeric_limits<T>::is_integer
was not introduced by C++11. It was just updated to use the new constexpr
qualifier.
std :: is_integral< T>
是C ++ 11引入的,您说对了,它给出了相同的结果.至于为什么要添加它-可能是因为某种类型的完整性或逻辑上不是该类型 numeric_limits
的一部分?
std::is_integral<T>
was introduced by C++11, and you're right it gives the same results. As to why it was added - possibly because the integral-ness or otherwise of a type isn't logically part of that type's numeric_limits
?
< type_traits>
标头的目标似乎是将所有类型分类助手收集到一个地方,而较早的 numeric_limits
仅收集特定于,好,数字.如果不赞成使用 numeric_limits< T> :: is_integer
,则将存在一个稍微任意的边界,这些边界的类型特征存在于< type_traits>
中,并且被视为数字特征.在两个地方都拥有它并不是一个可怕的重复.
It seems to be the goal of the <type_traits>
header to gather all the type classification helpers in one place, while the older numeric_limits
collects only properties specific to, well, numbers. If numeric_limits<T>::is_integer
were deprecated, there'd be a slightly arbitrary boundary which type traits lived in <type_traits>
, and which were considered numerical. It's hardly a terrible duplication to have it in both places.
这篇关于is_integral与is_integer:其中之一是否多余?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!