Namespaces
Variants

std:: is_void

From cppreference.net
Metaprogramming library
Type traits
Type categories
is_void
(C++11)
(C++11) ( DR* )
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
Definido en el encabezado <type_traits>
template < class T >
struct is_void ;
(desde C++11)

std::is_void es un UnaryTypeTrait .

Comprueba si T es un tipo void. Proporciona la constante miembro value que es igual a true , si T es el tipo void , const void , volatile void , o const volatile void . De lo contrario, value es igual a false .

Si el programa añade especializaciones para std::is_void o std::is_void_v , el comportamiento es indefinido.

Contenidos

Parámetros de plantilla

T - un tipo a verificar

Plantilla de variable auxiliar

template < class T >
constexpr bool is_void_v = is_void < T > :: value ;
(desde C++17)

Heredado de std:: integral_constant

Constantes miembro

value
[static]
true si T es el tipo void (posiblemente calificado cv), false en caso contrario
(constante miembro pública estática)

Funciones miembro

operator bool
convierte el objeto a bool , devuelve value
(función miembro pública)
operator()
(C++14)
devuelve value
(función miembro pública)

Tipos miembro

Tipo Definición
value_type bool
type std:: integral_constant < bool , value >

Implementación posible

template<class T>
struct is_void : std::is_same<void, typename std::remove_cv<T>::type> {};

Ejemplo

#include <type_traits>
void foo();
static_assert
(
    std::is_void_v<void> == true and
    std::is_void_v<const void> == true and
    std::is_void_v<volatile void> == true and
    std::is_void_v<const volatile void> == true and
    std::is_void_v<std::void_t<>> == true and
    std::is_void_v<void*> == false and
    std::is_void_v<int> == false and
    std::is_void_v<decltype(foo)> == false and
    std::is_void_v<std::is_void<void>> == false
);
int main() {}

Véase también

(C++11)
comprueba si un tipo es un tipo array
(plantilla de clase)
(C++11)
comprueba si un tipo es un tipo puntero
(plantilla de clase)
(C++11)
comprueba si un tipo es un tipo enumeración
(plantilla de clase)
(C++11)
comprueba si un tipo es un tipo unión
(plantilla de clase)
(C++11)
comprueba si un tipo es un tipo clase no unión
(plantilla de clase)
comprueba si un tipo es un tipo función
(plantilla de clase)
(C++11)
comprueba si un tipo es un tipo objeto
(plantilla de clase)