Namespaces
Variants

std:: is_class

From cppreference.net
Metaprogramming library
Type traits
Type categories
(C++11)
(C++11) ( DR* )
(C++11)
(C++11)
(C++11)
(C++11)
is_class
(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_class ;
(seit C++11)

std::is_class ist ein UnaryTypeTrait .

Prüft, ob T ein Nicht-Union-Klassentyp ist. Stellt die Member-Konstante value bereit, die gleich true ist, falls T ein Klassentyp (aber keine Union) ist. Andernfalls ist value gleich false .

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

Inhaltsverzeichnis

Template-Parameter

T - ein zu prüfender Typ

Hilfsvariablen-Template

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

Geerbt von std:: integral_constant

Member-Konstanten

value
[static]
true wenn T ein Nicht-Union-Klassentyp 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

namespace detail
{
    template<class T>
    std::integral_constant<bool, !std::is_union<T>::value> test(int T::*);
    template<class>
    std::false_type test(...);
}
template<class T>
struct is_class : decltype(detail::test<T>(nullptr)) {};

Beispiel

#include <type_traits>
struct A {};
static_assert(std::is_class<A>::value);
class B {};
static_assert(std::is_class_v<B>);
static_assert(not std::is_class_v<B*>);
static_assert(not std::is_class_v<B&>);
static_assert(std::is_class_v<const B>);
enum class E {};
static_assert(not std::is_class<E>::value);
union U { class UC {}; };
static_assert(not std::is_class_v<U>);
static_assert(std::is_class_v<U::UC>);
static_assert(not std::is_class_v<int>);
static_assert(std::is_class_v<struct S>, "incomplete class");
static_assert(std::is_class_v<class C>, "incomplete class");
int main() {}

Siehe auch

(C++11)
prüft, ob ein Typ ein Union-Typ ist
(Klassentemplate)