std::integral
来自cppreference.com
<tbody>
</tbody>
| 在标头 <concepts> 定义
|
||
template< class T > concept integral = std::is_integral_v<T>; |
(C++20 起) | |
概念 integral<T> 当且仅当 T 为整数类型才得到满足。
示例
运行此代码
#include <concepts>
#include <iostream>
void print(std::integral auto i)
{
std::cout << "整型: " << i << '\n';
}
void print(auto x)
{
std::cout << "非整型: " << x << '\n';
}
int main()
{
std::cout << std::boolalpha;
static_assert(std::integral<bool>);
print(true);
static_assert(std::integral<char>);
print('o');
static_assert(std::integral<int>);
print(007);
static_assert( ! std::integral<double> );
print(2e2);
static_assert( ! std::integral<decltype("")> );
print("∫∫∫");
}
输出:
整型: true
整型: o
整型: 7
非整型: 200
非整型: ∫∫∫
引用
- C++23 标准(ISO/IEC 14882:2024):
- 18.4.7 Arithmetic concepts [concepts.arithmetic]
- C++20 标准(ISO/IEC 14882:2020):
- 18.4.7 Arithmetic concepts [concepts.arithmetic]
参阅
(C++11) |
检查类型是否为整数类型 (类模板) |