◐ Shell
clean mode source ↗

std::is_integral - cppreference.com

提供: cppreference.com

<tbody> </tbody>

template< class T > struct is_integral;

(C++11以上)

T が整数型かどうか調べます。 Tboolcharchar8_tchar16_tchar32_twchar_tshortintlonglong long、または何らかの処理系定義の拡張整数型 (あらゆる符号付き、符号なし、および cv 修飾された変種を含みます) であれば、 true に等しいメンバ定数 value が提供されます。 そうでなければ、 valuefalse に等しくなります。

is_integral または is_integral_v (C++17以上) に対して特殊化を追加するプログラムは未定義です。

テンプレート引数

ヘルパー変数テンプレート

<tbody> </tbody>

template< class T > inline constexpr bool is_integral_v = is_integral<T>::value;

(C++17以上)

std::integral_constant から継承

メンバ定数

T が整数型ならば true、そうでなければ false
(パブリック静的メンバ定数)

メンバ関数

オブジェクトを bool に変換します。 value を返します
(パブリックメンバ関数)
value を返します
(パブリックメンバ関数)

メンバ型

定義
value_type bool
type std::integral_constant<bool, value>

#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

関連項目