std::is_destructible, std::is_trivially_destructible, std::is_nothrow_destructible
ヘッダ <type_traits> で定義
|
||
template< class T > struct is_destructible; |
(1) | (C++11以上) |
template< class T > struct is_trivially_destructible; |
(2) | (C++11以上) |
template< class T > struct is_nothrow_destructible; |
(3) | (C++11以上) |
1) T 型のメンバオブジェクトを持つ架空の構造体が削除されていないデストラクタを持つ場合、 true に等しいメンバ定数 value が提供されます。 それ以外の型に対しては、 value は false です。 |
(C++14未満) |
1)
|
(C++14以上) |
2) 1) と同じですが、さらに std::remove_all_extents<T>::type が非クラス型またはトリビアルなデストラクタを持つクラス型です。
3) 1) と同じですが、デストラクタは noexcept です。
T
は完全型 (またはその cv 修飾された型)、 void、またはサイズの未知な配列でなければなりません。 そうでなければ、動作は未定義です。
上記のテンプレートの実体化が直接または間接的に不完全型に依存しており、もしその型が仮に完全型であったならばその実体化が異なる結果を産むであろう場合は、動作は未定義です。
目次 |
[編集] ヘルパー変数テンプレート
template< class T > inline constexpr bool is_destructible_v = is_destructible<T>::value; |
(C++17以上) | |
template< class T > inline constexpr bool is_trivially_destructible_v = is_trivially_destructible<T>::value; |
(C++17以上) | |
template< class T > inline constexpr bool is_nothrow_destructible_v = is_nothrow_destructible<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> |
[編集] ノート
スタックの巻き戻し中 (通常は予測できない) にデストラクタから例外が投げられると、 C++ のプログラムは終了してしまうため、すべての実用的なデストラクタは、 noexcept と宣言されていなくても、例外を投げません。 C++ 標準ライブラリ内のすべてのデストラクタは、例外を投げません。
トリビアルに破棄可能なオブジェクトによって占められている記憶域は、デストラクタを呼ぶことなく再利用できます。
[編集] 例
#include <iostream> #include <string> #include <type_traits> struct Foo { std::string str; ~Foo() noexcept {}; }; struct Bar { ~Bar() = default; }; int main() { std::cout << std::boolalpha << "std::string is destructible? " << std::is_destructible<std::string>::value << '\n' << "Foo is nothrow destructible? " << std::is_nothrow_destructible<Foo>::value << '\n' << "Bar is trivally destructible? " << std::is_trivially_destructible<Bar>::value << '\n'; }
出力:
std::string is destructible? true Foo is nothrow destructible? true Bar is trivally destructible? true
[編集] 関連項目
(C++11)(C++11)(C++11) |
型が特定の引数に対するコンストラクタを持っているかどうか調べます (クラステンプレート) |
(C++11) |
型が仮想デストラクタを持っているかどうか調べます (クラステンプレート) |