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
定義先ヘッダ <type_traits>
template < class T >
struct is_void ;
(C++11以降)

std::is_void UnaryTypeTrait です。

T がvoid型かどうかをチェックします。メンバー定数 value を提供します。この値は、 T が型 void const void volatile void または const volatile void の場合 true に等しくなります。それ以外の場合、 value false に等しくなります。

プログラムが std::is_void または std::is_void_v に対する特殊化を追加する場合、動作は未定義です。

目次

テンプレートパラメータ

T - チェックする型

ヘルパー変数テンプレート

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

std:: integral_constant から継承

メンバ定数

value
[static]
true T が型 void の場合(CV修飾可能性あり))、 false それ以外の場合
(公開静的メンバ定数)

メンバ関数

operator bool
オブジェクトを bool に変換し、 value を返す
(公開メンバ関数)
operator()
(C++14)
value を返す
(公開メンバ関数)

メンバ型

定義
value_type bool
type std:: integral_constant < bool , value >

実装例

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

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

関連項目

(C++11)
型が配列型かどうかをチェックする
(クラステンプレート)
(C++11)
型がポインタ型かどうかをチェックする
(クラステンプレート)
(C++11)
型が列挙型かどうかをチェックする
(クラステンプレート)
(C++11)
型が共用体型かどうかをチェックする
(クラステンプレート)
(C++11)
型が非共用体クラス型かどうかをチェックする
(クラステンプレート)
型が関数型かどうかをチェックする
(クラステンプレート)
(C++11)
型がオブジェクト型かどうかをチェックする
(クラステンプレート)