Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/134.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ 对于基本类型的所有常量/易失性/有符号/无符号版本均为真的类型特征_C++_C++11_Typetraits_Qualifiers - Fatal编程技术网

C++ 对于基本类型的所有常量/易失性/有符号/无符号版本均为真的类型特征

C++ 对于基本类型的所有常量/易失性/有符号/无符号版本均为真的类型特征,c++,c++11,typetraits,qualifiers,C++,C++11,Typetraits,Qualifiers,考虑以下测试: std::is_same<T, bool>::value std::is_same<T, char>::value std::is_same<T, short int>::value std::is_same<T, int>::value std::is_same<T, long int>::value std::is_same<T, long long int>::value std::is_same<

考虑以下测试:

std::is_same<T, bool>::value
std::is_same<T, char>::value
std::is_same<T, short int>::value
std::is_same<T, int>::value
std::is_same<T, long int>::value
std::is_same<T, long long int>::value
std::is_same<T, float>::value
std::is_same<T, double>::value
std::is_same<T, long double>::value
std::值是否相同
std::值是否相同
std::值是否相同
std::值是否相同
std::值是否相同
std::值是否相同
std::值是否相同
std::值是否相同
std::值是否相同
问题是如果
T=const unsigned char
,所有测试都将为false,我希望这一个
std::is_same::value
为true。或者如果
T=volatile signed long long int
我希望
std::is_same::value
为真。如何使用
type\u traits

用于删除
const
volatile
(如果存在):

std::is_same<std::remove_cv<T>::type, long long int>::value;
std::is_same::value;
您可以使用来处理常量volatile说明符

您可以使用来处理已签名/未签名的问题。尽管如此,我并不特别喜欢这个想法(无符号字符与无符号字符是否真的相同?)

std::is_same,char>::value;

对于
char
unsigned char
const char
const unsigned char
,以及它们的易失性版本,都是如此。

我设计了一个类来检测由异构系统生成的文件的数据模型,类型的有符号/无符号版本使用相同数量的字节进行编码。
无符号字符
有符号字符
和常规的
字符
是三种不同的类型(见§3.9.1.1)。因此,该示例将不正确,因为您生成了一个
有符号字符
,并将其与常规的
字符
进行比较。请随意测试:
std::is_same< std::make_signed< std::remove_cv<T> >, char >::value;