std::is_nothrow_destructible
STD::是[医]可销毁的,STD::[医]琐碎[医]可销毁的,STD::[医]无抛[医]可毁
Defined in header | | |
---|---|---|
template< class T > struct is_destructible; | (1) | (since C++11) |
template< class T > struct is_trivially_destructible; | (2) | (since C++11) |
template< class T > struct is_nothrow_destructible; | (3) | (since C++11) |
1) If an imaginary struct containing a member object of type T has a non-deleted destructor, provides the member constant value equal true. For any other type, value is false. | (until C++14) |
---|---|
1) If T is a reference type, provides the member constant value equal true. If T is an incomplete type (including void) or a function type, value equals false. If T is an object type, then, for the type U equal std::remove_all_extents<T>::type, if the expression std::declval<U&>().~U() is well-formed in unevaluated context, value equals true. Otherwise, value equals false. | (since C++14) |
2%29与1%29相同,但析构函数不调用任何不平凡的操作。
3%29和1%29相同,但破坏者除外。
T
为完整类型,%28可能是cv-合格%29void
,或者一系列未知的界限。否则,行为就没有定义。
辅助变量模板
template< class T > inline constexpr bool is_destructible_v = is_destructible | | (since C++17) |
---|---|---|
template< class T > inline constexpr bool is_trivially_destructible_v = is_trivially_destructible<T>::value; | | (since C++17) |
template< class T > inline constexpr bool is_nothrow_destructible_v = is_nothrow_destructible<T>::value; | | (since C++17) |
继承自STD:积分[医]常量
成员常数
value static | true if T is destructible, false otherwise (public static member constant) |
---|
成员函数
operator bool | converts the object to bool, returns value (public member function) |
---|---|
operator() (C++14) | returns value (public member function) |
成员类型
Type | Definition |
---|---|
value_type | bool |
type | std::integral_constant<bool, value> |
注记
由于C++程序在堆栈展开过程中抛出异常(通常无法预测为%29),则所有实际的析构函数都不会抛出,即使它们没有声明为no。在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
二次
另见
is_constructibleis_trivially_constructibleis_nothrow_constructible (C++11)(C++11)(C++11) | checks if a type has a constructor for specific arguments (class template) |
---|---|
has_virtual_destructor (C++11) | checks if a type has a virtual destructor (class template) |
© cppreference.com
在CreativeCommonsAttribution下授权-ShareAlike未移植许可v3.0。