std::is_aggregate
提供: cppreference.com
ヘッダ <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_type | bool |
type | std::integral_constant<bool, value> |
[編集]例
Run this code
#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");}