std::is_fundamental
來自 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 [靜態] |
如果 T 是基礎型別,則為 true,否則為 false(public static 成員常量) |
成員函式
operator bool |
將物件轉換為 bool,返回 value (公開成員函式) |
operator() (C++14) |
返回 value (公開成員函式) |
成員型別
型別 | 定義 |
value_type
|
bool |
型別
|
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 (類模板) |