名前空間
変種
操作

std::is_aggregate

提供: cppreference.com
< cpp‎ | types
 
 
ユーティリティライブラリ
汎用ユーティリティ
日付と時間
関数オブジェクト
書式化ライブラリ(C++20)
(C++11)
関係演算子 (C++20で非推奨)
整数比較関数
(C++20)
スワップと型操作
(C++14)
(C++11)
(C++11)
(C++11)
(C++17)
一般的な語彙の型
(C++11)
(C++17)
(C++17)
(C++17)
(C++17)

初等文字列変換
(C++17)
(C++17)
 
型サポート
型の性質
(C++11)
(C++11)
(C++14)
is_aggregate
(C++17)
(C++11)
(C++11)(C++20未満)
(C++11)(C++20で非推奨)
(C++11)
型特性定数
メタ関数
(C++17)
定数評価文脈
サポートされている操作
関係と性質の問い合わせ
型変更
型変換
(C++11)
(C++11)
(C++17)
(C++11)(C++20未満)(C++17)
 
ヘッダ <type_traits> で定義
template<class T >
struct is_aggregate;
(C++17以上)

T集成体型かどうか調べます。 T が集成体型であれば true、そうでなければ false に等しいメンバ定数 value が提供されます。

std::remove_all_extents_t<T> が不完全型であり、 void (または cv 修飾された void) でない場合、動作は未定義です。

is_aggregate または is_aggregate_v に対して特殊化を追加するプログラムは未定義です。

目次

[編集]テンプレート引数

T - 調べる型

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

template<class T >
inlineconstexprbool is_aggregate_v = is_aggregate<T>::value;
(C++17以上)

std::integral_constant から継承

メンバ定数

value
[静的]
T が集成体型ならば true、そうでなければ false
(パブリック静的メンバ定数)

メンバ関数

operator bool
オブジェクトを bool に変換します。 value を返します
(パブリックメンバ関数)
operator()
(C++14)
value を返します
(パブリックメンバ関数)

メンバ型

定義
value_typebool
typestd::integral_constant<bool, value>

[編集]

#include <type_traits>#include <new>#include <utility>   // constructs a T at the uninitialized memory pointed to by p// using list-initialization for aggregates and non-list initialization otherwisetemplate<class T, class... Args> T* construct(T* p, Args&&... args){ifconstexpr(std::is_aggregate_v<T>){return::new(static_cast<void*>(p)) T{std::forward<Args>(args)...};}else{return::new(static_cast<void*>(p)) T(std::forward<Args>(args)...);}}   struct A {int x, y;};struct B { B(int, constchar*){}};   int main(){std::aligned_union_t<1, A, B> storage; A* a = construct(reinterpret_cast<A*>(&storage), 1, 2); B* b = construct(reinterpret_cast<B*>(&storage), 1, "hello");}


close