std::is_destructible, std::is_trivially_destructible, std::is_nothrow_destructible
Min standard notice:
Header: <type_traits>
- If T is a reference type, provides the member constant value equal to true.
# Declarations
template< class T >
struct is_destructible;
(since C++11)
template< class T >
struct is_trivially_destructible;
(since C++11)
template< class T >
struct is_nothrow_destructible;
(since C++11)
# Notes
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.
Storage occupied by trivially destructible objects may be reused without calling the destructor.
# Example
#include <iostream>
#include <string>
#include <type_traits>
struct Foo
{
std::string str;
~Foo() noexcept {};
};
struct Bar
{
~Bar() = default;
};
static_assert(std::is_destructible<std::string>::value == true);
static_assert(std::is_trivially_destructible_v<Foo> == false);
static_assert(std::is_nothrow_destructible<Foo>() == true);
static_assert(std::is_trivially_destructible<Bar>{} == true);
int main() {}
# Defect reports
| DR | Applied to | Behavior as published | Correct behavior |
|---|---|---|---|
| LWG 2049 | C++11 | the specification was incompletable because of the imaginary wrapping struct | made complete |