std::is_empty - cppreference.com
提供: cppreference.com
<tbody> </tbody>
|
|
(C++11以上) | |
T が空の型 (つまり、サイズ0のビットフィールド以外の非静的データメンバ、仮想関数、仮想基底クラス、空でない基底クラスを持たない非 union クラス型) であれば、 true に等しいメンバ定数 value が提供されます。 それ以外の型に対しては、 value は false です。
T が非 union クラス型の場合、 T は完全型でなければなりません。 そうでなければ、動作は未定義です。
is_empty または is_empty_v (C++17以上) に対して特殊化を追加するプログラムは未定義です。
テンプレート引数
ヘルパー変数テンプレート
<tbody> </tbody>
|
|
(C++17以上) | |
std::integral_constant から継承
メンバ定数
T が空のクラス型ならば true、そうでなければ false (パブリック静的メンバ定数) |
メンバ関数
オブジェクトを bool に変換します。 value を返します (パブリックメンバ関数) | |
value を返します (パブリックメンバ関数) |
メンバ型
| 型 | 定義 |
value_type
|
bool
|
type
|
std::integral_constant<bool, value>
|
ノート
空の基底クラスからの継承は、通常、空の基底の最適化のため、クラスのサイズを増加させません。
std::is_empty<T> および他のすべての型特性クラスは、空のクラスです。
例
#include <iostream> #include <type_traits> struct A {}; struct B { int m; }; struct C { static int m; }; struct D { virtual ~D(); }; union E {}; struct F { [[no_unique_address]] E e; }; int main() { std::cout << std::boolalpha; std::cout << "A " << std::is_empty<A>::value << '\n'; std::cout << "B " << std::is_empty<B>::value << '\n'; std::cout << "C " << std::is_empty<C>::value << '\n'; std::cout << "D " << std::is_empty<D>::value << '\n'; std::cout << "E " << std::is_empty<E>::value << '\n'; std::cout << "F " << std::is_empty<F>::value << '\n'; // この結果は ABI 依存です。 }
出力例:
A true B false C true D false E false F true