std::integral

来自cppreference.com
< cpp‎ | concepts
在标头 <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 << "Integral: " << i << '\n';
}
 
void print(auto x) {
    std::cout << "Non-integral: " << x << '\n';
}
 
int main()
{
    print( 'o' ); static_assert( std::integral<char> );
    print( 007 ); static_assert( std::integral<int> );
    print( 2e2 ); static_assert( !std::integral<float> );
    print("∫∫∫"); static_assert( !std::integral<decltype("")> );
}

输出:

Integral: o
Integral: 7
Non-integral: 200
Non-integral: ∫∫∫

参阅

检查类型是否为整数类型
(类模板)