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
Défini dans l'en-tête <type_traits>
template < class T >
struct is_fundamental ;
(depuis C++11)

std::is_fundamental est un UnaryTypeTrait .

Si T est un type fondamental (c'est-à-dire un type arithmétique, void , ou nullptr_t ), fournit la constante membre value égale à true . Pour tout autre type, value est false .

Si le programme ajoute des spécialisations pour std::is_fundamental ou std::is_fundamental_v , le comportement est indéfini.

Table des matières

Paramètres du modèle

T - un type à vérifier

Modèle de variable d'assistance

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

Hérité de std:: integral_constant

Constantes membres

value
[static]
true si T est un type fondamental, false sinon
(constante membre publique statique)

Fonctions membres

operator bool
convertit l'objet en bool , retourne value
(fonction membre publique)
operator()
(C++14)
retourne value
(fonction membre publique)

Types membres

Type Définition
value_type bool
type std:: integral_constant < bool , value >

Implémentation possible

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
        // vous pouvez également utiliser 'std::is_null_pointer<T>::value' à la place en C++14
> {};

Exemple

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

Voir aussi

vérifie si un type est un type composé
(modèle de classe)
vérifie si un type est un type arithmétique
(modèle de classe)
(C++11)
vérifie si un type est void
(modèle de classe)
(C++11) ( DR* )
vérifie si un type est std::nullptr_t
(modèle de classe)