std:: signed_integral
From cppreference.net
|
定义于头文件
<concepts>
|
||
|
template
<
class
T
>
concept signed_integral = std:: integral < T > && std:: is_signed_v < T > ; |
(C++20 起) | |
当且仅当
T
为整数类型且
std::
is_signed_v
<
T
>
为
true
时,概念
signed_integral<T>
得到满足。
目录 |
注释
signed_integral<T>
可能被非
有符号整数类型
的类型所满足,例如
char
(在
char
为有符号类型的系统上)。
示例
运行此代码
#include <concepts> #include <iostream> #include <string_view> void test(std::signed_integral auto x, std::string_view text = "") { std::cout << text << " (" + (text == "") << x << ") is a signed integral\n"; } void test(std::unsigned_integral auto x, std::string_view text = "") { std::cout << text << " (" + (text == "") << x << ") is an unsigned integral\n"; } void test(auto x, std::string_view text = "") { std::cout << text << " (" + (text == "") << x << ") is non-integral\n"; } int main() { test(42); // 有符号 test(0xFULL, "0xFULL"); // 无符号 test('A'); // 平台相关 test(true, "true"); // 无符号 test(4e-2, "4e-2"); // 非整型(十六进制浮点数) test("∫∫"); // 非整型 }
可能的输出:
(42) is a signed integral 0xFULL (15) is an unsigned integral (A) is a signed integral true (1) is an unsigned integral 4e-2 (0.04) is non-integral (∫∫) is non-integral
参考文献
- C++23 标准 (ISO/IEC 14882:2024):
-
- 18.4.7 算术概念 [concepts.arithmetic]
- C++20 标准 (ISO/IEC 14882:2020):
-
- 18.4.7 算术概念 [concepts.arithmetic]
参见
|
(C++11)
|
检查类型是否为整型
(类模板) |
|
(C++11)
|
检查类型是否为有符号算术类型
(类模板) |