std::is_signed
STD::是[医]签名
Defined in header | | |
---|---|---|
template< class T > struct is_signed; | | (since C++11) |
如果T是算术类型,提供成员常量。value平等true如果T(-1) < T(0)*这导致true对于浮点类型和有符号整数类型,false对于无符号整数类型和类型bool...
对于任何其他类型,value
是false
...
模板参数
T | - | a type to check |
---|
辅助变量模板
template< class T > inline constexpr bool is_signed_v = is_signed | | (since C++17) |
---|
继承自STD:积分[医]常量
成员常数
value static | true if T is a signed arithmetic type , false otherwise (public static member constant) |
---|
成员函数
operator bool | converts the object to bool, returns value (public member function) |
---|---|
operator() (C++14) | returns value (public member function) |
成员类型
Type | Definition |
---|---|
value_type | bool |
type | std::integral_constant<bool, value> |
可能的实施
名称空间详细信息{Template<type Name T,bool=std::is[医]算术<T>*值>结构是[医]签名:STD::整数[医]常数<bool,T%28-1%29<T%280%29>{};模板<typename T>结构是[医]签名<T,false>:std::false[医]类型{};}//名称空间详细模板<typename T>结构是[医]签名:详细信息::IS[医]签名<T>*{}型;
*。
例
二次
#include <iostream>
#include <type_traits>
class A {};
enum B : int {};
enum class C : int {};
int main()
{
std::cout << std::boolalpha;
std::cout << std::is_signed<A>::value << '\n';
std::cout << std::is_signed<float>::value << '\n';
std::cout << std::is_signed<signed int>::value << '\n';
std::cout << std::is_signed<unsigned int>::value << '\n';
std::cout << std::is_signed<B>::value << '\n';
std::cout << std::is_signed<C>::value << '\n';
// shorter:
std::cout << std::is_signed<signed int>() << '\n';
std::cout << std::is_signed<unsigned int>() << '\n';
}
二次
产出:
二次
false
true
true
false
false
false
true
false
二次
另见
is_unsigned (C++11) | checks if a type is unsigned arithmetic type (class template) |
---|---|
is_signed static | identifies signed types (public static member constant of std::numeric_limits) |
is_arithmetic (C++11) | checks if a type is arithmetic type (class template) |
make_signed (C++11) | makes the given integral type signed (class template) |
make_unsigned (C++11) | makes the given integral type unsigned (class template) |
© cppreference.com
在CreativeCommonsAttribution下授权-ShareAlike未移植许可v3.0。