std::is_integral
提供: cppreference.com
<tbody>
</tbody>
| ヘッダ <type_traits> で定義
|
||
template< class T > struct is_integral; |
(C++11以上) | |
T が整数型かどうか調べます。 T が bool、char、char8_t、char16_t、char32_t、wchar_t、short、int、long、long long、または何らかの処理系定義の拡張整数型 (あらゆる符号付き、符号なし、および cv 修飾された変種を含みます) であれば、 true に等しいメンバ定数 value が提供されます。 そうでなければ、 value は false に等しくなります。
is_integral または is_integral_v (C++17以上) に対して特殊化を追加するプログラムは未定義です。
テンプレート引数
| T | - | 調べる型 |
ヘルパー変数テンプレート
<tbody> </tbody> template< class T > inline constexpr bool is_integral_v = is_integral<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>
|
例
Run this code
#include <iostream>
#include <type_traits>
class A {};
enum E : int {};
template <class T>
T f(T i)
{
static_assert(std::is_integral<T>::value, "Integral required.");
return i;
}
int main()
{
std::cout << std::boolalpha;
std::cout << std::is_integral<A>::value << '\n';
std::cout << std::is_integral<E>::value << '\n';
std::cout << std::is_integral<float>::value << '\n';
std::cout << std::is_integral<int>::value << '\n';
std::cout << std::is_integral<bool>::value << '\n';
std::cout << f(123) << '\n';
}
出力:
false
false
false
true
true
123
関連項目
[静的] |
整数型を識別します ( std::numeric_limits<T>のパブリック静的メンバ定数)
|
(C++11) |
型が浮動小数点型かどうか調べます (クラステンプレート) |
(C++11) |
型が算術型かどうか調べます (クラステンプレート) |
(C++11) |
型が列挙型かどうか調べます (クラステンプレート) |