std::is_fundamental
提供: cppreference.com
<tbody>
</tbody>
| ヘッダ <type_traits> で定義
|
||
template< class T > struct is_fundamental; |
(C++11以上) | |
T が基本型 (つまり、算術型、void、または nullptr_t) であれば、 true に等しいメンバ定数 value が提供されます。 それ以外の型に対しては、 value は false です。
is_fundamental または is_fundamental_v (C++17以上) に対して特殊化を追加するプログラムは未定義です。
テンプレート引数
| T | - | 調べる型 |
ヘルパー変数テンプレート
<tbody> </tbody> template< class T > inline constexpr bool is_fundamental_v = is_fundamental<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>
|
実装例
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
> {};
|
例
Run this code
#include <iostream>
#include <type_traits>
class A {};
int main()
{
std::cout << std::boolalpha;
std::cout << "A\t" << std::is_fundamental<A>::value << '\n';
std::cout << "int\t" << std::is_fundamental<int>::value << '\n';
std::cout << "int&\t" << std::is_fundamental<int&>::value << '\n';
std::cout << "int*\t" << std::is_fundamental<int*>::value << '\n';
std::cout << "float\t" << std::is_fundamental<float>::value << '\n';
std::cout << "float&\t" << std::is_fundamental<float&>::value << '\n';
std::cout << "float*\t" << std::is_fundamental<float*>::value << '\n';
}
出力:
A false
int true
int& false
int* false
float true
float& false
float* false
関連項目
(C++11) |
型が複合型かどうか調べます (クラステンプレート) |
(C++11) |
型が算術型かどうか調べます (クラステンプレート) |
(C++11) |
型が void かどうか調べます (クラステンプレート) |
(C++14) |
型が std::nullptr_t かどうか調べます (クラステンプレート) |