is_signed 类

测试类型是否为带符号整数。

语法

template <class Ty>
struct is_signed;

参数

Ty
要查询的类型。

注解

如果类型 Ty 是带符号整型类型或 cv-qualified 带符号整型类型,则类型谓词的实例将保留为 true,否则保留为 false。

示例

// std__type_traits__is_signed.cpp
// compile with: /EHsc
#include <type_traits>
#include <iostream>

struct trivial
    {
    int val;
    };

int main()
    {
    std::cout << "is_signed<trivial> == " << std::boolalpha
        << std::is_signed<trivial>::value << std::endl;
    std::cout << "is_signed<int> == " << std::boolalpha
        << std::is_signed<int>::value << std::endl;
    std::cout << "is_signed<unsigned int> == " << std::boolalpha
        << std::is_signed<unsigned int>::value << std::endl;
    std::cout << "is_signed<float> == " << std::boolalpha
        << std::is_signed<float>::value << std::endl;

    return (0);
    }
is_signed<trivial> == false
is_signed<int> == true
is_signed<unsigned int> == false
is_signed<float> == true

要求

标头:<type_traits>

命名空间: std

另请参阅

<type_traits>
is_unsigned 类