C++ 参考手册
- C++11
 - C++14
 - C++17
 - C++20
 - C++ 编译器支持情况表
 - 独立与宿主实现
 - C++ 语言
 - C++ 关键词
 - 预处理器
 - C++ 标准库头文件
 - 具名要求
 - 功能特性测试 (C++20)
 - 工具库
 - 类型支持(基本类型、RTTI、类型特性)
 - std::result_of, std::invoke_result
 - std::integral_constant
 - std::is_constant_evaluated
 - std::max_align_t
 - offsetof
 - NULL
 - std::bad_typeid
 - std::bad_cast
 - std::numeric_limits
 - std::type_info
 - std::ptrdiff_t
 - std::byte
 - std::conjunction
 - std::disjunction
 - std::negation
 - std::is_swappable_with, std::is_swappable, std::is_nothrow_swappable_with, std::is_nothrow_swappable
 - std::is_invocable, std::is_invocable_r, std::is_nothrow_invocable, std::is_nothrow_invocable_r
 - std::is_aggregate
 - std::has_unique_object_representations
 - std::endian
 - std::remove_cvref
 - std::type_index
 - C 数值极限接口
 - 定宽整数类型 (C++11 起)
 - std::is_bounded_array
 - std::is_unbounded_array
 - std::size_t
 - std::nullptr_t
 - std::is_integral
 - std::rank
 - std::is_void
 - std::is_null_pointer
 - std::is_array
 - std::is_pointer
 - std::is_enum
 - std::is_union
 - std::is_class
 - std::is_function
 - std::is_object
 - std::is_scalar
 - std::is_compound
 - std::is_floating_point
 - std::is_fundamental
 - std::is_arithmetic
 - std::is_reference
 - std::is_lvalue_reference
 - std::is_rvalue_reference
 - std::is_member_pointer
 - std::is_member_object_pointer
 - std::is_member_function_pointer
 - std::is_const
 - std::is_volatile
 - std::is_empty
 - std::is_polymorphic
 - std::is_final
 - std::is_abstract
 - std::is_trivial
 - std::is_trivially_copyable
 - std::is_standard_layout
 - std::is_literal_type
 - std::is_pod
 - std::is_signed
 - std::is_unsigned
 - std::is_constructible, std::is_trivially_constructible, std::is_nothrow_constructible
 - std::is_default_constructible, std::is_trivially_default_constructible, std::is_nothrow_default_constructible
 - std::is_copy_constructible, std::is_trivially_copy_constructible, std::is_nothrow_copy_constructible
 - std::is_move_constructible, std::is_trivially_move_constructible, std::is_nothrow_move_constructible
 - std::is_assignable, std::is_trivially_assignable, std::is_nothrow_assignable
 - std::is_copy_assignable, std::is_trivially_copy_assignable, std::is_nothrow_copy_assignable
 - std::is_move_assignable, std::is_trivially_move_assignable, std::is_nothrow_move_assignable
 - std::is_destructible, std::is_trivially_destructible, std::is_nothrow_destructible
 - std::has_virtual_destructor
 - std::is_same
 - std::is_base_of
 - std::is_convertible, std::is_nothrow_convertible
 - std::is_layout_compatible
 - std::is_pointer_interconvertible_base_of
 - std::is_pointer_interconvertible_with_class
 - std::is_corresponding_member
 - std::alignment_of
 - std::extent
 - std::remove_cv, std::remove_const, std::remove_volatile
 - std::add_cv, std::add_const, std::add_volatile
 - std::make_signed
 - std::make_unsigned
 - std::remove_reference
 - std::add_lvalue_reference, std::add_rvalue_reference
 - std::remove_pointer
 - std::add_pointer
 - std::remove_extent
 - std::remove_all_extents
 - std::aligned_storage
 - std::aligned_union
 - std::decay
 - std::enable_if
 - std::void_t
 - std::conditional
 - std::common_type
 - std::common_reference
 - std::underlying_type
 - std::type_identity
 - 注释
 - 概念库 (C++20)
 - 错误处理
 - 动态内存管理
 - 日期和时间工具
 - 字符串库
 - 容器库
 - 迭代器库
 - 范围库 (C++20)
 - 算法库
 - 数值库
 - 输入/输出库
 - 文件系统库
 - 本地化库
 - 正则表达式库
 - 原子操作库
 - 线程支持库
 - 实验性 C++ 特性
 - 有用的资源
 - 索引
 - std 符号索引
 - 协程支持 (C++20)
 - C++ 关键词
 
位置:首页 > C++ 参考手册 >类型支持(基本类型、RTTI、类型特性) > std::is_signed
std::is_signed
|   定义于头文件  <type_traits>
  | 
||
|   template< class T > struct is_signed;  | 
(C++11 起) | |
若 T 是算术类型且 T(-1) < T(0) ,则提供等于 true 的成员常量 value :这对于浮点类型和有符号整数类型产生 true ,并对无符号整数类型和 bool 类型产生 false 。
对于任何其他类型, value 为 false 。
添加 is_signed 或 is_signed_v (C++17 起) 的特化的程序行为未定义。
模板形参
| T | - | 要检查的类型 | 
辅助变量模板
|   template< class T > inline constexpr bool is_signed_v = is_signed<T>::value;  | 
(C++17 起) | |
继承自 std::integral_constant
成员常量
|    value [静态]  | 
   若 T 为有符号算术类型则为 true ,否则为 false  (公开静态成员常量)  | 
成员函数
|    operator bool  | 
   转换对象为 bool ,返回 value  (公开成员函数)  | 
|    operator() (C++14)  | 
   返回 value  (公开成员函数)  | 
成员类型
| 类型 | 定义 | 
  value_type
 | 
  bool
 | 
  type
 | 
std::integral_constant<bool, value> | 
可能的实现
namespace detail { template<typename T,bool = std::is_arithmetic<T>::value> struct is_signed : std::integral_constant<bool, T(-1) < T(0)> {}; template<typename T> struct is_signed<T,false> : std::false_type {}; } // namespace detail template<typename T> struct is_signed : detail::is_signed<T>::type {};  | 
示例
运行此代码
#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'; // 简短的形式: std::cout << std::is_signed<signed int>() << '\n'; std::cout << std::is_signed<unsigned int>() << '\n'; }
输出:
false true true false false false true false
参阅
|    (C++11)  | 
  检查类型是否为无符号算术类型  (类模板)  | 
|    [静态]  | 
   鉴别有符号类型   ( std::numeric_limits<T> 的公开静态成员常量)  | 
|    (C++11)  | 
  检查类型是否为算术类型  (类模板)  | 
|    (C++11)  | 
  使给定的整型类型有符号   (类模板)  | 
|    (C++11)  | 
  使给定的整型类型无符号   (类模板)  |