std:: is_aggregate
| Type traits | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Compile-time rational arithmetic | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Compile-time integer sequences | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
(C++14)
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
定義先ヘッダ
<type_traits>
|
||
|
template
<
class
T
>
struct is_aggregate ; |
(C++17以降) | |
std::is_aggregate
は
UnaryTypeTrait
です。
T
が
集成体型
である場合、メンバ定数
value
を
true
に設定します。それ以外の型の場合、
value
は
false
となります。
T
が配列型または(possibly cv-qualified)
void
以外の不完全型である場合、動作は未定義です。
プログラムが
std::is_aggregate
または
std::is_aggregate_v
に対する特殊化を追加する場合、動作は未定義です。
目次 |
テンプレートパラメータ
| T | - | チェックする型 |
ヘルパー変数テンプレート
|
template
<
class
T
>
constexpr bool is_aggregate_v = is_aggregate < T > :: value ; |
(C++17以降) | |
std:: integral_constant から継承
メンバ定数
|
value
[static]
|
true
(
T
が集成体型の場合)、
false
(それ以外の場合)
(public static member constant) |
メンバ関数
|
operator bool
|
オブジェクトを
bool
に変換し、
value
を返す
(public member function) |
|
operator()
(C++14)
|
value
を返す
(public member function) |
メンバ型
| 型 | 定義 |
value_type
|
bool |
type
|
std:: integral_constant < bool , value > |
注記
| 機能テスト マクロ | 値 | 標準 | 機能 |
|---|---|---|---|
__cpp_lib_is_aggregate
|
201703L
|
(C++17) |
std::is_agregate
|
例
#include <algorithm> #include <cassert> #include <cstddef> #include <new> #include <string_view> #include <type_traits> #include <utility> // 初期化されていないメモリ位置pにTを構築する。 // 集成体の場合はリスト初期化を、それ以外の場合は非リスト初期化を使用する。 template<class T, class... Args> T* construct(T* p, Args&&... args) { if constexpr (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; }; static_assert(std::is_aggregate_v<A>); struct B { int i; std::string_view str; B(int i, std::string_view str) : i(i), str(str) {} }; static_assert(not std::is_aggregate_v<B>); template <typename... Ts> using aligned_storage_t = alignas(Ts...) std::byte[std::max({sizeof(Ts)...})]; int main() { aligned_storage_t<A, B> storage; A& a = *construct(reinterpret_cast<A*>(&storage), 1, 2); assert(a.x == 1 and a.y == 2); B& b = *construct(reinterpret_cast<B*>(&storage), 3, "4"); assert(b.i == 3 and b.str == "4"); }
不具合報告
以下の動作変更の欠陥報告書は、以前に公開されたC++規格に対して遡及的に適用されました。
| DR | 適用対象 | 公開時の動作 | 正しい動作 |
|---|---|---|---|
| LWG 3823 | C++17 |
T
が配列型でありながら
std::remove_all_extents_t<T>
が不完全型の場合、動作は未定義
|
T
が配列型である限り、
std::remove_all_extents_t<T>
の不完全性に関わらず
動作は定義される |