std::is_destructible, std::is_trivially_destructible, std::is_nothrow_destructible
来自cppreference.com
该页由英文版wiki使用Google Translate机器翻译而来。
该翻译可能存在错误或用词不当。鼠标停留在文本上可以看到原版本。你可以帮助我们修正错误或改进翻译。参见说明请点击这里. |
在头文件 <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 起) |
如果一个虚构的结构,其中包含一个成员对象类型
2) T
具有不可删除的析构函数,成员常量value
等于true。对于任何其他类型,value
是false.原文:
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.1),但析构函数不调用任何操作,是不平凡的.
3) 原文:
same as 1), but the destructor does not call any operation that is not trivial.
同为1),但析构函数被noexcept.
原文:
same as 1), but the destructor is noexcept.
目录 |
Inherited from std::integral_constant
Member constants
value [静态的]</div></div>
|
true如果 T is destructible,false其他方式 原文: true if T is destructible, false otherwise (公共静态成员常量) |
Member functions
operator bool |
转换的对象bool,返回 value 原文: converts the object to bool, returns value (公共成员函数) |
Member types
类型
|
Definition |
value_type
|
bool
|
type
|
std::integral_constant<bool, value> |
</div>
[编辑] 注释
因为C + +程序终止,如果一个析构函数时抛出一个异常栈展开(通常无法预测),所有实用的析构函数都是非投掷即使它们不声明noexcept。析构函数在C + +标准库的非投掷的
原文:
Because the C++ program terminates if a destructor throws an exception during stack unwinding (which usually cannot be predicted), all practical destructors are non-throwing even if they are not declared noexcept. All destructors found in the C++ standard library are non-throwing.
[编辑] 示例
#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) |
检查对象是否声明了虚析构函数 (类模板) |