Namespaces
Variants

std:: is_fundamental

From cppreference.net
Metaprogramming library
Type traits
Type categories
(C++11)
(C++11) ( DR* )
(C++11)
(C++11)
is_fundamental
(C++11)
Type properties
(C++11)
(C++11)
(C++14)
(C++11) (deprecated in C++26)
(C++11) ( until C++20* )
(C++11) (deprecated in C++20)
(C++11)
Type trait constants
Metafunctions
(C++17)
Supported operations
Relationships and property queries
Type modifications
Type transformations
(C++11) (deprecated in C++23)
(C++11) (deprecated in C++23)
(C++11)
(C++11) ( until C++20* ) (C++17)

Compile-time rational arithmetic
Compile-time integer sequences
Definiert im Header <type_traits>
template < class T >
struct is_fundamental ;
(seit C++11)

std::is_fundamental ist ein UnaryTypeTrait .

Falls T ein fundamentaler Typ ist (also ein arithmetischer Typ, void , oder nullptr_t ), liefert die Konstante value den Wert true . Für alle anderen Typen ist value false .

Wenn das Programm Spezialisierungen für std::is_fundamental oder std::is_fundamental_v hinzufügt, ist das Verhalten undefiniert.

Inhaltsverzeichnis

Template-Parameter

T - ein zu prüfender Typ

Hilfsvariablen-Template

template < class T >
constexpr bool is_fundamental_v = is_fundamental < T > :: value ;
(seit C++17)

Geerbt von std:: integral_constant

Member-Konstanten

value
[static]
true wenn T ein fundamentaler Typ ist, false andernfalls
(öffentliche statische Member-Konstante)

Member-Funktionen

operator bool
konvertiert das Objekt zu bool , gibt value zurück
(öffentliche Member-Funktion)
operator()
(C++14)
gibt value zurück
(öffentliche Member-Funktion)

Member-Typen

Typ Definition
value_type bool
type std:: integral_constant < bool , value >

Mögliche Implementierung

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
        // Sie können stattdessen auch 'std::is_null_pointer<T>::value' in C++14 verwenden
> {};

Beispiel

#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() {}

Siehe auch

prüft, ob ein Typ ein zusammengesetzter Typ ist
(Klassentemplate)
prüft, ob ein Typ ein arithmetischer Typ ist
(Klassentemplate)
(C++11)
prüft, ob ein Typ void ist
(Klassentemplate)
(C++11) ( DR* )
prüft, ob ein Typ std::nullptr_t ist
(Klassentemplate)