首页
学习
活动
专区
工具
TVP
发布
精选内容/技术社群/优惠产品,尽在小程序
立即前往

std::is_nothrow_destructible

Defined in header <type_traits>

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<T>::value;

(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++标准库中找到的所有析构函数都是不抛出的。

可销毁物品占用的存储器可重复使用而不打电话给破坏者。

二次

代码语言:javascript
复制
#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';
}

二次

产出:

二次

代码语言:javascript
复制
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)

代码语言:txt
复制
 © cppreference.com

在CreativeCommonsAttribution下授权-ShareAlike未移植许可v3.0。

扫码关注腾讯云开发者

领取腾讯云代金券