名前空間
変種
操作

std::is_compound

From cppreference.com
< cpp‎ | types
 
 
メタプログラミングライブラリ
型特性
型のカテゴリ
(C++11)
(C++11)(DR*)
(C++11)
(C++11)
(C++11)
(C++11)
(C++11)
(C++11) 
(C++11)
(C++11)
is_compound
(C++11)
型のプロパティ
(C++11)
(C++11)
(C++14)
(C++11)(C++26で非推奨)
(C++11)(C++20まで*)
(C++11)(C++20で非推奨)
(C++11)
型特性定数
メタ関数
(C++17)
サポートされている操作
関係とプロパティクエリ
型の変更
(C++11)(C++11)(C++11)
型の変換
(C++11)(C++23で非推奨)
(C++11)(C++23で非推奨)
(C++11)
(C++11)(C++20まで*)(C++17)

(C++11)
(C++17)
コンパイル時有理数演算
コンパイル時整数シーケンス
 
ヘッダ <type_traits> で定義
template< class T >
struct is_compound;
(C++11以降)

std::is_compoundUnaryTypeTrait です。

T が複合型(つまり、配列、関数、オブジェクトポインタ、関数ポインタ、メンバオブジェクトポインタ、メンバ関数ポインタ、参照、クラス、共用体、または列挙型(あらゆるcv修飾バリアントを含む))である場合、メンバ定数 valuetrue となります。それ以外の型の場合、valuefalse となります。

プログラムが std::is_compound または std::is_compound_v の特殊化を追加した場合、動作は未定義です。

目次

[編集] テンプレートパラメータ

T - チェックする型

[編集] ヘルパー変数テンプレート

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

std::integral_constant から継承

メンバ定数

value
[static]
T が複合型であれば true、そうでなければ false
(公開静的メンバ定数)

メンバ関数

operator bool
オブジェクトを bool に変換し、value を返します。
(public member function)
operator()
(C++14)
value を返します。
(public member function)

メンバ型

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

[編集] 備考

複合型は、基本型から構築される型です。C++ の型は、基本型か複合型のいずれかです。

[編集] 実装例

template<class T>
struct is_compound : std::integral_constant<bool, !std::is_fundamental<T>::value> {};

[編集]

#include <type_traits>
#include <iostream>
 
static_assert(not std::is_compound_v<int>);
static_assert(std::is_compound_v<int*>);
static_assert(std::is_compound_v<int&>);
 
void f();
static_assert(std::is_compound_v<decltype(f)>);
static_assert(std::is_compound_v<decltype(&f)>);
 
static_assert(std::is_compound_v<char[100]>);
 
class C {};
static_assert(std::is_compound_v<C>);
 
union U {};
static_assert(std::is_compound_v<U>);
 
enum struct E { e };
static_assert(std::is_compound_v<E>);
static_assert(std::is_compound_v<decltype(E::e)>);
 
struct S
{
    int i : 8;
    int j;
    void foo();
};
static_assert(not std::is_compound_v<decltype(S::i)>);
static_assert(not std::is_compound_v<decltype(S::j)>);
static_assert(std::is_compound_v<decltype(&S::j)>);
static_assert(std::is_compound_v<decltype(&S::foo)>);
 
int main()
{
    std::cout << "All checks have passed\n";
}

[編集] 関連項目

型が基本型であるかをチェックする
(クラステンプレート) [編集]
(C++11)
型がスカラ型であるかをチェックする
(クラステンプレート) [編集]
(C++11)
型がオブジェクト型であるかをチェックする
(クラステンプレート) [編集]
(C++11)
型が配列型であるかをチェックする
(クラステンプレート) [編集]
English 日本語 中文(简体) 中文(繁體)