std::is_fundamental
From cppreference.com
| ヘッダ <type_traits> で定義 |
||
| template< class T > struct is_fundamental; |
(C++11以降) | |
std::is_fundamental は UnaryTypeTrait です。
もし T が 基本型(つまり、算術型、void、または nullptr_t)である場合、メンバ定数 value は true となります。その他の型については、value は false となります。
プログラムが std::is_fundamental または std::is_fundamental_v の特殊化を追加した場合、その動作は未定義です。
目次 |
[編集] テンプレートパラメータ
| T | - | チェックする型 |
[編集] ヘルパー変数テンプレート
| template< class T > constexpr bool is_fundamental_v = is_fundamental<T>::value; |
(C++17以降) | |
std::integral_constant から継承
メンバ定数
| value [static] |
T が基本型の場合 true、それ以外の場合 false(公開静的メンバ定数) |
メンバ関数
| operator bool |
オブジェクトを bool に変換し、value を返します。 (public member function) |
| operator() (C++14) |
value を返します。 (public member function) |
メンバ型
| 型 | 定義 |
value_type
|
bool |
type
|
std::integral_constant<bool, value> |
[編集] 可能な実装
template<class T> struct is_fundamental : std::integral_constant< bool, std::is_arithmetic<T>::value || std::is_void<T>::value || std::is_same<std::nullptr_t, typename std::remove_cv<T>::type>::value // you can also use 'std::is_null_pointer<T>::value' instead in C++14 > {}; |
[編集] 例
このコードを実行
#include <type_traits> static_assert(std::is_fundamental_v<int> == true); static_assert(std::is_fundamental_v<int&> == false); static_assert(std::is_fundamental_v<int*> == false); static_assert(std::is_fundamental_v<void> == true); static_assert(std::is_fundamental_v<void*> == false); static_assert(std::is_fundamental_v<float> == true); static_assert(std::is_fundamental_v<float&> == false); static_assert(std::is_fundamental_v<float*> == false); static_assert(std::is_fundamental_v<std::nullptr_t> == true); static_assert(std::is_fundamental_v<std::is_fundamental<int>> == false); class A {}; static_assert(std::is_fundamental_v<A> == false); static_assert(std::is_fundamental_v<std::is_fundamental<A>::value_type>); int main() {}
[編集] 関連項目
| (C++11) |
型が複合型であるかをチェックする (クラステンプレート) |
| (C++11) |
型が算術型であるかをチェックする (クラステンプレート) |
| (C++11) |
型が void であるかをチェックする (クラステンプレート) |
| (C++11)(DR*) |
型が std::nullptr_t であるかをチェックする (クラステンプレート) |